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${post.id}`}
670 aria-label={I18NextService.i18n.t("more")}
672 <Icon icon="more-vertical" inline />
676 className="dropdown-menu"
677 id={`advancedButtonsDropdown${post.id}`}
681 <li>{this.reportButton}</li>
682 <li>{this.blockButton}</li>
686 <li>{this.editButton}</li>
687 <li>{this.deleteButton}</li>
691 {/* Any mod can do these, not limited to hierarchy*/}
692 {(amMod(this.props.moderators) || amAdmin()) && (
695 <hr className="dropdown-divider" />
697 <li>{this.lockButton}</li>
698 {this.featureButtons}
702 {(this.canMod_ || this.canAdmin_) && (
703 <li>{this.modRemoveButton}</li>
711 get commentsButton() {
712 const post_view = this.postView;
713 const title = I18NextService.i18n.t("number_of_comments", {
714 count: Number(post_view.counts.comments),
715 formattedCount: Number(post_view.counts.comments),
720 className="btn btn-link btn-sm text-muted ps-0"
722 to={`/post/${post_view.post.id}?scrollToComments=true`}
723 data-tippy-content={title}
725 <Icon icon="message-square" classes="me-1" inline />
726 {post_view.counts.comments}
727 {this.unreadCount && (
728 <span className="text-muted fst-italic">
729 ({this.unreadCount} {I18NextService.i18n.t("new")})
736 get unreadCount(): number | undefined {
737 const pv = this.postView;
738 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
740 : pv.unread_comments;
744 const saved = this.postView.saved;
746 ? I18NextService.i18n.t("unsave")
747 : I18NextService.i18n.t("save");
750 className="btn btn-sm btn-animate text-muted py-0"
751 onClick={linkEvent(this, this.handleSavePostClick)}
752 data-tippy-content={label}
755 {this.state.saveLoading ? (
760 classes={classNames({ "text-warning": saved })}
768 get crossPostButton() {
771 className="btn btn-sm btn-animate text-muted py-0"
773 /* Empty string properties are required to satisfy type*/
774 pathname: "/create_post",
775 state: { ...this.crossPostParams },
780 title={I18NextService.i18n.t("cross_post")}
781 data-tippy-content={I18NextService.i18n.t("cross_post")}
782 aria-label={I18NextService.i18n.t("cross_post")}
784 <Icon icon="copy" inline />
792 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
793 onClick={linkEvent(this, this.handleShowReportDialog)}
794 aria-label={I18NextService.i18n.t("show_report_dialog")}
796 <Icon classes="me-1" icon="flag" inline />
797 {I18NextService.i18n.t("create_report")}
805 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
806 onClick={linkEvent(this, this.handleBlockPersonClick)}
807 aria-label={I18NextService.i18n.t("block_user")}
809 {this.state.blockLoading ? (
812 <Icon classes="me-1" icon="slash" inline />
814 {I18NextService.i18n.t("block_user")}
822 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
823 onClick={linkEvent(this, this.handleEditClick)}
824 aria-label={I18NextService.i18n.t("edit")}
826 <Icon classes="me-1" icon="edit" inline />
827 {I18NextService.i18n.t("edit")}
833 const deleted = this.postView.post.deleted;
834 const label = !deleted
835 ? I18NextService.i18n.t("delete")
836 : I18NextService.i18n.t("restore");
839 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
840 onClick={linkEvent(this, this.handleDeleteClick)}
842 {this.state.deleteLoading ? (
848 classes={classNames("me-1", { "text-danger": deleted })}
858 get viewSourceButton() {
861 className="btn btn-sm btn-animate text-muted py-0"
862 onClick={linkEvent(this, this.handleViewSource)}
863 data-tippy-content={I18NextService.i18n.t("view_source")}
864 aria-label={I18NextService.i18n.t("view_source")}
868 classes={classNames({ "text-success": this.state.viewSource })}
876 const locked = this.postView.post.locked;
878 ? I18NextService.i18n.t("unlock")
879 : I18NextService.i18n.t("lock");
882 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
883 onClick={linkEvent(this, this.handleModLock)}
886 {this.state.lockLoading ? (
892 classes={classNames("me-1", { "text-danger": locked })}
895 {capitalizeFirstLetter(label)}
902 get featureButtons() {
903 const featuredCommunity = this.postView.post.featured_community;
904 const labelCommunity = featuredCommunity
905 ? I18NextService.i18n.t("unfeature_from_community")
906 : I18NextService.i18n.t("feature_in_community");
908 const featuredLocal = this.postView.post.featured_local;
909 const labelLocal = featuredLocal
910 ? I18NextService.i18n.t("unfeature_from_local")
911 : I18NextService.i18n.t("feature_in_local");
916 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
917 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
918 data-tippy-content={labelCommunity}
919 aria-label={labelCommunity}
921 {this.state.featureCommunityLoading ? (
927 classes={classNames("me-1", {
928 "text-success": featuredCommunity,
932 {I18NextService.i18n.t("community")}
940 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
941 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
942 data-tippy-content={labelLocal}
943 aria-label={labelLocal}
945 {this.state.featureLocalLoading ? (
951 classes={classNames("me-1", {
952 "text-success": featuredLocal,
956 {I18NextService.i18n.t("local")}
966 get modRemoveButton() {
967 const removed = this.postView.post.removed;
970 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
973 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
976 {/* TODO: Find an icon for this. */}
977 {this.state.removeLoading ? (
980 I18NextService.i18n.t("remove")
982 I18NextService.i18n.t("restore")
989 * Mod/Admin actions to be taken against the author.
993 const post_view = this.postView;
995 this.state.showAdvanced && (
996 <div className="mt-3">
999 {!this.creatorIsMod_ &&
1000 (!post_view.creator_banned_from_community ? (
1002 className="btn btn-link btn-animate text-muted py-0"
1005 this.handleModBanFromCommunityShow
1007 aria-label={I18NextService.i18n.t("ban_from_community")}
1009 {I18NextService.i18n.t("ban_from_community")}
1013 className="btn btn-link btn-animate text-muted py-0"
1016 this.handleModBanFromCommunitySubmit
1018 aria-label={I18NextService.i18n.t("unban")}
1020 {this.state.banLoading ? (
1023 I18NextService.i18n.t("unban")
1027 {!post_view.creator_banned_from_community && (
1029 className="btn btn-link btn-animate text-muted py-0"
1030 onClick={linkEvent(this, this.handleAddModToCommunity)}
1033 ? I18NextService.i18n.t("remove_as_mod")
1034 : I18NextService.i18n.t("appoint_as_mod")
1037 {this.state.addModLoading ? (
1039 ) : this.creatorIsMod_ ? (
1040 I18NextService.i18n.t("remove_as_mod")
1042 I18NextService.i18n.t("appoint_as_mod")
1048 {/* Community creators and admins can transfer community to another mod */}
1049 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1051 this.creatorIsMod_ &&
1052 (!this.state.showConfirmTransferCommunity ? (
1054 className="btn btn-link btn-animate text-muted py-0"
1057 this.handleShowConfirmTransferCommunity
1059 aria-label={I18NextService.i18n.t("transfer_community")}
1061 {I18NextService.i18n.t("transfer_community")}
1066 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1067 aria-label={I18NextService.i18n.t("are_you_sure")}
1069 {I18NextService.i18n.t("are_you_sure")}
1072 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1073 aria-label={I18NextService.i18n.t("yes")}
1074 onClick={linkEvent(this, this.handleTransferCommunity)}
1076 {this.state.transferLoading ? (
1079 I18NextService.i18n.t("yes")
1083 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1086 this.handleCancelShowConfirmTransferCommunity
1088 aria-label={I18NextService.i18n.t("no")}
1090 {I18NextService.i18n.t("no")}
1094 {/* Admins can ban from all, and appoint other admins */}
1095 {this.canAdmin_ && (
1097 {!this.creatorIsAdmin_ && (
1099 {!isBanned(post_view.creator) ? (
1101 className="btn btn-link btn-animate text-muted py-0"
1102 onClick={linkEvent(this, this.handleModBanShow)}
1103 aria-label={I18NextService.i18n.t("ban_from_site")}
1105 {I18NextService.i18n.t("ban_from_site")}
1109 className="btn btn-link btn-animate text-muted py-0"
1110 onClick={linkEvent(this, this.handleModBanSubmit)}
1111 aria-label={I18NextService.i18n.t("unban_from_site")}
1113 {this.state.banLoading ? (
1116 I18NextService.i18n.t("unban_from_site")
1121 className="btn btn-link btn-animate text-muted py-0"
1122 onClick={linkEvent(this, this.handlePurgePersonShow)}
1123 aria-label={I18NextService.i18n.t("purge_user")}
1125 {I18NextService.i18n.t("purge_user")}
1128 className="btn btn-link btn-animate text-muted py-0"
1129 onClick={linkEvent(this, this.handlePurgePostShow)}
1130 aria-label={I18NextService.i18n.t("purge_post")}
1132 {I18NextService.i18n.t("purge_post")}
1136 {!isBanned(post_view.creator) && post_view.creator.local && (
1138 className="btn btn-link btn-animate text-muted py-0"
1139 onClick={linkEvent(this, this.handleAddAdmin)}
1141 this.creatorIsAdmin_
1142 ? I18NextService.i18n.t("remove_as_admin")
1143 : I18NextService.i18n.t("appoint_as_admin")
1146 {this.state.addAdminLoading ? (
1148 ) : this.creatorIsAdmin_ ? (
1149 I18NextService.i18n.t("remove_as_admin")
1151 I18NextService.i18n.t("appoint_as_admin")
1162 removeAndBanDialogs() {
1163 const post = this.postView;
1164 const purgeTypeText =
1165 this.state.purgeType == PurgeType.Post
1166 ? I18NextService.i18n.t("purge_post")
1167 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1170 {this.state.showRemoveDialog && (
1172 className="form-inline"
1173 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1176 className="visually-hidden"
1177 htmlFor="post-listing-remove-reason"
1179 {I18NextService.i18n.t("reason")}
1183 id="post-listing-remove-reason"
1184 className="form-control me-2"
1185 placeholder={I18NextService.i18n.t("reason")}
1186 value={this.state.removeReason}
1187 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1191 className="btn btn-secondary"
1192 aria-label={I18NextService.i18n.t("remove_post")}
1194 {this.state.removeLoading ? (
1197 I18NextService.i18n.t("remove_post")
1202 {this.state.showBanDialog && (
1203 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1204 <div className="mb-3 row col-12">
1206 className="col-form-label"
1207 htmlFor="post-listing-ban-reason"
1209 {I18NextService.i18n.t("reason")}
1213 id="post-listing-ban-reason"
1214 className="form-control me-2"
1215 placeholder={I18NextService.i18n.t("reason")}
1216 value={this.state.banReason}
1217 onInput={linkEvent(this, this.handleModBanReasonChange)}
1219 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1220 {I18NextService.i18n.t("expires")}
1224 id={`mod-ban-expires`}
1225 className="form-control me-2"
1226 placeholder={I18NextService.i18n.t("number_of_days")}
1227 value={this.state.banExpireDays}
1228 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1230 <div className="input-group mb-3">
1231 <div className="form-check">
1233 className="form-check-input"
1234 id="mod-ban-remove-data"
1236 checked={this.state.removeData}
1237 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1240 className="form-check-label"
1241 htmlFor="mod-ban-remove-data"
1242 title={I18NextService.i18n.t("remove_content_more")}
1244 {I18NextService.i18n.t("remove_content")}
1249 {/* TODO hold off on expires until later */}
1250 {/* <div class="mb-3 row"> */}
1251 {/* <label class="col-form-label">Expires</label> */}
1252 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1254 <div className="mb-3 row">
1257 className="btn btn-secondary"
1258 aria-label={I18NextService.i18n.t("ban")}
1260 {this.state.banLoading ? (
1264 {I18NextService.i18n.t("ban")} {post.creator.name}
1271 {this.state.showReportDialog && (
1273 className="form-inline"
1274 onSubmit={linkEvent(this, this.handleReportSubmit)}
1276 <label className="visually-hidden" htmlFor="post-report-reason">
1277 {I18NextService.i18n.t("reason")}
1281 id="post-report-reason"
1282 className="form-control me-2"
1283 placeholder={I18NextService.i18n.t("reason")}
1285 value={this.state.reportReason}
1286 onInput={linkEvent(this, this.handleReportReasonChange)}
1290 className="btn btn-secondary"
1291 aria-label={I18NextService.i18n.t("create_report")}
1293 {this.state.reportLoading ? (
1296 I18NextService.i18n.t("create_report")
1301 {this.state.showPurgeDialog && (
1303 className="form-inline"
1304 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1307 <label className="visually-hidden" htmlFor="purge-reason">
1308 {I18NextService.i18n.t("reason")}
1313 className="form-control me-2"
1314 placeholder={I18NextService.i18n.t("reason")}
1315 value={this.state.purgeReason}
1316 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1318 {this.state.purgeLoading ? (
1323 className="btn btn-secondary"
1324 aria-label={purgeTypeText}
1326 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1336 const post = this.postView.post;
1337 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1338 <div className="row">
1339 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1340 {this.postTitleLine()}
1342 <div className="col-4">
1343 {/* Post thumbnail */}
1344 {!this.state.imageExpanded && this.thumbnail()}
1348 this.postTitleLine()
1353 const { body, id } = this.postView.post;
1355 return !this.showBody && body ? (
1356 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1357 <div className="md-div mb-1 preview-lines">{body}</div>
1367 {/* The mobile view*/}
1368 <div className="d-block d-sm-none">
1369 <article className="row post-container">
1370 <div className="col-12">
1371 {this.createdLine()}
1373 {/* If it has a thumbnail, do a right aligned thumbnail */}
1374 {this.mobileThumbnail()}
1376 {/* Show a preview of the post body */}
1377 {this.showBodyPreview()}
1379 {this.commentsLine(true)}
1380 {this.userActionsLine()}
1381 {this.duplicatesLine()}
1382 {this.removeAndBanDialogs()}
1387 {/* The larger view*/}
1388 <div className="d-none d-sm-block">
1389 <article className="row post-container">
1390 {!this.props.viewOnly && (
1392 voteContentType={VoteContentType.Post}
1393 id={this.postView.post.id}
1394 onVote={this.props.onPostVote}
1395 enableDownvotes={this.props.enableDownvotes}
1396 counts={this.postView.counts}
1397 my_vote={this.postView.my_vote}
1400 <div className="col-sm-2 pe-0 post-media">
1401 <div className="">{this.thumbnail()}</div>
1403 <div className="col-12 col-sm-9">
1404 <div className="row">
1405 <div className="col-12">
1406 {this.postTitleLine()}
1407 {this.createdLine()}
1408 {this.showBodyPreview()}
1409 {this.commentsLine()}
1410 {this.duplicatesLine()}
1411 {this.userActionsLine()}
1412 {this.removeAndBanDialogs()}
1422 private get myPost(): boolean {
1424 this.postView.creator.id ==
1425 UserService.Instance.myUserInfo?.local_user_view.person.id
1428 handleEditClick(i: PostListing) {
1429 i.setState({ showEdit: true });
1432 handleEditCancel() {
1433 this.setState({ showEdit: false });
1436 // The actual editing is done in the receive for post
1437 handleEditPost(form: EditPost) {
1438 this.setState({ showEdit: false });
1439 this.props.onPostEdit(form);
1442 handleShare(i: PostListing) {
1443 const { name, body, id } = i.props.post_view.post;
1446 text: body?.slice(0, 50),
1447 url: `${getHttpBase()}/post/${id}`,
1451 handleShowReportDialog(i: PostListing) {
1452 i.setState({ showReportDialog: !i.state.showReportDialog });
1455 handleReportReasonChange(i: PostListing, event: any) {
1456 i.setState({ reportReason: event.target.value });
1459 handleReportSubmit(i: PostListing, event: any) {
1460 event.preventDefault();
1461 i.setState({ reportLoading: true });
1462 i.props.onPostReport({
1463 post_id: i.postView.post.id,
1464 reason: i.state.reportReason ?? "",
1465 auth: myAuthRequired(),
1469 handleBlockPersonClick(i: PostListing) {
1470 i.setState({ blockLoading: true });
1471 i.props.onBlockPerson({
1472 person_id: i.postView.creator.id,
1474 auth: myAuthRequired(),
1478 handleDeleteClick(i: PostListing) {
1479 i.setState({ deleteLoading: true });
1480 i.props.onDeletePost({
1481 post_id: i.postView.post.id,
1482 deleted: !i.postView.post.deleted,
1483 auth: myAuthRequired(),
1487 handleSavePostClick(i: PostListing) {
1488 i.setState({ saveLoading: true });
1489 i.props.onSavePost({
1490 post_id: i.postView.post.id,
1491 save: !i.postView.saved,
1492 auth: myAuthRequired(),
1496 get crossPostParams(): PostFormParams {
1497 const queryParams: PostFormParams = {};
1498 const { name, url } = this.postView.post;
1500 queryParams.name = name;
1503 queryParams.url = url;
1506 const crossPostBody = this.crossPostBody();
1507 if (crossPostBody) {
1508 queryParams.body = crossPostBody;
1514 crossPostBody(): string | undefined {
1515 const post = this.postView.post;
1516 const body = post.body;
1519 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1521 }\n\n${body.replace(/^/gm, "> ")}`
1525 get showBody(): boolean {
1526 return this.props.showBody || this.state.showBody;
1529 handleModRemoveShow(i: PostListing) {
1531 showRemoveDialog: !i.state.showRemoveDialog,
1532 showBanDialog: false,
1536 handleModRemoveReasonChange(i: PostListing, event: any) {
1537 i.setState({ removeReason: event.target.value });
1540 handleModRemoveDataChange(i: PostListing, event: any) {
1541 i.setState({ removeData: event.target.checked });
1544 handleModRemoveSubmit(i: PostListing, event: any) {
1545 event.preventDefault();
1546 i.setState({ removeLoading: true });
1547 i.props.onRemovePost({
1548 post_id: i.postView.post.id,
1549 removed: !i.postView.post.removed,
1550 auth: myAuthRequired(),
1554 handleModLock(i: PostListing) {
1555 i.setState({ lockLoading: true });
1556 i.props.onLockPost({
1557 post_id: i.postView.post.id,
1558 locked: !i.postView.post.locked,
1559 auth: myAuthRequired(),
1563 handleModFeaturePostLocal(i: PostListing) {
1564 i.setState({ featureLocalLoading: true });
1565 i.props.onFeaturePost({
1566 post_id: i.postView.post.id,
1567 featured: !i.postView.post.featured_local,
1568 feature_type: "Local",
1569 auth: myAuthRequired(),
1573 handleModFeaturePostCommunity(i: PostListing) {
1574 i.setState({ featureCommunityLoading: true });
1575 i.props.onFeaturePost({
1576 post_id: i.postView.post.id,
1577 featured: !i.postView.post.featured_community,
1578 feature_type: "Community",
1579 auth: myAuthRequired(),
1583 handleModBanFromCommunityShow(i: PostListing) {
1585 showBanDialog: true,
1586 banType: BanType.Community,
1587 showRemoveDialog: false,
1591 handleModBanShow(i: PostListing) {
1593 showBanDialog: true,
1594 banType: BanType.Site,
1595 showRemoveDialog: false,
1599 handlePurgePersonShow(i: PostListing) {
1601 showPurgeDialog: true,
1602 purgeType: PurgeType.Person,
1603 showRemoveDialog: false,
1607 handlePurgePostShow(i: PostListing) {
1609 showPurgeDialog: true,
1610 purgeType: PurgeType.Post,
1611 showRemoveDialog: false,
1615 handlePurgeReasonChange(i: PostListing, event: any) {
1616 i.setState({ purgeReason: event.target.value });
1619 handlePurgeSubmit(i: PostListing, event: any) {
1620 event.preventDefault();
1621 i.setState({ purgeLoading: true });
1622 if (i.state.purgeType == PurgeType.Person) {
1623 i.props.onPurgePerson({
1624 person_id: i.postView.creator.id,
1625 reason: i.state.purgeReason,
1626 auth: myAuthRequired(),
1628 } else if (i.state.purgeType == PurgeType.Post) {
1629 i.props.onPurgePost({
1630 post_id: i.postView.post.id,
1631 reason: i.state.purgeReason,
1632 auth: myAuthRequired(),
1637 handleModBanReasonChange(i: PostListing, event: any) {
1638 i.setState({ banReason: event.target.value });
1641 handleModBanExpireDaysChange(i: PostListing, event: any) {
1642 i.setState({ banExpireDays: event.target.value });
1645 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1646 i.setState({ banType: BanType.Community });
1647 i.handleModBanBothSubmit(i, event);
1650 handleModBanSubmit(i: PostListing, event: any) {
1651 i.setState({ banType: BanType.Site });
1652 i.handleModBanBothSubmit(i, event);
1655 handleModBanBothSubmit(i: PostListing, event: any) {
1656 event.preventDefault();
1657 i.setState({ banLoading: true });
1659 const ban = !i.props.post_view.creator_banned_from_community;
1660 // If its an unban, restore all their data
1662 i.setState({ removeData: false });
1664 const person_id = i.props.post_view.creator.id;
1665 const remove_data = i.state.removeData;
1666 const reason = i.state.banReason;
1667 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1669 if (i.state.banType == BanType.Community) {
1670 const community_id = i.postView.community.id;
1671 i.props.onBanPersonFromCommunity({
1678 auth: myAuthRequired(),
1681 i.props.onBanPerson({
1687 auth: myAuthRequired(),
1692 handleAddModToCommunity(i: PostListing) {
1693 i.setState({ addModLoading: true });
1694 i.props.onAddModToCommunity({
1695 community_id: i.postView.community.id,
1696 person_id: i.postView.creator.id,
1697 added: !i.creatorIsMod_,
1698 auth: myAuthRequired(),
1702 handleAddAdmin(i: PostListing) {
1703 i.setState({ addAdminLoading: true });
1704 i.props.onAddAdmin({
1705 person_id: i.postView.creator.id,
1706 added: !i.creatorIsAdmin_,
1707 auth: myAuthRequired(),
1711 handleShowConfirmTransferCommunity(i: PostListing) {
1712 i.setState({ showConfirmTransferCommunity: true });
1715 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1716 i.setState({ showConfirmTransferCommunity: false });
1719 handleTransferCommunity(i: PostListing) {
1720 i.setState({ transferLoading: true });
1721 i.props.onTransferCommunity({
1722 community_id: i.postView.community.id,
1723 person_id: i.postView.creator.id,
1724 auth: myAuthRequired(),
1728 handleShowConfirmTransferSite(i: PostListing) {
1729 i.setState({ showConfirmTransferSite: true });
1732 handleCancelShowConfirmTransferSite(i: PostListing) {
1733 i.setState({ showConfirmTransferSite: false });
1736 handleImageExpandClick(i: PostListing, event: any) {
1737 event.preventDefault();
1738 i.setState({ imageExpanded: !i.state.imageExpanded });
1742 handleViewSource(i: PostListing) {
1743 i.setState({ viewSource: !i.state.viewSource });
1746 handleShowAdvanced(i: PostListing) {
1747 i.setState({ showAdvanced: !i.state.showAdvanced });
1751 handleShowMoreMobile(i: PostListing) {
1753 showMoreMobile: !i.state.showMoreMobile,
1754 showAdvanced: !i.state.showAdvanced,
1759 handleShowBody(i: PostListing) {
1760 i.setState({ showBody: !i.state.showBody });
1764 get pointsTippy(): string {
1765 const points = I18NextService.i18n.t("number_of_points", {
1766 count: Number(this.postView.counts.score),
1767 formattedCount: Number(this.postView.counts.score),
1770 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1771 count: Number(this.postView.counts.upvotes),
1772 formattedCount: Number(this.postView.counts.upvotes),
1775 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1776 count: Number(this.postView.counts.downvotes),
1777 formattedCount: Number(this.postView.counts.downvotes),
1780 return `${points} • ${upvotes} • ${downvotes}`;
1783 get canModOnSelf_(): boolean {
1785 this.postView.creator.id,
1786 this.props.moderators,
1793 get canMod_(): boolean {
1795 this.postView.creator.id,
1796 this.props.moderators,
1801 get canAdmin_(): boolean {
1802 return canAdmin(this.postView.creator.id, this.props.admins);
1805 get creatorIsMod_(): boolean {
1806 return isMod(this.postView.creator.id, this.props.moderators);
1809 get creatorIsAdmin_(): boolean {
1810 return isAdmin(this.postView.creator.id, this.props.admins);