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 { 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;
109 * Controls whether to show both the body *and* the metadata preview card
113 enableDownvotes?: boolean;
114 enableNsfw?: boolean;
116 onPostEdit(form: EditPost): void;
117 onPostVote(form: CreatePostLike): void;
118 onPostReport(form: CreatePostReport): void;
119 onBlockPerson(form: BlockPerson): void;
120 onLockPost(form: LockPost): void;
121 onDeletePost(form: DeletePost): void;
122 onRemovePost(form: RemovePost): void;
123 onSavePost(form: SavePost): void;
124 onFeaturePost(form: FeaturePost): void;
125 onPurgePerson(form: PurgePerson): void;
126 onPurgePost(form: PurgePost): void;
127 onBanPersonFromCommunity(form: BanFromCommunity): void;
128 onBanPerson(form: BanPerson): void;
129 onAddModToCommunity(form: AddModToCommunity): void;
130 onAddAdmin(form: AddAdmin): void;
131 onTransferCommunity(form: TransferCommunity): void;
134 export class PostListing extends Component<PostListingProps, PostListingState> {
135 state: PostListingState = {
137 showRemoveDialog: false,
138 showPurgeDialog: false,
139 purgeType: PurgeType.Person,
140 showBanDialog: false,
141 banType: BanType.Community,
143 showConfirmTransferSite: false,
144 showConfirmTransferCommunity: false,
145 imageExpanded: false,
148 showMoreMobile: false,
150 showReportDialog: false,
152 reportLoading: false,
155 deleteLoading: false,
156 removeLoading: false,
158 featureCommunityLoading: false,
159 featureLocalLoading: false,
161 addModLoading: false,
162 addAdminLoading: false,
163 transferLoading: false,
166 constructor(props: any, context: any) {
167 super(props, context);
169 this.handleEditPost = this.handleEditPost.bind(this);
170 this.handleEditCancel = this.handleEditCancel.bind(this);
173 componentWillReceiveProps(nextProps: PostListingProps) {
174 if (this.props !== nextProps) {
177 reportLoading: false,
180 deleteLoading: false,
181 removeLoading: false,
183 featureCommunityLoading: false,
184 featureLocalLoading: false,
186 addModLoading: false,
187 addAdminLoading: false,
188 transferLoading: false,
193 get postView(): PostView {
194 return this.props.post_view;
198 const post = this.postView.post;
201 <div className="post-listing mt-2">
202 {!this.state.showEdit ? (
205 {this.state.imageExpanded && !this.props.hideImage && this.img}
206 {this.showBody && post.url && post.embed_title && (
207 <MetadataCard post={post} />
209 {this.showBody && this.body()}
213 post_view={this.postView}
214 crossPosts={this.props.crossPosts}
215 onEdit={this.handleEditPost}
216 onCancel={this.handleEditCancel}
217 enableNsfw={this.props.enableNsfw}
218 enableDownvotes={this.props.enableDownvotes}
219 allLanguages={this.props.allLanguages}
220 siteLanguages={this.props.siteLanguages}
228 const body = this.postView.post.body;
230 <article id="postContent" className="col-12 card my-2 p-2">
231 {this.state.viewSource ? (
234 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
246 <div className="offset-sm-3 my-2 d-none d-sm-block">
247 <a href={this.imageSrc} className="d-inline-block">
248 <PictrsImage src={this.imageSrc} />
251 <div className="my-2 d-block d-sm-none">
254 className="p-0 border-0 bg-transparent d-inline-block"
255 onClick={linkEvent(this, this.handleImageExpandClick)}
257 <PictrsImage src={this.imageSrc} />
264 const { post } = this.postView;
265 const { url } = post;
267 // if direct video link
268 if (url && isVideo(url)) {
270 <div className="embed-responsive mt-3">
271 <video muted controls className="embed-responsive-item col-12">
272 <source src={url} type="video/mp4" />
278 // if embedded video link
279 if (url && post.embed_video_url) {
281 <div className="ratio ratio-16x9">
284 className="post-metadata-iframe"
285 src={post.embed_video_url}
286 title={post.embed_title}
295 imgThumb(src: string) {
296 const post_view = this.postView;
302 nsfw={post_view.post.nsfw || post_view.community.nsfw}
307 get imageSrc(): string | undefined {
308 const post = this.postView.post;
309 const url = post.url;
310 const thumbnail = post.thumbnail_url;
312 if (url && isImage(url)) {
313 if (url.includes("pictrs")) {
315 } else if (thumbnail) {
320 } else if (thumbnail) {
328 const post = this.postView.post;
329 const url = post.url;
330 const thumbnail = post.thumbnail_url;
332 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
336 className="text-body d-inline-block position-relative mb-2"
337 data-tippy-content={I18NextService.i18n.t("expand_here")}
338 onClick={linkEvent(this, this.handleImageExpandClick)}
339 aria-label={I18NextService.i18n.t("expand_here")}
341 {this.imgThumb(this.imageSrc)}
342 <Icon icon="image" classes="mini-overlay" />
345 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
348 className="text-body d-inline-block position-relative mb-2"
353 {this.imgThumb(this.imageSrc)}
354 <Icon icon="external-link" classes="mini-overlay" />
358 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
361 className="text-body"
365 data-tippy-content={I18NextService.i18n.t("expand_here")}
366 onClick={linkEvent(this, this.handleImageExpandClick)}
367 aria-label={I18NextService.i18n.t("expand_here")}
369 <div className="thumbnail rounded bg-light d-flex justify-content-center">
370 <Icon icon="play" classes="d-flex align-items-center" />
376 <a className="text-body" href={url} title={url} rel={relTags}>
377 <div className="thumbnail rounded bg-light d-flex justify-content-center">
378 <Icon icon="external-link" classes="d-flex align-items-center" />
386 className="text-body"
387 to={`/post/${post.id}`}
388 title={I18NextService.i18n.t("comments")}
390 <div className="thumbnail rounded bg-light d-flex justify-content-center">
391 <Icon icon="message-square" classes="d-flex align-items-center" />
399 const post_view = this.postView;
401 <span className="small">
402 <PersonListing person={post_view.creator} />
403 {this.creatorIsMod_ && (
404 <span className="mx-1 badge text-bg-light">
405 {I18NextService.i18n.t("mod")}
408 {this.creatorIsAdmin_ && (
409 <span className="mx-1 badge text-bg-light">
410 {I18NextService.i18n.t("admin")}
413 {post_view.creator.bot_account && (
414 <span className="mx-1 badge text-bg-light">
415 {I18NextService.i18n.t("bot_account").toLowerCase()}
418 {this.props.showCommunity && (
421 {I18NextService.i18n.t("to")}{" "}
422 <CommunityLink community={post_view.community} />
425 {post_view.post.language_id !== 0 && (
426 <span className="mx-1 badge text-bg-light">
428 this.props.allLanguages.find(
429 lang => lang.id === post_view.post.language_id
436 published={post_view.post.published}
437 updated={post_view.post.updated}
444 const post = this.postView.post;
447 className={`d-inline ${
448 !post.featured_community && !post.featured_local
452 to={`/post/${post.id}`}
453 title={I18NextService.i18n.t("comments")}
457 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
464 const post = this.postView.post;
465 const url = post.url;
469 <div className="post-title overflow-hidden">
470 <h5 className="d-inline">
471 {url && this.props.showBody ? (
474 !post.featured_community && !post.featured_local
481 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
489 * If there is a URL, an embed title, and we were not told to show the
490 * body by the parent component, show the MetadataCard/body toggle.
492 {!this.props.showBody &&
495 this.showPreviewButton()}
498 <small className="ms-2 badge text-bg-secondary">
499 {I18NextService.i18n.t("removed")}
505 className="unselectable pointer ms-2 text-muted fst-italic"
506 data-tippy-content={I18NextService.i18n.t("deleted")}
508 <Icon icon="trash" classes="icon-inline text-danger" />
514 className="unselectable pointer ms-2 text-muted fst-italic"
515 data-tippy-content={I18NextService.i18n.t("locked")}
517 <Icon icon="lock" classes="icon-inline text-danger" />
521 {post.featured_community && (
523 className="unselectable pointer ms-2 text-muted fst-italic"
524 data-tippy-content={I18NextService.i18n.t(
525 "featured_in_community"
527 aria-label={I18NextService.i18n.t("featured_in_community")}
529 <Icon icon="pin" classes="icon-inline text-primary" />
533 {post.featured_local && (
535 className="unselectable pointer ms-2 text-muted fst-italic"
536 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
537 aria-label={I18NextService.i18n.t("featured_in_local")}
539 <Icon icon="pin" classes="icon-inline text-secondary" />
544 <small className="ms-2 badge text-bg-danger">
545 {I18NextService.i18n.t("nsfw")}
549 {url && this.urlLine()}
555 const post = this.postView.post;
556 const url = post.url;
559 <p className="small m-0">
560 {url && !(hostname(url) === getExternalHost()) && (
562 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
575 const dupes = this.props.crossPosts;
576 return dupes && dupes.length > 0 ? (
577 <ul className="list-inline mb-1 small text-muted">
579 <li className="list-inline-item me-2">
580 {I18NextService.i18n.t("cross_posted_to")}
583 <li key={pv.post.id} className="list-inline-item me-2">
584 <Link to={`/post/${pv.post.id}`}>
587 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
598 commentsLine(mobile = false) {
599 const post = this.postView.post;
602 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
603 {this.commentsButton}
606 className="btn btn-sm btn-animate text-muted py-0"
607 onClick={linkEvent(this, this.handleShare)}
610 <Icon icon="share" inline />
615 className="btn btn-sm btn-animate text-muted py-0"
616 title={I18NextService.i18n.t("link")}
619 <Icon icon="fedilink" inline />
622 {mobile && !this.props.viewOnly && (
624 voteContentType={VoteContentType.Post}
625 id={this.postView.post.id}
626 onVote={this.props.onPostVote}
627 enableDownvotes={this.props.enableDownvotes}
628 counts={this.postView.counts}
629 my_vote={this.postView.my_vote}
632 {UserService.Instance.myUserInfo &&
633 !this.props.viewOnly &&
640 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
641 // Possible enhancement: Make each button a component.
642 const post_view = this.postView;
643 const post = post_view.post;
648 {this.crossPostButton}
650 {this.props.showBody && post_view.post.body && this.viewSourceButton}
652 <div className="dropdown">
654 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
655 onClick={linkEvent(this, this.handleShowAdvanced)}
656 data-tippy-content={I18NextService.i18n.t("more")}
657 data-bs-toggle="dropdown"
658 aria-expanded="false"
659 aria-controls={`advancedButtonsDropdown${post.id}`}
660 aria-label={I18NextService.i18n.t("more")}
662 <Icon icon="more-vertical" inline />
666 className="dropdown-menu"
667 id={`advancedButtonsDropdown${post.id}`}
671 <li>{this.reportButton}</li>
672 <li>{this.blockButton}</li>
676 <li>{this.editButton}</li>
677 <li>{this.deleteButton}</li>
681 {/* Any mod can do these, not limited to hierarchy*/}
682 {(amMod(this.props.moderators) || amAdmin()) && (
685 <hr className="dropdown-divider" />
687 <li>{this.lockButton}</li>
688 {this.featureButtons}
692 {(this.canMod_ || this.canAdmin_) && (
693 <li>{this.modRemoveButton}</li>
701 get commentsButton() {
702 const post_view = this.postView;
703 const title = I18NextService.i18n.t("number_of_comments", {
704 count: Number(post_view.counts.comments),
705 formattedCount: Number(post_view.counts.comments),
710 className="btn btn-link btn-sm text-muted ps-0"
712 to={`/post/${post_view.post.id}?scrollToComments=true`}
713 data-tippy-content={title}
715 <Icon icon="message-square" classes="me-1" inline />
716 {post_view.counts.comments}
717 {this.unreadCount && (
720 <span className="fst-italic">
721 ({this.unreadCount} {I18NextService.i18n.t("new")})
729 get unreadCount(): number | undefined {
730 const pv = this.postView;
731 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
733 : pv.unread_comments;
737 const saved = this.postView.saved;
739 ? I18NextService.i18n.t("unsave")
740 : I18NextService.i18n.t("save");
743 className="btn btn-sm btn-animate text-muted py-0"
744 onClick={linkEvent(this, this.handleSavePostClick)}
745 data-tippy-content={label}
748 {this.state.saveLoading ? (
753 classes={classNames({ "text-warning": saved })}
761 get crossPostButton() {
764 className="btn btn-sm btn-animate text-muted py-0"
766 /* Empty string properties are required to satisfy type*/
767 pathname: "/create_post",
768 state: { ...this.crossPostParams },
773 title={I18NextService.i18n.t("cross_post")}
774 data-tippy-content={I18NextService.i18n.t("cross_post")}
775 aria-label={I18NextService.i18n.t("cross_post")}
777 <Icon icon="copy" inline />
785 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
786 onClick={linkEvent(this, this.handleShowReportDialog)}
787 aria-label={I18NextService.i18n.t("show_report_dialog")}
789 <Icon classes="me-1" icon="flag" inline />
790 {I18NextService.i18n.t("create_report")}
798 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
799 onClick={linkEvent(this, this.handleBlockPersonClick)}
800 aria-label={I18NextService.i18n.t("block_user")}
802 {this.state.blockLoading ? (
805 <Icon classes="me-1" icon="slash" inline />
807 {I18NextService.i18n.t("block_user")}
815 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
816 onClick={linkEvent(this, this.handleEditClick)}
817 aria-label={I18NextService.i18n.t("edit")}
819 <Icon classes="me-1" icon="edit" inline />
820 {I18NextService.i18n.t("edit")}
826 const deleted = this.postView.post.deleted;
827 const label = !deleted
828 ? I18NextService.i18n.t("delete")
829 : I18NextService.i18n.t("restore");
832 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
833 onClick={linkEvent(this, this.handleDeleteClick)}
835 {this.state.deleteLoading ? (
841 classes={classNames("me-1", { "text-danger": deleted })}
851 get viewSourceButton() {
854 className="btn btn-sm btn-animate text-muted py-0"
855 onClick={linkEvent(this, this.handleViewSource)}
856 data-tippy-content={I18NextService.i18n.t("view_source")}
857 aria-label={I18NextService.i18n.t("view_source")}
861 classes={classNames({ "text-success": this.state.viewSource })}
869 const locked = this.postView.post.locked;
871 ? I18NextService.i18n.t("unlock")
872 : I18NextService.i18n.t("lock");
875 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
876 onClick={linkEvent(this, this.handleModLock)}
879 {this.state.lockLoading ? (
885 classes={classNames("me-1", { "text-danger": locked })}
888 {capitalizeFirstLetter(label)}
895 get featureButtons() {
896 const featuredCommunity = this.postView.post.featured_community;
897 const labelCommunity = featuredCommunity
898 ? I18NextService.i18n.t("unfeature_from_community")
899 : I18NextService.i18n.t("feature_in_community");
901 const featuredLocal = this.postView.post.featured_local;
902 const labelLocal = featuredLocal
903 ? I18NextService.i18n.t("unfeature_from_local")
904 : I18NextService.i18n.t("feature_in_local");
909 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
910 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
911 data-tippy-content={labelCommunity}
912 aria-label={labelCommunity}
914 {this.state.featureCommunityLoading ? (
920 classes={classNames("me-1", {
921 "text-success": featuredCommunity,
925 {I18NextService.i18n.t("community")}
933 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
934 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
935 data-tippy-content={labelLocal}
936 aria-label={labelLocal}
938 {this.state.featureLocalLoading ? (
944 classes={classNames("me-1", {
945 "text-success": featuredLocal,
949 {I18NextService.i18n.t("local")}
959 get modBanFromCommunityButton() {
962 className="btn btn-link btn-animate text-muted py-0"
963 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
964 aria-label={I18NextService.i18n.t("ban_from_community")}
966 {I18NextService.i18n.t("ban_from_community")}
971 get modUnbanFromCommunityButton() {
974 className="btn btn-link btn-animate text-muted py-0"
975 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
976 aria-label={I18NextService.i18n.t("unban")}
978 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
983 get addModToCommunityButton() {
986 className="btn btn-link btn-animate text-muted py-0"
987 onClick={linkEvent(this, this.handleAddModToCommunity)}
990 ? I18NextService.i18n.t("remove_as_mod")
991 : I18NextService.i18n.t("appoint_as_mod")
994 {this.state.addModLoading ? (
996 ) : this.creatorIsMod_ ? (
997 I18NextService.i18n.t("remove_as_mod")
999 I18NextService.i18n.t("appoint_as_mod")
1005 get modBanButton() {
1008 className="btn btn-link btn-animate text-muted py-0"
1009 onClick={linkEvent(this, this.handleModBanShow)}
1010 aria-label={I18NextService.i18n.t("ban_from_site")}
1012 {I18NextService.i18n.t("ban_from_site")}
1017 get modUnbanButton() {
1020 className="btn btn-link btn-animate text-muted py-0"
1021 onClick={linkEvent(this, this.handleModBanSubmit)}
1022 aria-label={I18NextService.i18n.t("unban_from_site")}
1024 {this.state.banLoading ? (
1027 I18NextService.i18n.t("unban_from_site")
1033 get purgePersonButton() {
1036 className="btn btn-link btn-animate text-muted py-0"
1037 onClick={linkEvent(this, this.handlePurgePersonShow)}
1038 aria-label={I18NextService.i18n.t("purge_user")}
1040 {I18NextService.i18n.t("purge_user")}
1045 get purgePostButton() {
1048 className="btn btn-link btn-animate text-muted py-0"
1049 onClick={linkEvent(this, this.handlePurgePostShow)}
1050 aria-label={I18NextService.i18n.t("purge_post")}
1052 {I18NextService.i18n.t("purge_post")}
1057 get toggleAdminButton() {
1060 className="btn btn-link btn-animate text-muted py-0"
1061 onClick={linkEvent(this, this.handleAddAdmin)}
1063 {this.state.addAdminLoading ? (
1065 ) : this.creatorIsAdmin_ ? (
1066 I18NextService.i18n.t("remove_as_admin")
1068 I18NextService.i18n.t("appoint_as_admin")
1074 get modRemoveButton() {
1075 const removed = this.postView.post.removed;
1078 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1081 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1084 {/* TODO: Find an icon for this. */}
1085 {this.state.removeLoading ? (
1088 I18NextService.i18n.t("remove")
1090 I18NextService.i18n.t("restore")
1097 * Mod/Admin actions to be taken against the author.
1101 const post_view = this.postView;
1103 this.state.showAdvanced && (
1104 <div className="mt-3">
1107 {!this.creatorIsMod_ &&
1108 (!post_view.creator_banned_from_community
1109 ? this.modBanFromCommunityButton
1110 : this.modUnbanFromCommunityButton)}
1111 {!post_view.creator_banned_from_community &&
1112 this.addModToCommunityButton}
1116 {/* Community creators and admins can transfer community to another mod */}
1117 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1119 this.creatorIsMod_ &&
1120 (!this.state.showConfirmTransferCommunity ? (
1122 className="btn btn-link btn-animate text-muted py-0"
1125 this.handleShowConfirmTransferCommunity
1127 aria-label={I18NextService.i18n.t("transfer_community")}
1129 {I18NextService.i18n.t("transfer_community")}
1134 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1135 aria-label={I18NextService.i18n.t("are_you_sure")}
1137 {I18NextService.i18n.t("are_you_sure")}
1140 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1141 aria-label={I18NextService.i18n.t("yes")}
1142 onClick={linkEvent(this, this.handleTransferCommunity)}
1144 {this.state.transferLoading ? (
1147 I18NextService.i18n.t("yes")
1151 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1154 this.handleCancelShowConfirmTransferCommunity
1156 aria-label={I18NextService.i18n.t("no")}
1158 {I18NextService.i18n.t("no")}
1162 {/* Admins can ban from all, and appoint other admins */}
1163 {this.canAdmin_ && (
1165 {!this.creatorIsAdmin_ && (
1167 {!isBanned(post_view.creator)
1169 : this.modUnbanButton}
1170 {this.purgePersonButton}
1171 {this.purgePostButton}
1174 {!isBanned(post_view.creator) &&
1175 post_view.creator.local &&
1176 this.toggleAdminButton}
1184 removeAndBanDialogs() {
1185 const post = this.postView;
1186 const purgeTypeText =
1187 this.state.purgeType == PurgeType.Post
1188 ? I18NextService.i18n.t("purge_post")
1189 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1192 {this.state.showRemoveDialog && (
1194 className="form-inline"
1195 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1198 className="visually-hidden"
1199 htmlFor="post-listing-remove-reason"
1201 {I18NextService.i18n.t("reason")}
1205 id="post-listing-remove-reason"
1206 className="form-control me-2"
1207 placeholder={I18NextService.i18n.t("reason")}
1208 value={this.state.removeReason}
1209 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1213 className="btn btn-secondary"
1214 aria-label={I18NextService.i18n.t("remove_post")}
1216 {this.state.removeLoading ? (
1219 I18NextService.i18n.t("remove_post")
1224 {this.state.showBanDialog && (
1225 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1226 <div className="mb-3 row col-12">
1228 className="col-form-label"
1229 htmlFor="post-listing-ban-reason"
1231 {I18NextService.i18n.t("reason")}
1235 id="post-listing-ban-reason"
1236 className="form-control me-2"
1237 placeholder={I18NextService.i18n.t("reason")}
1238 value={this.state.banReason}
1239 onInput={linkEvent(this, this.handleModBanReasonChange)}
1241 <label className="col-form-label" htmlFor="mod-ban-expires">
1242 {I18NextService.i18n.t("expires")}
1246 id="mod-ban-expires"
1247 className="form-control me-2"
1248 placeholder={I18NextService.i18n.t("number_of_days")}
1249 value={this.state.banExpireDays}
1250 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1252 <div className="input-group mb-3">
1253 <div className="form-check">
1255 className="form-check-input"
1256 id="mod-ban-remove-data"
1258 checked={this.state.removeData}
1259 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1262 className="form-check-label"
1263 htmlFor="mod-ban-remove-data"
1264 title={I18NextService.i18n.t("remove_content_more")}
1266 {I18NextService.i18n.t("remove_content")}
1271 {/* TODO hold off on expires until later */}
1272 {/* <div class="mb-3 row"> */}
1273 {/* <label class="col-form-label">Expires</label> */}
1274 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1276 <div className="mb-3 row">
1279 className="btn btn-secondary"
1280 aria-label={I18NextService.i18n.t("ban")}
1282 {this.state.banLoading ? (
1286 {I18NextService.i18n.t("ban")} {post.creator.name}
1293 {this.state.showReportDialog && (
1295 className="form-inline"
1296 onSubmit={linkEvent(this, this.handleReportSubmit)}
1298 <label className="visually-hidden" htmlFor="post-report-reason">
1299 {I18NextService.i18n.t("reason")}
1303 id="post-report-reason"
1304 className="form-control me-2"
1305 placeholder={I18NextService.i18n.t("reason")}
1307 value={this.state.reportReason}
1308 onInput={linkEvent(this, this.handleReportReasonChange)}
1312 className="btn btn-secondary"
1313 aria-label={I18NextService.i18n.t("create_report")}
1315 {this.state.reportLoading ? (
1318 I18NextService.i18n.t("create_report")
1323 {this.state.showPurgeDialog && (
1325 className="form-inline"
1326 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1329 <label className="visually-hidden" htmlFor="purge-reason">
1330 {I18NextService.i18n.t("reason")}
1335 className="form-control me-2"
1336 placeholder={I18NextService.i18n.t("reason")}
1337 value={this.state.purgeReason}
1338 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1340 {this.state.purgeLoading ? (
1345 className="btn btn-secondary"
1346 aria-label={purgeTypeText}
1348 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1358 const post = this.postView.post;
1359 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1360 <div className="row">
1361 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1362 {this.postTitleLine()}
1364 <div className="col-4">
1365 {/* Post thumbnail */}
1366 {!this.state.imageExpanded && this.thumbnail()}
1370 this.postTitleLine()
1374 showPreviewButton() {
1378 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1379 onClick={linkEvent(this, this.handleShowBody)}
1382 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1383 classes="icon-inline"
1392 {/* The mobile view*/}
1393 <div className="d-block d-sm-none">
1394 <article className="row post-container">
1395 <div className="col-12">
1396 {this.createdLine()}
1398 {/* If it has a thumbnail, do a right aligned thumbnail */}
1399 {this.mobileThumbnail()}
1401 {this.commentsLine(true)}
1402 {this.userActionsLine()}
1403 {this.duplicatesLine()}
1404 {this.removeAndBanDialogs()}
1409 {/* The larger view*/}
1410 <div className="d-none d-sm-block">
1411 <article className="row post-container">
1412 {!this.props.viewOnly && (
1413 <div className="col flex-grow-0">
1415 voteContentType={VoteContentType.Post}
1416 id={this.postView.post.id}
1417 onVote={this.props.onPostVote}
1418 enableDownvotes={this.props.enableDownvotes}
1419 counts={this.postView.counts}
1420 my_vote={this.postView.my_vote}
1424 <div className="col flex-grow-1">
1425 <div className="row">
1426 <div className="col-sm-3 col-lg-2 pe-0 post-media">
1427 <div className="">{this.thumbnail()}</div>
1429 <div className="col-12 col-sm-9 col-lg-10">
1430 {this.postTitleLine()}
1431 {this.createdLine()}
1432 {this.commentsLine()}
1433 {this.duplicatesLine()}
1434 {this.userActionsLine()}
1435 {this.removeAndBanDialogs()}
1445 private get myPost(): boolean {
1447 this.postView.creator.id ==
1448 UserService.Instance.myUserInfo?.local_user_view.person.id
1451 handleEditClick(i: PostListing) {
1452 i.setState({ showEdit: true });
1455 handleEditCancel() {
1456 this.setState({ showEdit: false });
1459 // The actual editing is done in the receive for post
1460 handleEditPost(form: EditPost) {
1461 this.setState({ showEdit: false });
1462 this.props.onPostEdit(form);
1465 handleShare(i: PostListing) {
1466 const { name, body, id } = i.props.post_view.post;
1469 text: body?.slice(0, 50),
1470 url: `${getHttpBase()}/post/${id}`,
1474 handleShowReportDialog(i: PostListing) {
1475 i.setState({ showReportDialog: !i.state.showReportDialog });
1478 handleReportReasonChange(i: PostListing, event: any) {
1479 i.setState({ reportReason: event.target.value });
1482 handleReportSubmit(i: PostListing, event: any) {
1483 event.preventDefault();
1484 i.setState({ reportLoading: true });
1485 i.props.onPostReport({
1486 post_id: i.postView.post.id,
1487 reason: i.state.reportReason ?? "",
1488 auth: myAuthRequired(),
1492 handleBlockPersonClick(i: PostListing) {
1493 i.setState({ blockLoading: true });
1494 i.props.onBlockPerson({
1495 person_id: i.postView.creator.id,
1497 auth: myAuthRequired(),
1501 handleDeleteClick(i: PostListing) {
1502 i.setState({ deleteLoading: true });
1503 i.props.onDeletePost({
1504 post_id: i.postView.post.id,
1505 deleted: !i.postView.post.deleted,
1506 auth: myAuthRequired(),
1510 handleSavePostClick(i: PostListing) {
1511 i.setState({ saveLoading: true });
1512 i.props.onSavePost({
1513 post_id: i.postView.post.id,
1514 save: !i.postView.saved,
1515 auth: myAuthRequired(),
1519 get crossPostParams(): PostFormParams {
1520 const queryParams: PostFormParams = {};
1521 const { name, url } = this.postView.post;
1523 queryParams.name = name;
1526 queryParams.url = url;
1529 const crossPostBody = this.crossPostBody();
1530 if (crossPostBody) {
1531 queryParams.body = crossPostBody;
1537 crossPostBody(): string | undefined {
1538 const post = this.postView.post;
1539 const body = post.body;
1542 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1544 }\n\n${body.replace(/^/gm, "> ")}`
1548 get showBody(): boolean {
1549 return this.props.showBody || this.state.showBody;
1552 handleModRemoveShow(i: PostListing) {
1554 showRemoveDialog: !i.state.showRemoveDialog,
1555 showBanDialog: false,
1559 handleModRemoveReasonChange(i: PostListing, event: any) {
1560 i.setState({ removeReason: event.target.value });
1563 handleModRemoveDataChange(i: PostListing, event: any) {
1564 i.setState({ removeData: event.target.checked });
1567 handleModRemoveSubmit(i: PostListing, event: any) {
1568 event.preventDefault();
1569 i.setState({ removeLoading: true });
1570 i.props.onRemovePost({
1571 post_id: i.postView.post.id,
1572 removed: !i.postView.post.removed,
1573 auth: myAuthRequired(),
1577 handleModLock(i: PostListing) {
1578 i.setState({ lockLoading: true });
1579 i.props.onLockPost({
1580 post_id: i.postView.post.id,
1581 locked: !i.postView.post.locked,
1582 auth: myAuthRequired(),
1586 handleModFeaturePostLocal(i: PostListing) {
1587 i.setState({ featureLocalLoading: true });
1588 i.props.onFeaturePost({
1589 post_id: i.postView.post.id,
1590 featured: !i.postView.post.featured_local,
1591 feature_type: "Local",
1592 auth: myAuthRequired(),
1596 handleModFeaturePostCommunity(i: PostListing) {
1597 i.setState({ featureCommunityLoading: true });
1598 i.props.onFeaturePost({
1599 post_id: i.postView.post.id,
1600 featured: !i.postView.post.featured_community,
1601 feature_type: "Community",
1602 auth: myAuthRequired(),
1606 handleModBanFromCommunityShow(i: PostListing) {
1608 showBanDialog: true,
1609 banType: BanType.Community,
1610 showRemoveDialog: false,
1614 handleModBanShow(i: PostListing) {
1616 showBanDialog: true,
1617 banType: BanType.Site,
1618 showRemoveDialog: false,
1622 handlePurgePersonShow(i: PostListing) {
1624 showPurgeDialog: true,
1625 purgeType: PurgeType.Person,
1626 showRemoveDialog: false,
1630 handlePurgePostShow(i: PostListing) {
1632 showPurgeDialog: true,
1633 purgeType: PurgeType.Post,
1634 showRemoveDialog: false,
1638 handlePurgeReasonChange(i: PostListing, event: any) {
1639 i.setState({ purgeReason: event.target.value });
1642 handlePurgeSubmit(i: PostListing, event: any) {
1643 event.preventDefault();
1644 i.setState({ purgeLoading: true });
1645 if (i.state.purgeType == PurgeType.Person) {
1646 i.props.onPurgePerson({
1647 person_id: i.postView.creator.id,
1648 reason: i.state.purgeReason,
1649 auth: myAuthRequired(),
1651 } else if (i.state.purgeType == PurgeType.Post) {
1652 i.props.onPurgePost({
1653 post_id: i.postView.post.id,
1654 reason: i.state.purgeReason,
1655 auth: myAuthRequired(),
1660 handleModBanReasonChange(i: PostListing, event: any) {
1661 i.setState({ banReason: event.target.value });
1664 handleModBanExpireDaysChange(i: PostListing, event: any) {
1665 i.setState({ banExpireDays: event.target.value });
1668 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1669 i.setState({ banType: BanType.Community });
1670 i.handleModBanBothSubmit(i, event);
1673 handleModBanSubmit(i: PostListing, event: any) {
1674 i.setState({ banType: BanType.Site });
1675 i.handleModBanBothSubmit(i, event);
1678 handleModBanBothSubmit(i: PostListing, event: any) {
1679 event.preventDefault();
1680 i.setState({ banLoading: true });
1682 const ban = !i.props.post_view.creator_banned_from_community;
1683 // If its an unban, restore all their data
1685 i.setState({ removeData: false });
1687 const person_id = i.props.post_view.creator.id;
1688 const remove_data = i.state.removeData;
1689 const reason = i.state.banReason;
1690 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1692 if (i.state.banType == BanType.Community) {
1693 const community_id = i.postView.community.id;
1694 i.props.onBanPersonFromCommunity({
1701 auth: myAuthRequired(),
1704 i.props.onBanPerson({
1710 auth: myAuthRequired(),
1715 handleAddModToCommunity(i: PostListing) {
1716 i.setState({ addModLoading: true });
1717 i.props.onAddModToCommunity({
1718 community_id: i.postView.community.id,
1719 person_id: i.postView.creator.id,
1720 added: !i.creatorIsMod_,
1721 auth: myAuthRequired(),
1725 handleAddAdmin(i: PostListing) {
1726 i.setState({ addAdminLoading: true });
1727 i.props.onAddAdmin({
1728 person_id: i.postView.creator.id,
1729 added: !i.creatorIsAdmin_,
1730 auth: myAuthRequired(),
1734 handleShowConfirmTransferCommunity(i: PostListing) {
1735 i.setState({ showConfirmTransferCommunity: true });
1738 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1739 i.setState({ showConfirmTransferCommunity: false });
1742 handleTransferCommunity(i: PostListing) {
1743 i.setState({ transferLoading: true });
1744 i.props.onTransferCommunity({
1745 community_id: i.postView.community.id,
1746 person_id: i.postView.creator.id,
1747 auth: myAuthRequired(),
1751 handleShowConfirmTransferSite(i: PostListing) {
1752 i.setState({ showConfirmTransferSite: true });
1755 handleCancelShowConfirmTransferSite(i: PostListing) {
1756 i.setState({ showConfirmTransferSite: false });
1759 handleImageExpandClick(i: PostListing, event: any) {
1760 event.preventDefault();
1761 i.setState({ imageExpanded: !i.state.imageExpanded });
1765 handleViewSource(i: PostListing) {
1766 i.setState({ viewSource: !i.state.viewSource });
1769 handleShowAdvanced(i: PostListing) {
1770 i.setState({ showAdvanced: !i.state.showAdvanced });
1774 handleShowMoreMobile(i: PostListing) {
1776 showMoreMobile: !i.state.showMoreMobile,
1777 showAdvanced: !i.state.showAdvanced,
1782 handleShowBody(i: PostListing) {
1783 i.setState({ showBody: !i.state.showBody });
1787 get pointsTippy(): string {
1788 const points = I18NextService.i18n.t("number_of_points", {
1789 count: Number(this.postView.counts.score),
1790 formattedCount: Number(this.postView.counts.score),
1793 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1794 count: Number(this.postView.counts.upvotes),
1795 formattedCount: Number(this.postView.counts.upvotes),
1798 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1799 count: Number(this.postView.counts.downvotes),
1800 formattedCount: Number(this.postView.counts.downvotes),
1803 return `${points} • ${upvotes} • ${downvotes}`;
1806 get canModOnSelf_(): boolean {
1808 this.postView.creator.id,
1809 this.props.moderators,
1816 get canMod_(): boolean {
1818 this.postView.creator.id,
1819 this.props.moderators,
1824 get canAdmin_(): boolean {
1825 return canAdmin(this.postView.creator.id, this.props.admins);
1828 get creatorIsMod_(): boolean {
1829 return isMod(this.postView.creator.id, this.props.moderators);
1832 get creatorIsAdmin_(): boolean {
1833 return isAdmin(this.postView.creator.id, this.props.admins);