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 direct video link
266 if (url && isVideo(url)) {
268 <div className="embed-responsive mt-3">
269 <video muted controls className="embed-responsive-item col-12">
270 <source src={url} type="video/mp4" />
276 // if embedded video link
277 if (url && post.embed_video_url) {
279 <div className="ratio ratio-16x9">
282 className="post-metadata-iframe"
283 src={post.embed_video_url}
284 title={post.embed_title}
293 imgThumb(src: string) {
294 const post_view = this.postView;
300 nsfw={post_view.post.nsfw || post_view.community.nsfw}
305 get imageSrc(): string | undefined {
306 const post = this.postView.post;
307 const url = post.url;
308 const thumbnail = post.thumbnail_url;
310 if (url && isImage(url)) {
311 if (url.includes("pictrs")) {
313 } else if (thumbnail) {
318 } else if (thumbnail) {
326 const post = this.postView.post;
327 const url = post.url;
328 const thumbnail = post.thumbnail_url;
330 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
334 className="text-body d-inline-block position-relative mb-2"
335 data-tippy-content={I18NextService.i18n.t("expand_here")}
336 onClick={linkEvent(this, this.handleImageExpandClick)}
337 aria-label={I18NextService.i18n.t("expand_here")}
339 {this.imgThumb(this.imageSrc)}
340 <Icon icon="image" classes="mini-overlay" />
343 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
346 className="text-body d-inline-block position-relative mb-2"
351 {this.imgThumb(this.imageSrc)}
352 <Icon icon="external-link" classes="mini-overlay" />
356 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
359 className="text-body"
363 data-tippy-content={I18NextService.i18n.t("expand_here")}
364 onClick={linkEvent(this, this.handleImageExpandClick)}
365 aria-label={I18NextService.i18n.t("expand_here")}
367 <div className="thumbnail rounded bg-light d-flex justify-content-center">
368 <Icon icon="play" classes="d-flex align-items-center" />
374 <a className="text-body" href={url} title={url} rel={relTags}>
375 <div className="thumbnail rounded bg-light d-flex justify-content-center">
376 <Icon icon="external-link" classes="d-flex align-items-center" />
384 className="text-body"
385 to={`/post/${post.id}`}
386 title={I18NextService.i18n.t("comments")}
388 <div className="thumbnail rounded bg-light d-flex justify-content-center">
389 <Icon icon="message-square" classes="d-flex align-items-center" />
397 const post_view = this.postView;
399 <span className="small">
400 <PersonListing person={post_view.creator} muted={true} />
401 {this.creatorIsMod_ && (
402 <span className="mx-1 badge text-bg-light">
403 {I18NextService.i18n.t("mod")}
406 {this.creatorIsAdmin_ && (
407 <span className="mx-1 badge text-bg-light">
408 {I18NextService.i18n.t("admin")}
411 {post_view.creator.bot_account && (
412 <span className="mx-1 badge text-bg-light">
413 {I18NextService.i18n.t("bot_account").toLowerCase()}
416 {this.props.showCommunity && (
419 {I18NextService.i18n.t("to")}{" "}
420 <CommunityLink community={post_view.community} />
423 {post_view.post.language_id !== 0 && (
424 <span className="mx-1 badge text-bg-light">
426 this.props.allLanguages.find(
427 lang => lang.id === post_view.post.language_id
434 published={post_view.post.published}
435 updated={post_view.post.updated}
442 const post = this.postView.post;
445 className={`d-inline ${
446 !post.featured_community && !post.featured_local
450 to={`/post/${post.id}`}
451 title={I18NextService.i18n.t("comments")}
455 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
462 const post = this.postView.post;
463 const url = post.url;
467 <div className="post-title overflow-hidden">
468 <h5 className="d-inline">
469 {url && this.props.showBody ? (
472 !post.featured_community && !post.featured_local
479 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
485 {(url && isImage(url)) ||
486 (post.thumbnail_url && (
488 className="btn btn-sm text-monospace text-muted d-inline-block"
489 data-tippy-content={I18NextService.i18n.t("expand_here")}
490 onClick={linkEvent(this, this.handleImageExpandClick)}
494 !this.state.imageExpanded ? "plus-square" : "minus-square"
496 classes="icon-inline"
502 * If there is a URL, or if the post has a body and we were told not to
503 * show the body, show the MetadataCard/body toggle.
505 {(post.url || (post.body && !this.props.showBody)) && (
507 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
508 data-tippy-content={post.body && mdNoImages.render(post.body)}
509 data-tippy-allowHtml={true}
510 onClick={linkEvent(this, this.handleShowBody)}
513 icon={!this.state.showBody ? "plus-square" : "minus-square"}
514 classes="icon-inline"
520 <small className="ms-2 badge text-bg-secondary">
521 {I18NextService.i18n.t("removed")}
526 className="unselectable pointer ms-2 text-muted fst-italic"
527 data-tippy-content={I18NextService.i18n.t("deleted")}
529 <Icon icon="trash" classes="icon-inline text-danger" />
534 className="unselectable pointer ms-2 text-muted fst-italic"
535 data-tippy-content={I18NextService.i18n.t("locked")}
537 <Icon icon="lock" classes="icon-inline text-danger" />
540 {post.featured_community && (
542 className="unselectable pointer ms-2 text-muted fst-italic"
543 data-tippy-content={I18NextService.i18n.t(
544 "featured_in_community"
546 aria-label={I18NextService.i18n.t("featured_in_community")}
548 <Icon icon="pin" classes="icon-inline text-primary" />
551 {post.featured_local && (
553 className="unselectable pointer ms-2 text-muted fst-italic"
554 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
555 aria-label={I18NextService.i18n.t("featured_in_local")}
557 <Icon icon="pin" classes="icon-inline text-secondary" />
561 <small className="ms-2 badge text-bg-danger">
562 {I18NextService.i18n.t("nsfw")}
566 {url && this.urlLine()}
572 const post = this.postView.post;
573 const url = post.url;
576 <p className="small m-0">
577 {url && !(hostname(url) === getExternalHost()) && (
579 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
592 const dupes = this.props.crossPosts;
593 return dupes && dupes.length > 0 ? (
594 <ul className="list-inline mb-1 small text-muted">
596 <li className="list-inline-item me-2">
597 {I18NextService.i18n.t("cross_posted_to")}
600 <li key={pv.post.id} className="list-inline-item me-2">
601 <Link to={`/post/${pv.post.id}`}>
604 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
615 commentsLine(mobile = false) {
616 const post = this.postView.post;
619 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
620 {this.commentsButton}
623 className="btn btn-sm btn-animate text-muted py-0"
624 onClick={linkEvent(this, this.handleShare)}
627 <Icon icon="share" inline />
632 className="btn btn-sm btn-animate text-muted py-0"
633 title={I18NextService.i18n.t("link")}
636 <Icon icon="fedilink" inline />
639 {mobile && !this.props.viewOnly && (
641 voteContentType={VoteContentType.Post}
642 id={this.postView.post.id}
643 onVote={this.props.onPostVote}
644 enableDownvotes={this.props.enableDownvotes}
645 counts={this.postView.counts}
646 my_vote={this.postView.my_vote}
649 {UserService.Instance.myUserInfo &&
650 !this.props.viewOnly &&
657 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
658 // Possible enhancement: Make each button a component.
659 const post_view = this.postView;
660 const post = post_view.post;
665 {this.crossPostButton}
667 {this.props.showBody && post_view.post.body && this.viewSourceButton}
669 <div className="dropdown">
671 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
672 onClick={linkEvent(this, this.handleShowAdvanced)}
673 data-tippy-content={I18NextService.i18n.t("more")}
674 data-bs-toggle="dropdown"
675 aria-expanded="false"
676 aria-controls={`advancedButtonsDropdown${post.id}`}
677 aria-label={I18NextService.i18n.t("more")}
679 <Icon icon="more-vertical" inline />
683 className="dropdown-menu"
684 id={`advancedButtonsDropdown${post.id}`}
688 <li>{this.reportButton}</li>
689 <li>{this.blockButton}</li>
693 <li>{this.editButton}</li>
694 <li>{this.deleteButton}</li>
698 {/* Any mod can do these, not limited to hierarchy*/}
699 {(amMod(this.props.moderators) || amAdmin()) && (
702 <hr className="dropdown-divider" />
704 <li>{this.lockButton}</li>
705 {this.featureButtons}
709 {(this.canMod_ || this.canAdmin_) && (
710 <li>{this.modRemoveButton}</li>
718 get commentsButton() {
719 const post_view = this.postView;
720 const title = I18NextService.i18n.t("number_of_comments", {
721 count: Number(post_view.counts.comments),
722 formattedCount: Number(post_view.counts.comments),
727 className="btn btn-link btn-sm text-muted ps-0"
729 to={`/post/${post_view.post.id}?scrollToComments=true`}
730 data-tippy-content={title}
732 <Icon icon="message-square" classes="me-1" inline />
733 {post_view.counts.comments}
734 {this.unreadCount && (
737 <span className="fst-italic">
738 ({this.unreadCount} {I18NextService.i18n.t("new")})
746 get unreadCount(): number | undefined {
747 const pv = this.postView;
748 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
750 : pv.unread_comments;
754 const saved = this.postView.saved;
756 ? I18NextService.i18n.t("unsave")
757 : I18NextService.i18n.t("save");
760 className="btn btn-sm btn-animate text-muted py-0"
761 onClick={linkEvent(this, this.handleSavePostClick)}
762 data-tippy-content={label}
765 {this.state.saveLoading ? (
770 classes={classNames({ "text-warning": saved })}
778 get crossPostButton() {
781 className="btn btn-sm btn-animate text-muted py-0"
783 /* Empty string properties are required to satisfy type*/
784 pathname: "/create_post",
785 state: { ...this.crossPostParams },
790 title={I18NextService.i18n.t("cross_post")}
791 data-tippy-content={I18NextService.i18n.t("cross_post")}
792 aria-label={I18NextService.i18n.t("cross_post")}
794 <Icon icon="copy" inline />
802 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
803 onClick={linkEvent(this, this.handleShowReportDialog)}
804 aria-label={I18NextService.i18n.t("show_report_dialog")}
806 <Icon classes="me-1" icon="flag" inline />
807 {I18NextService.i18n.t("create_report")}
815 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
816 onClick={linkEvent(this, this.handleBlockPersonClick)}
817 aria-label={I18NextService.i18n.t("block_user")}
819 {this.state.blockLoading ? (
822 <Icon classes="me-1" icon="slash" inline />
824 {I18NextService.i18n.t("block_user")}
832 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
833 onClick={linkEvent(this, this.handleEditClick)}
834 aria-label={I18NextService.i18n.t("edit")}
836 <Icon classes="me-1" icon="edit" inline />
837 {I18NextService.i18n.t("edit")}
843 const deleted = this.postView.post.deleted;
844 const label = !deleted
845 ? I18NextService.i18n.t("delete")
846 : I18NextService.i18n.t("restore");
849 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
850 onClick={linkEvent(this, this.handleDeleteClick)}
852 {this.state.deleteLoading ? (
858 classes={classNames("me-1", { "text-danger": deleted })}
868 get viewSourceButton() {
871 className="btn btn-sm btn-animate text-muted py-0"
872 onClick={linkEvent(this, this.handleViewSource)}
873 data-tippy-content={I18NextService.i18n.t("view_source")}
874 aria-label={I18NextService.i18n.t("view_source")}
878 classes={classNames({ "text-success": this.state.viewSource })}
886 const locked = this.postView.post.locked;
888 ? I18NextService.i18n.t("unlock")
889 : I18NextService.i18n.t("lock");
892 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
893 onClick={linkEvent(this, this.handleModLock)}
896 {this.state.lockLoading ? (
902 classes={classNames("me-1", { "text-danger": locked })}
905 {capitalizeFirstLetter(label)}
912 get featureButtons() {
913 const featuredCommunity = this.postView.post.featured_community;
914 const labelCommunity = featuredCommunity
915 ? I18NextService.i18n.t("unfeature_from_community")
916 : I18NextService.i18n.t("feature_in_community");
918 const featuredLocal = this.postView.post.featured_local;
919 const labelLocal = featuredLocal
920 ? I18NextService.i18n.t("unfeature_from_local")
921 : I18NextService.i18n.t("feature_in_local");
926 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
927 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
928 data-tippy-content={labelCommunity}
929 aria-label={labelCommunity}
931 {this.state.featureCommunityLoading ? (
937 classes={classNames("me-1", {
938 "text-success": featuredCommunity,
942 {I18NextService.i18n.t("community")}
950 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
951 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
952 data-tippy-content={labelLocal}
953 aria-label={labelLocal}
955 {this.state.featureLocalLoading ? (
961 classes={classNames("me-1", {
962 "text-success": featuredLocal,
966 {I18NextService.i18n.t("local")}
976 get modRemoveButton() {
977 const removed = this.postView.post.removed;
980 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
983 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
986 {/* TODO: Find an icon for this. */}
987 {this.state.removeLoading ? (
990 I18NextService.i18n.t("remove")
992 I18NextService.i18n.t("restore")
999 * Mod/Admin actions to be taken against the author.
1003 const post_view = this.postView;
1005 this.state.showAdvanced && (
1006 <div className="mt-3">
1009 {!this.creatorIsMod_ &&
1010 (!post_view.creator_banned_from_community ? (
1012 className="btn btn-link btn-animate text-muted py-0"
1015 this.handleModBanFromCommunityShow
1017 aria-label={I18NextService.i18n.t("ban_from_community")}
1019 {I18NextService.i18n.t("ban_from_community")}
1023 className="btn btn-link btn-animate text-muted py-0"
1026 this.handleModBanFromCommunitySubmit
1028 aria-label={I18NextService.i18n.t("unban")}
1030 {this.state.banLoading ? (
1033 I18NextService.i18n.t("unban")
1037 {!post_view.creator_banned_from_community && (
1039 className="btn btn-link btn-animate text-muted py-0"
1040 onClick={linkEvent(this, this.handleAddModToCommunity)}
1043 ? I18NextService.i18n.t("remove_as_mod")
1044 : I18NextService.i18n.t("appoint_as_mod")
1047 {this.state.addModLoading ? (
1049 ) : this.creatorIsMod_ ? (
1050 I18NextService.i18n.t("remove_as_mod")
1052 I18NextService.i18n.t("appoint_as_mod")
1058 {/* Community creators and admins can transfer community to another mod */}
1059 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1061 this.creatorIsMod_ &&
1062 (!this.state.showConfirmTransferCommunity ? (
1064 className="btn btn-link btn-animate text-muted py-0"
1067 this.handleShowConfirmTransferCommunity
1069 aria-label={I18NextService.i18n.t("transfer_community")}
1071 {I18NextService.i18n.t("transfer_community")}
1076 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1077 aria-label={I18NextService.i18n.t("are_you_sure")}
1079 {I18NextService.i18n.t("are_you_sure")}
1082 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1083 aria-label={I18NextService.i18n.t("yes")}
1084 onClick={linkEvent(this, this.handleTransferCommunity)}
1086 {this.state.transferLoading ? (
1089 I18NextService.i18n.t("yes")
1093 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1096 this.handleCancelShowConfirmTransferCommunity
1098 aria-label={I18NextService.i18n.t("no")}
1100 {I18NextService.i18n.t("no")}
1104 {/* Admins can ban from all, and appoint other admins */}
1105 {this.canAdmin_ && (
1107 {!this.creatorIsAdmin_ && (
1109 {!isBanned(post_view.creator) ? (
1111 className="btn btn-link btn-animate text-muted py-0"
1112 onClick={linkEvent(this, this.handleModBanShow)}
1113 aria-label={I18NextService.i18n.t("ban_from_site")}
1115 {I18NextService.i18n.t("ban_from_site")}
1119 className="btn btn-link btn-animate text-muted py-0"
1120 onClick={linkEvent(this, this.handleModBanSubmit)}
1121 aria-label={I18NextService.i18n.t("unban_from_site")}
1123 {this.state.banLoading ? (
1126 I18NextService.i18n.t("unban_from_site")
1131 className="btn btn-link btn-animate text-muted py-0"
1132 onClick={linkEvent(this, this.handlePurgePersonShow)}
1133 aria-label={I18NextService.i18n.t("purge_user")}
1135 {I18NextService.i18n.t("purge_user")}
1138 className="btn btn-link btn-animate text-muted py-0"
1139 onClick={linkEvent(this, this.handlePurgePostShow)}
1140 aria-label={I18NextService.i18n.t("purge_post")}
1142 {I18NextService.i18n.t("purge_post")}
1146 {!isBanned(post_view.creator) && post_view.creator.local && (
1148 className="btn btn-link btn-animate text-muted py-0"
1149 onClick={linkEvent(this, this.handleAddAdmin)}
1151 this.creatorIsAdmin_
1152 ? I18NextService.i18n.t("remove_as_admin")
1153 : I18NextService.i18n.t("appoint_as_admin")
1156 {this.state.addAdminLoading ? (
1158 ) : this.creatorIsAdmin_ ? (
1159 I18NextService.i18n.t("remove_as_admin")
1161 I18NextService.i18n.t("appoint_as_admin")
1172 removeAndBanDialogs() {
1173 const post = this.postView;
1174 const purgeTypeText =
1175 this.state.purgeType == PurgeType.Post
1176 ? I18NextService.i18n.t("purge_post")
1177 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1180 {this.state.showRemoveDialog && (
1182 className="form-inline"
1183 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1186 className="visually-hidden"
1187 htmlFor="post-listing-remove-reason"
1189 {I18NextService.i18n.t("reason")}
1193 id="post-listing-remove-reason"
1194 className="form-control me-2"
1195 placeholder={I18NextService.i18n.t("reason")}
1196 value={this.state.removeReason}
1197 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1201 className="btn btn-secondary"
1202 aria-label={I18NextService.i18n.t("remove_post")}
1204 {this.state.removeLoading ? (
1207 I18NextService.i18n.t("remove_post")
1212 {this.state.showBanDialog && (
1213 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1214 <div className="mb-3 row col-12">
1216 className="col-form-label"
1217 htmlFor="post-listing-ban-reason"
1219 {I18NextService.i18n.t("reason")}
1223 id="post-listing-ban-reason"
1224 className="form-control me-2"
1225 placeholder={I18NextService.i18n.t("reason")}
1226 value={this.state.banReason}
1227 onInput={linkEvent(this, this.handleModBanReasonChange)}
1229 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1230 {I18NextService.i18n.t("expires")}
1234 id={`mod-ban-expires`}
1235 className="form-control me-2"
1236 placeholder={I18NextService.i18n.t("number_of_days")}
1237 value={this.state.banExpireDays}
1238 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1240 <div className="input-group mb-3">
1241 <div className="form-check">
1243 className="form-check-input"
1244 id="mod-ban-remove-data"
1246 checked={this.state.removeData}
1247 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1250 className="form-check-label"
1251 htmlFor="mod-ban-remove-data"
1252 title={I18NextService.i18n.t("remove_content_more")}
1254 {I18NextService.i18n.t("remove_content")}
1259 {/* TODO hold off on expires until later */}
1260 {/* <div class="mb-3 row"> */}
1261 {/* <label class="col-form-label">Expires</label> */}
1262 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1264 <div className="mb-3 row">
1267 className="btn btn-secondary"
1268 aria-label={I18NextService.i18n.t("ban")}
1270 {this.state.banLoading ? (
1274 {I18NextService.i18n.t("ban")} {post.creator.name}
1281 {this.state.showReportDialog && (
1283 className="form-inline"
1284 onSubmit={linkEvent(this, this.handleReportSubmit)}
1286 <label className="visually-hidden" htmlFor="post-report-reason">
1287 {I18NextService.i18n.t("reason")}
1291 id="post-report-reason"
1292 className="form-control me-2"
1293 placeholder={I18NextService.i18n.t("reason")}
1295 value={this.state.reportReason}
1296 onInput={linkEvent(this, this.handleReportReasonChange)}
1300 className="btn btn-secondary"
1301 aria-label={I18NextService.i18n.t("create_report")}
1303 {this.state.reportLoading ? (
1306 I18NextService.i18n.t("create_report")
1311 {this.state.showPurgeDialog && (
1313 className="form-inline"
1314 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1317 <label className="visually-hidden" htmlFor="purge-reason">
1318 {I18NextService.i18n.t("reason")}
1323 className="form-control me-2"
1324 placeholder={I18NextService.i18n.t("reason")}
1325 value={this.state.purgeReason}
1326 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1328 {this.state.purgeLoading ? (
1333 className="btn btn-secondary"
1334 aria-label={purgeTypeText}
1336 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1346 const post = this.postView.post;
1347 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1348 <div className="row">
1349 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1350 {this.postTitleLine()}
1352 <div className="col-4">
1353 {/* Post thumbnail */}
1354 {!this.state.imageExpanded && this.thumbnail()}
1358 this.postTitleLine()
1365 {/* The mobile view*/}
1366 <div className="d-block d-sm-none">
1367 <article className="row post-container">
1368 <div className="col-12">
1369 {this.createdLine()}
1371 {/* If it has a thumbnail, do a right aligned thumbnail */}
1372 {this.mobileThumbnail()}
1374 {this.commentsLine(true)}
1375 {this.userActionsLine()}
1376 {this.duplicatesLine()}
1377 {this.removeAndBanDialogs()}
1382 {/* The larger view*/}
1383 <div className="d-none d-sm-block">
1384 <article className="row post-container">
1385 {!this.props.viewOnly && (
1387 voteContentType={VoteContentType.Post}
1388 id={this.postView.post.id}
1389 onVote={this.props.onPostVote}
1390 enableDownvotes={this.props.enableDownvotes}
1391 counts={this.postView.counts}
1392 my_vote={this.postView.my_vote}
1395 <div className="col-sm-2 pe-0 post-media">
1396 <div className="">{this.thumbnail()}</div>
1398 <div className="col-12 col-sm-9">
1399 <div className="row">
1400 <div className="col-12">
1401 {this.postTitleLine()}
1402 {this.createdLine()}
1403 {this.commentsLine()}
1404 {this.duplicatesLine()}
1405 {this.userActionsLine()}
1406 {this.removeAndBanDialogs()}
1416 private get myPost(): boolean {
1418 this.postView.creator.id ==
1419 UserService.Instance.myUserInfo?.local_user_view.person.id
1422 handleEditClick(i: PostListing) {
1423 i.setState({ showEdit: true });
1426 handleEditCancel() {
1427 this.setState({ showEdit: false });
1430 // The actual editing is done in the receive for post
1431 handleEditPost(form: EditPost) {
1432 this.setState({ showEdit: false });
1433 this.props.onPostEdit(form);
1436 handleShare(i: PostListing) {
1437 const { name, body, id } = i.props.post_view.post;
1440 text: body?.slice(0, 50),
1441 url: `${getHttpBase()}/post/${id}`,
1445 handleShowReportDialog(i: PostListing) {
1446 i.setState({ showReportDialog: !i.state.showReportDialog });
1449 handleReportReasonChange(i: PostListing, event: any) {
1450 i.setState({ reportReason: event.target.value });
1453 handleReportSubmit(i: PostListing, event: any) {
1454 event.preventDefault();
1455 i.setState({ reportLoading: true });
1456 i.props.onPostReport({
1457 post_id: i.postView.post.id,
1458 reason: i.state.reportReason ?? "",
1459 auth: myAuthRequired(),
1463 handleBlockPersonClick(i: PostListing) {
1464 i.setState({ blockLoading: true });
1465 i.props.onBlockPerson({
1466 person_id: i.postView.creator.id,
1468 auth: myAuthRequired(),
1472 handleDeleteClick(i: PostListing) {
1473 i.setState({ deleteLoading: true });
1474 i.props.onDeletePost({
1475 post_id: i.postView.post.id,
1476 deleted: !i.postView.post.deleted,
1477 auth: myAuthRequired(),
1481 handleSavePostClick(i: PostListing) {
1482 i.setState({ saveLoading: true });
1483 i.props.onSavePost({
1484 post_id: i.postView.post.id,
1485 save: !i.postView.saved,
1486 auth: myAuthRequired(),
1490 get crossPostParams(): PostFormParams {
1491 const queryParams: PostFormParams = {};
1492 const { name, url } = this.postView.post;
1494 queryParams.name = name;
1497 queryParams.url = url;
1500 const crossPostBody = this.crossPostBody();
1501 if (crossPostBody) {
1502 queryParams.body = crossPostBody;
1508 crossPostBody(): string | undefined {
1509 const post = this.postView.post;
1510 const body = post.body;
1513 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1515 }\n\n${body.replace(/^/gm, "> ")}`
1519 get showBody(): boolean {
1520 return this.props.showBody || this.state.showBody;
1523 handleModRemoveShow(i: PostListing) {
1525 showRemoveDialog: !i.state.showRemoveDialog,
1526 showBanDialog: false,
1530 handleModRemoveReasonChange(i: PostListing, event: any) {
1531 i.setState({ removeReason: event.target.value });
1534 handleModRemoveDataChange(i: PostListing, event: any) {
1535 i.setState({ removeData: event.target.checked });
1538 handleModRemoveSubmit(i: PostListing, event: any) {
1539 event.preventDefault();
1540 i.setState({ removeLoading: true });
1541 i.props.onRemovePost({
1542 post_id: i.postView.post.id,
1543 removed: !i.postView.post.removed,
1544 auth: myAuthRequired(),
1548 handleModLock(i: PostListing) {
1549 i.setState({ lockLoading: true });
1550 i.props.onLockPost({
1551 post_id: i.postView.post.id,
1552 locked: !i.postView.post.locked,
1553 auth: myAuthRequired(),
1557 handleModFeaturePostLocal(i: PostListing) {
1558 i.setState({ featureLocalLoading: true });
1559 i.props.onFeaturePost({
1560 post_id: i.postView.post.id,
1561 featured: !i.postView.post.featured_local,
1562 feature_type: "Local",
1563 auth: myAuthRequired(),
1567 handleModFeaturePostCommunity(i: PostListing) {
1568 i.setState({ featureCommunityLoading: true });
1569 i.props.onFeaturePost({
1570 post_id: i.postView.post.id,
1571 featured: !i.postView.post.featured_community,
1572 feature_type: "Community",
1573 auth: myAuthRequired(),
1577 handleModBanFromCommunityShow(i: PostListing) {
1579 showBanDialog: true,
1580 banType: BanType.Community,
1581 showRemoveDialog: false,
1585 handleModBanShow(i: PostListing) {
1587 showBanDialog: true,
1588 banType: BanType.Site,
1589 showRemoveDialog: false,
1593 handlePurgePersonShow(i: PostListing) {
1595 showPurgeDialog: true,
1596 purgeType: PurgeType.Person,
1597 showRemoveDialog: false,
1601 handlePurgePostShow(i: PostListing) {
1603 showPurgeDialog: true,
1604 purgeType: PurgeType.Post,
1605 showRemoveDialog: false,
1609 handlePurgeReasonChange(i: PostListing, event: any) {
1610 i.setState({ purgeReason: event.target.value });
1613 handlePurgeSubmit(i: PostListing, event: any) {
1614 event.preventDefault();
1615 i.setState({ purgeLoading: true });
1616 if (i.state.purgeType == PurgeType.Person) {
1617 i.props.onPurgePerson({
1618 person_id: i.postView.creator.id,
1619 reason: i.state.purgeReason,
1620 auth: myAuthRequired(),
1622 } else if (i.state.purgeType == PurgeType.Post) {
1623 i.props.onPurgePost({
1624 post_id: i.postView.post.id,
1625 reason: i.state.purgeReason,
1626 auth: myAuthRequired(),
1631 handleModBanReasonChange(i: PostListing, event: any) {
1632 i.setState({ banReason: event.target.value });
1635 handleModBanExpireDaysChange(i: PostListing, event: any) {
1636 i.setState({ banExpireDays: event.target.value });
1639 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1640 i.setState({ banType: BanType.Community });
1641 i.handleModBanBothSubmit(i, event);
1644 handleModBanSubmit(i: PostListing, event: any) {
1645 i.setState({ banType: BanType.Site });
1646 i.handleModBanBothSubmit(i, event);
1649 handleModBanBothSubmit(i: PostListing, event: any) {
1650 event.preventDefault();
1651 i.setState({ banLoading: true });
1653 const ban = !i.props.post_view.creator_banned_from_community;
1654 // If its an unban, restore all their data
1656 i.setState({ removeData: false });
1658 const person_id = i.props.post_view.creator.id;
1659 const remove_data = i.state.removeData;
1660 const reason = i.state.banReason;
1661 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1663 if (i.state.banType == BanType.Community) {
1664 const community_id = i.postView.community.id;
1665 i.props.onBanPersonFromCommunity({
1672 auth: myAuthRequired(),
1675 i.props.onBanPerson({
1681 auth: myAuthRequired(),
1686 handleAddModToCommunity(i: PostListing) {
1687 i.setState({ addModLoading: true });
1688 i.props.onAddModToCommunity({
1689 community_id: i.postView.community.id,
1690 person_id: i.postView.creator.id,
1691 added: !i.creatorIsMod_,
1692 auth: myAuthRequired(),
1696 handleAddAdmin(i: PostListing) {
1697 i.setState({ addAdminLoading: true });
1698 i.props.onAddAdmin({
1699 person_id: i.postView.creator.id,
1700 added: !i.creatorIsAdmin_,
1701 auth: myAuthRequired(),
1705 handleShowConfirmTransferCommunity(i: PostListing) {
1706 i.setState({ showConfirmTransferCommunity: true });
1709 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1710 i.setState({ showConfirmTransferCommunity: false });
1713 handleTransferCommunity(i: PostListing) {
1714 i.setState({ transferLoading: true });
1715 i.props.onTransferCommunity({
1716 community_id: i.postView.community.id,
1717 person_id: i.postView.creator.id,
1718 auth: myAuthRequired(),
1722 handleShowConfirmTransferSite(i: PostListing) {
1723 i.setState({ showConfirmTransferSite: true });
1726 handleCancelShowConfirmTransferSite(i: PostListing) {
1727 i.setState({ showConfirmTransferSite: false });
1730 handleImageExpandClick(i: PostListing, event: any) {
1731 event.preventDefault();
1732 i.setState({ imageExpanded: !i.state.imageExpanded });
1736 handleViewSource(i: PostListing) {
1737 i.setState({ viewSource: !i.state.viewSource });
1740 handleShowAdvanced(i: PostListing) {
1741 i.setState({ showAdvanced: !i.state.showAdvanced });
1745 handleShowMoreMobile(i: PostListing) {
1747 showMoreMobile: !i.state.showMoreMobile,
1748 showAdvanced: !i.state.showAdvanced,
1753 handleShowBody(i: PostListing) {
1754 i.setState({ showBody: !i.state.showBody });
1758 // handleShowPreview(i: PostListing) {
1762 get pointsTippy(): string {
1763 const points = I18NextService.i18n.t("number_of_points", {
1764 count: Number(this.postView.counts.score),
1765 formattedCount: Number(this.postView.counts.score),
1768 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1769 count: Number(this.postView.counts.upvotes),
1770 formattedCount: Number(this.postView.counts.upvotes),
1773 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1774 count: Number(this.postView.counts.downvotes),
1775 formattedCount: Number(this.postView.counts.downvotes),
1778 return `${points} • ${upvotes} • ${downvotes}`;
1781 get canModOnSelf_(): boolean {
1783 this.postView.creator.id,
1784 this.props.moderators,
1791 get canMod_(): boolean {
1793 this.postView.creator.id,
1794 this.props.moderators,
1799 get canAdmin_(): boolean {
1800 return canAdmin(this.postView.creator.id, this.props.admins);
1803 get creatorIsMod_(): boolean {
1804 return isMod(this.postView.creator.id, this.props.moderators);
1807 get creatorIsAdmin_(): boolean {
1808 return isAdmin(this.postView.creator.id, this.props.admins);