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,
190 get postView(): PostView {
191 return this.props.post_view;
195 const post = this.postView.post;
198 <div className="post-listing mt-2">
199 {!this.state.showEdit ? (
202 {this.state.imageExpanded && !this.props.hideImage && this.img}
203 {post.url && this.state.showBody && post.embed_title && (
204 <MetadataCard post={post} />
206 {this.showBody && this.body()}
210 post_view={this.postView}
211 crossPosts={this.props.crossPosts}
212 onEdit={this.handleEditPost}
213 onCancel={this.handleEditCancel}
214 enableNsfw={this.props.enableNsfw}
215 enableDownvotes={this.props.enableDownvotes}
216 allLanguages={this.props.allLanguages}
217 siteLanguages={this.props.siteLanguages}
225 const body = this.postView.post.body;
227 <article id="postContent" className="col-12 card my-2 p-2">
228 {this.state.viewSource ? (
231 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
243 <div className="offset-sm-3 my-2 d-none d-sm-block">
244 <a href={this.imageSrc} className="d-inline-block">
245 <PictrsImage src={this.imageSrc} />
248 <div className="my-2 d-block d-sm-none">
251 className="p-0 border-0 bg-transparent d-inline-block"
252 onClick={linkEvent(this, this.handleImageExpandClick)}
254 <PictrsImage src={this.imageSrc} />
261 const { post } = this.postView;
262 const { url } = post;
264 // if direct video link
265 if (url && isVideo(url)) {
267 <div className="embed-responsive mt-3">
268 <video muted controls className="embed-responsive-item col-12">
269 <source src={url} type="video/mp4" />
275 // if embedded video link
276 if (url && post.embed_video_url) {
278 <div className="ratio ratio-16x9">
281 className="post-metadata-iframe"
282 src={post.embed_video_url}
283 title={post.embed_title}
292 imgThumb(src: string) {
293 const post_view = this.postView;
299 nsfw={post_view.post.nsfw || post_view.community.nsfw}
304 get imageSrc(): string | undefined {
305 const post = this.postView.post;
306 const url = post.url;
307 const thumbnail = post.thumbnail_url;
309 if (url && isImage(url)) {
310 if (url.includes("pictrs")) {
312 } else if (thumbnail) {
317 } else if (thumbnail) {
325 const post = this.postView.post;
326 const url = post.url;
327 const thumbnail = post.thumbnail_url;
329 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
333 className="text-body d-inline-block position-relative mb-2"
334 data-tippy-content={I18NextService.i18n.t("expand_here")}
335 onClick={linkEvent(this, this.handleImageExpandClick)}
336 aria-label={I18NextService.i18n.t("expand_here")}
338 {this.imgThumb(this.imageSrc)}
339 <Icon icon="image" classes="mini-overlay" />
342 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
345 className="text-body d-inline-block position-relative mb-2"
350 {this.imgThumb(this.imageSrc)}
351 <Icon icon="external-link" classes="mini-overlay" />
355 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
358 className="text-body"
362 data-tippy-content={I18NextService.i18n.t("expand_here")}
363 onClick={linkEvent(this, this.handleImageExpandClick)}
364 aria-label={I18NextService.i18n.t("expand_here")}
366 <div className="thumbnail rounded bg-light d-flex justify-content-center">
367 <Icon icon="play" classes="d-flex align-items-center" />
373 <a className="text-body" href={url} title={url} rel={relTags}>
374 <div className="thumbnail rounded bg-light d-flex justify-content-center">
375 <Icon icon="external-link" classes="d-flex align-items-center" />
383 className="text-body"
384 to={`/post/${post.id}`}
385 title={I18NextService.i18n.t("comments")}
387 <div className="thumbnail rounded bg-light d-flex justify-content-center">
388 <Icon icon="message-square" classes="d-flex align-items-center" />
396 const post_view = this.postView;
398 <span className="small">
399 <PersonListing person={post_view.creator} muted={true} />
400 {this.creatorIsMod_ && (
401 <span className="mx-1 badge text-bg-light">
402 {I18NextService.i18n.t("mod")}
405 {this.creatorIsAdmin_ && (
406 <span className="mx-1 badge text-bg-light">
407 {I18NextService.i18n.t("admin")}
410 {post_view.creator.bot_account && (
411 <span className="mx-1 badge text-bg-light">
412 {I18NextService.i18n.t("bot_account").toLowerCase()}
415 {this.props.showCommunity && (
418 {I18NextService.i18n.t("to")}{" "}
419 <CommunityLink community={post_view.community} />
422 {post_view.post.language_id !== 0 && (
423 <span className="mx-1 badge text-bg-light">
425 this.props.allLanguages.find(
426 lang => lang.id === post_view.post.language_id
433 published={post_view.post.published}
434 updated={post_view.post.updated}
441 const post = this.postView.post;
444 className={`d-inline ${
445 !post.featured_community && !post.featured_local
449 to={`/post/${post.id}`}
450 title={I18NextService.i18n.t("comments")}
454 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
461 const post = this.postView.post;
462 const url = post.url;
466 <div className="post-title overflow-hidden">
467 <h5 className="d-inline">
468 {url && this.props.showBody ? (
471 !post.featured_community && !post.featured_local
478 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
486 <small className="ms-2 badge text-bg-secondary">
487 {I18NextService.i18n.t("removed")}
493 className="unselectable pointer ms-2 text-muted fst-italic"
494 data-tippy-content={I18NextService.i18n.t("deleted")}
496 <Icon icon="trash" classes="icon-inline text-danger" />
502 className="unselectable pointer ms-2 text-muted fst-italic"
503 data-tippy-content={I18NextService.i18n.t("locked")}
505 <Icon icon="lock" classes="icon-inline text-danger" />
509 {post.featured_community && (
511 className="unselectable pointer ms-2 text-muted fst-italic"
512 data-tippy-content={I18NextService.i18n.t(
513 "featured_in_community"
515 aria-label={I18NextService.i18n.t("featured_in_community")}
517 <Icon icon="pin" classes="icon-inline text-primary" />
521 {post.featured_local && (
523 className="unselectable pointer ms-2 text-muted fst-italic"
524 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
525 aria-label={I18NextService.i18n.t("featured_in_local")}
527 <Icon icon="pin" classes="icon-inline text-secondary" />
532 <small className="ms-2 badge text-bg-danger">
533 {I18NextService.i18n.t("nsfw")}
537 {url && this.urlLine()}
543 const post = this.postView.post;
544 const url = post.url;
547 <p className="small m-0">
548 {url && !(hostname(url) === getExternalHost()) && (
550 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
563 const dupes = this.props.crossPosts;
564 return dupes && dupes.length > 0 ? (
565 <ul className="list-inline mb-1 small text-muted">
567 <li className="list-inline-item me-2">
568 {I18NextService.i18n.t("cross_posted_to")}
571 <li key={pv.post.id} className="list-inline-item me-2">
572 <Link to={`/post/${pv.post.id}`}>
575 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
586 commentsLine(mobile = false) {
587 const post = this.postView.post;
590 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
591 {this.commentsButton}
594 className="btn btn-sm btn-animate text-muted py-0"
595 onClick={linkEvent(this, this.handleShare)}
598 <Icon icon="share" inline />
603 className="btn btn-sm btn-animate text-muted py-0"
604 title={I18NextService.i18n.t("link")}
607 <Icon icon="fedilink" inline />
610 {mobile && !this.props.viewOnly && (
612 voteContentType={VoteContentType.Post}
613 id={this.postView.post.id}
614 onVote={this.props.onPostVote}
615 enableDownvotes={this.props.enableDownvotes}
616 counts={this.postView.counts}
617 my_vote={this.postView.my_vote}
620 {UserService.Instance.myUserInfo &&
621 !this.props.viewOnly &&
627 showPreviewButton() {
628 const post_view = this.postView;
629 const body = post_view.post.body;
633 className="btn btn-sm btn-animate text-muted py-0"
634 data-tippy-content={body && mdNoImages.render(body)}
635 data-tippy-allowHtml={true}
636 onClick={linkEvent(this, this.handleShowBody)}
640 classes={classNames("icon-inline me-1", {
641 "text-success": this.state.showBody,
649 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
650 // Possible enhancement: Make each button a component.
651 const post_view = this.postView;
652 const post = post_view.post;
657 {this.crossPostButton}
660 * If there is a URL, or if the post has a body and we were told not to
661 * show the body, show the MetadataCard/body toggle.
663 {(post.url || (post.body && !this.props.showBody)) &&
664 this.showPreviewButton()}
666 {this.showBody && post_view.post.body && this.viewSourceButton}
668 <div className="dropdown">
670 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
671 onClick={linkEvent(this, this.handleShowAdvanced)}
672 data-tippy-content={I18NextService.i18n.t("more")}
673 data-bs-toggle="dropdown"
674 aria-expanded="false"
675 aria-controls={`advancedButtonsDropdown${post.id}`}
676 aria-label={I18NextService.i18n.t("more")}
678 <Icon icon="more-vertical" inline />
682 className="dropdown-menu"
683 id={`advancedButtonsDropdown${post.id}`}
687 <li>{this.reportButton}</li>
688 <li>{this.blockButton}</li>
692 <li>{this.editButton}</li>
693 <li>{this.deleteButton}</li>
697 {/* Any mod can do these, not limited to hierarchy*/}
698 {(amMod(this.props.moderators) || amAdmin()) && (
701 <hr className="dropdown-divider" />
703 <li>{this.lockButton}</li>
704 {this.featureButtons}
708 {(this.canMod_ || this.canAdmin_) && (
709 <li>{this.modRemoveButton}</li>
717 get commentsButton() {
718 const post_view = this.postView;
719 const title = I18NextService.i18n.t("number_of_comments", {
720 count: Number(post_view.counts.comments),
721 formattedCount: Number(post_view.counts.comments),
726 className="btn btn-link btn-sm text-muted ps-0"
728 to={`/post/${post_view.post.id}?scrollToComments=true`}
729 data-tippy-content={title}
731 <Icon icon="message-square" classes="me-1" inline />
732 {post_view.counts.comments}
733 {this.unreadCount && (
736 <span className="fst-italic">
737 ({this.unreadCount} {I18NextService.i18n.t("new")})
745 get unreadCount(): number | undefined {
746 const pv = this.postView;
747 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
749 : pv.unread_comments;
753 const saved = this.postView.saved;
755 ? I18NextService.i18n.t("unsave")
756 : I18NextService.i18n.t("save");
759 className="btn btn-sm btn-animate text-muted py-0"
760 onClick={linkEvent(this, this.handleSavePostClick)}
761 data-tippy-content={label}
764 {this.state.saveLoading ? (
769 classes={classNames({ "text-warning": saved })}
777 get crossPostButton() {
780 className="btn btn-sm btn-animate text-muted py-0"
782 /* Empty string properties are required to satisfy type*/
783 pathname: "/create_post",
784 state: { ...this.crossPostParams },
789 title={I18NextService.i18n.t("cross_post")}
790 data-tippy-content={I18NextService.i18n.t("cross_post")}
791 aria-label={I18NextService.i18n.t("cross_post")}
793 <Icon icon="copy" inline />
801 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
802 onClick={linkEvent(this, this.handleShowReportDialog)}
803 aria-label={I18NextService.i18n.t("show_report_dialog")}
805 <Icon classes="me-1" icon="flag" inline />
806 {I18NextService.i18n.t("create_report")}
814 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
815 onClick={linkEvent(this, this.handleBlockPersonClick)}
816 aria-label={I18NextService.i18n.t("block_user")}
818 {this.state.blockLoading ? (
821 <Icon classes="me-1" icon="slash" inline />
823 {I18NextService.i18n.t("block_user")}
831 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
832 onClick={linkEvent(this, this.handleEditClick)}
833 aria-label={I18NextService.i18n.t("edit")}
835 <Icon classes="me-1" icon="edit" inline />
836 {I18NextService.i18n.t("edit")}
842 const deleted = this.postView.post.deleted;
843 const label = !deleted
844 ? I18NextService.i18n.t("delete")
845 : I18NextService.i18n.t("restore");
848 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
849 onClick={linkEvent(this, this.handleDeleteClick)}
851 {this.state.deleteLoading ? (
857 classes={classNames("me-1", { "text-danger": deleted })}
867 get viewSourceButton() {
870 className="btn btn-sm btn-animate text-muted py-0"
871 onClick={linkEvent(this, this.handleViewSource)}
872 data-tippy-content={I18NextService.i18n.t("view_source")}
873 aria-label={I18NextService.i18n.t("view_source")}
877 classes={classNames({ "text-success": this.state.viewSource })}
885 const locked = this.postView.post.locked;
887 ? I18NextService.i18n.t("unlock")
888 : I18NextService.i18n.t("lock");
891 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
892 onClick={linkEvent(this, this.handleModLock)}
895 {this.state.lockLoading ? (
901 classes={classNames("me-1", { "text-danger": locked })}
904 {capitalizeFirstLetter(label)}
911 get featureButtons() {
912 const featuredCommunity = this.postView.post.featured_community;
913 const labelCommunity = featuredCommunity
914 ? I18NextService.i18n.t("unfeature_from_community")
915 : I18NextService.i18n.t("feature_in_community");
917 const featuredLocal = this.postView.post.featured_local;
918 const labelLocal = featuredLocal
919 ? I18NextService.i18n.t("unfeature_from_local")
920 : I18NextService.i18n.t("feature_in_local");
925 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
926 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
927 data-tippy-content={labelCommunity}
928 aria-label={labelCommunity}
930 {this.state.featureCommunityLoading ? (
936 classes={classNames("me-1", {
937 "text-success": featuredCommunity,
941 {I18NextService.i18n.t("community")}
949 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
950 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
951 data-tippy-content={labelLocal}
952 aria-label={labelLocal}
954 {this.state.featureLocalLoading ? (
960 classes={classNames("me-1", {
961 "text-success": featuredLocal,
965 {I18NextService.i18n.t("local")}
975 get modBanFromCommunityButton() {
978 className="btn btn-link btn-animate text-muted py-0"
979 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
980 aria-label={I18NextService.i18n.t("ban_from_community")}
982 {I18NextService.i18n.t("ban_from_community")}
987 get modUnbanFromCommunityButton() {
990 className="btn btn-link btn-animate text-muted py-0"
991 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
992 aria-label={I18NextService.i18n.t("unban")}
994 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
999 get addModToCommunityButton() {
1002 className="btn btn-link btn-animate text-muted py-0"
1003 onClick={linkEvent(this, this.handleAddModToCommunity)}
1006 ? I18NextService.i18n.t("remove_as_mod")
1007 : I18NextService.i18n.t("appoint_as_mod")
1010 {this.state.addModLoading ? (
1012 ) : this.creatorIsMod_ ? (
1013 I18NextService.i18n.t("remove_as_mod")
1015 I18NextService.i18n.t("appoint_as_mod")
1021 get modBanButton() {
1024 className="btn btn-link btn-animate text-muted py-0"
1025 onClick={linkEvent(this, this.handleModBanShow)}
1026 aria-label={I18NextService.i18n.t("ban_from_site")}
1028 {I18NextService.i18n.t("ban_from_site")}
1033 get modUnbanButton() {
1036 className="btn btn-link btn-animate text-muted py-0"
1037 onClick={linkEvent(this, this.handleModBanSubmit)}
1038 aria-label={I18NextService.i18n.t("unban_from_site")}
1040 {this.state.banLoading ? (
1043 I18NextService.i18n.t("unban_from_site")
1049 get purgePersonButton() {
1052 className="btn btn-link btn-animate text-muted py-0"
1053 onClick={linkEvent(this, this.handlePurgePersonShow)}
1054 aria-label={I18NextService.i18n.t("purge_user")}
1056 {I18NextService.i18n.t("purge_user")}
1061 get purgePostButton() {
1064 className="btn btn-link btn-animate text-muted py-0"
1065 onClick={linkEvent(this, this.handlePurgePostShow)}
1066 aria-label={I18NextService.i18n.t("purge_post")}
1068 {I18NextService.i18n.t("purge_post")}
1073 get toggleAdminButton() {
1076 className="btn btn-link btn-animate text-muted py-0"
1077 onClick={linkEvent(this, this.handleAddAdmin)}
1079 {this.state.addAdminLoading ? (
1081 ) : this.creatorIsAdmin_ ? (
1082 I18NextService.i18n.t("remove_as_admin")
1084 I18NextService.i18n.t("appoint_as_admin")
1090 get modRemoveButton() {
1091 const removed = this.postView.post.removed;
1094 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1097 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1100 {/* TODO: Find an icon for this. */}
1101 {this.state.removeLoading ? (
1104 I18NextService.i18n.t("remove")
1106 I18NextService.i18n.t("restore")
1113 * Mod/Admin actions to be taken against the author.
1117 const post_view = this.postView;
1119 this.state.showAdvanced && (
1120 <div className="mt-3">
1123 {!this.creatorIsMod_ &&
1124 (!post_view.creator_banned_from_community
1125 ? this.modBanFromCommunityButton
1126 : this.modUnbanFromCommunityButton)}
1127 {!post_view.creator_banned_from_community &&
1128 this.addModToCommunityButton}
1132 {/* Community creators and admins can transfer community to another mod */}
1133 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1135 this.creatorIsMod_ &&
1136 (!this.state.showConfirmTransferCommunity ? (
1138 className="btn btn-link btn-animate text-muted py-0"
1141 this.handleShowConfirmTransferCommunity
1143 aria-label={I18NextService.i18n.t("transfer_community")}
1145 {I18NextService.i18n.t("transfer_community")}
1150 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1151 aria-label={I18NextService.i18n.t("are_you_sure")}
1153 {I18NextService.i18n.t("are_you_sure")}
1156 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1157 aria-label={I18NextService.i18n.t("yes")}
1158 onClick={linkEvent(this, this.handleTransferCommunity)}
1160 {this.state.transferLoading ? (
1163 I18NextService.i18n.t("yes")
1167 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1170 this.handleCancelShowConfirmTransferCommunity
1172 aria-label={I18NextService.i18n.t("no")}
1174 {I18NextService.i18n.t("no")}
1178 {/* Admins can ban from all, and appoint other admins */}
1179 {this.canAdmin_ && (
1181 {!this.creatorIsAdmin_ && (
1183 {!isBanned(post_view.creator)
1185 : this.modUnbanButton}
1186 {this.purgePersonButton}
1187 {this.purgePostButton}
1190 {!isBanned(post_view.creator) &&
1191 post_view.creator.local &&
1192 this.toggleAdminButton}
1200 removeAndBanDialogs() {
1201 const post = this.postView;
1202 const purgeTypeText =
1203 this.state.purgeType == PurgeType.Post
1204 ? I18NextService.i18n.t("purge_post")
1205 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1208 {this.state.showRemoveDialog && (
1210 className="form-inline"
1211 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1214 className="visually-hidden"
1215 htmlFor="post-listing-remove-reason"
1217 {I18NextService.i18n.t("reason")}
1221 id="post-listing-remove-reason"
1222 className="form-control me-2"
1223 placeholder={I18NextService.i18n.t("reason")}
1224 value={this.state.removeReason}
1225 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1229 className="btn btn-secondary"
1230 aria-label={I18NextService.i18n.t("remove_post")}
1232 {this.state.removeLoading ? (
1235 I18NextService.i18n.t("remove_post")
1240 {this.state.showBanDialog && (
1241 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1242 <div className="mb-3 row col-12">
1244 className="col-form-label"
1245 htmlFor="post-listing-ban-reason"
1247 {I18NextService.i18n.t("reason")}
1251 id="post-listing-ban-reason"
1252 className="form-control me-2"
1253 placeholder={I18NextService.i18n.t("reason")}
1254 value={this.state.banReason}
1255 onInput={linkEvent(this, this.handleModBanReasonChange)}
1257 <label className="col-form-label" htmlFor="mod-ban-expires">
1258 {I18NextService.i18n.t("expires")}
1262 id="mod-ban-expires"
1263 className="form-control me-2"
1264 placeholder={I18NextService.i18n.t("number_of_days")}
1265 value={this.state.banExpireDays}
1266 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1268 <div className="input-group mb-3">
1269 <div className="form-check">
1271 className="form-check-input"
1272 id="mod-ban-remove-data"
1274 checked={this.state.removeData}
1275 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1278 className="form-check-label"
1279 htmlFor="mod-ban-remove-data"
1280 title={I18NextService.i18n.t("remove_content_more")}
1282 {I18NextService.i18n.t("remove_content")}
1287 {/* TODO hold off on expires until later */}
1288 {/* <div class="mb-3 row"> */}
1289 {/* <label class="col-form-label">Expires</label> */}
1290 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1292 <div className="mb-3 row">
1295 className="btn btn-secondary"
1296 aria-label={I18NextService.i18n.t("ban")}
1298 {this.state.banLoading ? (
1302 {I18NextService.i18n.t("ban")} {post.creator.name}
1309 {this.state.showReportDialog && (
1311 className="form-inline"
1312 onSubmit={linkEvent(this, this.handleReportSubmit)}
1314 <label className="visually-hidden" htmlFor="post-report-reason">
1315 {I18NextService.i18n.t("reason")}
1319 id="post-report-reason"
1320 className="form-control me-2"
1321 placeholder={I18NextService.i18n.t("reason")}
1323 value={this.state.reportReason}
1324 onInput={linkEvent(this, this.handleReportReasonChange)}
1328 className="btn btn-secondary"
1329 aria-label={I18NextService.i18n.t("create_report")}
1331 {this.state.reportLoading ? (
1334 I18NextService.i18n.t("create_report")
1339 {this.state.showPurgeDialog && (
1341 className="form-inline"
1342 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1345 <label className="visually-hidden" htmlFor="purge-reason">
1346 {I18NextService.i18n.t("reason")}
1351 className="form-control me-2"
1352 placeholder={I18NextService.i18n.t("reason")}
1353 value={this.state.purgeReason}
1354 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1356 {this.state.purgeLoading ? (
1361 className="btn btn-secondary"
1362 aria-label={purgeTypeText}
1364 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1374 const post = this.postView.post;
1375 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1376 <div className="row">
1377 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1378 {this.postTitleLine()}
1380 <div className="col-4">
1381 {/* Post thumbnail */}
1382 {!this.state.imageExpanded && this.thumbnail()}
1386 this.postTitleLine()
1391 const { body, id } = this.postView.post;
1393 return !this.showBody && body ? (
1394 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1395 <div className="md-div mb-1 preview-lines">{body}</div>
1405 {/* The mobile view*/}
1406 <div className="d-block d-sm-none">
1407 <article className="row post-container">
1408 <div className="col-12">
1409 {this.createdLine()}
1411 {/* If it has a thumbnail, do a right aligned thumbnail */}
1412 {this.mobileThumbnail()}
1414 {/* Show a preview of the post body */}
1415 {this.showBodyPreview()}
1417 {this.commentsLine(true)}
1418 {this.userActionsLine()}
1419 {this.duplicatesLine()}
1420 {this.removeAndBanDialogs()}
1425 {/* The larger view*/}
1426 <div className="d-none d-sm-block">
1427 <article className="row post-container">
1428 {!this.props.viewOnly && (
1429 <div className="col flex-grow-0">
1431 voteContentType={VoteContentType.Post}
1432 id={this.postView.post.id}
1433 onVote={this.props.onPostVote}
1434 enableDownvotes={this.props.enableDownvotes}
1435 counts={this.postView.counts}
1436 my_vote={this.postView.my_vote}
1440 <div className="col flex-grow-1">
1441 <div className="row">
1442 <div className="col-sm-3 col-lg-2 pe-0 post-media">
1443 <div className="">{this.thumbnail()}</div>
1445 <div className="col-12 col-sm-9 col-lg-10">
1446 {this.postTitleLine()}
1447 {this.createdLine()}
1448 {this.showBodyPreview()}
1449 {this.commentsLine()}
1450 {this.duplicatesLine()}
1451 {this.userActionsLine()}
1452 {this.removeAndBanDialogs()}
1462 private get myPost(): boolean {
1464 this.postView.creator.id ==
1465 UserService.Instance.myUserInfo?.local_user_view.person.id
1468 handleEditClick(i: PostListing) {
1469 i.setState({ showEdit: true });
1472 handleEditCancel() {
1473 this.setState({ showEdit: false });
1476 // The actual editing is done in the receive for post
1477 handleEditPost(form: EditPost) {
1478 this.setState({ showEdit: false });
1479 this.props.onPostEdit(form);
1482 handleShare(i: PostListing) {
1483 const { name, body, id } = i.props.post_view.post;
1486 text: body?.slice(0, 50),
1487 url: `${getHttpBase()}/post/${id}`,
1491 handleShowReportDialog(i: PostListing) {
1492 i.setState({ showReportDialog: !i.state.showReportDialog });
1495 handleReportReasonChange(i: PostListing, event: any) {
1496 i.setState({ reportReason: event.target.value });
1499 handleReportSubmit(i: PostListing, event: any) {
1500 event.preventDefault();
1501 i.setState({ reportLoading: true });
1502 i.props.onPostReport({
1503 post_id: i.postView.post.id,
1504 reason: i.state.reportReason ?? "",
1505 auth: myAuthRequired(),
1509 handleBlockPersonClick(i: PostListing) {
1510 i.setState({ blockLoading: true });
1511 i.props.onBlockPerson({
1512 person_id: i.postView.creator.id,
1514 auth: myAuthRequired(),
1518 handleDeleteClick(i: PostListing) {
1519 i.setState({ deleteLoading: true });
1520 i.props.onDeletePost({
1521 post_id: i.postView.post.id,
1522 deleted: !i.postView.post.deleted,
1523 auth: myAuthRequired(),
1527 handleSavePostClick(i: PostListing) {
1528 i.setState({ saveLoading: true });
1529 i.props.onSavePost({
1530 post_id: i.postView.post.id,
1531 save: !i.postView.saved,
1532 auth: myAuthRequired(),
1536 get crossPostParams(): PostFormParams {
1537 const queryParams: PostFormParams = {};
1538 const { name, url } = this.postView.post;
1540 queryParams.name = name;
1543 queryParams.url = url;
1546 const crossPostBody = this.crossPostBody();
1547 if (crossPostBody) {
1548 queryParams.body = crossPostBody;
1554 crossPostBody(): string | undefined {
1555 const post = this.postView.post;
1556 const body = post.body;
1559 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1561 }\n\n${body.replace(/^/gm, "> ")}`
1565 get showBody(): boolean {
1566 return this.props.showBody || this.state.showBody;
1569 handleModRemoveShow(i: PostListing) {
1571 showRemoveDialog: !i.state.showRemoveDialog,
1572 showBanDialog: false,
1576 handleModRemoveReasonChange(i: PostListing, event: any) {
1577 i.setState({ removeReason: event.target.value });
1580 handleModRemoveDataChange(i: PostListing, event: any) {
1581 i.setState({ removeData: event.target.checked });
1584 handleModRemoveSubmit(i: PostListing, event: any) {
1585 event.preventDefault();
1586 i.setState({ removeLoading: true });
1587 i.props.onRemovePost({
1588 post_id: i.postView.post.id,
1589 removed: !i.postView.post.removed,
1590 auth: myAuthRequired(),
1594 handleModLock(i: PostListing) {
1595 i.setState({ lockLoading: true });
1596 i.props.onLockPost({
1597 post_id: i.postView.post.id,
1598 locked: !i.postView.post.locked,
1599 auth: myAuthRequired(),
1603 handleModFeaturePostLocal(i: PostListing) {
1604 i.setState({ featureLocalLoading: true });
1605 i.props.onFeaturePost({
1606 post_id: i.postView.post.id,
1607 featured: !i.postView.post.featured_local,
1608 feature_type: "Local",
1609 auth: myAuthRequired(),
1613 handleModFeaturePostCommunity(i: PostListing) {
1614 i.setState({ featureCommunityLoading: true });
1615 i.props.onFeaturePost({
1616 post_id: i.postView.post.id,
1617 featured: !i.postView.post.featured_community,
1618 feature_type: "Community",
1619 auth: myAuthRequired(),
1623 handleModBanFromCommunityShow(i: PostListing) {
1625 showBanDialog: true,
1626 banType: BanType.Community,
1627 showRemoveDialog: false,
1631 handleModBanShow(i: PostListing) {
1633 showBanDialog: true,
1634 banType: BanType.Site,
1635 showRemoveDialog: false,
1639 handlePurgePersonShow(i: PostListing) {
1641 showPurgeDialog: true,
1642 purgeType: PurgeType.Person,
1643 showRemoveDialog: false,
1647 handlePurgePostShow(i: PostListing) {
1649 showPurgeDialog: true,
1650 purgeType: PurgeType.Post,
1651 showRemoveDialog: false,
1655 handlePurgeReasonChange(i: PostListing, event: any) {
1656 i.setState({ purgeReason: event.target.value });
1659 handlePurgeSubmit(i: PostListing, event: any) {
1660 event.preventDefault();
1661 i.setState({ purgeLoading: true });
1662 if (i.state.purgeType == PurgeType.Person) {
1663 i.props.onPurgePerson({
1664 person_id: i.postView.creator.id,
1665 reason: i.state.purgeReason,
1666 auth: myAuthRequired(),
1668 } else if (i.state.purgeType == PurgeType.Post) {
1669 i.props.onPurgePost({
1670 post_id: i.postView.post.id,
1671 reason: i.state.purgeReason,
1672 auth: myAuthRequired(),
1677 handleModBanReasonChange(i: PostListing, event: any) {
1678 i.setState({ banReason: event.target.value });
1681 handleModBanExpireDaysChange(i: PostListing, event: any) {
1682 i.setState({ banExpireDays: event.target.value });
1685 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1686 i.setState({ banType: BanType.Community });
1687 i.handleModBanBothSubmit(i, event);
1690 handleModBanSubmit(i: PostListing, event: any) {
1691 i.setState({ banType: BanType.Site });
1692 i.handleModBanBothSubmit(i, event);
1695 handleModBanBothSubmit(i: PostListing, event: any) {
1696 event.preventDefault();
1697 i.setState({ banLoading: true });
1699 const ban = !i.props.post_view.creator_banned_from_community;
1700 // If its an unban, restore all their data
1702 i.setState({ removeData: false });
1704 const person_id = i.props.post_view.creator.id;
1705 const remove_data = i.state.removeData;
1706 const reason = i.state.banReason;
1707 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1709 if (i.state.banType == BanType.Community) {
1710 const community_id = i.postView.community.id;
1711 i.props.onBanPersonFromCommunity({
1718 auth: myAuthRequired(),
1721 i.props.onBanPerson({
1727 auth: myAuthRequired(),
1732 handleAddModToCommunity(i: PostListing) {
1733 i.setState({ addModLoading: true });
1734 i.props.onAddModToCommunity({
1735 community_id: i.postView.community.id,
1736 person_id: i.postView.creator.id,
1737 added: !i.creatorIsMod_,
1738 auth: myAuthRequired(),
1742 handleAddAdmin(i: PostListing) {
1743 i.setState({ addAdminLoading: true });
1744 i.props.onAddAdmin({
1745 person_id: i.postView.creator.id,
1746 added: !i.creatorIsAdmin_,
1747 auth: myAuthRequired(),
1751 handleShowConfirmTransferCommunity(i: PostListing) {
1752 i.setState({ showConfirmTransferCommunity: true });
1755 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1756 i.setState({ showConfirmTransferCommunity: false });
1759 handleTransferCommunity(i: PostListing) {
1760 i.setState({ transferLoading: true });
1761 i.props.onTransferCommunity({
1762 community_id: i.postView.community.id,
1763 person_id: i.postView.creator.id,
1764 auth: myAuthRequired(),
1768 handleShowConfirmTransferSite(i: PostListing) {
1769 i.setState({ showConfirmTransferSite: true });
1772 handleCancelShowConfirmTransferSite(i: PostListing) {
1773 i.setState({ showConfirmTransferSite: false });
1776 handleImageExpandClick(i: PostListing, event: any) {
1777 event.preventDefault();
1778 i.setState({ imageExpanded: !i.state.imageExpanded });
1782 handleViewSource(i: PostListing) {
1783 i.setState({ viewSource: !i.state.viewSource });
1786 handleShowAdvanced(i: PostListing) {
1787 i.setState({ showAdvanced: !i.state.showAdvanced });
1791 handleShowMoreMobile(i: PostListing) {
1793 showMoreMobile: !i.state.showMoreMobile,
1794 showAdvanced: !i.state.showAdvanced,
1799 handleShowBody(i: PostListing) {
1800 i.setState({ showBody: !i.state.showBody });
1804 get pointsTippy(): string {
1805 const points = I18NextService.i18n.t("number_of_points", {
1806 count: Number(this.postView.counts.score),
1807 formattedCount: Number(this.postView.counts.score),
1810 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1811 count: Number(this.postView.counts.upvotes),
1812 formattedCount: Number(this.postView.counts.upvotes),
1815 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1816 count: Number(this.postView.counts.downvotes),
1817 formattedCount: Number(this.postView.counts.downvotes),
1820 return `${points} • ${upvotes} • ${downvotes}`;
1823 get canModOnSelf_(): boolean {
1825 this.postView.creator.id,
1826 this.props.moderators,
1833 get canMod_(): boolean {
1835 this.postView.creator.id,
1836 this.props.moderators,
1841 get canAdmin_(): boolean {
1842 return canAdmin(this.postView.creator.id, this.props.admins);
1845 get creatorIsMod_(): boolean {
1846 return isMod(this.postView.creator.id, this.props.moderators);
1849 get creatorIsAdmin_(): boolean {
1850 return isAdmin(this.postView.creator.id, this.props.admins);