1 import { myAuthRequired } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
51 } from "../../interfaces";
52 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
53 import { I18NextService, UserService } from "../../services";
54 import { setupTippy } from "../../tippy";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
59 import { CommunityLink } from "../community/community-link";
60 import { PersonListing } from "../person/person-listing";
61 import { MetadataCard } from "./metadata-card";
62 import { PostForm } from "./post-form";
64 interface PostListingState {
66 showRemoveDialog: boolean;
67 showPurgeDialog: boolean;
69 purgeType?: PurgeType;
70 purgeLoading: boolean;
71 removeReason?: string;
72 showBanDialog: boolean;
74 banExpireDays?: number;
77 showConfirmTransferSite: boolean;
78 showConfirmTransferCommunity: boolean;
79 imageExpanded: boolean;
81 showAdvanced: boolean;
82 showMoreMobile: boolean;
84 showReportDialog: boolean;
85 reportReason?: string;
86 reportLoading: boolean;
87 blockLoading: boolean;
89 deleteLoading: boolean;
90 removeLoading: boolean;
92 featureCommunityLoading: boolean;
93 featureLocalLoading: boolean;
95 addModLoading: boolean;
96 addAdminLoading: boolean;
97 transferLoading: boolean;
100 interface PostListingProps {
102 crossPosts?: PostView[];
103 moderators?: CommunityModeratorView[];
104 admins?: PersonView[];
105 allLanguages: Language[];
106 siteLanguages: number[];
107 showCommunity?: boolean;
110 enableDownvotes?: boolean;
111 enableNsfw?: boolean;
113 onPostEdit(form: EditPost): void;
114 onPostVote(form: CreatePostLike): void;
115 onPostReport(form: CreatePostReport): void;
116 onBlockPerson(form: BlockPerson): void;
117 onLockPost(form: LockPost): void;
118 onDeletePost(form: DeletePost): void;
119 onRemovePost(form: RemovePost): void;
120 onSavePost(form: SavePost): void;
121 onFeaturePost(form: FeaturePost): void;
122 onPurgePerson(form: PurgePerson): void;
123 onPurgePost(form: PurgePost): void;
124 onBanPersonFromCommunity(form: BanFromCommunity): void;
125 onBanPerson(form: BanPerson): void;
126 onAddModToCommunity(form: AddModToCommunity): void;
127 onAddAdmin(form: AddAdmin): void;
128 onTransferCommunity(form: TransferCommunity): void;
131 export class PostListing extends Component<PostListingProps, PostListingState> {
132 state: PostListingState = {
134 showRemoveDialog: false,
135 showPurgeDialog: false,
136 purgeType: PurgeType.Person,
137 showBanDialog: false,
138 banType: BanType.Community,
140 showConfirmTransferSite: false,
141 showConfirmTransferCommunity: false,
142 imageExpanded: false,
145 showMoreMobile: false,
147 showReportDialog: false,
149 reportLoading: false,
152 deleteLoading: false,
153 removeLoading: false,
155 featureCommunityLoading: false,
156 featureLocalLoading: false,
158 addModLoading: false,
159 addAdminLoading: false,
160 transferLoading: false,
163 constructor(props: any, context: any) {
164 super(props, context);
166 this.handleEditPost = this.handleEditPost.bind(this);
167 this.handleEditCancel = this.handleEditCancel.bind(this);
170 componentWillReceiveProps(nextProps: PostListingProps) {
171 if (this.props !== nextProps) {
174 reportLoading: false,
177 deleteLoading: false,
178 removeLoading: false,
180 featureCommunityLoading: false,
181 featureLocalLoading: false,
183 addModLoading: false,
184 addAdminLoading: false,
185 transferLoading: false,
186 imageExpanded: false,
191 get postView(): PostView {
192 return this.props.post_view;
196 const post = this.postView.post;
199 <div className="post-listing mt-2">
200 {!this.state.showEdit ? (
203 {this.state.imageExpanded && !this.props.hideImage && this.img}
204 {post.url && this.state.showBody && post.embed_title && (
205 <MetadataCard post={post} />
207 {this.showBody && this.body()}
211 post_view={this.postView}
212 crossPosts={this.props.crossPosts}
213 onEdit={this.handleEditPost}
214 onCancel={this.handleEditCancel}
215 enableNsfw={this.props.enableNsfw}
216 enableDownvotes={this.props.enableDownvotes}
217 allLanguages={this.props.allLanguages}
218 siteLanguages={this.props.siteLanguages}
226 const body = this.postView.post.body;
228 <article id="postContent" className="col-12 card my-2 p-2">
229 {this.state.viewSource ? (
232 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
244 <div className="offset-sm-3 my-2 d-none d-sm-block">
245 <a href={this.imageSrc} className="d-inline-block">
246 <PictrsImage src={this.imageSrc} />
249 <div className="my-2 d-block d-sm-none">
251 className="d-inline-block"
252 onClick={linkEvent(this, this.handleImageExpandClick)}
254 <PictrsImage src={this.imageSrc} />
261 const { post } = this.postView;
262 const { url } = post;
264 if (url && isVideo(url)) {
266 <div className="embed-responsive mt-3">
267 <video muted controls className="embed-responsive-item col-12">
268 <source src={url} type="video/mp4" />
277 imgThumb(src: string) {
278 const post_view = this.postView;
284 nsfw={post_view.post.nsfw || post_view.community.nsfw}
289 get imageSrc(): string | undefined {
290 const post = this.postView.post;
291 const url = post.url;
292 const thumbnail = post.thumbnail_url;
294 if (url && isImage(url)) {
295 if (url.includes("pictrs")) {
297 } else if (thumbnail) {
302 } else if (thumbnail) {
310 const post = this.postView.post;
311 const url = post.url;
312 const thumbnail = post.thumbnail_url;
314 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
318 className="text-body d-inline-block position-relative mb-2"
319 data-tippy-content={I18NextService.i18n.t("expand_here")}
320 onClick={linkEvent(this, this.handleImageExpandClick)}
321 aria-label={I18NextService.i18n.t("expand_here")}
323 {this.imgThumb(this.imageSrc)}
324 <Icon icon="image" classes="mini-overlay" />
327 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
330 className="text-body d-inline-block position-relative mb-2"
335 {this.imgThumb(this.imageSrc)}
336 <Icon icon="external-link" classes="mini-overlay" />
340 if (!this.props.hideImage && isVideo(url)) {
343 className="text-body"
347 data-tippy-content={I18NextService.i18n.t("expand_here")}
348 onClick={linkEvent(this, this.handleImageExpandClick)}
349 aria-label={I18NextService.i18n.t("expand_here")}
351 <div className="thumbnail rounded bg-light d-flex justify-content-center">
352 <Icon icon="play" classes="d-flex align-items-center" />
358 <a className="text-body" href={url} title={url} rel={relTags}>
359 <div className="thumbnail rounded bg-light d-flex justify-content-center">
360 <Icon icon="external-link" classes="d-flex align-items-center" />
368 className="text-body"
369 to={`/post/${post.id}`}
370 title={I18NextService.i18n.t("comments")}
372 <div className="thumbnail rounded bg-light d-flex justify-content-center">
373 <Icon icon="message-square" classes="d-flex align-items-center" />
381 const post_view = this.postView;
383 <span className="small">
384 <PersonListing person={post_view.creator} />
385 {this.creatorIsMod_ && (
386 <span className="mx-1 badge text-bg-light">
387 {I18NextService.i18n.t("mod")}
390 {this.creatorIsAdmin_ && (
391 <span className="mx-1 badge text-bg-light">
392 {I18NextService.i18n.t("admin")}
395 {post_view.creator.bot_account && (
396 <span className="mx-1 badge text-bg-light">
397 {I18NextService.i18n.t("bot_account").toLowerCase()}
400 {this.props.showCommunity && (
403 {I18NextService.i18n.t("to")}{" "}
404 <CommunityLink community={post_view.community} />
407 {post_view.post.language_id !== 0 && (
408 <span className="mx-1 badge text-bg-light">
410 this.props.allLanguages.find(
411 lang => lang.id === post_view.post.language_id
418 published={post_view.post.published}
419 updated={post_view.post.updated}
426 const post = this.postView.post;
429 className={`d-inline ${
430 !post.featured_community && !post.featured_local
434 to={`/post/${post.id}`}
435 title={I18NextService.i18n.t("comments")}
439 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
446 const post = this.postView.post;
447 const url = post.url;
451 <div className="post-title overflow-hidden">
452 <h5 className="d-inline">
453 {url && this.props.showBody ? (
456 !post.featured_community && !post.featured_local
463 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
469 {(url && isImage(url)) ||
470 (post.thumbnail_url && (
472 className="btn btn-sm text-monospace text-muted d-inline-block"
473 data-tippy-content={I18NextService.i18n.t("expand_here")}
474 onClick={linkEvent(this, this.handleImageExpandClick)}
478 !this.state.imageExpanded ? "plus-square" : "minus-square"
480 classes="icon-inline"
485 <small className="ms-2 badge text-bg-secondary">
486 {I18NextService.i18n.t("removed")}
491 className="unselectable pointer ms-2 text-muted font-italic"
492 data-tippy-content={I18NextService.i18n.t("deleted")}
494 <Icon icon="trash" classes="icon-inline text-danger" />
499 className="unselectable pointer ms-2 text-muted font-italic"
500 data-tippy-content={I18NextService.i18n.t("locked")}
502 <Icon icon="lock" classes="icon-inline text-danger" />
505 {post.featured_community && (
507 className="unselectable pointer ms-2 text-muted font-italic"
508 data-tippy-content={I18NextService.i18n.t(
509 "featured_in_community"
511 aria-label={I18NextService.i18n.t("featured_in_community")}
513 <Icon icon="pin" classes="icon-inline text-primary" />
516 {post.featured_local && (
518 className="unselectable pointer ms-2 text-muted font-italic"
519 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
520 aria-label={I18NextService.i18n.t("featured_in_local")}
522 <Icon icon="pin" classes="icon-inline text-secondary" />
526 <small className="ms-2 badge text-bg-danger">
527 {I18NextService.i18n.t("nsfw")}
531 {url && this.urlLine()}
537 const post = this.postView.post;
538 const url = post.url;
541 <p className="d-flex text-muted align-items-center gap-1 small m-0">
542 {url && !(hostname(url) === getExternalHost()) && (
544 className="text-muted font-italic"
557 const dupes = this.props.crossPosts;
558 return dupes && dupes.length > 0 ? (
559 <ul className="list-inline mb-1 small text-muted">
561 <li className="list-inline-item me-2">
562 {I18NextService.i18n.t("cross_posted_to")}
565 <li key={pv.post.id} className="list-inline-item me-2">
566 <Link to={`/post/${pv.post.id}`}>
569 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
580 commentsLine(mobile = false) {
581 const post = this.postView.post;
584 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
585 {this.commentsButton}
588 className="btn btn-sm btn-animate text-muted py-0"
589 onClick={linkEvent(this, this.handleShare)}
592 <Icon icon="share" inline />
597 className="btn btn-sm btn-animate text-muted py-0"
598 title={I18NextService.i18n.t("link")}
601 <Icon icon="fedilink" inline />
604 {mobile && !this.props.viewOnly && (
606 voteContentType={VoteContentType.Post}
607 id={this.postView.post.id}
608 onVote={this.props.onPostVote}
609 enableDownvotes={this.props.enableDownvotes}
610 counts={this.postView.counts}
611 my_vote={this.postView.my_vote}
614 {UserService.Instance.myUserInfo &&
615 !this.props.viewOnly &&
621 showPreviewButton() {
622 const post_view = this.postView;
623 const body = post_view.post.body;
627 className="btn btn-sm btn-animate text-muted py-0"
628 data-tippy-content={body && mdNoImages.render(body)}
629 data-tippy-allowHtml={true}
630 onClick={linkEvent(this, this.handleShowBody)}
634 classes={classNames("icon-inline me-1", {
635 "text-success": this.state.showBody,
643 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
644 // Possible enhancement: Make each button a component.
645 const post_view = this.postView;
646 const post = post_view.post;
651 {this.crossPostButton}
654 * If there is a URL, or if the post has a body and we were told not to
655 * show the body, show the MetadataCard/body toggle.
657 {(post.url || (post.body && !this.props.showBody)) &&
658 this.showPreviewButton()}
660 {this.showBody && post_view.post.body && this.viewSourceButton}
662 <div className="dropdown">
664 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
665 onClick={linkEvent(this, this.handleShowAdvanced)}
666 data-tippy-content={I18NextService.i18n.t("more")}
667 data-bs-toggle="dropdown"
668 aria-expanded="false"
669 aria-controls="advancedButtonsDropdown"
670 aria-label={I18NextService.i18n.t("more")}
672 <Icon icon="more-vertical" inline />
675 <ul className="dropdown-menu" id="advancedButtonsDropdown">
678 <li>{this.reportButton}</li>
679 <li>{this.blockButton}</li>
683 <li>{this.editButton}</li>
684 <li>{this.deleteButton}</li>
688 {/* Any mod can do these, not limited to hierarchy*/}
689 {(amMod(this.props.moderators) || amAdmin()) && (
692 <hr className="dropdown-divider" />
694 <li>{this.lockButton}</li>
695 {this.featureButtons}
699 {(this.canMod_ || this.canAdmin_) && (
700 <li>{this.modRemoveButton}</li>
708 get commentsButton() {
709 const post_view = this.postView;
710 const title = I18NextService.i18n.t("number_of_comments", {
711 count: Number(post_view.counts.comments),
712 formattedCount: Number(post_view.counts.comments),
717 className="btn btn-link btn-sm text-muted ps-0"
719 to={`/post/${post_view.post.id}?scrollToComments=true`}
720 data-tippy-content={title}
722 <Icon icon="message-square" classes="me-1" inline />
723 {post_view.counts.comments}
724 {this.unreadCount && (
725 <span className="text-muted fst-italic">
726 ({this.unreadCount} {I18NextService.i18n.t("new")})
733 get unreadCount(): number | undefined {
734 const pv = this.postView;
735 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
737 : pv.unread_comments;
741 const saved = this.postView.saved;
743 ? I18NextService.i18n.t("unsave")
744 : I18NextService.i18n.t("save");
747 className="btn btn-sm btn-animate text-muted py-0"
748 onClick={linkEvent(this, this.handleSavePostClick)}
749 data-tippy-content={label}
752 {this.state.saveLoading ? (
757 classes={classNames({ "text-warning": saved })}
765 get crossPostButton() {
768 className="btn btn-sm btn-animate text-muted py-0"
770 /* Empty string properties are required to satisfy type*/
771 pathname: "/create_post",
772 state: { ...this.crossPostParams },
777 title={I18NextService.i18n.t("cross_post")}
778 data-tippy-content={I18NextService.i18n.t("cross_post")}
779 aria-label={I18NextService.i18n.t("cross_post")}
781 <Icon icon="copy" inline />
789 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
790 onClick={linkEvent(this, this.handleShowReportDialog)}
791 aria-label={I18NextService.i18n.t("show_report_dialog")}
793 <Icon classes="me-1" icon="flag" inline />
794 {I18NextService.i18n.t("create_report")}
802 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
803 onClick={linkEvent(this, this.handleBlockPersonClick)}
804 aria-label={I18NextService.i18n.t("block_user")}
806 {this.state.blockLoading ? (
809 <Icon classes="me-1" icon="slash" inline />
811 {I18NextService.i18n.t("block_user")}
819 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
820 onClick={linkEvent(this, this.handleEditClick)}
821 aria-label={I18NextService.i18n.t("edit")}
823 <Icon classes="me-1" icon="edit" inline />
824 {I18NextService.i18n.t("edit")}
830 const deleted = this.postView.post.deleted;
831 const label = !deleted
832 ? I18NextService.i18n.t("delete")
833 : I18NextService.i18n.t("restore");
836 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
837 onClick={linkEvent(this, this.handleDeleteClick)}
839 {this.state.deleteLoading ? (
845 classes={classNames("me-1", { "text-danger": deleted })}
855 get viewSourceButton() {
858 className="btn btn-sm btn-animate text-muted py-0"
859 onClick={linkEvent(this, this.handleViewSource)}
860 data-tippy-content={I18NextService.i18n.t("view_source")}
861 aria-label={I18NextService.i18n.t("view_source")}
865 classes={classNames({ "text-success": this.state.viewSource })}
873 const locked = this.postView.post.locked;
875 ? I18NextService.i18n.t("unlock")
876 : I18NextService.i18n.t("lock");
879 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
880 onClick={linkEvent(this, this.handleModLock)}
883 {this.state.lockLoading ? (
889 classes={classNames("me-1", { "text-danger": locked })}
892 {capitalizeFirstLetter(label)}
899 get featureButtons() {
900 const featuredCommunity = this.postView.post.featured_community;
901 const labelCommunity = featuredCommunity
902 ? I18NextService.i18n.t("unfeature_from_community")
903 : I18NextService.i18n.t("feature_in_community");
905 const featuredLocal = this.postView.post.featured_local;
906 const labelLocal = featuredLocal
907 ? I18NextService.i18n.t("unfeature_from_local")
908 : I18NextService.i18n.t("feature_in_local");
913 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
914 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
915 data-tippy-content={labelCommunity}
916 aria-label={labelCommunity}
918 {this.state.featureCommunityLoading ? (
924 classes={classNames("me-1", {
925 "text-success": featuredCommunity,
929 {I18NextService.i18n.t("community")}
937 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
938 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
939 data-tippy-content={labelLocal}
940 aria-label={labelLocal}
942 {this.state.featureLocalLoading ? (
948 classes={classNames("me-1", {
949 "text-success": featuredLocal,
953 {I18NextService.i18n.t("local")}
963 get modRemoveButton() {
964 const removed = this.postView.post.removed;
967 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
970 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
973 {/* TODO: Find an icon for this. */}
974 {this.state.removeLoading ? (
977 I18NextService.i18n.t("remove")
979 I18NextService.i18n.t("restore")
986 * Mod/Admin actions to be taken against the author.
990 const post_view = this.postView;
992 this.state.showAdvanced && (
993 <div className="mt-3">
996 {!this.creatorIsMod_ &&
997 (!post_view.creator_banned_from_community ? (
999 className="btn btn-link btn-animate text-muted py-0"
1002 this.handleModBanFromCommunityShow
1004 aria-label={I18NextService.i18n.t("ban_from_community")}
1006 {I18NextService.i18n.t("ban_from_community")}
1010 className="btn btn-link btn-animate text-muted py-0"
1013 this.handleModBanFromCommunitySubmit
1015 aria-label={I18NextService.i18n.t("unban")}
1017 {this.state.banLoading ? (
1020 I18NextService.i18n.t("unban")
1024 {!post_view.creator_banned_from_community && (
1026 className="btn btn-link btn-animate text-muted py-0"
1027 onClick={linkEvent(this, this.handleAddModToCommunity)}
1030 ? I18NextService.i18n.t("remove_as_mod")
1031 : I18NextService.i18n.t("appoint_as_mod")
1034 {this.state.addModLoading ? (
1036 ) : this.creatorIsMod_ ? (
1037 I18NextService.i18n.t("remove_as_mod")
1039 I18NextService.i18n.t("appoint_as_mod")
1045 {/* Community creators and admins can transfer community to another mod */}
1046 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1048 this.creatorIsMod_ &&
1049 (!this.state.showConfirmTransferCommunity ? (
1051 className="btn btn-link btn-animate text-muted py-0"
1054 this.handleShowConfirmTransferCommunity
1056 aria-label={I18NextService.i18n.t("transfer_community")}
1058 {I18NextService.i18n.t("transfer_community")}
1063 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1064 aria-label={I18NextService.i18n.t("are_you_sure")}
1066 {I18NextService.i18n.t("are_you_sure")}
1069 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1070 aria-label={I18NextService.i18n.t("yes")}
1071 onClick={linkEvent(this, this.handleTransferCommunity)}
1073 {this.state.transferLoading ? (
1076 I18NextService.i18n.t("yes")
1080 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1083 this.handleCancelShowConfirmTransferCommunity
1085 aria-label={I18NextService.i18n.t("no")}
1087 {I18NextService.i18n.t("no")}
1091 {/* Admins can ban from all, and appoint other admins */}
1092 {this.canAdmin_ && (
1094 {!this.creatorIsAdmin_ && (
1096 {!isBanned(post_view.creator) ? (
1098 className="btn btn-link btn-animate text-muted py-0"
1099 onClick={linkEvent(this, this.handleModBanShow)}
1100 aria-label={I18NextService.i18n.t("ban_from_site")}
1102 {I18NextService.i18n.t("ban_from_site")}
1106 className="btn btn-link btn-animate text-muted py-0"
1107 onClick={linkEvent(this, this.handleModBanSubmit)}
1108 aria-label={I18NextService.i18n.t("unban_from_site")}
1110 {this.state.banLoading ? (
1113 I18NextService.i18n.t("unban_from_site")
1118 className="btn btn-link btn-animate text-muted py-0"
1119 onClick={linkEvent(this, this.handlePurgePersonShow)}
1120 aria-label={I18NextService.i18n.t("purge_user")}
1122 {I18NextService.i18n.t("purge_user")}
1125 className="btn btn-link btn-animate text-muted py-0"
1126 onClick={linkEvent(this, this.handlePurgePostShow)}
1127 aria-label={I18NextService.i18n.t("purge_post")}
1129 {I18NextService.i18n.t("purge_post")}
1133 {!isBanned(post_view.creator) && post_view.creator.local && (
1135 className="btn btn-link btn-animate text-muted py-0"
1136 onClick={linkEvent(this, this.handleAddAdmin)}
1138 this.creatorIsAdmin_
1139 ? I18NextService.i18n.t("remove_as_admin")
1140 : I18NextService.i18n.t("appoint_as_admin")
1143 {this.state.addAdminLoading ? (
1145 ) : this.creatorIsAdmin_ ? (
1146 I18NextService.i18n.t("remove_as_admin")
1148 I18NextService.i18n.t("appoint_as_admin")
1159 removeAndBanDialogs() {
1160 const post = this.postView;
1161 const purgeTypeText =
1162 this.state.purgeType == PurgeType.Post
1163 ? I18NextService.i18n.t("purge_post")
1164 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1167 {this.state.showRemoveDialog && (
1169 className="form-inline"
1170 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1173 className="visually-hidden"
1174 htmlFor="post-listing-remove-reason"
1176 {I18NextService.i18n.t("reason")}
1180 id="post-listing-remove-reason"
1181 className="form-control me-2"
1182 placeholder={I18NextService.i18n.t("reason")}
1183 value={this.state.removeReason}
1184 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1188 className="btn btn-secondary"
1189 aria-label={I18NextService.i18n.t("remove_post")}
1191 {this.state.removeLoading ? (
1194 I18NextService.i18n.t("remove_post")
1199 {this.state.showBanDialog && (
1200 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1201 <div className="mb-3 row col-12">
1203 className="col-form-label"
1204 htmlFor="post-listing-ban-reason"
1206 {I18NextService.i18n.t("reason")}
1210 id="post-listing-ban-reason"
1211 className="form-control me-2"
1212 placeholder={I18NextService.i18n.t("reason")}
1213 value={this.state.banReason}
1214 onInput={linkEvent(this, this.handleModBanReasonChange)}
1216 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1217 {I18NextService.i18n.t("expires")}
1221 id={`mod-ban-expires`}
1222 className="form-control me-2"
1223 placeholder={I18NextService.i18n.t("number_of_days")}
1224 value={this.state.banExpireDays}
1225 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1227 <div className="input-group mb-3">
1228 <div className="form-check">
1230 className="form-check-input"
1231 id="mod-ban-remove-data"
1233 checked={this.state.removeData}
1234 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1237 className="form-check-label"
1238 htmlFor="mod-ban-remove-data"
1239 title={I18NextService.i18n.t("remove_content_more")}
1241 {I18NextService.i18n.t("remove_content")}
1246 {/* TODO hold off on expires until later */}
1247 {/* <div class="mb-3 row"> */}
1248 {/* <label class="col-form-label">Expires</label> */}
1249 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1251 <div className="mb-3 row">
1254 className="btn btn-secondary"
1255 aria-label={I18NextService.i18n.t("ban")}
1257 {this.state.banLoading ? (
1261 {I18NextService.i18n.t("ban")} {post.creator.name}
1268 {this.state.showReportDialog && (
1270 className="form-inline"
1271 onSubmit={linkEvent(this, this.handleReportSubmit)}
1273 <label className="visually-hidden" htmlFor="post-report-reason">
1274 {I18NextService.i18n.t("reason")}
1278 id="post-report-reason"
1279 className="form-control me-2"
1280 placeholder={I18NextService.i18n.t("reason")}
1282 value={this.state.reportReason}
1283 onInput={linkEvent(this, this.handleReportReasonChange)}
1287 className="btn btn-secondary"
1288 aria-label={I18NextService.i18n.t("create_report")}
1290 {this.state.reportLoading ? (
1293 I18NextService.i18n.t("create_report")
1298 {this.state.showPurgeDialog && (
1300 className="form-inline"
1301 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1304 <label className="visually-hidden" htmlFor="purge-reason">
1305 {I18NextService.i18n.t("reason")}
1310 className="form-control me-2"
1311 placeholder={I18NextService.i18n.t("reason")}
1312 value={this.state.purgeReason}
1313 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1315 {this.state.purgeLoading ? (
1320 className="btn btn-secondary"
1321 aria-label={purgeTypeText}
1323 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1333 const post = this.postView.post;
1334 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1335 <div className="row">
1336 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1337 {this.postTitleLine()}
1339 <div className="col-4">
1340 {/* Post thumbnail */}
1341 {!this.state.imageExpanded && this.thumbnail()}
1345 this.postTitleLine()
1350 const { body, id } = this.postView.post;
1352 return !this.showBody && body ? (
1353 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1354 <div className="md-div mb-1 preview-lines">{body}</div>
1364 {/* The mobile view*/}
1365 <div className="d-block d-sm-none">
1366 <article className="row post-container">
1367 <div className="col-12">
1368 {this.createdLine()}
1370 {/* If it has a thumbnail, do a right aligned thumbnail */}
1371 {this.mobileThumbnail()}
1373 {/* Show a preview of the post body */}
1374 {this.showBodyPreview()}
1376 {this.commentsLine(true)}
1377 {this.userActionsLine()}
1378 {this.duplicatesLine()}
1379 {this.removeAndBanDialogs()}
1384 {/* The larger view*/}
1385 <div className="d-none d-sm-block">
1386 <article className="row post-container">
1387 {!this.props.viewOnly && (
1389 voteContentType={VoteContentType.Post}
1390 id={this.postView.post.id}
1391 onVote={this.props.onPostVote}
1392 enableDownvotes={this.props.enableDownvotes}
1393 counts={this.postView.counts}
1394 my_vote={this.postView.my_vote}
1397 <div className="col-sm-2 pe-0 post-media">
1398 <div className="">{this.thumbnail()}</div>
1400 <div className="col-12 col-sm-9">
1401 <div className="row">
1402 <div className="col-12">
1403 {this.postTitleLine()}
1404 {this.createdLine()}
1405 {this.showBodyPreview()}
1406 {this.commentsLine()}
1407 {this.duplicatesLine()}
1408 {this.userActionsLine()}
1409 {this.removeAndBanDialogs()}
1419 private get myPost(): boolean {
1421 this.postView.creator.id ==
1422 UserService.Instance.myUserInfo?.local_user_view.person.id
1425 handleEditClick(i: PostListing) {
1426 i.setState({ showEdit: true });
1429 handleEditCancel() {
1430 this.setState({ showEdit: false });
1433 // The actual editing is done in the receive for post
1434 handleEditPost(form: EditPost) {
1435 this.setState({ showEdit: false });
1436 this.props.onPostEdit(form);
1439 handleShare(i: PostListing) {
1440 const { name, body, id } = i.props.post_view.post;
1443 text: body?.slice(0, 50),
1444 url: `${getHttpBase()}/post/${id}`,
1448 handleShowReportDialog(i: PostListing) {
1449 i.setState({ showReportDialog: !i.state.showReportDialog });
1452 handleReportReasonChange(i: PostListing, event: any) {
1453 i.setState({ reportReason: event.target.value });
1456 handleReportSubmit(i: PostListing, event: any) {
1457 event.preventDefault();
1458 i.setState({ reportLoading: true });
1459 i.props.onPostReport({
1460 post_id: i.postView.post.id,
1461 reason: i.state.reportReason ?? "",
1462 auth: myAuthRequired(),
1466 handleBlockPersonClick(i: PostListing) {
1467 i.setState({ blockLoading: true });
1468 i.props.onBlockPerson({
1469 person_id: i.postView.creator.id,
1471 auth: myAuthRequired(),
1475 handleDeleteClick(i: PostListing) {
1476 i.setState({ deleteLoading: true });
1477 i.props.onDeletePost({
1478 post_id: i.postView.post.id,
1479 deleted: !i.postView.post.deleted,
1480 auth: myAuthRequired(),
1484 handleSavePostClick(i: PostListing) {
1485 i.setState({ saveLoading: true });
1486 i.props.onSavePost({
1487 post_id: i.postView.post.id,
1488 save: !i.postView.saved,
1489 auth: myAuthRequired(),
1493 get crossPostParams(): PostFormParams {
1494 const queryParams: PostFormParams = {};
1495 const { name, url } = this.postView.post;
1497 queryParams.name = name;
1500 queryParams.url = url;
1503 const crossPostBody = this.crossPostBody();
1504 if (crossPostBody) {
1505 queryParams.body = crossPostBody;
1511 crossPostBody(): string | undefined {
1512 const post = this.postView.post;
1513 const body = post.body;
1516 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1518 }\n\n${body.replace(/^/gm, "> ")}`
1522 get showBody(): boolean {
1523 return this.props.showBody || this.state.showBody;
1526 handleModRemoveShow(i: PostListing) {
1528 showRemoveDialog: !i.state.showRemoveDialog,
1529 showBanDialog: false,
1533 handleModRemoveReasonChange(i: PostListing, event: any) {
1534 i.setState({ removeReason: event.target.value });
1537 handleModRemoveDataChange(i: PostListing, event: any) {
1538 i.setState({ removeData: event.target.checked });
1541 handleModRemoveSubmit(i: PostListing, event: any) {
1542 event.preventDefault();
1543 i.setState({ removeLoading: true });
1544 i.props.onRemovePost({
1545 post_id: i.postView.post.id,
1546 removed: !i.postView.post.removed,
1547 auth: myAuthRequired(),
1551 handleModLock(i: PostListing) {
1552 i.setState({ lockLoading: true });
1553 i.props.onLockPost({
1554 post_id: i.postView.post.id,
1555 locked: !i.postView.post.locked,
1556 auth: myAuthRequired(),
1560 handleModFeaturePostLocal(i: PostListing) {
1561 i.setState({ featureLocalLoading: true });
1562 i.props.onFeaturePost({
1563 post_id: i.postView.post.id,
1564 featured: !i.postView.post.featured_local,
1565 feature_type: "Local",
1566 auth: myAuthRequired(),
1570 handleModFeaturePostCommunity(i: PostListing) {
1571 i.setState({ featureCommunityLoading: true });
1572 i.props.onFeaturePost({
1573 post_id: i.postView.post.id,
1574 featured: !i.postView.post.featured_community,
1575 feature_type: "Community",
1576 auth: myAuthRequired(),
1580 handleModBanFromCommunityShow(i: PostListing) {
1582 showBanDialog: true,
1583 banType: BanType.Community,
1584 showRemoveDialog: false,
1588 handleModBanShow(i: PostListing) {
1590 showBanDialog: true,
1591 banType: BanType.Site,
1592 showRemoveDialog: false,
1596 handlePurgePersonShow(i: PostListing) {
1598 showPurgeDialog: true,
1599 purgeType: PurgeType.Person,
1600 showRemoveDialog: false,
1604 handlePurgePostShow(i: PostListing) {
1606 showPurgeDialog: true,
1607 purgeType: PurgeType.Post,
1608 showRemoveDialog: false,
1612 handlePurgeReasonChange(i: PostListing, event: any) {
1613 i.setState({ purgeReason: event.target.value });
1616 handlePurgeSubmit(i: PostListing, event: any) {
1617 event.preventDefault();
1618 i.setState({ purgeLoading: true });
1619 if (i.state.purgeType == PurgeType.Person) {
1620 i.props.onPurgePerson({
1621 person_id: i.postView.creator.id,
1622 reason: i.state.purgeReason,
1623 auth: myAuthRequired(),
1625 } else if (i.state.purgeType == PurgeType.Post) {
1626 i.props.onPurgePost({
1627 post_id: i.postView.post.id,
1628 reason: i.state.purgeReason,
1629 auth: myAuthRequired(),
1634 handleModBanReasonChange(i: PostListing, event: any) {
1635 i.setState({ banReason: event.target.value });
1638 handleModBanExpireDaysChange(i: PostListing, event: any) {
1639 i.setState({ banExpireDays: event.target.value });
1642 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1643 i.setState({ banType: BanType.Community });
1644 i.handleModBanBothSubmit(i, event);
1647 handleModBanSubmit(i: PostListing, event: any) {
1648 i.setState({ banType: BanType.Site });
1649 i.handleModBanBothSubmit(i, event);
1652 handleModBanBothSubmit(i: PostListing, event: any) {
1653 event.preventDefault();
1654 i.setState({ banLoading: true });
1656 const ban = !i.props.post_view.creator_banned_from_community;
1657 // If its an unban, restore all their data
1659 i.setState({ removeData: false });
1661 const person_id = i.props.post_view.creator.id;
1662 const remove_data = i.state.removeData;
1663 const reason = i.state.banReason;
1664 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1666 if (i.state.banType == BanType.Community) {
1667 const community_id = i.postView.community.id;
1668 i.props.onBanPersonFromCommunity({
1675 auth: myAuthRequired(),
1678 i.props.onBanPerson({
1684 auth: myAuthRequired(),
1689 handleAddModToCommunity(i: PostListing) {
1690 i.setState({ addModLoading: true });
1691 i.props.onAddModToCommunity({
1692 community_id: i.postView.community.id,
1693 person_id: i.postView.creator.id,
1694 added: !i.creatorIsMod_,
1695 auth: myAuthRequired(),
1699 handleAddAdmin(i: PostListing) {
1700 i.setState({ addAdminLoading: true });
1701 i.props.onAddAdmin({
1702 person_id: i.postView.creator.id,
1703 added: !i.creatorIsAdmin_,
1704 auth: myAuthRequired(),
1708 handleShowConfirmTransferCommunity(i: PostListing) {
1709 i.setState({ showConfirmTransferCommunity: true });
1712 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1713 i.setState({ showConfirmTransferCommunity: false });
1716 handleTransferCommunity(i: PostListing) {
1717 i.setState({ transferLoading: true });
1718 i.props.onTransferCommunity({
1719 community_id: i.postView.community.id,
1720 person_id: i.postView.creator.id,
1721 auth: myAuthRequired(),
1725 handleShowConfirmTransferSite(i: PostListing) {
1726 i.setState({ showConfirmTransferSite: true });
1729 handleCancelShowConfirmTransferSite(i: PostListing) {
1730 i.setState({ showConfirmTransferSite: false });
1733 handleImageExpandClick(i: PostListing, event: any) {
1734 event.preventDefault();
1735 i.setState({ imageExpanded: !i.state.imageExpanded });
1739 handleViewSource(i: PostListing) {
1740 i.setState({ viewSource: !i.state.viewSource });
1743 handleShowAdvanced(i: PostListing) {
1744 i.setState({ showAdvanced: !i.state.showAdvanced });
1748 handleShowMoreMobile(i: PostListing) {
1750 showMoreMobile: !i.state.showMoreMobile,
1751 showAdvanced: !i.state.showAdvanced,
1756 handleShowBody(i: PostListing) {
1757 i.setState({ showBody: !i.state.showBody });
1761 get pointsTippy(): string {
1762 const points = I18NextService.i18n.t("number_of_points", {
1763 count: Number(this.postView.counts.score),
1764 formattedCount: Number(this.postView.counts.score),
1767 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1768 count: Number(this.postView.counts.upvotes),
1769 formattedCount: Number(this.postView.counts.upvotes),
1772 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1773 count: Number(this.postView.counts.downvotes),
1774 formattedCount: Number(this.postView.counts.downvotes),
1777 return `${points} • ${upvotes} • ${downvotes}`;
1780 get canModOnSelf_(): boolean {
1782 this.postView.creator.id,
1783 this.props.moderators,
1790 get canMod_(): boolean {
1792 this.postView.creator.id,
1793 this.props.moderators,
1798 get canAdmin_(): boolean {
1799 return canAdmin(this.postView.creator.id, this.props.admins);
1802 get creatorIsMod_(): boolean {
1803 return isMod(this.postView.creator.id, this.props.moderators);
1806 get creatorIsAdmin_(): boolean {
1807 return isAdmin(this.postView.creator.id, this.props.admins);