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;
109 hideAvatars?: boolean;
111 enableDownvotes?: boolean;
112 enableNsfw?: boolean;
114 onPostEdit(form: EditPost): void;
115 onPostVote(form: CreatePostLike): void;
116 onPostReport(form: CreatePostReport): void;
117 onBlockPerson(form: BlockPerson): void;
118 onLockPost(form: LockPost): void;
119 onDeletePost(form: DeletePost): void;
120 onRemovePost(form: RemovePost): void;
121 onSavePost(form: SavePost): void;
122 onFeaturePost(form: FeaturePost): void;
123 onPurgePerson(form: PurgePerson): void;
124 onPurgePost(form: PurgePost): void;
125 onBanPersonFromCommunity(form: BanFromCommunity): void;
126 onBanPerson(form: BanPerson): void;
127 onAddModToCommunity(form: AddModToCommunity): void;
128 onAddAdmin(form: AddAdmin): void;
129 onTransferCommunity(form: TransferCommunity): void;
132 export class PostListing extends Component<PostListingProps, PostListingState> {
133 state: PostListingState = {
135 showRemoveDialog: false,
136 showPurgeDialog: false,
137 purgeType: PurgeType.Person,
138 showBanDialog: false,
139 banType: BanType.Community,
141 showConfirmTransferSite: false,
142 showConfirmTransferCommunity: false,
143 imageExpanded: false,
146 showMoreMobile: false,
148 showReportDialog: false,
150 reportLoading: false,
153 deleteLoading: false,
154 removeLoading: false,
156 featureCommunityLoading: false,
157 featureLocalLoading: false,
159 addModLoading: false,
160 addAdminLoading: false,
161 transferLoading: false,
164 constructor(props: any, context: any) {
165 super(props, context);
167 this.handleEditPost = this.handleEditPost.bind(this);
168 this.handleEditCancel = this.handleEditCancel.bind(this);
171 componentWillReceiveProps(nextProps: PostListingProps) {
172 if (this.props !== nextProps) {
175 reportLoading: false,
178 deleteLoading: false,
179 removeLoading: false,
181 featureCommunityLoading: false,
182 featureLocalLoading: false,
184 addModLoading: false,
185 addAdminLoading: false,
186 transferLoading: false,
187 imageExpanded: false,
192 get postView(): PostView {
193 return this.props.post_view;
197 const post = this.postView.post;
200 <div className="post-listing mt-2">
201 {!this.state.showEdit ? (
204 {this.state.imageExpanded && !this.props.hideImage && this.img}
205 {post.url && this.state.showBody && post.embed_title && (
206 <MetadataCard post={post} />
208 {this.showBody && this.body()}
212 post_view={this.postView}
213 crossPosts={this.props.crossPosts}
214 onEdit={this.handleEditPost}
215 onCancel={this.handleEditCancel}
216 enableNsfw={this.props.enableNsfw}
217 enableDownvotes={this.props.enableDownvotes}
218 allLanguages={this.props.allLanguages}
219 siteLanguages={this.props.siteLanguages}
227 const body = this.postView.post.body;
229 <article id="postContent" className="col-12 card my-2 p-2">
230 {this.state.viewSource ? (
233 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
245 <div className="offset-sm-3 my-2 d-none d-sm-block">
246 <a href={this.imageSrc} className="d-inline-block">
247 <PictrsImage src={this.imageSrc} />
250 <div className="my-2 d-block d-sm-none">
253 className="p-0 border-0 bg-transparent d-inline-block"
254 onClick={linkEvent(this, this.handleImageExpandClick)}
256 <PictrsImage src={this.imageSrc} />
263 const { post } = this.postView;
264 const { url } = post;
266 // if direct video link
267 if (url && isVideo(url)) {
269 <div className="embed-responsive mt-3">
270 <video muted controls className="embed-responsive-item col-12">
271 <source src={url} type="video/mp4" />
277 // if embedded video link
278 if (url && post.embed_video_url) {
280 <div className="ratio ratio-16x9">
283 className="post-metadata-iframe"
284 src={post.embed_video_url}
285 title={post.embed_title}
294 imgThumb(src: string) {
295 const post_view = this.postView;
301 nsfw={post_view.post.nsfw || post_view.community.nsfw}
306 get imageSrc(): string | undefined {
307 const post = this.postView.post;
308 const url = post.url;
309 const thumbnail = post.thumbnail_url;
311 if (url && isImage(url)) {
312 if (url.includes("pictrs")) {
314 } else if (thumbnail) {
319 } else if (thumbnail) {
327 const post = this.postView.post;
328 const url = post.url;
329 const thumbnail = post.thumbnail_url;
331 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
335 className="text-body d-inline-block position-relative mb-2"
336 data-tippy-content={I18NextService.i18n.t("expand_here")}
337 onClick={linkEvent(this, this.handleImageExpandClick)}
338 aria-label={I18NextService.i18n.t("expand_here")}
340 {this.imgThumb(this.imageSrc)}
341 <Icon icon="image" classes="mini-overlay" />
344 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
347 className="text-body d-inline-block position-relative mb-2"
352 {this.imgThumb(this.imageSrc)}
353 <Icon icon="external-link" classes="mini-overlay" />
357 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
360 className="text-body"
364 data-tippy-content={I18NextService.i18n.t("expand_here")}
365 onClick={linkEvent(this, this.handleImageExpandClick)}
366 aria-label={I18NextService.i18n.t("expand_here")}
368 <div className="thumbnail rounded bg-light d-flex justify-content-center">
369 <Icon icon="play" classes="d-flex align-items-center" />
375 <a className="text-body" href={url} title={url} rel={relTags}>
376 <div className="thumbnail rounded bg-light d-flex justify-content-center">
377 <Icon icon="external-link" classes="d-flex align-items-center" />
385 className="text-body"
386 to={`/post/${post.id}`}
387 title={I18NextService.i18n.t("comments")}
389 <div className="thumbnail rounded bg-light d-flex justify-content-center">
390 <Icon icon="message-square" classes="d-flex align-items-center" />
398 const post_view = this.postView;
400 <span className="small">
402 person={post_view.creator}
403 hideAvatar={this.props.hideAvatars}
405 {this.creatorIsMod_ && (
406 <span className="mx-1 badge text-bg-light">
407 {I18NextService.i18n.t("mod")}
410 {this.creatorIsAdmin_ && (
411 <span className="mx-1 badge text-bg-light">
412 {I18NextService.i18n.t("admin")}
415 {post_view.creator.bot_account && (
416 <span className="mx-1 badge text-bg-light">
417 {I18NextService.i18n.t("bot_account").toLowerCase()}
420 {this.props.showCommunity && (
423 {I18NextService.i18n.t("to")}{" "}
425 community={post_view.community}
426 hideAvatar={this.props.hideAvatars}
430 {post_view.post.language_id !== 0 && (
431 <span className="mx-1 badge text-bg-light">
433 this.props.allLanguages.find(
434 lang => lang.id === post_view.post.language_id
441 published={post_view.post.published}
442 updated={post_view.post.updated}
449 const post = this.postView.post;
452 className={`d-inline ${
453 !post.featured_community && !post.featured_local
457 to={`/post/${post.id}`}
458 title={I18NextService.i18n.t("comments")}
462 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
469 const post = this.postView.post;
470 const url = post.url;
474 <div className="post-title overflow-hidden">
475 <h5 className="d-inline">
476 {url && this.props.showBody ? (
479 !post.featured_community && !post.featured_local
486 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
492 {(url && isImage(url)) ||
493 (post.thumbnail_url && (
495 className="btn btn-sm text-monospace text-muted d-inline-block"
496 data-tippy-content={I18NextService.i18n.t("expand_here")}
497 onClick={linkEvent(this, this.handleImageExpandClick)}
501 !this.state.imageExpanded ? "plus-square" : "minus-square"
503 classes="icon-inline"
508 <small className="ms-2 badge text-bg-secondary">
509 {I18NextService.i18n.t("removed")}
514 className="unselectable pointer ms-2 text-muted fst-italic"
515 data-tippy-content={I18NextService.i18n.t("deleted")}
517 <Icon icon="trash" classes="icon-inline text-danger" />
522 className="unselectable pointer ms-2 text-muted fst-italic"
523 data-tippy-content={I18NextService.i18n.t("locked")}
525 <Icon icon="lock" classes="icon-inline text-danger" />
528 {post.featured_community && (
530 className="unselectable pointer ms-2 text-muted fst-italic"
531 data-tippy-content={I18NextService.i18n.t(
532 "featured_in_community"
534 aria-label={I18NextService.i18n.t("featured_in_community")}
536 <Icon icon="pin" classes="icon-inline text-primary" />
539 {post.featured_local && (
541 className="unselectable pointer ms-2 text-muted fst-italic"
542 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
543 aria-label={I18NextService.i18n.t("featured_in_local")}
545 <Icon icon="pin" classes="icon-inline text-secondary" />
549 <small className="ms-2 badge text-bg-danger">
550 {I18NextService.i18n.t("nsfw")}
554 {url && this.urlLine()}
560 const post = this.postView.post;
561 const url = post.url;
564 <p className="small m-0">
565 {url && !(hostname(url) === getExternalHost()) && (
567 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
580 const dupes = this.props.crossPosts;
581 return dupes && dupes.length > 0 ? (
582 <ul className="list-inline mb-1 small text-muted">
584 <li className="list-inline-item me-2">
585 {I18NextService.i18n.t("cross_posted_to")}
588 <li key={pv.post.id} className="list-inline-item me-2">
589 <Link to={`/post/${pv.post.id}`}>
592 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
603 commentsLine(mobile = false) {
604 const post = this.postView.post;
607 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
608 {this.commentsButton}
611 className="btn btn-sm btn-animate text-muted py-0"
612 onClick={linkEvent(this, this.handleShare)}
615 <Icon icon="share" inline />
620 className="btn btn-sm btn-animate text-muted py-0"
621 title={I18NextService.i18n.t("link")}
624 <Icon icon="fedilink" inline />
627 {mobile && !this.props.viewOnly && (
629 voteContentType={VoteContentType.Post}
630 id={this.postView.post.id}
631 onVote={this.props.onPostVote}
632 enableDownvotes={this.props.enableDownvotes}
633 counts={this.postView.counts}
634 my_vote={this.postView.my_vote}
637 {UserService.Instance.myUserInfo &&
638 !this.props.viewOnly &&
644 showPreviewButton() {
645 const post_view = this.postView;
646 const body = post_view.post.body;
650 className="btn btn-sm btn-animate text-muted py-0"
651 data-tippy-content={body && mdNoImages.render(body)}
652 data-tippy-allowHtml={true}
653 onClick={linkEvent(this, this.handleShowBody)}
657 classes={classNames("icon-inline me-1", {
658 "text-success": this.state.showBody,
666 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
667 // Possible enhancement: Make each button a component.
668 const post_view = this.postView;
669 const post = post_view.post;
674 {this.crossPostButton}
677 * If there is a URL, or if the post has a body and we were told not to
678 * show the body, show the MetadataCard/body toggle.
680 {(post.url || (post.body && !this.props.showBody)) &&
681 this.showPreviewButton()}
683 {this.showBody && post_view.post.body && this.viewSourceButton}
685 <div className="dropdown">
687 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
688 onClick={linkEvent(this, this.handleShowAdvanced)}
689 data-tippy-content={I18NextService.i18n.t("more")}
690 data-bs-toggle="dropdown"
691 aria-expanded="false"
692 aria-controls={`advancedButtonsDropdown${post.id}`}
693 aria-label={I18NextService.i18n.t("more")}
695 <Icon icon="more-vertical" inline />
699 className="dropdown-menu"
700 id={`advancedButtonsDropdown${post.id}`}
704 <li>{this.reportButton}</li>
705 <li>{this.blockButton}</li>
709 <li>{this.editButton}</li>
710 <li>{this.deleteButton}</li>
714 {/* Any mod can do these, not limited to hierarchy*/}
715 {(amMod(this.props.moderators) || amAdmin()) && (
718 <hr className="dropdown-divider" />
720 <li>{this.lockButton}</li>
721 {this.featureButtons}
725 {(this.canMod_ || this.canAdmin_) && (
726 <li>{this.modRemoveButton}</li>
734 get commentsButton() {
735 const post_view = this.postView;
736 const title = I18NextService.i18n.t("number_of_comments", {
737 count: Number(post_view.counts.comments),
738 formattedCount: Number(post_view.counts.comments),
743 className="btn btn-link btn-sm text-muted ps-0"
745 to={`/post/${post_view.post.id}?scrollToComments=true`}
746 data-tippy-content={title}
748 <Icon icon="message-square" classes="me-1" inline />
749 {post_view.counts.comments}
750 {this.unreadCount && (
753 <span className="fst-italic">
754 ({this.unreadCount} {I18NextService.i18n.t("new")})
762 get unreadCount(): number | undefined {
763 const pv = this.postView;
764 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
766 : pv.unread_comments;
770 const saved = this.postView.saved;
772 ? I18NextService.i18n.t("unsave")
773 : I18NextService.i18n.t("save");
776 className="btn btn-sm btn-animate text-muted py-0"
777 onClick={linkEvent(this, this.handleSavePostClick)}
778 data-tippy-content={label}
781 {this.state.saveLoading ? (
786 classes={classNames({ "text-warning": saved })}
794 get crossPostButton() {
797 className="btn btn-sm btn-animate text-muted py-0"
799 /* Empty string properties are required to satisfy type*/
800 pathname: "/create_post",
801 state: { ...this.crossPostParams },
806 title={I18NextService.i18n.t("cross_post")}
807 data-tippy-content={I18NextService.i18n.t("cross_post")}
808 aria-label={I18NextService.i18n.t("cross_post")}
810 <Icon icon="copy" inline />
818 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
819 onClick={linkEvent(this, this.handleShowReportDialog)}
820 aria-label={I18NextService.i18n.t("show_report_dialog")}
822 <Icon classes="me-1" icon="flag" inline />
823 {I18NextService.i18n.t("create_report")}
831 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
832 onClick={linkEvent(this, this.handleBlockPersonClick)}
833 aria-label={I18NextService.i18n.t("block_user")}
835 {this.state.blockLoading ? (
838 <Icon classes="me-1" icon="slash" inline />
840 {I18NextService.i18n.t("block_user")}
848 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
849 onClick={linkEvent(this, this.handleEditClick)}
850 aria-label={I18NextService.i18n.t("edit")}
852 <Icon classes="me-1" icon="edit" inline />
853 {I18NextService.i18n.t("edit")}
859 const deleted = this.postView.post.deleted;
860 const label = !deleted
861 ? I18NextService.i18n.t("delete")
862 : I18NextService.i18n.t("restore");
865 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
866 onClick={linkEvent(this, this.handleDeleteClick)}
868 {this.state.deleteLoading ? (
874 classes={classNames("me-1", { "text-danger": deleted })}
884 get viewSourceButton() {
887 className="btn btn-sm btn-animate text-muted py-0"
888 onClick={linkEvent(this, this.handleViewSource)}
889 data-tippy-content={I18NextService.i18n.t("view_source")}
890 aria-label={I18NextService.i18n.t("view_source")}
894 classes={classNames({ "text-success": this.state.viewSource })}
902 const locked = this.postView.post.locked;
904 ? I18NextService.i18n.t("unlock")
905 : I18NextService.i18n.t("lock");
908 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
909 onClick={linkEvent(this, this.handleModLock)}
912 {this.state.lockLoading ? (
918 classes={classNames("me-1", { "text-danger": locked })}
921 {capitalizeFirstLetter(label)}
928 get featureButtons() {
929 const featuredCommunity = this.postView.post.featured_community;
930 const labelCommunity = featuredCommunity
931 ? I18NextService.i18n.t("unfeature_from_community")
932 : I18NextService.i18n.t("feature_in_community");
934 const featuredLocal = this.postView.post.featured_local;
935 const labelLocal = featuredLocal
936 ? I18NextService.i18n.t("unfeature_from_local")
937 : I18NextService.i18n.t("feature_in_local");
942 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
943 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
944 data-tippy-content={labelCommunity}
945 aria-label={labelCommunity}
947 {this.state.featureCommunityLoading ? (
953 classes={classNames("me-1", {
954 "text-success": featuredCommunity,
958 {I18NextService.i18n.t("community")}
966 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
967 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
968 data-tippy-content={labelLocal}
969 aria-label={labelLocal}
971 {this.state.featureLocalLoading ? (
977 classes={classNames("me-1", {
978 "text-success": featuredLocal,
982 {I18NextService.i18n.t("local")}
992 get modRemoveButton() {
993 const removed = this.postView.post.removed;
996 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
999 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1002 {/* TODO: Find an icon for this. */}
1003 {this.state.removeLoading ? (
1006 I18NextService.i18n.t("remove")
1008 I18NextService.i18n.t("restore")
1015 * Mod/Admin actions to be taken against the author.
1019 const post_view = this.postView;
1021 this.state.showAdvanced && (
1022 <div className="mt-3">
1025 {!this.creatorIsMod_ &&
1026 (!post_view.creator_banned_from_community ? (
1028 className="btn btn-link btn-animate text-muted py-0"
1031 this.handleModBanFromCommunityShow
1033 aria-label={I18NextService.i18n.t("ban_from_community")}
1035 {I18NextService.i18n.t("ban_from_community")}
1039 className="btn btn-link btn-animate text-muted py-0"
1042 this.handleModBanFromCommunitySubmit
1044 aria-label={I18NextService.i18n.t("unban")}
1046 {this.state.banLoading ? (
1049 I18NextService.i18n.t("unban")
1053 {!post_view.creator_banned_from_community && (
1055 className="btn btn-link btn-animate text-muted py-0"
1056 onClick={linkEvent(this, this.handleAddModToCommunity)}
1059 ? I18NextService.i18n.t("remove_as_mod")
1060 : I18NextService.i18n.t("appoint_as_mod")
1063 {this.state.addModLoading ? (
1065 ) : this.creatorIsMod_ ? (
1066 I18NextService.i18n.t("remove_as_mod")
1068 I18NextService.i18n.t("appoint_as_mod")
1074 {/* Community creators and admins can transfer community to another mod */}
1075 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1077 this.creatorIsMod_ &&
1078 (!this.state.showConfirmTransferCommunity ? (
1080 className="btn btn-link btn-animate text-muted py-0"
1083 this.handleShowConfirmTransferCommunity
1085 aria-label={I18NextService.i18n.t("transfer_community")}
1087 {I18NextService.i18n.t("transfer_community")}
1092 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1093 aria-label={I18NextService.i18n.t("are_you_sure")}
1095 {I18NextService.i18n.t("are_you_sure")}
1098 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1099 aria-label={I18NextService.i18n.t("yes")}
1100 onClick={linkEvent(this, this.handleTransferCommunity)}
1102 {this.state.transferLoading ? (
1105 I18NextService.i18n.t("yes")
1109 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1112 this.handleCancelShowConfirmTransferCommunity
1114 aria-label={I18NextService.i18n.t("no")}
1116 {I18NextService.i18n.t("no")}
1120 {/* Admins can ban from all, and appoint other admins */}
1121 {this.canAdmin_ && (
1123 {!this.creatorIsAdmin_ && (
1125 {!isBanned(post_view.creator) ? (
1127 className="btn btn-link btn-animate text-muted py-0"
1128 onClick={linkEvent(this, this.handleModBanShow)}
1129 aria-label={I18NextService.i18n.t("ban_from_site")}
1131 {I18NextService.i18n.t("ban_from_site")}
1135 className="btn btn-link btn-animate text-muted py-0"
1136 onClick={linkEvent(this, this.handleModBanSubmit)}
1137 aria-label={I18NextService.i18n.t("unban_from_site")}
1139 {this.state.banLoading ? (
1142 I18NextService.i18n.t("unban_from_site")
1147 className="btn btn-link btn-animate text-muted py-0"
1148 onClick={linkEvent(this, this.handlePurgePersonShow)}
1149 aria-label={I18NextService.i18n.t("purge_user")}
1151 {I18NextService.i18n.t("purge_user")}
1154 className="btn btn-link btn-animate text-muted py-0"
1155 onClick={linkEvent(this, this.handlePurgePostShow)}
1156 aria-label={I18NextService.i18n.t("purge_post")}
1158 {I18NextService.i18n.t("purge_post")}
1162 {!isBanned(post_view.creator) && post_view.creator.local && (
1164 className="btn btn-link btn-animate text-muted py-0"
1165 onClick={linkEvent(this, this.handleAddAdmin)}
1167 this.creatorIsAdmin_
1168 ? I18NextService.i18n.t("remove_as_admin")
1169 : I18NextService.i18n.t("appoint_as_admin")
1172 {this.state.addAdminLoading ? (
1174 ) : this.creatorIsAdmin_ ? (
1175 I18NextService.i18n.t("remove_as_admin")
1177 I18NextService.i18n.t("appoint_as_admin")
1188 removeAndBanDialogs() {
1189 const post = this.postView;
1190 const purgeTypeText =
1191 this.state.purgeType == PurgeType.Post
1192 ? I18NextService.i18n.t("purge_post")
1193 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1196 {this.state.showRemoveDialog && (
1198 className="form-inline"
1199 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1202 className="visually-hidden"
1203 htmlFor="post-listing-remove-reason"
1205 {I18NextService.i18n.t("reason")}
1209 id="post-listing-remove-reason"
1210 className="form-control me-2"
1211 placeholder={I18NextService.i18n.t("reason")}
1212 value={this.state.removeReason}
1213 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1217 className="btn btn-secondary"
1218 aria-label={I18NextService.i18n.t("remove_post")}
1220 {this.state.removeLoading ? (
1223 I18NextService.i18n.t("remove_post")
1228 {this.state.showBanDialog && (
1229 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1230 <div className="mb-3 row col-12">
1232 className="col-form-label"
1233 htmlFor="post-listing-ban-reason"
1235 {I18NextService.i18n.t("reason")}
1239 id="post-listing-ban-reason"
1240 className="form-control me-2"
1241 placeholder={I18NextService.i18n.t("reason")}
1242 value={this.state.banReason}
1243 onInput={linkEvent(this, this.handleModBanReasonChange)}
1245 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1246 {I18NextService.i18n.t("expires")}
1250 id={`mod-ban-expires`}
1251 className="form-control me-2"
1252 placeholder={I18NextService.i18n.t("number_of_days")}
1253 value={this.state.banExpireDays}
1254 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1256 <div className="input-group mb-3">
1257 <div className="form-check">
1259 className="form-check-input"
1260 id="mod-ban-remove-data"
1262 checked={this.state.removeData}
1263 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1266 className="form-check-label"
1267 htmlFor="mod-ban-remove-data"
1268 title={I18NextService.i18n.t("remove_content_more")}
1270 {I18NextService.i18n.t("remove_content")}
1275 {/* TODO hold off on expires until later */}
1276 {/* <div class="mb-3 row"> */}
1277 {/* <label class="col-form-label">Expires</label> */}
1278 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1280 <div className="mb-3 row">
1283 className="btn btn-secondary"
1284 aria-label={I18NextService.i18n.t("ban")}
1286 {this.state.banLoading ? (
1290 {I18NextService.i18n.t("ban")} {post.creator.name}
1297 {this.state.showReportDialog && (
1299 className="form-inline"
1300 onSubmit={linkEvent(this, this.handleReportSubmit)}
1302 <label className="visually-hidden" htmlFor="post-report-reason">
1303 {I18NextService.i18n.t("reason")}
1307 id="post-report-reason"
1308 className="form-control me-2"
1309 placeholder={I18NextService.i18n.t("reason")}
1311 value={this.state.reportReason}
1312 onInput={linkEvent(this, this.handleReportReasonChange)}
1316 className="btn btn-secondary"
1317 aria-label={I18NextService.i18n.t("create_report")}
1319 {this.state.reportLoading ? (
1322 I18NextService.i18n.t("create_report")
1327 {this.state.showPurgeDialog && (
1329 className="form-inline"
1330 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1333 <label className="visually-hidden" htmlFor="purge-reason">
1334 {I18NextService.i18n.t("reason")}
1339 className="form-control me-2"
1340 placeholder={I18NextService.i18n.t("reason")}
1341 value={this.state.purgeReason}
1342 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1344 {this.state.purgeLoading ? (
1349 className="btn btn-secondary"
1350 aria-label={purgeTypeText}
1352 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1362 const post = this.postView.post;
1363 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1364 <div className="row">
1365 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1366 {this.postTitleLine()}
1368 <div className="col-4">
1369 {/* Post thumbnail */}
1370 {!this.state.imageExpanded && this.thumbnail()}
1374 this.postTitleLine()
1379 const { body, id } = this.postView.post;
1381 return !this.showBody && body ? (
1382 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1383 <div className="md-div mb-1 preview-lines">{body}</div>
1393 {/* The mobile view*/}
1394 <div className="d-block d-sm-none">
1395 <article className="row post-container">
1396 <div className="col-12">
1397 {this.createdLine()}
1399 {/* If it has a thumbnail, do a right aligned thumbnail */}
1400 {this.mobileThumbnail()}
1402 {/* Show a preview of the post body */}
1403 {this.showBodyPreview()}
1405 {this.commentsLine(true)}
1406 {this.userActionsLine()}
1407 {this.duplicatesLine()}
1408 {this.removeAndBanDialogs()}
1413 {/* The larger view*/}
1414 <div className="d-none d-sm-block">
1415 <article className="row post-container">
1416 {!this.props.viewOnly && (
1418 voteContentType={VoteContentType.Post}
1419 id={this.postView.post.id}
1420 onVote={this.props.onPostVote}
1421 enableDownvotes={this.props.enableDownvotes}
1422 counts={this.postView.counts}
1423 my_vote={this.postView.my_vote}
1426 <div className="col-sm-2 pe-0 post-media">
1427 <div className="">{this.thumbnail()}</div>
1429 <div className="col-12 col-sm-9">
1430 <div className="row">
1431 <div className="col-12">
1432 {this.postTitleLine()}
1433 {this.createdLine()}
1434 {this.showBodyPreview()}
1435 {this.commentsLine()}
1436 {this.duplicatesLine()}
1437 {this.userActionsLine()}
1438 {this.removeAndBanDialogs()}
1448 private get myPost(): boolean {
1450 this.postView.creator.id ==
1451 UserService.Instance.myUserInfo?.local_user_view.person.id
1454 handleEditClick(i: PostListing) {
1455 i.setState({ showEdit: true });
1458 handleEditCancel() {
1459 this.setState({ showEdit: false });
1462 // The actual editing is done in the receive for post
1463 handleEditPost(form: EditPost) {
1464 this.setState({ showEdit: false });
1465 this.props.onPostEdit(form);
1468 handleShare(i: PostListing) {
1469 const { name, body, id } = i.props.post_view.post;
1472 text: body?.slice(0, 50),
1473 url: `${getHttpBase()}/post/${id}`,
1477 handleShowReportDialog(i: PostListing) {
1478 i.setState({ showReportDialog: !i.state.showReportDialog });
1481 handleReportReasonChange(i: PostListing, event: any) {
1482 i.setState({ reportReason: event.target.value });
1485 handleReportSubmit(i: PostListing, event: any) {
1486 event.preventDefault();
1487 i.setState({ reportLoading: true });
1488 i.props.onPostReport({
1489 post_id: i.postView.post.id,
1490 reason: i.state.reportReason ?? "",
1491 auth: myAuthRequired(),
1495 handleBlockPersonClick(i: PostListing) {
1496 i.setState({ blockLoading: true });
1497 i.props.onBlockPerson({
1498 person_id: i.postView.creator.id,
1500 auth: myAuthRequired(),
1504 handleDeleteClick(i: PostListing) {
1505 i.setState({ deleteLoading: true });
1506 i.props.onDeletePost({
1507 post_id: i.postView.post.id,
1508 deleted: !i.postView.post.deleted,
1509 auth: myAuthRequired(),
1513 handleSavePostClick(i: PostListing) {
1514 i.setState({ saveLoading: true });
1515 i.props.onSavePost({
1516 post_id: i.postView.post.id,
1517 save: !i.postView.saved,
1518 auth: myAuthRequired(),
1522 get crossPostParams(): PostFormParams {
1523 const queryParams: PostFormParams = {};
1524 const { name, url } = this.postView.post;
1526 queryParams.name = name;
1529 queryParams.url = url;
1532 const crossPostBody = this.crossPostBody();
1533 if (crossPostBody) {
1534 queryParams.body = crossPostBody;
1540 crossPostBody(): string | undefined {
1541 const post = this.postView.post;
1542 const body = post.body;
1545 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1547 }\n\n${body.replace(/^/gm, "> ")}`
1551 get showBody(): boolean {
1552 return this.props.showBody || this.state.showBody;
1555 handleModRemoveShow(i: PostListing) {
1557 showRemoveDialog: !i.state.showRemoveDialog,
1558 showBanDialog: false,
1562 handleModRemoveReasonChange(i: PostListing, event: any) {
1563 i.setState({ removeReason: event.target.value });
1566 handleModRemoveDataChange(i: PostListing, event: any) {
1567 i.setState({ removeData: event.target.checked });
1570 handleModRemoveSubmit(i: PostListing, event: any) {
1571 event.preventDefault();
1572 i.setState({ removeLoading: true });
1573 i.props.onRemovePost({
1574 post_id: i.postView.post.id,
1575 removed: !i.postView.post.removed,
1576 auth: myAuthRequired(),
1580 handleModLock(i: PostListing) {
1581 i.setState({ lockLoading: true });
1582 i.props.onLockPost({
1583 post_id: i.postView.post.id,
1584 locked: !i.postView.post.locked,
1585 auth: myAuthRequired(),
1589 handleModFeaturePostLocal(i: PostListing) {
1590 i.setState({ featureLocalLoading: true });
1591 i.props.onFeaturePost({
1592 post_id: i.postView.post.id,
1593 featured: !i.postView.post.featured_local,
1594 feature_type: "Local",
1595 auth: myAuthRequired(),
1599 handleModFeaturePostCommunity(i: PostListing) {
1600 i.setState({ featureCommunityLoading: true });
1601 i.props.onFeaturePost({
1602 post_id: i.postView.post.id,
1603 featured: !i.postView.post.featured_community,
1604 feature_type: "Community",
1605 auth: myAuthRequired(),
1609 handleModBanFromCommunityShow(i: PostListing) {
1611 showBanDialog: true,
1612 banType: BanType.Community,
1613 showRemoveDialog: false,
1617 handleModBanShow(i: PostListing) {
1619 showBanDialog: true,
1620 banType: BanType.Site,
1621 showRemoveDialog: false,
1625 handlePurgePersonShow(i: PostListing) {
1627 showPurgeDialog: true,
1628 purgeType: PurgeType.Person,
1629 showRemoveDialog: false,
1633 handlePurgePostShow(i: PostListing) {
1635 showPurgeDialog: true,
1636 purgeType: PurgeType.Post,
1637 showRemoveDialog: false,
1641 handlePurgeReasonChange(i: PostListing, event: any) {
1642 i.setState({ purgeReason: event.target.value });
1645 handlePurgeSubmit(i: PostListing, event: any) {
1646 event.preventDefault();
1647 i.setState({ purgeLoading: true });
1648 if (i.state.purgeType == PurgeType.Person) {
1649 i.props.onPurgePerson({
1650 person_id: i.postView.creator.id,
1651 reason: i.state.purgeReason,
1652 auth: myAuthRequired(),
1654 } else if (i.state.purgeType == PurgeType.Post) {
1655 i.props.onPurgePost({
1656 post_id: i.postView.post.id,
1657 reason: i.state.purgeReason,
1658 auth: myAuthRequired(),
1663 handleModBanReasonChange(i: PostListing, event: any) {
1664 i.setState({ banReason: event.target.value });
1667 handleModBanExpireDaysChange(i: PostListing, event: any) {
1668 i.setState({ banExpireDays: event.target.value });
1671 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1672 i.setState({ banType: BanType.Community });
1673 i.handleModBanBothSubmit(i, event);
1676 handleModBanSubmit(i: PostListing, event: any) {
1677 i.setState({ banType: BanType.Site });
1678 i.handleModBanBothSubmit(i, event);
1681 handleModBanBothSubmit(i: PostListing, event: any) {
1682 event.preventDefault();
1683 i.setState({ banLoading: true });
1685 const ban = !i.props.post_view.creator_banned_from_community;
1686 // If its an unban, restore all their data
1688 i.setState({ removeData: false });
1690 const person_id = i.props.post_view.creator.id;
1691 const remove_data = i.state.removeData;
1692 const reason = i.state.banReason;
1693 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1695 if (i.state.banType == BanType.Community) {
1696 const community_id = i.postView.community.id;
1697 i.props.onBanPersonFromCommunity({
1704 auth: myAuthRequired(),
1707 i.props.onBanPerson({
1713 auth: myAuthRequired(),
1718 handleAddModToCommunity(i: PostListing) {
1719 i.setState({ addModLoading: true });
1720 i.props.onAddModToCommunity({
1721 community_id: i.postView.community.id,
1722 person_id: i.postView.creator.id,
1723 added: !i.creatorIsMod_,
1724 auth: myAuthRequired(),
1728 handleAddAdmin(i: PostListing) {
1729 i.setState({ addAdminLoading: true });
1730 i.props.onAddAdmin({
1731 person_id: i.postView.creator.id,
1732 added: !i.creatorIsAdmin_,
1733 auth: myAuthRequired(),
1737 handleShowConfirmTransferCommunity(i: PostListing) {
1738 i.setState({ showConfirmTransferCommunity: true });
1741 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1742 i.setState({ showConfirmTransferCommunity: false });
1745 handleTransferCommunity(i: PostListing) {
1746 i.setState({ transferLoading: true });
1747 i.props.onTransferCommunity({
1748 community_id: i.postView.community.id,
1749 person_id: i.postView.creator.id,
1750 auth: myAuthRequired(),
1754 handleShowConfirmTransferSite(i: PostListing) {
1755 i.setState({ showConfirmTransferSite: true });
1758 handleCancelShowConfirmTransferSite(i: PostListing) {
1759 i.setState({ showConfirmTransferSite: false });
1762 handleImageExpandClick(i: PostListing, event: any) {
1763 event.preventDefault();
1764 i.setState({ imageExpanded: !i.state.imageExpanded });
1768 handleViewSource(i: PostListing) {
1769 i.setState({ viewSource: !i.state.viewSource });
1772 handleShowAdvanced(i: PostListing) {
1773 i.setState({ showAdvanced: !i.state.showAdvanced });
1777 handleShowMoreMobile(i: PostListing) {
1779 showMoreMobile: !i.state.showMoreMobile,
1780 showAdvanced: !i.state.showAdvanced,
1785 handleShowBody(i: PostListing) {
1786 i.setState({ showBody: !i.state.showBody });
1790 get pointsTippy(): string {
1791 const points = I18NextService.i18n.t("number_of_points", {
1792 count: Number(this.postView.counts.score),
1793 formattedCount: Number(this.postView.counts.score),
1796 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1797 count: Number(this.postView.counts.upvotes),
1798 formattedCount: Number(this.postView.counts.upvotes),
1801 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1802 count: Number(this.postView.counts.downvotes),
1803 formattedCount: Number(this.postView.counts.downvotes),
1806 return `${points} • ${upvotes} • ${downvotes}`;
1809 get canModOnSelf_(): boolean {
1811 this.postView.creator.id,
1812 this.props.moderators,
1819 get canMod_(): boolean {
1821 this.postView.creator.id,
1822 this.props.moderators,
1827 get canAdmin_(): boolean {
1828 return canAdmin(this.postView.creator.id, this.props.admins);
1831 get creatorIsMod_(): boolean {
1832 return isMod(this.postView.creator.id, this.props.moderators);
1835 get creatorIsAdmin_(): boolean {
1836 return isAdmin(this.postView.creator.id, this.props.admins);