1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
10 CommunityModeratorView,
25 } from "lemmy-js-client";
26 import { getExternalHost, getHttpBase } from "../../env";
27 import { i18n } from "../../i18next";
28 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
29 import { UserService } from "../../services";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { CommunityLink } from "../community/community-link";
59 import { PersonListing } from "../person/person-listing";
60 import { MetadataCard } from "./metadata-card";
61 import { PostForm } from "./post-form";
63 interface PostListingState {
65 showRemoveDialog: boolean;
66 showPurgeDialog: boolean;
68 purgeType?: PurgeType;
69 purgeLoading: boolean;
70 removeReason?: string;
71 showBanDialog: boolean;
73 banExpireDays?: number;
76 showConfirmTransferSite: boolean;
77 showConfirmTransferCommunity: boolean;
78 imageExpanded: boolean;
80 showAdvanced: boolean;
81 showMoreMobile: boolean;
83 showReportDialog: boolean;
84 reportReason?: string;
85 upvoteLoading: boolean;
86 downvoteLoading: boolean;
87 reportLoading: boolean;
88 blockLoading: boolean;
90 deleteLoading: boolean;
91 removeLoading: boolean;
93 featureCommunityLoading: boolean;
94 featureLocalLoading: boolean;
96 addModLoading: boolean;
97 addAdminLoading: boolean;
98 transferLoading: boolean;
101 interface PostListingProps {
103 crossPosts?: PostView[];
104 moderators?: CommunityModeratorView[];
105 admins?: PersonView[];
106 allLanguages: Language[];
107 siteLanguages: number[];
108 showCommunity?: boolean;
111 enableDownvotes?: boolean;
112 enableNsfw?: boolean;
114 onPostEdit(form: EditPost): void;
115 onPostVote(form: CreatePostLike): void;
116 onPostReport(form: CreatePostReport): void;
117 onBlockPerson(form: BlockPerson): void;
118 onLockPost(form: LockPost): void;
119 onDeletePost(form: DeletePost): void;
120 onRemovePost(form: RemovePost): void;
121 onSavePost(form: SavePost): void;
122 onFeaturePost(form: FeaturePost): void;
123 onPurgePerson(form: PurgePerson): void;
124 onPurgePost(form: PurgePost): void;
125 onBanPersonFromCommunity(form: BanFromCommunity): void;
126 onBanPerson(form: BanPerson): void;
127 onAddModToCommunity(form: AddModToCommunity): void;
128 onAddAdmin(form: AddAdmin): void;
129 onTransferCommunity(form: TransferCommunity): void;
132 export class PostListing extends Component<PostListingProps, PostListingState> {
133 state: PostListingState = {
135 showRemoveDialog: false,
136 showPurgeDialog: false,
137 purgeType: PurgeType.Person,
138 showBanDialog: false,
139 banType: BanType.Community,
141 showConfirmTransferSite: false,
142 showConfirmTransferCommunity: false,
143 imageExpanded: false,
146 showMoreMobile: false,
148 showReportDialog: false,
149 upvoteLoading: false,
150 downvoteLoading: false,
152 reportLoading: false,
155 deleteLoading: false,
156 removeLoading: false,
158 featureCommunityLoading: false,
159 featureLocalLoading: false,
161 addModLoading: false,
162 addAdminLoading: false,
163 transferLoading: false,
166 constructor(props: any, context: any) {
167 super(props, context);
169 this.handleEditPost = this.handleEditPost.bind(this);
170 this.handleEditCancel = this.handleEditCancel.bind(this);
173 componentWillReceiveProps(nextProps: PostListingProps) {
174 if (this.props !== nextProps) {
176 upvoteLoading: false,
177 downvoteLoading: false,
179 reportLoading: false,
182 deleteLoading: false,
183 removeLoading: false,
185 featureCommunityLoading: false,
186 featureLocalLoading: false,
188 addModLoading: false,
189 addAdminLoading: false,
190 transferLoading: false,
191 imageExpanded: false,
196 get postView(): PostView {
197 return this.props.post_view;
201 const post = this.postView.post;
204 <div className="post-listing mt-2">
205 {!this.state.showEdit ? (
208 {this.state.imageExpanded && !this.props.hideImage && this.img}
209 {post.url && this.state.showBody && post.embed_title && (
210 <MetadataCard post={post} />
212 {this.showBody && this.body()}
216 post_view={this.postView}
217 crossPosts={this.props.crossPosts}
218 onEdit={this.handleEditPost}
219 onCancel={this.handleEditCancel}
220 enableNsfw={this.props.enableNsfw}
221 enableDownvotes={this.props.enableDownvotes}
222 allLanguages={this.props.allLanguages}
223 siteLanguages={this.props.siteLanguages}
231 const body = this.postView.post.body;
233 <article id="postContent" className="col-12 card my-2 p-2">
234 {this.state.viewSource ? (
237 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
246 return this.imageSrc ? (
248 <div className="offset-sm-3 my-2 d-none d-sm-block">
249 <a href={this.imageSrc} className="d-inline-block">
250 <PictrsImage src={this.imageSrc} />
253 <div className="my-2 d-block d-sm-none">
255 className="d-inline-block"
256 onClick={linkEvent(this, this.handleImageExpandClick)}
258 <PictrsImage src={this.imageSrc} />
267 imgThumb(src: string) {
268 const post_view = this.postView;
274 nsfw={post_view.post.nsfw || post_view.community.nsfw}
279 get imageSrc(): string | undefined {
280 const post = this.postView.post;
281 const url = post.url;
282 const thumbnail = post.thumbnail_url;
284 if (url && isImage(url)) {
285 if (url.includes("pictrs")) {
287 } else if (thumbnail) {
292 } else if (thumbnail) {
300 const post = this.postView.post;
301 const url = post.url;
302 const thumbnail = post.thumbnail_url;
304 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
308 className="text-body d-inline-block position-relative mb-2"
309 data-tippy-content={i18n.t("expand_here")}
310 onClick={linkEvent(this, this.handleImageExpandClick)}
311 aria-label={i18n.t("expand_here")}
313 {this.imgThumb(this.imageSrc)}
314 <Icon icon="image" classes="mini-overlay" />
317 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
320 className="text-body d-inline-block position-relative mb-2"
325 {this.imgThumb(this.imageSrc)}
326 <Icon icon="external-link" classes="mini-overlay" />
330 if (!this.props.hideImage && isVideo(url)) {
332 <div className="embed-responsive embed-responsive-16by9">
338 className="embed-responsive-item"
340 <source src={url} type="video/mp4" />
346 <a className="text-body" href={url} title={url} rel={relTags}>
347 <div className="thumbnail rounded bg-light d-flex justify-content-center">
348 <Icon icon="external-link" classes="d-flex align-items-center" />
356 className="text-body"
357 to={`/post/${post.id}`}
358 title={i18n.t("comments")}
360 <div className="thumbnail rounded bg-light d-flex justify-content-center">
361 <Icon icon="message-square" classes="d-flex align-items-center" />
369 const post_view = this.postView;
371 <ul className="list-inline mb-1 text-muted small mt-2">
372 <li className="list-inline-item">
373 <PersonListing person={post_view.creator} />
375 {this.creatorIsMod_ && (
376 <span className="mx-1 badge text-bg-light">{i18n.t("mod")}</span>
378 {this.creatorIsAdmin_ && (
379 <span className="mx-1 badge text-bg-light">{i18n.t("admin")}</span>
381 {post_view.creator.bot_account && (
382 <span className="mx-1 badge text-bg-light">
383 {i18n.t("bot_account").toLowerCase()}
386 {this.props.showCommunity && (
389 {i18n.t("to")} <CommunityLink community={post_view.community} />
393 {post_view.post.language_id !== 0 && (
394 <span className="mx-1 badge text-bg-light">
396 this.props.allLanguages.find(
397 lang => lang.id === post_view.post.language_id
402 <li className="list-inline-item">•</li>
403 <li className="list-inline-item">
406 published={post_view.post.published}
407 updated={post_view.post.updated}
417 <div className={`vote-bar col-1 pe-0 small text-center`}>
419 className={`btn-animate btn btn-link p-0 ${
420 this.postView.my_vote == 1 ? "text-info" : "text-muted"
422 onClick={linkEvent(this, this.handleUpvote)}
423 data-tippy-content={i18n.t("upvote")}
424 aria-label={i18n.t("upvote")}
425 aria-pressed={this.postView.my_vote === 1}
427 {this.state.upvoteLoading ? (
430 <Icon icon="arrow-up1" classes="upvote" />
435 className={`unselectable pointer text-muted px-1 post-score`}
436 data-tippy-content={this.pointsTippy}
438 {numToSI(this.postView.counts.score)}
441 <div className="p-1"></div>
443 {this.props.enableDownvotes && (
445 className={`btn-animate btn btn-link p-0 ${
446 this.postView.my_vote == -1 ? "text-danger" : "text-muted"
448 onClick={linkEvent(this, this.handleDownvote)}
449 data-tippy-content={i18n.t("downvote")}
450 aria-label={i18n.t("downvote")}
451 aria-pressed={this.postView.my_vote === -1}
453 {this.state.downvoteLoading ? (
456 <Icon icon="arrow-down1" classes="downvote" />
465 const post = this.postView.post;
468 className={`d-inline ${
469 !post.featured_community && !post.featured_local
473 to={`/post/${post.id}`}
474 title={i18n.t("comments")}
478 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
485 const post = this.postView.post;
486 const url = post.url;
490 <div className="post-title overflow-hidden">
491 <h5 className="d-inline">
492 {url && this.props.showBody ? (
495 !post.featured_community && !post.featured_local
502 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
508 {(url && isImage(url)) ||
509 (post.thumbnail_url && (
511 className="btn btn-sm text-monospace text-muted d-inline-block"
512 data-tippy-content={i18n.t("expand_here")}
513 onClick={linkEvent(this, this.handleImageExpandClick)}
517 !this.state.imageExpanded ? "plus-square" : "minus-square"
519 classes="icon-inline"
524 <small className="ms-2 badge text-bg-secondary">
530 className="unselectable pointer ms-2 text-muted font-italic"
531 data-tippy-content={i18n.t("deleted")}
533 <Icon icon="trash" classes="icon-inline text-danger" />
538 className="unselectable pointer ms-2 text-muted font-italic"
539 data-tippy-content={i18n.t("locked")}
541 <Icon icon="lock" classes="icon-inline text-danger" />
544 {post.featured_community && (
546 className="unselectable pointer ms-2 text-muted font-italic"
547 data-tippy-content={i18n.t("featured_in_community")}
548 aria-label={i18n.t("featured_in_community")}
550 <Icon icon="pin" classes="icon-inline text-primary" />
553 {post.featured_local && (
555 className="unselectable pointer ms-2 text-muted font-italic"
556 data-tippy-content={i18n.t("featured_in_local")}
557 aria-label={i18n.t("featured_in_local")}
559 <Icon icon="pin" classes="icon-inline text-secondary" />
563 <small className="ms-2 badge text-bg-danger">
568 {url && this.urlLine()}
574 const post = this.postView.post;
575 const url = post.url;
578 <p className="d-flex text-muted align-items-center gap-1 small m-0">
579 {url && !(hostname(url) === getExternalHost()) && (
581 className="text-muted font-italic"
594 const dupes = this.props.crossPosts;
595 return dupes && dupes.length > 0 ? (
596 <ul className="list-inline mb-1 small text-muted">
598 <li className="list-inline-item me-2">{i18n.t("cross_posted_to")}</li>
600 <li key={pv.post.id} className="list-inline-item me-2">
601 <Link to={`/post/${pv.post.id}`}>
604 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
615 commentsLine(mobile = false) {
616 const post = this.postView.post;
619 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
620 {this.commentsButton}
623 className="btn btn-sm btn-animate text-muted py-0"
624 onClick={linkEvent(this, this.handleShare)}
627 <Icon icon="share" inline />
632 className="btn btn-sm btn-animate text-muted py-0"
633 title={i18n.t("link")}
636 <Icon icon="fedilink" inline />
639 {mobile && !this.props.viewOnly && this.mobileVotes}
640 {UserService.Instance.myUserInfo &&
641 !this.props.viewOnly &&
647 showPreviewButton() {
648 const post_view = this.postView;
649 const body = post_view.post.body;
653 className="btn btn-sm btn-animate text-muted py-0"
654 data-tippy-content={body && mdNoImages.render(body)}
655 data-tippy-allowHtml={true}
656 onClick={linkEvent(this, this.handleShowBody)}
660 classes={classNames("icon-inline me-1", {
661 "text-success": this.state.showBody,
669 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
670 // Possible enhancement: Make each button a component.
671 const post_view = this.postView;
672 const post = post_view.post;
677 {this.crossPostButton}
680 * If there is a URL, or if the post has a body and we were told not to
681 * show the body, show the MetadataCard/body toggle.
683 {(post.url || (post.body && !this.props.showBody)) &&
684 this.showPreviewButton()}
686 {this.showBody && post_view.post.body && this.viewSourceButton}
688 <div className="dropdown">
690 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
691 onClick={linkEvent(this, this.handleShowAdvanced)}
692 data-tippy-content={i18n.t("more")}
693 data-bs-toggle="dropdown"
694 aria-expanded="false"
695 aria-controls="advancedButtonsDropdown"
696 aria-label={i18n.t("more")}
698 <Icon icon="more-vertical" inline />
701 <ul className="dropdown-menu" id="advancedButtonsDropdown">
704 <li>{this.reportButton}</li>
705 <li>{this.blockButton}</li>
709 <li>{this.editButton}</li>
710 <li>{this.deleteButton}</li>
714 {/* Any mod can do these, not limited to hierarchy*/}
715 {(amMod(this.props.moderators) || amAdmin()) && (
718 <hr className="dropdown-divider" />
720 <li>{this.lockButton}</li>
721 {this.featureButtons}
725 {(this.canMod_ || this.canAdmin_) && (
726 <li>{this.modRemoveButton}</li>
734 get commentsButton() {
735 const post_view = this.postView;
738 className="btn btn-link text-muted ps-0 text-muted"
739 title={i18n.t("number_of_comments", {
740 count: Number(post_view.counts.comments),
741 formattedCount: Number(post_view.counts.comments),
743 to={`/post/${post_view.post.id}?scrollToComments=true`}
745 <Icon icon="message-square" classes="me-1" inline />
746 <span className="me-2">
747 {i18n.t("number_of_comments", {
748 count: Number(post_view.counts.comments),
749 formattedCount: numToSI(post_view.counts.comments),
752 {this.unreadCount && (
753 <span className="small text-warning">
754 ({this.unreadCount} {i18n.t("new")})
761 get unreadCount(): number | undefined {
762 const pv = this.postView;
763 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
765 : pv.unread_comments;
770 const tippy = showScores()
771 ? { "data-tippy-content": this.pointsTippy }
777 className={`btn-animate btn py-0 px-1 ${
778 this.postView.my_vote === 1 ? "text-info" : "text-muted"
781 onClick={linkEvent(this, this.handleUpvote)}
782 aria-label={i18n.t("upvote")}
783 aria-pressed={this.postView.my_vote === 1}
785 {this.state.upvoteLoading ? (
789 <Icon icon="arrow-up1" classes="icon-inline small" />
791 <span className="ms-2">
792 {numToSI(this.postView.counts.upvotes)}
798 {this.props.enableDownvotes && (
800 className={`ms-2 btn-animate btn py-0 px-1 ${
801 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
803 onClick={linkEvent(this, this.handleDownvote)}
805 aria-label={i18n.t("downvote")}
806 aria-pressed={this.postView.my_vote === -1}
808 {this.state.downvoteLoading ? (
812 <Icon icon="arrow-down1" classes="icon-inline small" />
815 className={classNames("ms-2", {
816 invisible: this.postView.counts.downvotes === 0,
819 {numToSI(this.postView.counts.downvotes)}
832 const saved = this.postView.saved;
833 const label = saved ? i18n.t("unsave") : i18n.t("save");
836 className="btn btn-sm btn-animate text-muted py-0"
837 onClick={linkEvent(this, this.handleSavePostClick)}
838 data-tippy-content={label}
841 {this.state.saveLoading ? (
846 classes={classNames({ "text-warning": saved })}
854 get crossPostButton() {
857 className="btn btn-sm btn-animate text-muted py-0"
859 /* Empty string properties are required to satisfy type*/
860 pathname: "/create_post",
861 state: { ...this.crossPostParams },
866 title={i18n.t("cross_post")}
867 data-tippy-content={i18n.t("cross_post")}
868 aria-label={i18n.t("cross_post")}
870 <Icon icon="copy" inline />
878 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
879 onClick={linkEvent(this, this.handleShowReportDialog)}
880 aria-label={i18n.t("show_report_dialog")}
882 <Icon classes="me-1" icon="flag" inline />
883 {i18n.t("create_report")}
891 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
892 onClick={linkEvent(this, this.handleBlockPersonClick)}
893 aria-label={i18n.t("block_user")}
895 {this.state.blockLoading ? (
898 <Icon classes="me-1" icon="slash" inline />
900 {i18n.t("block_user")}
908 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
909 onClick={linkEvent(this, this.handleEditClick)}
910 aria-label={i18n.t("edit")}
912 <Icon classes="me-1" icon="edit" inline />
919 const deleted = this.postView.post.deleted;
920 const label = !deleted ? i18n.t("delete") : i18n.t("restore");
923 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
924 onClick={linkEvent(this, this.handleDeleteClick)}
927 {this.state.deleteLoading ? (
933 classes={classNames("me-1", { "text-danger": deleted })}
943 get viewSourceButton() {
946 className="btn btn-sm btn-animate text-muted py-0"
947 onClick={linkEvent(this, this.handleViewSource)}
948 data-tippy-content={i18n.t("view_source")}
949 aria-label={i18n.t("view_source")}
953 classes={classNames({ "text-success": this.state.viewSource })}
961 const locked = this.postView.post.locked;
962 const label = locked ? i18n.t("unlock") : i18n.t("lock");
965 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
966 onClick={linkEvent(this, this.handleModLock)}
969 {this.state.lockLoading ? (
975 classes={classNames("me-1", { "text-danger": locked })}
985 get featureButtons() {
986 const featuredCommunity = this.postView.post.featured_community;
987 const labelCommunity = featuredCommunity
988 ? i18n.t("unfeature_from_community")
989 : i18n.t("feature_in_community");
991 const featuredLocal = this.postView.post.featured_local;
992 const labelLocal = featuredLocal
993 ? i18n.t("unfeature_from_local")
994 : i18n.t("feature_in_local");
999 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1000 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
1001 data-tippy-content={labelCommunity}
1002 aria-label={labelCommunity}
1004 {this.state.featureCommunityLoading ? (
1010 classes={classNames("me-1", {
1011 "text-success": featuredCommunity,
1015 {i18n.t("community")}
1023 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1024 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1025 data-tippy-content={labelLocal}
1026 aria-label={labelLocal}
1028 {this.state.featureLocalLoading ? (
1034 classes={classNames("me-1", {
1035 "text-success": featuredLocal,
1049 get modRemoveButton() {
1050 const removed = this.postView.post.removed;
1053 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1056 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1059 {/* TODO: Find an icon for this. */}
1060 {this.state.removeLoading ? (
1072 * Mod/Admin actions to be taken against the author.
1076 const post_view = this.postView;
1078 this.state.showAdvanced && (
1082 {!this.creatorIsMod_ &&
1083 (!post_view.creator_banned_from_community ? (
1085 className="btn btn-link btn-animate text-muted py-0"
1088 this.handleModBanFromCommunityShow
1090 aria-label={i18n.t("ban_from_community")}
1092 {i18n.t("ban_from_community")}
1096 className="btn btn-link btn-animate text-muted py-0"
1099 this.handleModBanFromCommunitySubmit
1101 aria-label={i18n.t("unban")}
1103 {this.state.banLoading ? <Spinner /> : i18n.t("unban")}
1106 {!post_view.creator_banned_from_community && (
1108 className="btn btn-link btn-animate text-muted py-0"
1109 onClick={linkEvent(this, this.handleAddModToCommunity)}
1112 ? i18n.t("remove_as_mod")
1113 : i18n.t("appoint_as_mod")
1116 {this.state.addModLoading ? (
1118 ) : this.creatorIsMod_ ? (
1119 i18n.t("remove_as_mod")
1121 i18n.t("appoint_as_mod")
1127 {/* Community creators and admins can transfer community to another mod */}
1128 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1130 this.creatorIsMod_ &&
1131 (!this.state.showConfirmTransferCommunity ? (
1133 className="btn btn-link btn-animate text-muted py-0"
1136 this.handleShowConfirmTransferCommunity
1138 aria-label={i18n.t("transfer_community")}
1140 {i18n.t("transfer_community")}
1145 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1146 aria-label={i18n.t("are_you_sure")}
1148 {i18n.t("are_you_sure")}
1151 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1152 aria-label={i18n.t("yes")}
1153 onClick={linkEvent(this, this.handleTransferCommunity)}
1155 {this.state.transferLoading ? <Spinner /> : i18n.t("yes")}
1158 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1161 this.handleCancelShowConfirmTransferCommunity
1163 aria-label={i18n.t("no")}
1169 {/* Admins can ban from all, and appoint other admins */}
1170 {this.canAdmin_ && (
1172 {!this.creatorIsAdmin_ && (
1174 {!isBanned(post_view.creator) ? (
1176 className="btn btn-link btn-animate text-muted py-0"
1177 onClick={linkEvent(this, this.handleModBanShow)}
1178 aria-label={i18n.t("ban_from_site")}
1180 {i18n.t("ban_from_site")}
1184 className="btn btn-link btn-animate text-muted py-0"
1185 onClick={linkEvent(this, this.handleModBanSubmit)}
1186 aria-label={i18n.t("unban_from_site")}
1188 {this.state.banLoading ? (
1191 i18n.t("unban_from_site")
1196 className="btn btn-link btn-animate text-muted py-0"
1197 onClick={linkEvent(this, this.handlePurgePersonShow)}
1198 aria-label={i18n.t("purge_user")}
1200 {i18n.t("purge_user")}
1203 className="btn btn-link btn-animate text-muted py-0"
1204 onClick={linkEvent(this, this.handlePurgePostShow)}
1205 aria-label={i18n.t("purge_post")}
1207 {i18n.t("purge_post")}
1211 {!isBanned(post_view.creator) && post_view.creator.local && (
1213 className="btn btn-link btn-animate text-muted py-0"
1214 onClick={linkEvent(this, this.handleAddAdmin)}
1216 this.creatorIsAdmin_
1217 ? i18n.t("remove_as_admin")
1218 : i18n.t("appoint_as_admin")
1221 {this.state.addAdminLoading ? (
1223 ) : this.creatorIsAdmin_ ? (
1224 i18n.t("remove_as_admin")
1226 i18n.t("appoint_as_admin")
1237 removeAndBanDialogs() {
1238 const post = this.postView;
1239 const purgeTypeText =
1240 this.state.purgeType == PurgeType.Post
1241 ? i18n.t("purge_post")
1242 : `${i18n.t("purge")} ${post.creator.name}`;
1245 {this.state.showRemoveDialog && (
1247 className="form-inline"
1248 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1251 className="visually-hidden"
1252 htmlFor="post-listing-remove-reason"
1258 id="post-listing-remove-reason"
1259 className="form-control me-2"
1260 placeholder={i18n.t("reason")}
1261 value={this.state.removeReason}
1262 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1266 className="btn btn-secondary"
1267 aria-label={i18n.t("remove_post")}
1269 {this.state.removeLoading ? <Spinner /> : i18n.t("remove_post")}
1273 {this.state.showBanDialog && (
1274 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1275 <div className="mb-3 row col-12">
1277 className="col-form-label"
1278 htmlFor="post-listing-ban-reason"
1284 id="post-listing-ban-reason"
1285 className="form-control me-2"
1286 placeholder={i18n.t("reason")}
1287 value={this.state.banReason}
1288 onInput={linkEvent(this, this.handleModBanReasonChange)}
1290 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1295 id={`mod-ban-expires`}
1296 className="form-control me-2"
1297 placeholder={i18n.t("number_of_days")}
1298 value={this.state.banExpireDays}
1299 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1301 <div className="input-group mb-3">
1302 <div className="form-check">
1304 className="form-check-input"
1305 id="mod-ban-remove-data"
1307 checked={this.state.removeData}
1308 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1311 className="form-check-label"
1312 htmlFor="mod-ban-remove-data"
1313 title={i18n.t("remove_content_more")}
1315 {i18n.t("remove_content")}
1320 {/* TODO hold off on expires until later */}
1321 {/* <div class="mb-3 row"> */}
1322 {/* <label class="col-form-label">Expires</label> */}
1323 {/* <input type="date" class="form-control me-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1325 <div className="mb-3 row">
1328 className="btn btn-secondary"
1329 aria-label={i18n.t("ban")}
1331 {this.state.banLoading ? (
1335 {i18n.t("ban")} {post.creator.name}
1342 {this.state.showReportDialog && (
1344 className="form-inline"
1345 onSubmit={linkEvent(this, this.handleReportSubmit)}
1347 <label className="visually-hidden" htmlFor="post-report-reason">
1352 id="post-report-reason"
1353 className="form-control me-2"
1354 placeholder={i18n.t("reason")}
1356 value={this.state.reportReason}
1357 onInput={linkEvent(this, this.handleReportReasonChange)}
1361 className="btn btn-secondary"
1362 aria-label={i18n.t("create_report")}
1364 {this.state.reportLoading ? <Spinner /> : i18n.t("create_report")}
1368 {this.state.showPurgeDialog && (
1370 className="form-inline"
1371 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1374 <label className="visually-hidden" htmlFor="purge-reason">
1380 className="form-control me-2"
1381 placeholder={i18n.t("reason")}
1382 value={this.state.purgeReason}
1383 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1385 {this.state.purgeLoading ? (
1390 className="btn btn-secondary"
1391 aria-label={purgeTypeText}
1393 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1403 const post = this.postView.post;
1404 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1405 <div className="row">
1406 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1407 {this.postTitleLine()}
1409 <div className="col-4">
1410 {/* Post body prev or thumbnail */}
1411 {!this.state.imageExpanded && this.thumbnail()}
1415 this.postTitleLine()
1419 showMobilePreview() {
1420 const { body, id } = this.postView.post;
1422 return !this.showBody && body ? (
1423 <Link className="text-body" to={`/post/${id}`}>
1424 <div className="md-div mb-1 preview-lines">{body}</div>
1434 {/* The mobile view*/}
1435 <div className="d-block d-sm-none">
1436 <article className="row post-container">
1437 <div className="col-12">
1438 {this.createdLine()}
1440 {/* If it has a thumbnail, do a right aligned thumbnail */}
1441 {this.mobileThumbnail()}
1443 {/* Show a preview of the post body */}
1444 {this.showMobilePreview()}
1446 {this.commentsLine(true)}
1447 {this.userActionsLine()}
1448 {this.duplicatesLine()}
1449 {this.removeAndBanDialogs()}
1454 {/* The larger view*/}
1455 <div className="d-none d-sm-block">
1456 <article className="row post-container">
1457 {!this.props.viewOnly && this.voteBar()}
1458 <div className="col-sm-2 pe-0 post-media">
1459 <div className="">{this.thumbnail()}</div>
1461 <div className="col-12 col-sm-9">
1462 <div className="row">
1463 <div className="col-12">
1464 {this.postTitleLine()}
1465 {this.createdLine()}
1466 {this.commentsLine()}
1467 {this.duplicatesLine()}
1468 {this.userActionsLine()}
1469 {this.removeAndBanDialogs()}
1479 private get myPost(): boolean {
1481 this.postView.creator.id ==
1482 UserService.Instance.myUserInfo?.local_user_view.person.id
1485 handleEditClick(i: PostListing) {
1486 i.setState({ showEdit: true });
1489 handleEditCancel() {
1490 this.setState({ showEdit: false });
1493 // The actual editing is done in the receive for post
1494 handleEditPost(form: EditPost) {
1495 this.setState({ showEdit: false });
1496 this.props.onPostEdit(form);
1499 handleShare(i: PostListing) {
1500 const { name, body, id } = i.props.post_view.post;
1503 text: body?.slice(0, 50),
1504 url: `${getHttpBase()}/post/${id}`,
1508 handleShowReportDialog(i: PostListing) {
1509 i.setState({ showReportDialog: !i.state.showReportDialog });
1512 handleReportReasonChange(i: PostListing, event: any) {
1513 i.setState({ reportReason: event.target.value });
1516 handleReportSubmit(i: PostListing, event: any) {
1517 event.preventDefault();
1518 i.setState({ reportLoading: true });
1519 i.props.onPostReport({
1520 post_id: i.postView.post.id,
1521 reason: i.state.reportReason ?? "",
1522 auth: myAuthRequired(),
1526 handleBlockPersonClick(i: PostListing) {
1527 i.setState({ blockLoading: true });
1528 i.props.onBlockPerson({
1529 person_id: i.postView.creator.id,
1531 auth: myAuthRequired(),
1535 handleDeleteClick(i: PostListing) {
1536 i.setState({ deleteLoading: true });
1537 i.props.onDeletePost({
1538 post_id: i.postView.post.id,
1539 deleted: !i.postView.post.deleted,
1540 auth: myAuthRequired(),
1544 handleSavePostClick(i: PostListing) {
1545 i.setState({ saveLoading: true });
1546 i.props.onSavePost({
1547 post_id: i.postView.post.id,
1548 save: !i.postView.saved,
1549 auth: myAuthRequired(),
1553 get crossPostParams(): PostFormParams {
1554 const queryParams: PostFormParams = {};
1555 const { name, url } = this.postView.post;
1557 queryParams.name = name;
1560 queryParams.url = url;
1563 const crossPostBody = this.crossPostBody();
1564 if (crossPostBody) {
1565 queryParams.body = crossPostBody;
1571 crossPostBody(): string | undefined {
1572 const post = this.postView.post;
1573 const body = post.body;
1576 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1583 get showBody(): boolean {
1584 return this.props.showBody || this.state.showBody;
1587 handleModRemoveShow(i: PostListing) {
1589 showRemoveDialog: !i.state.showRemoveDialog,
1590 showBanDialog: false,
1594 handleModRemoveReasonChange(i: PostListing, event: any) {
1595 i.setState({ removeReason: event.target.value });
1598 handleModRemoveDataChange(i: PostListing, event: any) {
1599 i.setState({ removeData: event.target.checked });
1602 handleModRemoveSubmit(i: PostListing, event: any) {
1603 event.preventDefault();
1604 i.setState({ removeLoading: true });
1605 i.props.onRemovePost({
1606 post_id: i.postView.post.id,
1607 removed: !i.postView.post.removed,
1608 auth: myAuthRequired(),
1612 handleModLock(i: PostListing) {
1613 i.setState({ lockLoading: true });
1614 i.props.onLockPost({
1615 post_id: i.postView.post.id,
1616 locked: !i.postView.post.locked,
1617 auth: myAuthRequired(),
1621 handleModFeaturePostLocal(i: PostListing) {
1622 i.setState({ featureLocalLoading: true });
1623 i.props.onFeaturePost({
1624 post_id: i.postView.post.id,
1625 featured: !i.postView.post.featured_local,
1626 feature_type: "Local",
1627 auth: myAuthRequired(),
1631 handleModFeaturePostCommunity(i: PostListing) {
1632 i.setState({ featureCommunityLoading: true });
1633 i.props.onFeaturePost({
1634 post_id: i.postView.post.id,
1635 featured: !i.postView.post.featured_community,
1636 feature_type: "Community",
1637 auth: myAuthRequired(),
1641 handleModBanFromCommunityShow(i: PostListing) {
1643 showBanDialog: true,
1644 banType: BanType.Community,
1645 showRemoveDialog: false,
1649 handleModBanShow(i: PostListing) {
1651 showBanDialog: true,
1652 banType: BanType.Site,
1653 showRemoveDialog: false,
1657 handlePurgePersonShow(i: PostListing) {
1659 showPurgeDialog: true,
1660 purgeType: PurgeType.Person,
1661 showRemoveDialog: false,
1665 handlePurgePostShow(i: PostListing) {
1667 showPurgeDialog: true,
1668 purgeType: PurgeType.Post,
1669 showRemoveDialog: false,
1673 handlePurgeReasonChange(i: PostListing, event: any) {
1674 i.setState({ purgeReason: event.target.value });
1677 handlePurgeSubmit(i: PostListing, event: any) {
1678 event.preventDefault();
1679 i.setState({ purgeLoading: true });
1680 if (i.state.purgeType == PurgeType.Person) {
1681 i.props.onPurgePerson({
1682 person_id: i.postView.creator.id,
1683 reason: i.state.purgeReason,
1684 auth: myAuthRequired(),
1686 } else if (i.state.purgeType == PurgeType.Post) {
1687 i.props.onPurgePost({
1688 post_id: i.postView.post.id,
1689 reason: i.state.purgeReason,
1690 auth: myAuthRequired(),
1695 handleModBanReasonChange(i: PostListing, event: any) {
1696 i.setState({ banReason: event.target.value });
1699 handleModBanExpireDaysChange(i: PostListing, event: any) {
1700 i.setState({ banExpireDays: event.target.value });
1703 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1704 i.setState({ banType: BanType.Community });
1705 i.handleModBanBothSubmit(i, event);
1708 handleModBanSubmit(i: PostListing, event: any) {
1709 i.setState({ banType: BanType.Site });
1710 i.handleModBanBothSubmit(i, event);
1713 handleModBanBothSubmit(i: PostListing, event: any) {
1714 event.preventDefault();
1715 i.setState({ banLoading: true });
1717 const ban = !i.props.post_view.creator_banned_from_community;
1718 // If its an unban, restore all their data
1720 i.setState({ removeData: false });
1722 const person_id = i.props.post_view.creator.id;
1723 const remove_data = i.state.removeData;
1724 const reason = i.state.banReason;
1725 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1727 if (i.state.banType == BanType.Community) {
1728 const community_id = i.postView.community.id;
1729 i.props.onBanPersonFromCommunity({
1736 auth: myAuthRequired(),
1739 i.props.onBanPerson({
1745 auth: myAuthRequired(),
1750 handleAddModToCommunity(i: PostListing) {
1751 i.setState({ addModLoading: true });
1752 i.props.onAddModToCommunity({
1753 community_id: i.postView.community.id,
1754 person_id: i.postView.creator.id,
1755 added: !i.creatorIsMod_,
1756 auth: myAuthRequired(),
1760 handleAddAdmin(i: PostListing) {
1761 i.setState({ addAdminLoading: true });
1762 i.props.onAddAdmin({
1763 person_id: i.postView.creator.id,
1764 added: !i.creatorIsAdmin_,
1765 auth: myAuthRequired(),
1769 handleShowConfirmTransferCommunity(i: PostListing) {
1770 i.setState({ showConfirmTransferCommunity: true });
1773 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1774 i.setState({ showConfirmTransferCommunity: false });
1777 handleTransferCommunity(i: PostListing) {
1778 i.setState({ transferLoading: true });
1779 i.props.onTransferCommunity({
1780 community_id: i.postView.community.id,
1781 person_id: i.postView.creator.id,
1782 auth: myAuthRequired(),
1786 handleShowConfirmTransferSite(i: PostListing) {
1787 i.setState({ showConfirmTransferSite: true });
1790 handleCancelShowConfirmTransferSite(i: PostListing) {
1791 i.setState({ showConfirmTransferSite: false });
1794 handleImageExpandClick(i: PostListing, event: any) {
1795 event.preventDefault();
1796 i.setState({ imageExpanded: !i.state.imageExpanded });
1800 handleViewSource(i: PostListing) {
1801 i.setState({ viewSource: !i.state.viewSource });
1804 handleShowAdvanced(i: PostListing) {
1805 i.setState({ showAdvanced: !i.state.showAdvanced });
1809 handleShowMoreMobile(i: PostListing) {
1811 showMoreMobile: !i.state.showMoreMobile,
1812 showAdvanced: !i.state.showAdvanced,
1817 handleShowBody(i: PostListing) {
1818 i.setState({ showBody: !i.state.showBody });
1822 handleUpvote(i: PostListing) {
1823 i.setState({ upvoteLoading: true });
1824 i.props.onPostVote({
1825 post_id: i.postView.post.id,
1826 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1827 auth: myAuthRequired(),
1831 handleDownvote(i: PostListing) {
1832 i.setState({ downvoteLoading: true });
1833 i.props.onPostVote({
1834 post_id: i.postView.post.id,
1835 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1836 auth: myAuthRequired(),
1840 get pointsTippy(): string {
1841 const points = i18n.t("number_of_points", {
1842 count: Number(this.postView.counts.score),
1843 formattedCount: Number(this.postView.counts.score),
1846 const upvotes = i18n.t("number_of_upvotes", {
1847 count: Number(this.postView.counts.upvotes),
1848 formattedCount: Number(this.postView.counts.upvotes),
1851 const downvotes = i18n.t("number_of_downvotes", {
1852 count: Number(this.postView.counts.downvotes),
1853 formattedCount: Number(this.postView.counts.downvotes),
1856 return `${points} • ${upvotes} • ${downvotes}`;
1859 get canModOnSelf_(): boolean {
1861 this.postView.creator.id,
1862 this.props.moderators,
1869 get canMod_(): boolean {
1871 this.postView.creator.id,
1872 this.props.moderators,
1877 get canAdmin_(): boolean {
1878 return canAdmin(this.postView.creator.id, this.props.admins);
1881 get creatorIsMod_(): boolean {
1882 return isMod(this.postView.creator.id, this.props.moderators);
1885 get creatorIsAdmin_(): boolean {
1886 return isAdmin(this.postView.creator.id, this.props.admins);