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">
252 className="p-0 border-0 bg-transparent d-inline-block"
253 onClick={linkEvent(this, this.handleImageExpandClick)}
255 <PictrsImage src={this.imageSrc} />
262 const { post } = this.postView;
263 const { url } = post;
265 if (url && isVideo(url)) {
267 <div className="embed-responsive mt-3">
268 <video muted controls className="embed-responsive-item col-12">
269 <source src={url} type="video/mp4" />
278 imgThumb(src: string) {
279 const post_view = this.postView;
285 nsfw={post_view.post.nsfw || post_view.community.nsfw}
290 get imageSrc(): string | undefined {
291 const post = this.postView.post;
292 const url = post.url;
293 const thumbnail = post.thumbnail_url;
295 if (url && isImage(url)) {
296 if (url.includes("pictrs")) {
298 } else if (thumbnail) {
303 } else if (thumbnail) {
311 const post = this.postView.post;
312 const url = post.url;
313 const thumbnail = post.thumbnail_url;
315 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
319 className="text-body d-inline-block position-relative mb-2"
320 data-tippy-content={I18NextService.i18n.t("expand_here")}
321 onClick={linkEvent(this, this.handleImageExpandClick)}
322 aria-label={I18NextService.i18n.t("expand_here")}
324 {this.imgThumb(this.imageSrc)}
325 <Icon icon="image" classes="mini-overlay" />
328 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
331 className="text-body d-inline-block position-relative mb-2"
336 {this.imgThumb(this.imageSrc)}
337 <Icon icon="external-link" classes="mini-overlay" />
341 if (!this.props.hideImage && isVideo(url)) {
344 className="text-body"
348 data-tippy-content={I18NextService.i18n.t("expand_here")}
349 onClick={linkEvent(this, this.handleImageExpandClick)}
350 aria-label={I18NextService.i18n.t("expand_here")}
352 <div className="thumbnail rounded bg-light d-flex justify-content-center">
353 <Icon icon="play" classes="d-flex align-items-center" />
359 <a className="text-body" href={url} title={url} rel={relTags}>
360 <div className="thumbnail rounded bg-light d-flex justify-content-center">
361 <Icon icon="external-link" classes="d-flex align-items-center" />
369 className="text-body"
370 to={`/post/${post.id}`}
371 title={I18NextService.i18n.t("comments")}
373 <div className="thumbnail rounded bg-light d-flex justify-content-center">
374 <Icon icon="message-square" classes="d-flex align-items-center" />
382 const post_view = this.postView;
384 <span className="small">
385 <PersonListing person={post_view.creator} />
386 {this.creatorIsMod_ && (
387 <span className="mx-1 badge text-bg-light">
388 {I18NextService.i18n.t("mod")}
391 {this.creatorIsAdmin_ && (
392 <span className="mx-1 badge text-bg-light">
393 {I18NextService.i18n.t("admin")}
396 {post_view.creator.bot_account && (
397 <span className="mx-1 badge text-bg-light">
398 {I18NextService.i18n.t("bot_account").toLowerCase()}
401 {this.props.showCommunity && (
404 {I18NextService.i18n.t("to")}{" "}
405 <CommunityLink community={post_view.community} />
408 {post_view.post.language_id !== 0 && (
409 <span className="mx-1 badge text-bg-light">
411 this.props.allLanguages.find(
412 lang => lang.id === post_view.post.language_id
419 published={post_view.post.published}
420 updated={post_view.post.updated}
427 const post = this.postView.post;
430 className={`d-inline ${
431 !post.featured_community && !post.featured_local
435 to={`/post/${post.id}`}
436 title={I18NextService.i18n.t("comments")}
440 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
447 const post = this.postView.post;
448 const url = post.url;
452 <div className="post-title overflow-hidden">
453 <h5 className="d-inline">
454 {url && this.props.showBody ? (
457 !post.featured_community && !post.featured_local
464 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
470 {(url && isImage(url)) ||
471 (post.thumbnail_url && (
473 className="btn btn-sm text-monospace text-muted d-inline-block"
474 data-tippy-content={I18NextService.i18n.t("expand_here")}
475 onClick={linkEvent(this, this.handleImageExpandClick)}
479 !this.state.imageExpanded ? "plus-square" : "minus-square"
481 classes="icon-inline"
486 <small className="ms-2 badge text-bg-secondary">
487 {I18NextService.i18n.t("removed")}
492 className="unselectable pointer ms-2 text-muted fst-italic"
493 data-tippy-content={I18NextService.i18n.t("deleted")}
495 <Icon icon="trash" classes="icon-inline text-danger" />
500 className="unselectable pointer ms-2 text-muted fst-italic"
501 data-tippy-content={I18NextService.i18n.t("locked")}
503 <Icon icon="lock" classes="icon-inline text-danger" />
506 {post.featured_community && (
508 className="unselectable pointer ms-2 text-muted fst-italic"
509 data-tippy-content={I18NextService.i18n.t(
510 "featured_in_community"
512 aria-label={I18NextService.i18n.t("featured_in_community")}
514 <Icon icon="pin" classes="icon-inline text-primary" />
517 {post.featured_local && (
519 className="unselectable pointer ms-2 text-muted fst-italic"
520 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
521 aria-label={I18NextService.i18n.t("featured_in_local")}
523 <Icon icon="pin" classes="icon-inline text-secondary" />
527 <small className="ms-2 badge text-bg-danger">
528 {I18NextService.i18n.t("nsfw")}
532 {url && this.urlLine()}
538 const post = this.postView.post;
539 const url = post.url;
542 <p className="d-flex text-muted align-items-center gap-1 small m-0">
543 {url && !(hostname(url) === getExternalHost()) && (
545 className="text-muted fst-italic"
558 const dupes = this.props.crossPosts;
559 return dupes && dupes.length > 0 ? (
560 <ul className="list-inline mb-1 small text-muted">
562 <li className="list-inline-item me-2">
563 {I18NextService.i18n.t("cross_posted_to")}
566 <li key={pv.post.id} className="list-inline-item me-2">
567 <Link to={`/post/${pv.post.id}`}>
570 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
581 commentsLine(mobile = false) {
582 const post = this.postView.post;
585 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
586 {this.commentsButton}
589 className="btn btn-sm btn-animate text-muted py-0"
590 onClick={linkEvent(this, this.handleShare)}
593 <Icon icon="share" inline />
598 className="btn btn-sm btn-animate text-muted py-0"
599 title={I18NextService.i18n.t("link")}
602 <Icon icon="fedilink" inline />
605 {mobile && !this.props.viewOnly && (
607 voteContentType={VoteContentType.Post}
608 id={this.postView.post.id}
609 onVote={this.props.onPostVote}
610 enableDownvotes={this.props.enableDownvotes}
611 counts={this.postView.counts}
612 my_vote={this.postView.my_vote}
615 {UserService.Instance.myUserInfo &&
616 !this.props.viewOnly &&
622 showPreviewButton() {
623 const post_view = this.postView;
624 const body = post_view.post.body;
628 className="btn btn-sm btn-animate text-muted py-0"
629 data-tippy-content={body && mdNoImages.render(body)}
630 data-tippy-allowHtml={true}
631 onClick={linkEvent(this, this.handleShowBody)}
635 classes={classNames("icon-inline me-1", {
636 "text-success": this.state.showBody,
644 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
645 // Possible enhancement: Make each button a component.
646 const post_view = this.postView;
647 const post = post_view.post;
652 {this.crossPostButton}
655 * If there is a URL, or if the post has a body and we were told not to
656 * show the body, show the MetadataCard/body toggle.
658 {(post.url || (post.body && !this.props.showBody)) &&
659 this.showPreviewButton()}
661 {this.showBody && post_view.post.body && this.viewSourceButton}
663 <div className="dropdown">
665 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
666 onClick={linkEvent(this, this.handleShowAdvanced)}
667 data-tippy-content={I18NextService.i18n.t("more")}
668 data-bs-toggle="dropdown"
669 aria-expanded="false"
670 aria-controls={`advancedButtonsDropdown${post.id}`}
671 aria-label={I18NextService.i18n.t("more")}
673 <Icon icon="more-vertical" inline />
677 className="dropdown-menu"
678 id={`advancedButtonsDropdown${post.id}`}
682 <li>{this.reportButton}</li>
683 <li>{this.blockButton}</li>
687 <li>{this.editButton}</li>
688 <li>{this.deleteButton}</li>
692 {/* Any mod can do these, not limited to hierarchy*/}
693 {(amMod(this.props.moderators) || amAdmin()) && (
696 <hr className="dropdown-divider" />
698 <li>{this.lockButton}</li>
699 {this.featureButtons}
703 {(this.canMod_ || this.canAdmin_) && (
704 <li>{this.modRemoveButton}</li>
712 get commentsButton() {
713 const post_view = this.postView;
714 const title = I18NextService.i18n.t("number_of_comments", {
715 count: Number(post_view.counts.comments),
716 formattedCount: Number(post_view.counts.comments),
721 className="btn btn-link btn-sm text-muted ps-0"
723 to={`/post/${post_view.post.id}?scrollToComments=true`}
724 data-tippy-content={title}
726 <Icon icon="message-square" classes="me-1" inline />
727 {post_view.counts.comments}
728 {this.unreadCount && (
729 <span className="text-muted fst-italic">
730 ({this.unreadCount} {I18NextService.i18n.t("new")})
737 get unreadCount(): number | undefined {
738 const pv = this.postView;
739 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
741 : pv.unread_comments;
745 const saved = this.postView.saved;
747 ? I18NextService.i18n.t("unsave")
748 : I18NextService.i18n.t("save");
751 className="btn btn-sm btn-animate text-muted py-0"
752 onClick={linkEvent(this, this.handleSavePostClick)}
753 data-tippy-content={label}
756 {this.state.saveLoading ? (
761 classes={classNames({ "text-warning": saved })}
769 get crossPostButton() {
772 className="btn btn-sm btn-animate text-muted py-0"
774 /* Empty string properties are required to satisfy type*/
775 pathname: "/create_post",
776 state: { ...this.crossPostParams },
781 title={I18NextService.i18n.t("cross_post")}
782 data-tippy-content={I18NextService.i18n.t("cross_post")}
783 aria-label={I18NextService.i18n.t("cross_post")}
785 <Icon icon="copy" inline />
793 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
794 onClick={linkEvent(this, this.handleShowReportDialog)}
795 aria-label={I18NextService.i18n.t("show_report_dialog")}
797 <Icon classes="me-1" icon="flag" inline />
798 {I18NextService.i18n.t("create_report")}
806 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
807 onClick={linkEvent(this, this.handleBlockPersonClick)}
808 aria-label={I18NextService.i18n.t("block_user")}
810 {this.state.blockLoading ? (
813 <Icon classes="me-1" icon="slash" inline />
815 {I18NextService.i18n.t("block_user")}
823 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
824 onClick={linkEvent(this, this.handleEditClick)}
825 aria-label={I18NextService.i18n.t("edit")}
827 <Icon classes="me-1" icon="edit" inline />
828 {I18NextService.i18n.t("edit")}
834 const deleted = this.postView.post.deleted;
835 const label = !deleted
836 ? I18NextService.i18n.t("delete")
837 : I18NextService.i18n.t("restore");
840 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
841 onClick={linkEvent(this, this.handleDeleteClick)}
843 {this.state.deleteLoading ? (
849 classes={classNames("me-1", { "text-danger": deleted })}
859 get viewSourceButton() {
862 className="btn btn-sm btn-animate text-muted py-0"
863 onClick={linkEvent(this, this.handleViewSource)}
864 data-tippy-content={I18NextService.i18n.t("view_source")}
865 aria-label={I18NextService.i18n.t("view_source")}
869 classes={classNames({ "text-success": this.state.viewSource })}
877 const locked = this.postView.post.locked;
879 ? I18NextService.i18n.t("unlock")
880 : I18NextService.i18n.t("lock");
883 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
884 onClick={linkEvent(this, this.handleModLock)}
887 {this.state.lockLoading ? (
893 classes={classNames("me-1", { "text-danger": locked })}
896 {capitalizeFirstLetter(label)}
903 get featureButtons() {
904 const featuredCommunity = this.postView.post.featured_community;
905 const labelCommunity = featuredCommunity
906 ? I18NextService.i18n.t("unfeature_from_community")
907 : I18NextService.i18n.t("feature_in_community");
909 const featuredLocal = this.postView.post.featured_local;
910 const labelLocal = featuredLocal
911 ? I18NextService.i18n.t("unfeature_from_local")
912 : I18NextService.i18n.t("feature_in_local");
917 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
918 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
919 data-tippy-content={labelCommunity}
920 aria-label={labelCommunity}
922 {this.state.featureCommunityLoading ? (
928 classes={classNames("me-1", {
929 "text-success": featuredCommunity,
933 {I18NextService.i18n.t("community")}
941 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
942 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
943 data-tippy-content={labelLocal}
944 aria-label={labelLocal}
946 {this.state.featureLocalLoading ? (
952 classes={classNames("me-1", {
953 "text-success": featuredLocal,
957 {I18NextService.i18n.t("local")}
967 get modRemoveButton() {
968 const removed = this.postView.post.removed;
971 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
974 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
977 {/* TODO: Find an icon for this. */}
978 {this.state.removeLoading ? (
981 I18NextService.i18n.t("remove")
983 I18NextService.i18n.t("restore")
990 * Mod/Admin actions to be taken against the author.
994 const post_view = this.postView;
996 this.state.showAdvanced && (
997 <div className="mt-3">
1000 {!this.creatorIsMod_ &&
1001 (!post_view.creator_banned_from_community ? (
1003 className="btn btn-link btn-animate text-muted py-0"
1006 this.handleModBanFromCommunityShow
1008 aria-label={I18NextService.i18n.t("ban_from_community")}
1010 {I18NextService.i18n.t("ban_from_community")}
1014 className="btn btn-link btn-animate text-muted py-0"
1017 this.handleModBanFromCommunitySubmit
1019 aria-label={I18NextService.i18n.t("unban")}
1021 {this.state.banLoading ? (
1024 I18NextService.i18n.t("unban")
1028 {!post_view.creator_banned_from_community && (
1030 className="btn btn-link btn-animate text-muted py-0"
1031 onClick={linkEvent(this, this.handleAddModToCommunity)}
1034 ? I18NextService.i18n.t("remove_as_mod")
1035 : I18NextService.i18n.t("appoint_as_mod")
1038 {this.state.addModLoading ? (
1040 ) : this.creatorIsMod_ ? (
1041 I18NextService.i18n.t("remove_as_mod")
1043 I18NextService.i18n.t("appoint_as_mod")
1049 {/* Community creators and admins can transfer community to another mod */}
1050 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1052 this.creatorIsMod_ &&
1053 (!this.state.showConfirmTransferCommunity ? (
1055 className="btn btn-link btn-animate text-muted py-0"
1058 this.handleShowConfirmTransferCommunity
1060 aria-label={I18NextService.i18n.t("transfer_community")}
1062 {I18NextService.i18n.t("transfer_community")}
1067 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1068 aria-label={I18NextService.i18n.t("are_you_sure")}
1070 {I18NextService.i18n.t("are_you_sure")}
1073 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1074 aria-label={I18NextService.i18n.t("yes")}
1075 onClick={linkEvent(this, this.handleTransferCommunity)}
1077 {this.state.transferLoading ? (
1080 I18NextService.i18n.t("yes")
1084 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1087 this.handleCancelShowConfirmTransferCommunity
1089 aria-label={I18NextService.i18n.t("no")}
1091 {I18NextService.i18n.t("no")}
1095 {/* Admins can ban from all, and appoint other admins */}
1096 {this.canAdmin_ && (
1098 {!this.creatorIsAdmin_ && (
1100 {!isBanned(post_view.creator) ? (
1102 className="btn btn-link btn-animate text-muted py-0"
1103 onClick={linkEvent(this, this.handleModBanShow)}
1104 aria-label={I18NextService.i18n.t("ban_from_site")}
1106 {I18NextService.i18n.t("ban_from_site")}
1110 className="btn btn-link btn-animate text-muted py-0"
1111 onClick={linkEvent(this, this.handleModBanSubmit)}
1112 aria-label={I18NextService.i18n.t("unban_from_site")}
1114 {this.state.banLoading ? (
1117 I18NextService.i18n.t("unban_from_site")
1122 className="btn btn-link btn-animate text-muted py-0"
1123 onClick={linkEvent(this, this.handlePurgePersonShow)}
1124 aria-label={I18NextService.i18n.t("purge_user")}
1126 {I18NextService.i18n.t("purge_user")}
1129 className="btn btn-link btn-animate text-muted py-0"
1130 onClick={linkEvent(this, this.handlePurgePostShow)}
1131 aria-label={I18NextService.i18n.t("purge_post")}
1133 {I18NextService.i18n.t("purge_post")}
1137 {!isBanned(post_view.creator) && post_view.creator.local && (
1139 className="btn btn-link btn-animate text-muted py-0"
1140 onClick={linkEvent(this, this.handleAddAdmin)}
1142 this.creatorIsAdmin_
1143 ? I18NextService.i18n.t("remove_as_admin")
1144 : I18NextService.i18n.t("appoint_as_admin")
1147 {this.state.addAdminLoading ? (
1149 ) : this.creatorIsAdmin_ ? (
1150 I18NextService.i18n.t("remove_as_admin")
1152 I18NextService.i18n.t("appoint_as_admin")
1163 removeAndBanDialogs() {
1164 const post = this.postView;
1165 const purgeTypeText =
1166 this.state.purgeType == PurgeType.Post
1167 ? I18NextService.i18n.t("purge_post")
1168 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1171 {this.state.showRemoveDialog && (
1173 className="form-inline"
1174 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1177 className="visually-hidden"
1178 htmlFor="post-listing-remove-reason"
1180 {I18NextService.i18n.t("reason")}
1184 id="post-listing-remove-reason"
1185 className="form-control me-2"
1186 placeholder={I18NextService.i18n.t("reason")}
1187 value={this.state.removeReason}
1188 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1192 className="btn btn-secondary"
1193 aria-label={I18NextService.i18n.t("remove_post")}
1195 {this.state.removeLoading ? (
1198 I18NextService.i18n.t("remove_post")
1203 {this.state.showBanDialog && (
1204 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1205 <div className="mb-3 row col-12">
1207 className="col-form-label"
1208 htmlFor="post-listing-ban-reason"
1210 {I18NextService.i18n.t("reason")}
1214 id="post-listing-ban-reason"
1215 className="form-control me-2"
1216 placeholder={I18NextService.i18n.t("reason")}
1217 value={this.state.banReason}
1218 onInput={linkEvent(this, this.handleModBanReasonChange)}
1220 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1221 {I18NextService.i18n.t("expires")}
1225 id={`mod-ban-expires`}
1226 className="form-control me-2"
1227 placeholder={I18NextService.i18n.t("number_of_days")}
1228 value={this.state.banExpireDays}
1229 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1231 <div className="input-group mb-3">
1232 <div className="form-check">
1234 className="form-check-input"
1235 id="mod-ban-remove-data"
1237 checked={this.state.removeData}
1238 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1241 className="form-check-label"
1242 htmlFor="mod-ban-remove-data"
1243 title={I18NextService.i18n.t("remove_content_more")}
1245 {I18NextService.i18n.t("remove_content")}
1250 {/* TODO hold off on expires until later */}
1251 {/* <div class="mb-3 row"> */}
1252 {/* <label class="col-form-label">Expires</label> */}
1253 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1255 <div className="mb-3 row">
1258 className="btn btn-secondary"
1259 aria-label={I18NextService.i18n.t("ban")}
1261 {this.state.banLoading ? (
1265 {I18NextService.i18n.t("ban")} {post.creator.name}
1272 {this.state.showReportDialog && (
1274 className="form-inline"
1275 onSubmit={linkEvent(this, this.handleReportSubmit)}
1277 <label className="visually-hidden" htmlFor="post-report-reason">
1278 {I18NextService.i18n.t("reason")}
1282 id="post-report-reason"
1283 className="form-control me-2"
1284 placeholder={I18NextService.i18n.t("reason")}
1286 value={this.state.reportReason}
1287 onInput={linkEvent(this, this.handleReportReasonChange)}
1291 className="btn btn-secondary"
1292 aria-label={I18NextService.i18n.t("create_report")}
1294 {this.state.reportLoading ? (
1297 I18NextService.i18n.t("create_report")
1302 {this.state.showPurgeDialog && (
1304 className="form-inline"
1305 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1308 <label className="visually-hidden" htmlFor="purge-reason">
1309 {I18NextService.i18n.t("reason")}
1314 className="form-control me-2"
1315 placeholder={I18NextService.i18n.t("reason")}
1316 value={this.state.purgeReason}
1317 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1319 {this.state.purgeLoading ? (
1324 className="btn btn-secondary"
1325 aria-label={purgeTypeText}
1327 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1337 const post = this.postView.post;
1338 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1339 <div className="row">
1340 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1341 {this.postTitleLine()}
1343 <div className="col-4">
1344 {/* Post thumbnail */}
1345 {!this.state.imageExpanded && this.thumbnail()}
1349 this.postTitleLine()
1354 const { body, id } = this.postView.post;
1356 return !this.showBody && body ? (
1357 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1358 <div className="md-div mb-1 preview-lines">{body}</div>
1368 {/* The mobile view*/}
1369 <div className="d-block d-sm-none">
1370 <article className="row post-container">
1371 <div className="col-12">
1372 {this.createdLine()}
1374 {/* If it has a thumbnail, do a right aligned thumbnail */}
1375 {this.mobileThumbnail()}
1377 {/* Show a preview of the post body */}
1378 {this.showBodyPreview()}
1380 {this.commentsLine(true)}
1381 {this.userActionsLine()}
1382 {this.duplicatesLine()}
1383 {this.removeAndBanDialogs()}
1388 {/* The larger view*/}
1389 <div className="d-none d-sm-block">
1390 <article className="row post-container">
1391 {!this.props.viewOnly && (
1393 voteContentType={VoteContentType.Post}
1394 id={this.postView.post.id}
1395 onVote={this.props.onPostVote}
1396 enableDownvotes={this.props.enableDownvotes}
1397 counts={this.postView.counts}
1398 my_vote={this.postView.my_vote}
1401 <div className="col-sm-2 pe-0 post-media">
1402 <div className="">{this.thumbnail()}</div>
1404 <div className="col-12 col-sm-9">
1405 <div className="row">
1406 <div className="col-12">
1407 {this.postTitleLine()}
1408 {this.createdLine()}
1409 {this.showBodyPreview()}
1410 {this.commentsLine()}
1411 {this.duplicatesLine()}
1412 {this.userActionsLine()}
1413 {this.removeAndBanDialogs()}
1423 private get myPost(): boolean {
1425 this.postView.creator.id ==
1426 UserService.Instance.myUserInfo?.local_user_view.person.id
1429 handleEditClick(i: PostListing) {
1430 i.setState({ showEdit: true });
1433 handleEditCancel() {
1434 this.setState({ showEdit: false });
1437 // The actual editing is done in the receive for post
1438 handleEditPost(form: EditPost) {
1439 this.setState({ showEdit: false });
1440 this.props.onPostEdit(form);
1443 handleShare(i: PostListing) {
1444 const { name, body, id } = i.props.post_view.post;
1447 text: body?.slice(0, 50),
1448 url: `${getHttpBase()}/post/${id}`,
1452 handleShowReportDialog(i: PostListing) {
1453 i.setState({ showReportDialog: !i.state.showReportDialog });
1456 handleReportReasonChange(i: PostListing, event: any) {
1457 i.setState({ reportReason: event.target.value });
1460 handleReportSubmit(i: PostListing, event: any) {
1461 event.preventDefault();
1462 i.setState({ reportLoading: true });
1463 i.props.onPostReport({
1464 post_id: i.postView.post.id,
1465 reason: i.state.reportReason ?? "",
1466 auth: myAuthRequired(),
1470 handleBlockPersonClick(i: PostListing) {
1471 i.setState({ blockLoading: true });
1472 i.props.onBlockPerson({
1473 person_id: i.postView.creator.id,
1475 auth: myAuthRequired(),
1479 handleDeleteClick(i: PostListing) {
1480 i.setState({ deleteLoading: true });
1481 i.props.onDeletePost({
1482 post_id: i.postView.post.id,
1483 deleted: !i.postView.post.deleted,
1484 auth: myAuthRequired(),
1488 handleSavePostClick(i: PostListing) {
1489 i.setState({ saveLoading: true });
1490 i.props.onSavePost({
1491 post_id: i.postView.post.id,
1492 save: !i.postView.saved,
1493 auth: myAuthRequired(),
1497 get crossPostParams(): PostFormParams {
1498 const queryParams: PostFormParams = {};
1499 const { name, url } = this.postView.post;
1501 queryParams.name = name;
1504 queryParams.url = url;
1507 const crossPostBody = this.crossPostBody();
1508 if (crossPostBody) {
1509 queryParams.body = crossPostBody;
1515 crossPostBody(): string | undefined {
1516 const post = this.postView.post;
1517 const body = post.body;
1520 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1522 }\n\n${body.replace(/^/gm, "> ")}`
1526 get showBody(): boolean {
1527 return this.props.showBody || this.state.showBody;
1530 handleModRemoveShow(i: PostListing) {
1532 showRemoveDialog: !i.state.showRemoveDialog,
1533 showBanDialog: false,
1537 handleModRemoveReasonChange(i: PostListing, event: any) {
1538 i.setState({ removeReason: event.target.value });
1541 handleModRemoveDataChange(i: PostListing, event: any) {
1542 i.setState({ removeData: event.target.checked });
1545 handleModRemoveSubmit(i: PostListing, event: any) {
1546 event.preventDefault();
1547 i.setState({ removeLoading: true });
1548 i.props.onRemovePost({
1549 post_id: i.postView.post.id,
1550 removed: !i.postView.post.removed,
1551 auth: myAuthRequired(),
1555 handleModLock(i: PostListing) {
1556 i.setState({ lockLoading: true });
1557 i.props.onLockPost({
1558 post_id: i.postView.post.id,
1559 locked: !i.postView.post.locked,
1560 auth: myAuthRequired(),
1564 handleModFeaturePostLocal(i: PostListing) {
1565 i.setState({ featureLocalLoading: true });
1566 i.props.onFeaturePost({
1567 post_id: i.postView.post.id,
1568 featured: !i.postView.post.featured_local,
1569 feature_type: "Local",
1570 auth: myAuthRequired(),
1574 handleModFeaturePostCommunity(i: PostListing) {
1575 i.setState({ featureCommunityLoading: true });
1576 i.props.onFeaturePost({
1577 post_id: i.postView.post.id,
1578 featured: !i.postView.post.featured_community,
1579 feature_type: "Community",
1580 auth: myAuthRequired(),
1584 handleModBanFromCommunityShow(i: PostListing) {
1586 showBanDialog: true,
1587 banType: BanType.Community,
1588 showRemoveDialog: false,
1592 handleModBanShow(i: PostListing) {
1594 showBanDialog: true,
1595 banType: BanType.Site,
1596 showRemoveDialog: false,
1600 handlePurgePersonShow(i: PostListing) {
1602 showPurgeDialog: true,
1603 purgeType: PurgeType.Person,
1604 showRemoveDialog: false,
1608 handlePurgePostShow(i: PostListing) {
1610 showPurgeDialog: true,
1611 purgeType: PurgeType.Post,
1612 showRemoveDialog: false,
1616 handlePurgeReasonChange(i: PostListing, event: any) {
1617 i.setState({ purgeReason: event.target.value });
1620 handlePurgeSubmit(i: PostListing, event: any) {
1621 event.preventDefault();
1622 i.setState({ purgeLoading: true });
1623 if (i.state.purgeType == PurgeType.Person) {
1624 i.props.onPurgePerson({
1625 person_id: i.postView.creator.id,
1626 reason: i.state.purgeReason,
1627 auth: myAuthRequired(),
1629 } else if (i.state.purgeType == PurgeType.Post) {
1630 i.props.onPurgePost({
1631 post_id: i.postView.post.id,
1632 reason: i.state.purgeReason,
1633 auth: myAuthRequired(),
1638 handleModBanReasonChange(i: PostListing, event: any) {
1639 i.setState({ banReason: event.target.value });
1642 handleModBanExpireDaysChange(i: PostListing, event: any) {
1643 i.setState({ banExpireDays: event.target.value });
1646 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1647 i.setState({ banType: BanType.Community });
1648 i.handleModBanBothSubmit(i, event);
1651 handleModBanSubmit(i: PostListing, event: any) {
1652 i.setState({ banType: BanType.Site });
1653 i.handleModBanBothSubmit(i, event);
1656 handleModBanBothSubmit(i: PostListing, event: any) {
1657 event.preventDefault();
1658 i.setState({ banLoading: true });
1660 const ban = !i.props.post_view.creator_banned_from_community;
1661 // If its an unban, restore all their data
1663 i.setState({ removeData: false });
1665 const person_id = i.props.post_view.creator.id;
1666 const remove_data = i.state.removeData;
1667 const reason = i.state.banReason;
1668 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1670 if (i.state.banType == BanType.Community) {
1671 const community_id = i.postView.community.id;
1672 i.props.onBanPersonFromCommunity({
1679 auth: myAuthRequired(),
1682 i.props.onBanPerson({
1688 auth: myAuthRequired(),
1693 handleAddModToCommunity(i: PostListing) {
1694 i.setState({ addModLoading: true });
1695 i.props.onAddModToCommunity({
1696 community_id: i.postView.community.id,
1697 person_id: i.postView.creator.id,
1698 added: !i.creatorIsMod_,
1699 auth: myAuthRequired(),
1703 handleAddAdmin(i: PostListing) {
1704 i.setState({ addAdminLoading: true });
1705 i.props.onAddAdmin({
1706 person_id: i.postView.creator.id,
1707 added: !i.creatorIsAdmin_,
1708 auth: myAuthRequired(),
1712 handleShowConfirmTransferCommunity(i: PostListing) {
1713 i.setState({ showConfirmTransferCommunity: true });
1716 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1717 i.setState({ showConfirmTransferCommunity: false });
1720 handleTransferCommunity(i: PostListing) {
1721 i.setState({ transferLoading: true });
1722 i.props.onTransferCommunity({
1723 community_id: i.postView.community.id,
1724 person_id: i.postView.creator.id,
1725 auth: myAuthRequired(),
1729 handleShowConfirmTransferSite(i: PostListing) {
1730 i.setState({ showConfirmTransferSite: true });
1733 handleCancelShowConfirmTransferSite(i: PostListing) {
1734 i.setState({ showConfirmTransferSite: false });
1737 handleImageExpandClick(i: PostListing, event: any) {
1738 event.preventDefault();
1739 i.setState({ imageExpanded: !i.state.imageExpanded });
1743 handleViewSource(i: PostListing) {
1744 i.setState({ viewSource: !i.state.viewSource });
1747 handleShowAdvanced(i: PostListing) {
1748 i.setState({ showAdvanced: !i.state.showAdvanced });
1752 handleShowMoreMobile(i: PostListing) {
1754 showMoreMobile: !i.state.showMoreMobile,
1755 showAdvanced: !i.state.showAdvanced,
1760 handleShowBody(i: PostListing) {
1761 i.setState({ showBody: !i.state.showBody });
1765 get pointsTippy(): string {
1766 const points = I18NextService.i18n.t("number_of_points", {
1767 count: Number(this.postView.counts.score),
1768 formattedCount: Number(this.postView.counts.score),
1771 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1772 count: Number(this.postView.counts.upvotes),
1773 formattedCount: Number(this.postView.counts.upvotes),
1776 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1777 count: Number(this.postView.counts.downvotes),
1778 formattedCount: Number(this.postView.counts.downvotes),
1781 return `${points} • ${upvotes} • ${downvotes}`;
1784 get canModOnSelf_(): boolean {
1786 this.postView.creator.id,
1787 this.props.moderators,
1794 get canMod_(): boolean {
1796 this.postView.creator.id,
1797 this.props.moderators,
1802 get canAdmin_(): boolean {
1803 return canAdmin(this.postView.creator.id, this.props.admins);
1806 get creatorIsMod_(): boolean {
1807 return isMod(this.postView.creator.id, this.props.moderators);
1810 get creatorIsAdmin_(): boolean {
1811 return isAdmin(this.postView.creator.id, this.props.admins);