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";
46 import { BanType, PostFormParams, PurgeType } from "../../interfaces";
47 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
48 import { I18NextService, UserService } from "../../services";
49 import { setupTippy } from "../../tippy";
50 import { Icon, PurgeWarning, Spinner } from "../common/icon";
51 import { MomentTime } from "../common/moment-time";
52 import { PictrsImage } from "../common/pictrs-image";
53 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
54 import { CommunityLink } from "../community/community-link";
55 import { PersonListing } from "../person/person-listing";
56 import { MetadataCard } from "./metadata-card";
57 import { PostForm } from "./post-form";
59 interface PostListingState {
61 showRemoveDialog: boolean;
62 showPurgeDialog: boolean;
64 purgeType?: PurgeType;
65 purgeLoading: boolean;
66 removeReason?: string;
67 showBanDialog: boolean;
69 banExpireDays?: number;
72 showConfirmTransferSite: boolean;
73 showConfirmTransferCommunity: boolean;
74 imageExpanded: boolean;
76 showAdvanced: boolean;
77 showMoreMobile: boolean;
79 showReportDialog: boolean;
80 reportReason?: string;
81 reportLoading: boolean;
82 blockLoading: boolean;
84 deleteLoading: boolean;
85 removeLoading: boolean;
87 featureCommunityLoading: boolean;
88 featureLocalLoading: boolean;
90 addModLoading: boolean;
91 addAdminLoading: boolean;
92 transferLoading: boolean;
95 interface PostListingProps {
97 crossPosts?: PostView[];
98 moderators?: CommunityModeratorView[];
99 admins?: PersonView[];
100 allLanguages: Language[];
101 siteLanguages: number[];
102 showCommunity?: boolean;
105 enableDownvotes?: boolean;
106 enableNsfw?: boolean;
108 onPostEdit(form: EditPost): void;
109 onPostVote(form: CreatePostLike): void;
110 onPostReport(form: CreatePostReport): void;
111 onBlockPerson(form: BlockPerson): void;
112 onLockPost(form: LockPost): void;
113 onDeletePost(form: DeletePost): void;
114 onRemovePost(form: RemovePost): void;
115 onSavePost(form: SavePost): void;
116 onFeaturePost(form: FeaturePost): void;
117 onPurgePerson(form: PurgePerson): void;
118 onPurgePost(form: PurgePost): void;
119 onBanPersonFromCommunity(form: BanFromCommunity): void;
120 onBanPerson(form: BanPerson): void;
121 onAddModToCommunity(form: AddModToCommunity): void;
122 onAddAdmin(form: AddAdmin): void;
123 onTransferCommunity(form: TransferCommunity): void;
126 export class PostListing extends Component<PostListingProps, PostListingState> {
127 state: PostListingState = {
129 showRemoveDialog: false,
130 showPurgeDialog: false,
131 purgeType: PurgeType.Person,
132 showBanDialog: false,
133 banType: BanType.Community,
135 showConfirmTransferSite: false,
136 showConfirmTransferCommunity: false,
137 imageExpanded: false,
140 showMoreMobile: false,
142 showReportDialog: false,
144 reportLoading: false,
147 deleteLoading: false,
148 removeLoading: false,
150 featureCommunityLoading: false,
151 featureLocalLoading: false,
153 addModLoading: false,
154 addAdminLoading: false,
155 transferLoading: false,
158 constructor(props: any, context: any) {
159 super(props, context);
161 this.handleEditPost = this.handleEditPost.bind(this);
162 this.handleEditCancel = this.handleEditCancel.bind(this);
165 componentWillReceiveProps(nextProps: PostListingProps) {
166 if (this.props !== nextProps) {
169 reportLoading: false,
172 deleteLoading: false,
173 removeLoading: false,
175 featureCommunityLoading: false,
176 featureLocalLoading: false,
178 addModLoading: false,
179 addAdminLoading: false,
180 transferLoading: false,
181 imageExpanded: false,
186 get postView(): PostView {
187 return this.props.post_view;
191 const post = this.postView.post;
194 <div className="post-listing mt-2">
195 {!this.state.showEdit ? (
198 {this.state.imageExpanded && !this.props.hideImage && this.img}
199 {post.url && this.state.showBody && post.embed_title && (
200 <MetadataCard post={post} />
202 {this.showBody && this.body()}
206 post_view={this.postView}
207 crossPosts={this.props.crossPosts}
208 onEdit={this.handleEditPost}
209 onCancel={this.handleEditCancel}
210 enableNsfw={this.props.enableNsfw}
211 enableDownvotes={this.props.enableDownvotes}
212 allLanguages={this.props.allLanguages}
213 siteLanguages={this.props.siteLanguages}
221 const body = this.postView.post.body;
223 <article id="postContent" className="col-12 card my-2 p-2">
224 {this.state.viewSource ? (
227 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
239 <div className="offset-sm-3 my-2 d-none d-sm-block">
240 <a href={this.imageSrc} className="d-inline-block">
241 <PictrsImage src={this.imageSrc} />
244 <div className="my-2 d-block d-sm-none">
246 className="d-inline-block"
247 onClick={linkEvent(this, this.handleImageExpandClick)}
249 <PictrsImage src={this.imageSrc} />
256 const { post } = this.postView;
257 const { url } = post;
259 if (url && isVideo(url)) {
261 <div className="embed-responsive mt-3">
262 <video muted controls className="embed-responsive-item col-12">
263 <source src={url} type="video/mp4" />
272 imgThumb(src: string) {
273 const post_view = this.postView;
279 nsfw={post_view.post.nsfw || post_view.community.nsfw}
284 get imageSrc(): string | undefined {
285 const post = this.postView.post;
286 const url = post.url;
287 const thumbnail = post.thumbnail_url;
289 if (url && isImage(url)) {
290 if (url.includes("pictrs")) {
292 } else if (thumbnail) {
297 } else if (thumbnail) {
305 const post = this.postView.post;
306 const url = post.url;
307 const thumbnail = post.thumbnail_url;
309 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
313 className="text-body d-inline-block position-relative mb-2"
314 data-tippy-content={I18NextService.i18n.t("expand_here")}
315 onClick={linkEvent(this, this.handleImageExpandClick)}
316 aria-label={I18NextService.i18n.t("expand_here")}
318 {this.imgThumb(this.imageSrc)}
319 <Icon icon="image" classes="mini-overlay" />
322 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
325 className="text-body d-inline-block position-relative mb-2"
330 {this.imgThumb(this.imageSrc)}
331 <Icon icon="external-link" classes="mini-overlay" />
335 if (!this.props.hideImage && isVideo(url)) {
338 className="text-body"
342 data-tippy-content={I18NextService.i18n.t("expand_here")}
343 onClick={linkEvent(this, this.handleImageExpandClick)}
344 aria-label={I18NextService.i18n.t("expand_here")}
346 <div className="thumbnail rounded bg-light d-flex justify-content-center">
347 <Icon icon="play" classes="d-flex align-items-center" />
353 <a className="text-body" href={url} title={url} rel={relTags}>
354 <div className="thumbnail rounded bg-light d-flex justify-content-center">
355 <Icon icon="external-link" classes="d-flex align-items-center" />
363 className="text-body"
364 to={`/post/${post.id}`}
365 title={I18NextService.i18n.t("comments")}
367 <div className="thumbnail rounded bg-light d-flex justify-content-center">
368 <Icon icon="message-square" classes="d-flex align-items-center" />
376 const post_view = this.postView;
378 <span className="small">
379 <PersonListing person={post_view.creator} />
380 {this.creatorIsMod_ && (
381 <span className="mx-1 badge text-bg-light">
382 {I18NextService.i18n.t("mod")}
385 {this.creatorIsAdmin_ && (
386 <span className="mx-1 badge text-bg-light">
387 {I18NextService.i18n.t("admin")}
390 {post_view.creator.bot_account && (
391 <span className="mx-1 badge text-bg-light">
392 {I18NextService.i18n.t("bot_account").toLowerCase()}
395 {this.props.showCommunity && (
398 {I18NextService.i18n.t("to")}{" "}
399 <CommunityLink community={post_view.community} />
402 {post_view.post.language_id !== 0 && (
403 <span className="mx-1 badge text-bg-light">
405 this.props.allLanguages.find(
406 lang => lang.id === post_view.post.language_id
413 published={post_view.post.published}
414 updated={post_view.post.updated}
421 const post = this.postView.post;
424 className={`d-inline ${
425 !post.featured_community && !post.featured_local
429 to={`/post/${post.id}`}
430 title={I18NextService.i18n.t("comments")}
434 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
441 const post = this.postView.post;
442 const url = post.url;
446 <div className="post-title overflow-hidden">
447 <h5 className="d-inline">
448 {url && this.props.showBody ? (
451 !post.featured_community && !post.featured_local
458 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
464 {(url && isImage(url)) ||
465 (post.thumbnail_url && (
467 className="btn btn-sm text-monospace text-muted d-inline-block"
468 data-tippy-content={I18NextService.i18n.t("expand_here")}
469 onClick={linkEvent(this, this.handleImageExpandClick)}
473 !this.state.imageExpanded ? "plus-square" : "minus-square"
475 classes="icon-inline"
480 <small className="ms-2 badge text-bg-secondary">
481 {I18NextService.i18n.t("removed")}
486 className="unselectable pointer ms-2 text-muted font-italic"
487 data-tippy-content={I18NextService.i18n.t("deleted")}
489 <Icon icon="trash" classes="icon-inline text-danger" />
494 className="unselectable pointer ms-2 text-muted font-italic"
495 data-tippy-content={I18NextService.i18n.t("locked")}
497 <Icon icon="lock" classes="icon-inline text-danger" />
500 {post.featured_community && (
502 className="unselectable pointer ms-2 text-muted font-italic"
503 data-tippy-content={I18NextService.i18n.t(
504 "featured_in_community"
506 aria-label={I18NextService.i18n.t("featured_in_community")}
508 <Icon icon="pin" classes="icon-inline text-primary" />
511 {post.featured_local && (
513 className="unselectable pointer ms-2 text-muted font-italic"
514 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
515 aria-label={I18NextService.i18n.t("featured_in_local")}
517 <Icon icon="pin" classes="icon-inline text-secondary" />
521 <small className="ms-2 badge text-bg-danger">
522 {I18NextService.i18n.t("nsfw")}
526 {url && this.urlLine()}
532 const post = this.postView.post;
533 const url = post.url;
536 <p className="d-flex text-muted align-items-center gap-1 small m-0">
537 {url && !(hostname(url) === getExternalHost()) && (
539 className="text-muted font-italic"
552 const dupes = this.props.crossPosts;
553 return dupes && dupes.length > 0 ? (
554 <ul className="list-inline mb-1 small text-muted">
556 <li className="list-inline-item me-2">
557 {I18NextService.i18n.t("cross_posted_to")}
560 <li key={pv.post.id} className="list-inline-item me-2">
561 <Link to={`/post/${pv.post.id}`}>
564 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
575 commentsLine(mobile = false) {
576 const post = this.postView.post;
579 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
580 {this.commentsButton}
583 className="btn btn-sm btn-animate text-muted py-0"
584 onClick={linkEvent(this, this.handleShare)}
587 <Icon icon="share" inline />
592 className="btn btn-sm btn-animate text-muted py-0"
593 title={I18NextService.i18n.t("link")}
596 <Icon icon="fedilink" inline />
599 {mobile && !this.props.viewOnly && (
601 id={this.postView.post.id}
602 onVote={this.props.onPostVote}
603 enableDownvotes={this.props.enableDownvotes}
604 counts={this.postView.counts}
605 my_vote={this.postView.my_vote}
608 {UserService.Instance.myUserInfo &&
609 !this.props.viewOnly &&
615 showPreviewButton() {
616 const post_view = this.postView;
617 const body = post_view.post.body;
621 className="btn btn-sm btn-animate text-muted py-0"
622 data-tippy-content={body && mdNoImages.render(body)}
623 data-tippy-allowHtml={true}
624 onClick={linkEvent(this, this.handleShowBody)}
628 classes={classNames("icon-inline me-1", {
629 "text-success": this.state.showBody,
637 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
638 // Possible enhancement: Make each button a component.
639 const post_view = this.postView;
640 const post = post_view.post;
645 {this.crossPostButton}
648 * If there is a URL, or if the post has a body and we were told not to
649 * show the body, show the MetadataCard/body toggle.
651 {(post.url || (post.body && !this.props.showBody)) &&
652 this.showPreviewButton()}
654 {this.showBody && post_view.post.body && this.viewSourceButton}
656 <div className="dropdown">
658 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
659 onClick={linkEvent(this, this.handleShowAdvanced)}
660 data-tippy-content={I18NextService.i18n.t("more")}
661 data-bs-toggle="dropdown"
662 aria-expanded="false"
663 aria-controls="advancedButtonsDropdown"
664 aria-label={I18NextService.i18n.t("more")}
666 <Icon icon="more-vertical" inline />
669 <ul className="dropdown-menu" id="advancedButtonsDropdown">
672 <li>{this.reportButton}</li>
673 <li>{this.blockButton}</li>
677 <li>{this.editButton}</li>
678 <li>{this.deleteButton}</li>
682 {/* Any mod can do these, not limited to hierarchy*/}
683 {(amMod(this.props.moderators) || amAdmin()) && (
686 <hr className="dropdown-divider" />
688 <li>{this.lockButton}</li>
689 {this.featureButtons}
693 {(this.canMod_ || this.canAdmin_) && (
694 <li>{this.modRemoveButton}</li>
702 get commentsButton() {
703 const post_view = this.postView;
704 const title = I18NextService.i18n.t("number_of_comments", {
705 count: Number(post_view.counts.comments),
706 formattedCount: Number(post_view.counts.comments),
711 className="btn btn-link btn-sm text-muted ps-0"
713 to={`/post/${post_view.post.id}?scrollToComments=true`}
714 data-tippy-content={title}
716 <Icon icon="message-square" classes="me-1" inline />
717 {post_view.counts.comments}
718 {this.unreadCount && (
719 <span className="text-muted fst-italic">
720 ({this.unreadCount} {I18NextService.i18n.t("new")})
727 get unreadCount(): number | undefined {
728 const pv = this.postView;
729 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
731 : pv.unread_comments;
735 const saved = this.postView.saved;
737 ? I18NextService.i18n.t("unsave")
738 : I18NextService.i18n.t("save");
741 className="btn btn-sm btn-animate text-muted py-0"
742 onClick={linkEvent(this, this.handleSavePostClick)}
743 data-tippy-content={label}
746 {this.state.saveLoading ? (
751 classes={classNames({ "text-warning": saved })}
759 get crossPostButton() {
762 className="btn btn-sm btn-animate text-muted py-0"
764 /* Empty string properties are required to satisfy type*/
765 pathname: "/create_post",
766 state: { ...this.crossPostParams },
771 title={I18NextService.i18n.t("cross_post")}
772 data-tippy-content={I18NextService.i18n.t("cross_post")}
773 aria-label={I18NextService.i18n.t("cross_post")}
775 <Icon icon="copy" inline />
783 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
784 onClick={linkEvent(this, this.handleShowReportDialog)}
785 aria-label={I18NextService.i18n.t("show_report_dialog")}
787 <Icon classes="me-1" icon="flag" inline />
788 {I18NextService.i18n.t("create_report")}
796 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
797 onClick={linkEvent(this, this.handleBlockPersonClick)}
798 aria-label={I18NextService.i18n.t("block_user")}
800 {this.state.blockLoading ? (
803 <Icon classes="me-1" icon="slash" inline />
805 {I18NextService.i18n.t("block_user")}
813 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
814 onClick={linkEvent(this, this.handleEditClick)}
815 aria-label={I18NextService.i18n.t("edit")}
817 <Icon classes="me-1" icon="edit" inline />
818 {I18NextService.i18n.t("edit")}
824 const deleted = this.postView.post.deleted;
825 const label = !deleted
826 ? I18NextService.i18n.t("delete")
827 : I18NextService.i18n.t("restore");
830 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
831 onClick={linkEvent(this, this.handleDeleteClick)}
833 {this.state.deleteLoading ? (
839 classes={classNames("me-1", { "text-danger": deleted })}
849 get viewSourceButton() {
852 className="btn btn-sm btn-animate text-muted py-0"
853 onClick={linkEvent(this, this.handleViewSource)}
854 data-tippy-content={I18NextService.i18n.t("view_source")}
855 aria-label={I18NextService.i18n.t("view_source")}
859 classes={classNames({ "text-success": this.state.viewSource })}
867 const locked = this.postView.post.locked;
869 ? I18NextService.i18n.t("unlock")
870 : I18NextService.i18n.t("lock");
873 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
874 onClick={linkEvent(this, this.handleModLock)}
877 {this.state.lockLoading ? (
883 classes={classNames("me-1", { "text-danger": locked })}
886 {capitalizeFirstLetter(label)}
893 get featureButtons() {
894 const featuredCommunity = this.postView.post.featured_community;
895 const labelCommunity = featuredCommunity
896 ? I18NextService.i18n.t("unfeature_from_community")
897 : I18NextService.i18n.t("feature_in_community");
899 const featuredLocal = this.postView.post.featured_local;
900 const labelLocal = featuredLocal
901 ? I18NextService.i18n.t("unfeature_from_local")
902 : I18NextService.i18n.t("feature_in_local");
907 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
908 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
909 data-tippy-content={labelCommunity}
910 aria-label={labelCommunity}
912 {this.state.featureCommunityLoading ? (
918 classes={classNames("me-1", {
919 "text-success": featuredCommunity,
923 {I18NextService.i18n.t("community")}
931 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
932 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
933 data-tippy-content={labelLocal}
934 aria-label={labelLocal}
936 {this.state.featureLocalLoading ? (
942 classes={classNames("me-1", {
943 "text-success": featuredLocal,
947 {I18NextService.i18n.t("local")}
957 get modRemoveButton() {
958 const removed = this.postView.post.removed;
961 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
964 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
967 {/* TODO: Find an icon for this. */}
968 {this.state.removeLoading ? (
971 I18NextService.i18n.t("remove")
973 I18NextService.i18n.t("restore")
980 * Mod/Admin actions to be taken against the author.
984 const post_view = this.postView;
986 this.state.showAdvanced && (
987 <div className="mt-3">
990 {!this.creatorIsMod_ &&
991 (!post_view.creator_banned_from_community ? (
993 className="btn btn-link btn-animate text-muted py-0"
996 this.handleModBanFromCommunityShow
998 aria-label={I18NextService.i18n.t("ban_from_community")}
1000 {I18NextService.i18n.t("ban_from_community")}
1004 className="btn btn-link btn-animate text-muted py-0"
1007 this.handleModBanFromCommunitySubmit
1009 aria-label={I18NextService.i18n.t("unban")}
1011 {this.state.banLoading ? (
1014 I18NextService.i18n.t("unban")
1018 {!post_view.creator_banned_from_community && (
1020 className="btn btn-link btn-animate text-muted py-0"
1021 onClick={linkEvent(this, this.handleAddModToCommunity)}
1024 ? I18NextService.i18n.t("remove_as_mod")
1025 : I18NextService.i18n.t("appoint_as_mod")
1028 {this.state.addModLoading ? (
1030 ) : this.creatorIsMod_ ? (
1031 I18NextService.i18n.t("remove_as_mod")
1033 I18NextService.i18n.t("appoint_as_mod")
1039 {/* Community creators and admins can transfer community to another mod */}
1040 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1042 this.creatorIsMod_ &&
1043 (!this.state.showConfirmTransferCommunity ? (
1045 className="btn btn-link btn-animate text-muted py-0"
1048 this.handleShowConfirmTransferCommunity
1050 aria-label={I18NextService.i18n.t("transfer_community")}
1052 {I18NextService.i18n.t("transfer_community")}
1057 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1058 aria-label={I18NextService.i18n.t("are_you_sure")}
1060 {I18NextService.i18n.t("are_you_sure")}
1063 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1064 aria-label={I18NextService.i18n.t("yes")}
1065 onClick={linkEvent(this, this.handleTransferCommunity)}
1067 {this.state.transferLoading ? (
1070 I18NextService.i18n.t("yes")
1074 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1077 this.handleCancelShowConfirmTransferCommunity
1079 aria-label={I18NextService.i18n.t("no")}
1081 {I18NextService.i18n.t("no")}
1085 {/* Admins can ban from all, and appoint other admins */}
1086 {this.canAdmin_ && (
1088 {!this.creatorIsAdmin_ && (
1090 {!isBanned(post_view.creator) ? (
1092 className="btn btn-link btn-animate text-muted py-0"
1093 onClick={linkEvent(this, this.handleModBanShow)}
1094 aria-label={I18NextService.i18n.t("ban_from_site")}
1096 {I18NextService.i18n.t("ban_from_site")}
1100 className="btn btn-link btn-animate text-muted py-0"
1101 onClick={linkEvent(this, this.handleModBanSubmit)}
1102 aria-label={I18NextService.i18n.t("unban_from_site")}
1104 {this.state.banLoading ? (
1107 I18NextService.i18n.t("unban_from_site")
1112 className="btn btn-link btn-animate text-muted py-0"
1113 onClick={linkEvent(this, this.handlePurgePersonShow)}
1114 aria-label={I18NextService.i18n.t("purge_user")}
1116 {I18NextService.i18n.t("purge_user")}
1119 className="btn btn-link btn-animate text-muted py-0"
1120 onClick={linkEvent(this, this.handlePurgePostShow)}
1121 aria-label={I18NextService.i18n.t("purge_post")}
1123 {I18NextService.i18n.t("purge_post")}
1127 {!isBanned(post_view.creator) && post_view.creator.local && (
1129 className="btn btn-link btn-animate text-muted py-0"
1130 onClick={linkEvent(this, this.handleAddAdmin)}
1132 this.creatorIsAdmin_
1133 ? I18NextService.i18n.t("remove_as_admin")
1134 : I18NextService.i18n.t("appoint_as_admin")
1137 {this.state.addAdminLoading ? (
1139 ) : this.creatorIsAdmin_ ? (
1140 I18NextService.i18n.t("remove_as_admin")
1142 I18NextService.i18n.t("appoint_as_admin")
1153 removeAndBanDialogs() {
1154 const post = this.postView;
1155 const purgeTypeText =
1156 this.state.purgeType == PurgeType.Post
1157 ? I18NextService.i18n.t("purge_post")
1158 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1161 {this.state.showRemoveDialog && (
1163 className="form-inline"
1164 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1167 className="visually-hidden"
1168 htmlFor="post-listing-remove-reason"
1170 {I18NextService.i18n.t("reason")}
1174 id="post-listing-remove-reason"
1175 className="form-control me-2"
1176 placeholder={I18NextService.i18n.t("reason")}
1177 value={this.state.removeReason}
1178 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1182 className="btn btn-secondary"
1183 aria-label={I18NextService.i18n.t("remove_post")}
1185 {this.state.removeLoading ? (
1188 I18NextService.i18n.t("remove_post")
1193 {this.state.showBanDialog && (
1194 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1195 <div className="mb-3 row col-12">
1197 className="col-form-label"
1198 htmlFor="post-listing-ban-reason"
1200 {I18NextService.i18n.t("reason")}
1204 id="post-listing-ban-reason"
1205 className="form-control me-2"
1206 placeholder={I18NextService.i18n.t("reason")}
1207 value={this.state.banReason}
1208 onInput={linkEvent(this, this.handleModBanReasonChange)}
1210 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1211 {I18NextService.i18n.t("expires")}
1215 id={`mod-ban-expires`}
1216 className="form-control me-2"
1217 placeholder={I18NextService.i18n.t("number_of_days")}
1218 value={this.state.banExpireDays}
1219 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1221 <div className="input-group mb-3">
1222 <div className="form-check">
1224 className="form-check-input"
1225 id="mod-ban-remove-data"
1227 checked={this.state.removeData}
1228 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1231 className="form-check-label"
1232 htmlFor="mod-ban-remove-data"
1233 title={I18NextService.i18n.t("remove_content_more")}
1235 {I18NextService.i18n.t("remove_content")}
1240 {/* TODO hold off on expires until later */}
1241 {/* <div class="mb-3 row"> */}
1242 {/* <label class="col-form-label">Expires</label> */}
1243 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1245 <div className="mb-3 row">
1248 className="btn btn-secondary"
1249 aria-label={I18NextService.i18n.t("ban")}
1251 {this.state.banLoading ? (
1255 {I18NextService.i18n.t("ban")} {post.creator.name}
1262 {this.state.showReportDialog && (
1264 className="form-inline"
1265 onSubmit={linkEvent(this, this.handleReportSubmit)}
1267 <label className="visually-hidden" htmlFor="post-report-reason">
1268 {I18NextService.i18n.t("reason")}
1272 id="post-report-reason"
1273 className="form-control me-2"
1274 placeholder={I18NextService.i18n.t("reason")}
1276 value={this.state.reportReason}
1277 onInput={linkEvent(this, this.handleReportReasonChange)}
1281 className="btn btn-secondary"
1282 aria-label={I18NextService.i18n.t("create_report")}
1284 {this.state.reportLoading ? (
1287 I18NextService.i18n.t("create_report")
1292 {this.state.showPurgeDialog && (
1294 className="form-inline"
1295 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1298 <label className="visually-hidden" htmlFor="purge-reason">
1299 {I18NextService.i18n.t("reason")}
1304 className="form-control me-2"
1305 placeholder={I18NextService.i18n.t("reason")}
1306 value={this.state.purgeReason}
1307 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1309 {this.state.purgeLoading ? (
1314 className="btn btn-secondary"
1315 aria-label={purgeTypeText}
1317 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1327 const post = this.postView.post;
1328 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1329 <div className="row">
1330 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1331 {this.postTitleLine()}
1333 <div className="col-4">
1334 {/* Post thumbnail */}
1335 {!this.state.imageExpanded && this.thumbnail()}
1339 this.postTitleLine()
1344 const { body, id } = this.postView.post;
1346 return !this.showBody && body ? (
1347 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1348 <div className="md-div mb-1 preview-lines">{body}</div>
1358 {/* The mobile view*/}
1359 <div className="d-block d-sm-none">
1360 <article className="row post-container">
1361 <div className="col-12">
1362 {this.createdLine()}
1364 {/* If it has a thumbnail, do a right aligned thumbnail */}
1365 {this.mobileThumbnail()}
1367 {/* Show a preview of the post body */}
1368 {this.showBodyPreview()}
1370 {this.commentsLine(true)}
1371 {this.userActionsLine()}
1372 {this.duplicatesLine()}
1373 {this.removeAndBanDialogs()}
1378 {/* The larger view*/}
1379 <div className="d-none d-sm-block">
1380 <article className="row post-container">
1381 {!this.props.viewOnly && (
1383 id={this.postView.post.id}
1384 onVote={this.props.onPostVote}
1385 enableDownvotes={this.props.enableDownvotes}
1386 counts={this.postView.counts}
1387 my_vote={this.postView.my_vote}
1390 <div className="col-sm-2 pe-0 post-media">
1391 <div className="">{this.thumbnail()}</div>
1393 <div className="col-12 col-sm-9">
1394 <div className="row">
1395 <div className="col-12">
1396 {this.postTitleLine()}
1397 {this.createdLine()}
1398 {this.showBodyPreview()}
1399 {this.commentsLine()}
1400 {this.duplicatesLine()}
1401 {this.userActionsLine()}
1402 {this.removeAndBanDialogs()}
1412 private get myPost(): boolean {
1414 this.postView.creator.id ==
1415 UserService.Instance.myUserInfo?.local_user_view.person.id
1418 handleEditClick(i: PostListing) {
1419 i.setState({ showEdit: true });
1422 handleEditCancel() {
1423 this.setState({ showEdit: false });
1426 // The actual editing is done in the receive for post
1427 handleEditPost(form: EditPost) {
1428 this.setState({ showEdit: false });
1429 this.props.onPostEdit(form);
1432 handleShare(i: PostListing) {
1433 const { name, body, id } = i.props.post_view.post;
1436 text: body?.slice(0, 50),
1437 url: `${getHttpBase()}/post/${id}`,
1441 handleShowReportDialog(i: PostListing) {
1442 i.setState({ showReportDialog: !i.state.showReportDialog });
1445 handleReportReasonChange(i: PostListing, event: any) {
1446 i.setState({ reportReason: event.target.value });
1449 handleReportSubmit(i: PostListing, event: any) {
1450 event.preventDefault();
1451 i.setState({ reportLoading: true });
1452 i.props.onPostReport({
1453 post_id: i.postView.post.id,
1454 reason: i.state.reportReason ?? "",
1455 auth: myAuthRequired(),
1459 handleBlockPersonClick(i: PostListing) {
1460 i.setState({ blockLoading: true });
1461 i.props.onBlockPerson({
1462 person_id: i.postView.creator.id,
1464 auth: myAuthRequired(),
1468 handleDeleteClick(i: PostListing) {
1469 i.setState({ deleteLoading: true });
1470 i.props.onDeletePost({
1471 post_id: i.postView.post.id,
1472 deleted: !i.postView.post.deleted,
1473 auth: myAuthRequired(),
1477 handleSavePostClick(i: PostListing) {
1478 i.setState({ saveLoading: true });
1479 i.props.onSavePost({
1480 post_id: i.postView.post.id,
1481 save: !i.postView.saved,
1482 auth: myAuthRequired(),
1486 get crossPostParams(): PostFormParams {
1487 const queryParams: PostFormParams = {};
1488 const { name, url } = this.postView.post;
1490 queryParams.name = name;
1493 queryParams.url = url;
1496 const crossPostBody = this.crossPostBody();
1497 if (crossPostBody) {
1498 queryParams.body = crossPostBody;
1504 crossPostBody(): string | undefined {
1505 const post = this.postView.post;
1506 const body = post.body;
1509 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1511 }\n\n${body.replace(/^/gm, "> ")}`
1515 get showBody(): boolean {
1516 return this.props.showBody || this.state.showBody;
1519 handleModRemoveShow(i: PostListing) {
1521 showRemoveDialog: !i.state.showRemoveDialog,
1522 showBanDialog: false,
1526 handleModRemoveReasonChange(i: PostListing, event: any) {
1527 i.setState({ removeReason: event.target.value });
1530 handleModRemoveDataChange(i: PostListing, event: any) {
1531 i.setState({ removeData: event.target.checked });
1534 handleModRemoveSubmit(i: PostListing, event: any) {
1535 event.preventDefault();
1536 i.setState({ removeLoading: true });
1537 i.props.onRemovePost({
1538 post_id: i.postView.post.id,
1539 removed: !i.postView.post.removed,
1540 auth: myAuthRequired(),
1544 handleModLock(i: PostListing) {
1545 i.setState({ lockLoading: true });
1546 i.props.onLockPost({
1547 post_id: i.postView.post.id,
1548 locked: !i.postView.post.locked,
1549 auth: myAuthRequired(),
1553 handleModFeaturePostLocal(i: PostListing) {
1554 i.setState({ featureLocalLoading: true });
1555 i.props.onFeaturePost({
1556 post_id: i.postView.post.id,
1557 featured: !i.postView.post.featured_local,
1558 feature_type: "Local",
1559 auth: myAuthRequired(),
1563 handleModFeaturePostCommunity(i: PostListing) {
1564 i.setState({ featureCommunityLoading: true });
1565 i.props.onFeaturePost({
1566 post_id: i.postView.post.id,
1567 featured: !i.postView.post.featured_community,
1568 feature_type: "Community",
1569 auth: myAuthRequired(),
1573 handleModBanFromCommunityShow(i: PostListing) {
1575 showBanDialog: true,
1576 banType: BanType.Community,
1577 showRemoveDialog: false,
1581 handleModBanShow(i: PostListing) {
1583 showBanDialog: true,
1584 banType: BanType.Site,
1585 showRemoveDialog: false,
1589 handlePurgePersonShow(i: PostListing) {
1591 showPurgeDialog: true,
1592 purgeType: PurgeType.Person,
1593 showRemoveDialog: false,
1597 handlePurgePostShow(i: PostListing) {
1599 showPurgeDialog: true,
1600 purgeType: PurgeType.Post,
1601 showRemoveDialog: false,
1605 handlePurgeReasonChange(i: PostListing, event: any) {
1606 i.setState({ purgeReason: event.target.value });
1609 handlePurgeSubmit(i: PostListing, event: any) {
1610 event.preventDefault();
1611 i.setState({ purgeLoading: true });
1612 if (i.state.purgeType == PurgeType.Person) {
1613 i.props.onPurgePerson({
1614 person_id: i.postView.creator.id,
1615 reason: i.state.purgeReason,
1616 auth: myAuthRequired(),
1618 } else if (i.state.purgeType == PurgeType.Post) {
1619 i.props.onPurgePost({
1620 post_id: i.postView.post.id,
1621 reason: i.state.purgeReason,
1622 auth: myAuthRequired(),
1627 handleModBanReasonChange(i: PostListing, event: any) {
1628 i.setState({ banReason: event.target.value });
1631 handleModBanExpireDaysChange(i: PostListing, event: any) {
1632 i.setState({ banExpireDays: event.target.value });
1635 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1636 i.setState({ banType: BanType.Community });
1637 i.handleModBanBothSubmit(i, event);
1640 handleModBanSubmit(i: PostListing, event: any) {
1641 i.setState({ banType: BanType.Site });
1642 i.handleModBanBothSubmit(i, event);
1645 handleModBanBothSubmit(i: PostListing, event: any) {
1646 event.preventDefault();
1647 i.setState({ banLoading: true });
1649 const ban = !i.props.post_view.creator_banned_from_community;
1650 // If its an unban, restore all their data
1652 i.setState({ removeData: false });
1654 const person_id = i.props.post_view.creator.id;
1655 const remove_data = i.state.removeData;
1656 const reason = i.state.banReason;
1657 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1659 if (i.state.banType == BanType.Community) {
1660 const community_id = i.postView.community.id;
1661 i.props.onBanPersonFromCommunity({
1668 auth: myAuthRequired(),
1671 i.props.onBanPerson({
1677 auth: myAuthRequired(),
1682 handleAddModToCommunity(i: PostListing) {
1683 i.setState({ addModLoading: true });
1684 i.props.onAddModToCommunity({
1685 community_id: i.postView.community.id,
1686 person_id: i.postView.creator.id,
1687 added: !i.creatorIsMod_,
1688 auth: myAuthRequired(),
1692 handleAddAdmin(i: PostListing) {
1693 i.setState({ addAdminLoading: true });
1694 i.props.onAddAdmin({
1695 person_id: i.postView.creator.id,
1696 added: !i.creatorIsAdmin_,
1697 auth: myAuthRequired(),
1701 handleShowConfirmTransferCommunity(i: PostListing) {
1702 i.setState({ showConfirmTransferCommunity: true });
1705 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1706 i.setState({ showConfirmTransferCommunity: false });
1709 handleTransferCommunity(i: PostListing) {
1710 i.setState({ transferLoading: true });
1711 i.props.onTransferCommunity({
1712 community_id: i.postView.community.id,
1713 person_id: i.postView.creator.id,
1714 auth: myAuthRequired(),
1718 handleShowConfirmTransferSite(i: PostListing) {
1719 i.setState({ showConfirmTransferSite: true });
1722 handleCancelShowConfirmTransferSite(i: PostListing) {
1723 i.setState({ showConfirmTransferSite: false });
1726 handleImageExpandClick(i: PostListing, event: any) {
1727 event.preventDefault();
1728 i.setState({ imageExpanded: !i.state.imageExpanded });
1732 handleViewSource(i: PostListing) {
1733 i.setState({ viewSource: !i.state.viewSource });
1736 handleShowAdvanced(i: PostListing) {
1737 i.setState({ showAdvanced: !i.state.showAdvanced });
1741 handleShowMoreMobile(i: PostListing) {
1743 showMoreMobile: !i.state.showMoreMobile,
1744 showAdvanced: !i.state.showAdvanced,
1749 handleShowBody(i: PostListing) {
1750 i.setState({ showBody: !i.state.showBody });
1754 get pointsTippy(): string {
1755 const points = I18NextService.i18n.t("number_of_points", {
1756 count: Number(this.postView.counts.score),
1757 formattedCount: Number(this.postView.counts.score),
1760 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1761 count: Number(this.postView.counts.upvotes),
1762 formattedCount: Number(this.postView.counts.upvotes),
1765 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1766 count: Number(this.postView.counts.downvotes),
1767 formattedCount: Number(this.postView.counts.downvotes),
1770 return `${points} • ${upvotes} • ${downvotes}`;
1773 get canModOnSelf_(): boolean {
1775 this.postView.creator.id,
1776 this.props.moderators,
1783 get canMod_(): boolean {
1785 this.postView.creator.id,
1786 this.props.moderators,
1791 get canAdmin_(): boolean {
1792 return canAdmin(this.postView.creator.id, this.props.admins);
1795 get creatorIsMod_(): boolean {
1796 return isMod(this.postView.creator.id, this.props.moderators);
1799 get creatorIsAdmin_(): boolean {
1800 return isAdmin(this.postView.creator.id, this.props.admins);