1 import { myAuth, 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,
45 } from "lemmy-js-client";
46 import { relTags } from "../../config";
52 } from "../../interfaces";
53 import { mdToHtml, mdToHtmlInline } from "../../markdown";
54 import { I18NextService, UserService } from "../../services";
55 import { setupTippy } from "../../tippy";
56 import { Icon, PurgeWarning, Spinner } from "../common/icon";
57 import { MomentTime } from "../common/moment-time";
58 import { PictrsImage } from "../common/pictrs-image";
59 import { UserBadges } from "../common/user-badges";
60 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
61 import { CommunityLink } from "../community/community-link";
62 import { PersonListing } from "../person/person-listing";
63 import { MetadataCard } from "./metadata-card";
64 import { PostForm } from "./post-form";
66 interface PostListingState {
68 showRemoveDialog: boolean;
69 showPurgeDialog: boolean;
71 purgeType?: PurgeType;
72 purgeLoading: boolean;
73 removeReason?: string;
74 showBanDialog: boolean;
76 banExpireDays?: number;
79 showConfirmTransferSite: boolean;
80 showConfirmTransferCommunity: boolean;
81 imageExpanded: boolean;
83 showAdvanced: boolean;
84 showMoreMobile: boolean;
86 showReportDialog: boolean;
87 reportReason?: string;
88 reportLoading: boolean;
89 blockLoading: boolean;
91 deleteLoading: boolean;
92 removeLoading: boolean;
94 featureCommunityLoading: boolean;
95 featureLocalLoading: boolean;
97 addModLoading: boolean;
98 addAdminLoading: boolean;
99 transferLoading: boolean;
102 interface PostListingProps {
104 crossPosts?: PostView[];
105 moderators?: CommunityModeratorView[];
106 admins?: PersonView[];
107 allLanguages: Language[];
108 siteLanguages: number[];
109 showCommunity?: boolean;
111 * Controls whether to show both the body *and* the metadata preview card
115 enableDownvotes?: boolean;
116 enableNsfw?: boolean;
118 onPostEdit(form: EditPost): void;
119 onPostVote(form: CreatePostLike): void;
120 onPostReport(form: CreatePostReport): void;
121 onBlockPerson(form: BlockPerson): void;
122 onLockPost(form: LockPost): void;
123 onDeletePost(form: DeletePost): void;
124 onRemovePost(form: RemovePost): void;
125 onSavePost(form: SavePost): void;
126 onFeaturePost(form: FeaturePost): void;
127 onPurgePerson(form: PurgePerson): void;
128 onPurgePost(form: PurgePost): void;
129 onBanPersonFromCommunity(form: BanFromCommunity): void;
130 onBanPerson(form: BanPerson): void;
131 onAddModToCommunity(form: AddModToCommunity): void;
132 onAddAdmin(form: AddAdmin): void;
133 onTransferCommunity(form: TransferCommunity): void;
134 onMarkPostAsRead(form: MarkPostAsRead): void;
137 export class PostListing extends Component<PostListingProps, PostListingState> {
138 state: PostListingState = {
140 showRemoveDialog: false,
141 showPurgeDialog: false,
142 purgeType: PurgeType.Person,
143 showBanDialog: false,
144 banType: BanType.Community,
146 showConfirmTransferSite: false,
147 showConfirmTransferCommunity: false,
148 imageExpanded: false,
151 showMoreMobile: false,
153 showReportDialog: false,
155 reportLoading: false,
158 deleteLoading: false,
159 removeLoading: false,
161 featureCommunityLoading: false,
162 featureLocalLoading: false,
164 addModLoading: false,
165 addAdminLoading: false,
166 transferLoading: false,
169 constructor(props: any, context: any) {
170 super(props, context);
172 this.handleEditPost = this.handleEditPost.bind(this);
173 this.handleEditCancel = this.handleEditCancel.bind(this);
176 componentWillReceiveProps(nextProps: PostListingProps) {
177 if (this.props !== nextProps) {
180 reportLoading: false,
183 deleteLoading: false,
184 removeLoading: false,
186 featureCommunityLoading: false,
187 featureLocalLoading: false,
189 addModLoading: false,
190 addAdminLoading: false,
191 transferLoading: false,
196 get postView(): PostView {
197 return this.props.post_view;
201 const post = this.postView.post;
204 <div className="post-listing mt-2">
205 {!this.state.showEdit ? (
208 {this.state.imageExpanded && !this.props.hideImage && this.img}
209 {this.showBody && post.url && post.embed_title && (
210 <MetadataCard post={post} />
212 {this.showBody && this.body()}
216 post_view={this.postView}
217 crossPosts={this.props.crossPosts}
218 onEdit={this.handleEditPost}
219 onCancel={this.handleEditCancel}
220 enableNsfw={this.props.enableNsfw}
221 enableDownvotes={this.props.enableDownvotes}
222 allLanguages={this.props.allLanguages}
223 siteLanguages={this.props.siteLanguages}
231 const body = this.postView.post.body;
233 <article id="postContent" className="col-12 card my-2 p-2">
234 {this.state.viewSource ? (
237 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
249 <div className="offset-sm-3 my-2 d-none d-sm-block">
250 <a href={this.imageSrc} className="d-inline-block">
251 <PictrsImage src={this.imageSrc} />
254 <div className="my-2 d-block d-sm-none">
257 className="p-0 border-0 bg-transparent d-inline-block"
258 onClick={linkEvent(this, this.handleImageExpandClick)}
260 <PictrsImage src={this.imageSrc} />
267 const { post } = this.postView;
268 const { url } = post;
270 // if direct video link
271 if (url && isVideo(url)) {
273 <div className="embed-responsive mt-3">
274 <video muted controls className="embed-responsive-item col-12">
275 <source src={url} type="video/mp4" />
281 // if embedded video link
282 if (url && post.embed_video_url) {
284 <div className="ratio ratio-16x9">
287 className="post-metadata-iframe"
288 src={post.embed_video_url}
289 title={post.embed_title}
298 imgThumb(src: string) {
299 const post_view = this.postView;
305 nsfw={post_view.post.nsfw || post_view.community.nsfw}
310 get imageSrc(): string | undefined {
311 const post = this.postView.post;
312 const url = post.url;
313 const thumbnail = post.thumbnail_url;
317 } else if (url && isImage(url)) {
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="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0 bg-transparent"
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)}
341 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
345 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
348 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0"
353 {this.imgThumb(this.imageSrc)}
356 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
361 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
364 className="text-body"
368 data-tippy-content={I18NextService.i18n.t("expand_here")}
369 onClick={linkEvent(this, this.handleImageExpandClick)}
370 aria-label={I18NextService.i18n.t("expand_here")}
372 <div className="thumbnail rounded bg-light d-flex justify-content-center">
373 <Icon icon="play" classes="d-flex align-items-center" />
379 <a className="text-body" href={url} title={url} rel={relTags}>
380 <div className="thumbnail rounded bg-light d-flex justify-content-center">
381 <Icon icon="external-link" classes="d-flex align-items-center" />
389 className="text-body"
390 to={`/post/${post.id}`}
391 title={I18NextService.i18n.t("comments")}
393 <div className="thumbnail rounded bg-light d-flex justify-content-center">
394 <Icon icon="message-square" classes="d-flex align-items-center" />
402 const post_view = this.postView;
405 <div className="small mb-1 mb-md-0">
406 <PersonListing person={post_view.creator} />
409 isMod={this.creatorIsMod_}
410 isAdmin={this.creatorIsAdmin_}
411 isBot={post_view.creator.bot_account}
413 {this.props.showCommunity && (
416 {I18NextService.i18n.t("to")}{" "}
417 <CommunityLink community={post_view.community} />
420 {post_view.post.language_id !== 0 && (
421 <span className="mx-1 badge text-bg-light">
423 this.props.allLanguages.find(
424 lang => lang.id === post_view.post.language_id,
431 published={post_view.post.published}
432 updated={post_view.post.updated}
439 const post = this.postView.post;
442 className={`d-inline ${
443 !post.featured_community && !post.featured_local
447 to={`/post/${post.id}`}
448 title={I18NextService.i18n.t("comments")}
452 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
459 const post = this.postView.post;
460 const url = post.url;
464 <div className="post-title">
465 <h1 className="h5 d-inline text-break">
466 {url && this.props.showBody ? (
469 !post.featured_community && !post.featured_local
476 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
484 * If there is (a) a URL and an embed title, or (b) a post body, and
485 * we were not told to show the body by the parent component, show the
486 * MetadataCard/body toggle.
488 {!this.props.showBody &&
489 ((post.url && post.embed_title) || post.body) &&
490 this.showPreviewButton()}
493 <small className="ms-2 badge text-bg-secondary">
494 {I18NextService.i18n.t("removed")}
500 className="unselectable pointer ms-2 text-muted fst-italic"
501 data-tippy-content={I18NextService.i18n.t("deleted")}
503 <Icon icon="trash" classes="icon-inline text-danger" />
509 className="unselectable pointer ms-2 text-muted fst-italic"
510 data-tippy-content={I18NextService.i18n.t("locked")}
512 <Icon icon="lock" classes="icon-inline text-danger" />
516 {post.featured_community && (
518 className="unselectable pointer ms-2 text-muted fst-italic"
519 data-tippy-content={I18NextService.i18n.t(
520 "featured_in_community",
522 aria-label={I18NextService.i18n.t("featured_in_community")}
524 <Icon icon="pin" classes="icon-inline text-primary" />
528 {post.featured_local && (
530 className="unselectable pointer ms-2 text-muted fst-italic"
531 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
532 aria-label={I18NextService.i18n.t("featured_in_local")}
534 <Icon icon="pin" classes="icon-inline text-secondary" />
539 <small className="ms-2 badge text-bg-danger">
540 {I18NextService.i18n.t("nsfw")}
544 {url && this.urlLine()}
550 const post = this.postView.post;
551 const url = post.url;
554 <p className="small m-0">
555 {url && !(hostname(url) === getExternalHost()) && (
557 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
570 const dupes = this.props.crossPosts;
571 return dupes && dupes.length > 0 ? (
572 <ul className="list-inline mb-1 small text-muted">
574 <li className="list-inline-item me-2">
575 {I18NextService.i18n.t("cross_posted_to")}
578 <li key={pv.post.id} className="list-inline-item me-2">
579 <Link to={`/post/${pv.post.id}`}>
582 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
593 commentsLine(mobile = false) {
594 const post = this.postView.post;
597 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
598 {this.commentsButton}
601 className="btn btn-sm btn-link btn-animate text-muted py-0"
602 onClick={linkEvent(this, this.handleShare)}
605 <Icon icon="share" inline />
610 className="btn btn-sm btn-link btn-animate text-muted py-0"
611 title={I18NextService.i18n.t("link")}
614 <Icon icon="fedilink" inline />
617 {mobile && !this.props.viewOnly && (
619 voteContentType={VoteContentType.Post}
620 id={this.postView.post.id}
621 onVote={this.props.onPostVote}
622 enableDownvotes={this.props.enableDownvotes}
623 counts={this.postView.counts}
624 my_vote={this.postView.my_vote}
627 {UserService.Instance.myUserInfo &&
628 !this.props.viewOnly &&
635 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
636 // Possible enhancement: Make each button a component.
637 const post_view = this.postView;
638 const post = post_view.post;
643 {this.crossPostButton}
645 {this.props.showBody && post_view.post.body && this.viewSourceButton}
647 <div className="dropdown">
649 className="btn btn-sm btn-link btn-animate text-muted py-0 dropdown-toggle"
650 onClick={linkEvent(this, this.handleShowAdvanced)}
651 data-tippy-content={I18NextService.i18n.t("more")}
652 data-bs-toggle="dropdown"
653 aria-expanded="false"
654 aria-controls={`advancedButtonsDropdown${post.id}`}
655 aria-label={I18NextService.i18n.t("more")}
657 <Icon icon="more-vertical" inline />
661 className="dropdown-menu"
662 id={`advancedButtonsDropdown${post.id}`}
666 <li>{this.reportButton}</li>
667 <li>{this.blockButton}</li>
671 <li>{this.editButton}</li>
672 <li>{this.deleteButton}</li>
676 {/* Any mod can do these, not limited to hierarchy*/}
677 {(amMod(this.props.moderators) || amAdmin()) && (
680 <hr className="dropdown-divider" />
682 <li>{this.lockButton}</li>
683 {this.featureButtons}
687 {(this.canMod_ || this.canAdmin_) && (
688 <li>{this.modRemoveButton}</li>
694 <hr className="dropdown-divider" />
696 {!this.creatorIsMod_ &&
697 (!post_view.creator_banned_from_community ? (
698 <li>{this.modBanFromCommunityButton}</li>
700 <li>{this.modUnbanFromCommunityButton}</li>
702 {!post_view.creator_banned_from_community && (
703 <li>{this.addModToCommunityButton}</li>
708 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
710 this.creatorIsMod_ && <li>{this.transferCommunityButton}</li>}
712 {/* Admins can ban from all, and appoint other admins */}
716 <hr className="dropdown-divider" />
718 {!this.creatorIsAdmin_ && (
720 {!isBanned(post_view.creator) ? (
721 <li>{this.modBanButton}</li>
723 <li>{this.modUnbanButton}</li>
725 <li>{this.purgePersonButton}</li>
726 <li>{this.purgePostButton}</li>
729 {!isBanned(post_view.creator) && post_view.creator.local && (
730 <li>{this.toggleAdminButton}</li>
740 get commentsButton() {
741 const post_view = this.postView;
742 const title = I18NextService.i18n.t("number_of_comments", {
743 count: Number(post_view.counts.comments),
744 formattedCount: Number(post_view.counts.comments),
749 className="btn btn-link btn-sm text-muted ps-0"
751 to={`/post/${post_view.post.id}?scrollToComments=true`}
752 data-tippy-content={title}
754 <Icon icon="message-square" classes="me-1" inline />
755 {post_view.counts.comments}
756 {this.unreadCount && (
759 <span className="fst-italic">
760 ({this.unreadCount} {I18NextService.i18n.t("new")})
768 get unreadCount(): number | undefined {
769 const pv = this.postView;
770 return pv.unread_comments === pv.counts.comments || pv.unread_comments === 0
772 : pv.unread_comments;
776 const saved = this.postView.saved;
778 ? I18NextService.i18n.t("unsave")
779 : I18NextService.i18n.t("save");
782 className="btn btn-sm btn-link btn-animate text-muted py-0"
783 onClick={linkEvent(this, this.handleSavePostClick)}
784 data-tippy-content={label}
787 {this.state.saveLoading ? (
792 classes={classNames({ "text-warning": saved })}
800 get crossPostButton() {
803 className="btn btn-sm btn-link btn-animate text-muted py-0"
805 /* Empty string properties are required to satisfy type*/
806 pathname: "/create_post",
807 state: { ...this.crossPostParams },
812 title={I18NextService.i18n.t("cross_post")}
813 data-tippy-content={I18NextService.i18n.t("cross_post")}
814 aria-label={I18NextService.i18n.t("cross_post")}
816 <Icon icon="copy" inline />
824 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
825 onClick={linkEvent(this, this.handleShowReportDialog)}
826 aria-label={I18NextService.i18n.t("show_report_dialog")}
828 <Icon classes="me-1" icon="flag" inline />
829 {I18NextService.i18n.t("create_report")}
837 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
838 onClick={linkEvent(this, this.handleBlockPersonClick)}
839 aria-label={I18NextService.i18n.t("block_user")}
841 {this.state.blockLoading ? (
844 <Icon classes="me-1" icon="slash" inline />
846 {I18NextService.i18n.t("block_user")}
854 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
855 onClick={linkEvent(this, this.handleEditClick)}
856 aria-label={I18NextService.i18n.t("edit")}
858 <Icon classes="me-1" icon="edit" inline />
859 {I18NextService.i18n.t("edit")}
865 const deleted = this.postView.post.deleted;
866 const label = !deleted
867 ? I18NextService.i18n.t("delete")
868 : I18NextService.i18n.t("restore");
871 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
872 onClick={linkEvent(this, this.handleDeleteClick)}
874 {this.state.deleteLoading ? (
880 classes={classNames("me-1", { "text-danger": deleted })}
890 get viewSourceButton() {
893 className="btn btn-sm btn-link btn-animate text-muted py-0"
894 onClick={linkEvent(this, this.handleViewSource)}
895 data-tippy-content={I18NextService.i18n.t("view_source")}
896 aria-label={I18NextService.i18n.t("view_source")}
900 classes={classNames({ "text-success": this.state.viewSource })}
908 const locked = this.postView.post.locked;
910 ? I18NextService.i18n.t("unlock")
911 : I18NextService.i18n.t("lock");
914 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
915 onClick={linkEvent(this, this.handleModLock)}
918 {this.state.lockLoading ? (
924 classes={classNames("me-1", { "text-danger": locked })}
927 {capitalizeFirstLetter(label)}
934 get featureButtons() {
935 const featuredCommunity = this.postView.post.featured_community;
936 const labelCommunity = featuredCommunity
937 ? I18NextService.i18n.t("unfeature_from_community")
938 : I18NextService.i18n.t("feature_in_community");
940 const featuredLocal = this.postView.post.featured_local;
941 const labelLocal = featuredLocal
942 ? I18NextService.i18n.t("unfeature_from_local")
943 : I18NextService.i18n.t("feature_in_local");
948 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
949 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
950 data-tippy-content={labelCommunity}
951 aria-label={labelCommunity}
953 {this.state.featureCommunityLoading ? (
959 classes={classNames("me-1", {
960 "text-success": featuredCommunity,
964 {I18NextService.i18n.t("community")}
972 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
973 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
974 data-tippy-content={labelLocal}
975 aria-label={labelLocal}
977 {this.state.featureLocalLoading ? (
983 classes={classNames("me-1", {
984 "text-success": featuredLocal,
988 {I18NextService.i18n.t("local")}
998 get modBanFromCommunityButton() {
1001 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1002 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
1004 {I18NextService.i18n.t("ban_from_community")}
1009 get modUnbanFromCommunityButton() {
1012 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1013 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
1015 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1020 get addModToCommunityButton() {
1023 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1024 onClick={linkEvent(this, this.handleAddModToCommunity)}
1026 {this.state.addModLoading ? (
1028 ) : this.creatorIsMod_ ? (
1029 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_mod"))
1031 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_mod"))
1037 get modBanButton() {
1040 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1041 onClick={linkEvent(this, this.handleModBanShow)}
1043 {capitalizeFirstLetter(I18NextService.i18n.t("ban_from_site"))}
1048 get modUnbanButton() {
1051 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1052 onClick={linkEvent(this, this.handleModBanSubmit)}
1054 {this.state.banLoading ? (
1057 capitalizeFirstLetter(I18NextService.i18n.t("unban_from_site"))
1063 get purgePersonButton() {
1066 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1067 onClick={linkEvent(this, this.handlePurgePersonShow)}
1069 {capitalizeFirstLetter(I18NextService.i18n.t("purge_user"))}
1074 get purgePostButton() {
1077 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1078 onClick={linkEvent(this, this.handlePurgePostShow)}
1080 {capitalizeFirstLetter(I18NextService.i18n.t("purge_post"))}
1085 get toggleAdminButton() {
1088 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1089 onClick={linkEvent(this, this.handleAddAdmin)}
1091 {this.state.addAdminLoading ? (
1093 ) : this.creatorIsAdmin_ ? (
1094 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_admin"))
1096 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_admin"))
1102 get transferCommunityButton() {
1105 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1106 onClick={linkEvent(this, this.handleShowConfirmTransferCommunity)}
1108 {capitalizeFirstLetter(I18NextService.i18n.t("transfer_community"))}
1113 get modRemoveButton() {
1114 const removed = this.postView.post.removed;
1117 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1120 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit,
1123 {/* TODO: Find an icon for this. */}
1124 {this.state.removeLoading ? (
1127 capitalizeFirstLetter(I18NextService.i18n.t("remove_post"))
1130 {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "}
1131 {I18NextService.i18n.t("post")}
1138 removeAndBanDialogs() {
1139 const post = this.postView;
1140 const purgeTypeText =
1141 this.state.purgeType === PurgeType.Post
1142 ? I18NextService.i18n.t("purge_post")
1143 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1146 {this.state.showRemoveDialog && (
1148 className="form-inline"
1149 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1152 className="visually-hidden"
1153 htmlFor="post-listing-remove-reason"
1155 {I18NextService.i18n.t("reason")}
1159 id="post-listing-remove-reason"
1160 className="form-control me-2"
1161 placeholder={I18NextService.i18n.t("reason")}
1162 value={this.state.removeReason}
1163 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1165 <button type="submit" className="btn btn-secondary">
1166 {this.state.removeLoading ? (
1169 I18NextService.i18n.t("remove_post")
1174 {this.state.showConfirmTransferCommunity && (
1176 <button className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0">
1177 {I18NextService.i18n.t("are_you_sure")}
1180 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1181 onClick={linkEvent(this, this.handleTransferCommunity)}
1183 {this.state.transferLoading ? (
1186 I18NextService.i18n.t("yes")
1190 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1193 this.handleCancelShowConfirmTransferCommunity,
1195 aria-label={I18NextService.i18n.t("no")}
1197 {I18NextService.i18n.t("no")}
1201 {this.state.showBanDialog && (
1202 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1203 <div className="mb-3 row col-12">
1205 className="col-form-label"
1206 htmlFor="post-listing-ban-reason"
1208 {I18NextService.i18n.t("reason")}
1212 id="post-listing-ban-reason"
1213 className="form-control me-2"
1214 placeholder={I18NextService.i18n.t("reason")}
1215 value={this.state.banReason}
1216 onInput={linkEvent(this, this.handleModBanReasonChange)}
1218 <label className="col-form-label" htmlFor="mod-ban-expires">
1219 {I18NextService.i18n.t("expires")}
1223 id="mod-ban-expires"
1224 className="form-control me-2"
1225 placeholder={I18NextService.i18n.t("number_of_days")}
1226 value={this.state.banExpireDays}
1227 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1229 <div className="input-group mb-3">
1230 <div className="form-check">
1232 className="form-check-input"
1233 id="mod-ban-remove-data"
1235 checked={this.state.removeData}
1236 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1239 className="form-check-label"
1240 htmlFor="mod-ban-remove-data"
1241 title={I18NextService.i18n.t("remove_content_more")}
1243 {I18NextService.i18n.t("remove_content")}
1248 {/* TODO hold off on expires until later */}
1249 {/* <div class="mb-3 row"> */}
1250 {/* <label class="col-form-label">Expires</label> */}
1251 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1253 <div className="mb-3 row">
1254 <button type="submit" className="btn btn-secondary">
1255 {this.state.banLoading ? (
1259 {I18NextService.i18n.t("ban")} {post.creator.name}
1266 {this.state.showReportDialog && (
1268 className="form-inline"
1269 onSubmit={linkEvent(this, this.handleReportSubmit)}
1271 <label className="visually-hidden" htmlFor="post-report-reason">
1272 {I18NextService.i18n.t("reason")}
1276 id="post-report-reason"
1277 className="form-control me-2"
1278 placeholder={I18NextService.i18n.t("reason")}
1280 value={this.state.reportReason}
1281 onInput={linkEvent(this, this.handleReportReasonChange)}
1283 <button type="submit" className="btn btn-secondary">
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 ? (
1312 <button type="submit" className="btn btn-secondary">
1313 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1323 const post = this.postView.post;
1324 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1325 <div className="row">
1326 <div className={`${this.state.imageExpanded ? "col-12" : "col-9"}`}>
1327 {this.postTitleLine()}
1329 <div className="col-3 mobile-thumbnail-container">
1330 {/* Post thumbnail */}
1331 {!this.state.imageExpanded && this.thumbnail()}
1335 this.postTitleLine()
1339 showPreviewButton() {
1343 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1344 onClick={linkEvent(this, this.handleShowBody)}
1347 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1348 classes="icon-inline"
1357 {/* The mobile view*/}
1358 <div className="d-block d-sm-none">
1359 <article className="row post-container">
1360 <div className="col-12">
1361 {this.createdLine()}
1363 {/* If it has a thumbnail, do a right aligned thumbnail */}
1364 {this.mobileThumbnail()}
1366 {this.commentsLine(true)}
1367 {this.duplicatesLine()}
1368 {this.removeAndBanDialogs()}
1373 {/* The larger view*/}
1374 <div className="d-none d-sm-block">
1375 <article className="row post-container">
1376 {!this.props.viewOnly && (
1377 <div className="col flex-grow-0">
1379 voteContentType={VoteContentType.Post}
1380 id={this.postView.post.id}
1381 onVote={this.props.onPostVote}
1382 enableDownvotes={this.props.enableDownvotes}
1383 counts={this.postView.counts}
1384 my_vote={this.postView.my_vote}
1388 <div className="col flex-grow-1">
1389 <div className="row">
1390 <div className="col flex-grow-0 px-0">
1391 <div className="">{this.thumbnail()}</div>
1393 <div className="col flex-grow-1">
1394 {this.postTitleLine()}
1395 {this.createdLine()}
1396 {this.commentsLine()}
1397 {this.duplicatesLine()}
1398 {this.removeAndBanDialogs()}
1408 private get myPost(): boolean {
1410 this.postView.creator.id ===
1411 UserService.Instance.myUserInfo?.local_user_view.person.id
1415 handleEditClick(i: PostListing) {
1416 i.setState({ showEdit: true });
1419 handleEditCancel() {
1420 this.setState({ showEdit: false });
1423 // The actual editing is done in the receive for post
1424 handleEditPost(form: EditPost) {
1425 this.setState({ showEdit: false });
1426 this.props.onPostEdit(form);
1429 handleShare(i: PostListing) {
1430 const { name, body, id } = i.props.post_view.post;
1433 text: body?.slice(0, 50),
1434 url: `${getHttpBase()}/post/${id}`,
1438 handleShowReportDialog(i: PostListing) {
1439 i.setState({ showReportDialog: !i.state.showReportDialog });
1442 handleReportReasonChange(i: PostListing, event: any) {
1443 i.setState({ reportReason: event.target.value });
1446 handleReportSubmit(i: PostListing, event: any) {
1447 event.preventDefault();
1448 i.setState({ reportLoading: true });
1449 i.props.onPostReport({
1450 post_id: i.postView.post.id,
1451 reason: i.state.reportReason ?? "",
1452 auth: myAuthRequired(),
1456 handleBlockPersonClick(i: PostListing) {
1457 i.setState({ blockLoading: true });
1458 i.props.onBlockPerson({
1459 person_id: i.postView.creator.id,
1461 auth: myAuthRequired(),
1465 handleDeleteClick(i: PostListing) {
1466 i.setState({ deleteLoading: true });
1467 i.props.onDeletePost({
1468 post_id: i.postView.post.id,
1469 deleted: !i.postView.post.deleted,
1470 auth: myAuthRequired(),
1474 handleSavePostClick(i: PostListing) {
1475 i.setState({ saveLoading: true });
1476 i.props.onSavePost({
1477 post_id: i.postView.post.id,
1478 save: !i.postView.saved,
1479 auth: myAuthRequired(),
1483 get crossPostParams(): PostFormParams {
1484 const queryParams: PostFormParams = {};
1485 const { name, url } = this.postView.post;
1487 queryParams.name = name;
1490 queryParams.url = url;
1493 const crossPostBody = this.crossPostBody();
1494 if (crossPostBody) {
1495 queryParams.body = crossPostBody;
1501 crossPostBody(): string | undefined {
1502 const post = this.postView.post;
1503 const body = post.body;
1506 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1508 }\n\n${body.replace(/^/gm, "> ")}`
1512 get showBody(): boolean {
1513 return this.props.showBody || this.state.showBody;
1516 handleModRemoveShow(i: PostListing) {
1518 showRemoveDialog: !i.state.showRemoveDialog,
1519 showBanDialog: false,
1523 handleModRemoveReasonChange(i: PostListing, event: any) {
1524 i.setState({ removeReason: event.target.value });
1527 handleModRemoveDataChange(i: PostListing, event: any) {
1528 i.setState({ removeData: event.target.checked });
1531 handleModRemoveSubmit(i: PostListing, event: any) {
1532 event.preventDefault();
1533 i.setState({ removeLoading: true });
1534 i.props.onRemovePost({
1535 post_id: i.postView.post.id,
1536 removed: !i.postView.post.removed,
1537 auth: myAuthRequired(),
1538 reason: i.state.removeReason,
1542 handleModLock(i: PostListing) {
1543 i.setState({ lockLoading: true });
1544 i.props.onLockPost({
1545 post_id: i.postView.post.id,
1546 locked: !i.postView.post.locked,
1547 auth: myAuthRequired(),
1551 handleModFeaturePostLocal(i: PostListing) {
1552 i.setState({ featureLocalLoading: true });
1553 i.props.onFeaturePost({
1554 post_id: i.postView.post.id,
1555 featured: !i.postView.post.featured_local,
1556 feature_type: "Local",
1557 auth: myAuthRequired(),
1561 handleModFeaturePostCommunity(i: PostListing) {
1562 i.setState({ featureCommunityLoading: true });
1563 i.props.onFeaturePost({
1564 post_id: i.postView.post.id,
1565 featured: !i.postView.post.featured_community,
1566 feature_type: "Community",
1567 auth: myAuthRequired(),
1571 handleModBanFromCommunityShow(i: PostListing) {
1573 showBanDialog: true,
1574 banType: BanType.Community,
1575 showRemoveDialog: false,
1579 handleModBanShow(i: PostListing) {
1581 showBanDialog: true,
1582 banType: BanType.Site,
1583 showRemoveDialog: false,
1587 handlePurgePersonShow(i: PostListing) {
1589 showPurgeDialog: true,
1590 purgeType: PurgeType.Person,
1591 showRemoveDialog: false,
1595 handlePurgePostShow(i: PostListing) {
1597 showPurgeDialog: true,
1598 purgeType: PurgeType.Post,
1599 showRemoveDialog: false,
1603 handlePurgeReasonChange(i: PostListing, event: any) {
1604 i.setState({ purgeReason: event.target.value });
1607 handlePurgeSubmit(i: PostListing, event: any) {
1608 event.preventDefault();
1609 i.setState({ purgeLoading: true });
1610 if (i.state.purgeType === PurgeType.Person) {
1611 i.props.onPurgePerson({
1612 person_id: i.postView.creator.id,
1613 reason: i.state.purgeReason,
1614 auth: myAuthRequired(),
1616 } else if (i.state.purgeType === PurgeType.Post) {
1617 i.props.onPurgePost({
1618 post_id: i.postView.post.id,
1619 reason: i.state.purgeReason,
1620 auth: myAuthRequired(),
1625 handleModBanReasonChange(i: PostListing, event: any) {
1626 i.setState({ banReason: event.target.value });
1629 handleModBanExpireDaysChange(i: PostListing, event: any) {
1630 i.setState({ banExpireDays: event.target.value });
1633 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1634 i.setState({ banType: BanType.Community });
1635 i.handleModBanBothSubmit(i, event);
1638 handleModBanSubmit(i: PostListing, event: any) {
1639 i.setState({ banType: BanType.Site });
1640 i.handleModBanBothSubmit(i, event);
1643 handleModBanBothSubmit(i: PostListing, event: any) {
1644 event.preventDefault();
1645 i.setState({ banLoading: true });
1647 const ban = !i.props.post_view.creator_banned_from_community;
1648 // If its an unban, restore all their data
1649 if (ban === false) {
1650 i.setState({ removeData: false });
1652 const person_id = i.props.post_view.creator.id;
1653 const remove_data = i.state.removeData;
1654 const reason = i.state.banReason;
1655 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1657 if (i.state.banType === BanType.Community) {
1658 const community_id = i.postView.community.id;
1659 i.props.onBanPersonFromCommunity({
1666 auth: myAuthRequired(),
1669 i.props.onBanPerson({
1675 auth: myAuthRequired(),
1680 handleAddModToCommunity(i: PostListing) {
1681 i.setState({ addModLoading: true });
1682 i.props.onAddModToCommunity({
1683 community_id: i.postView.community.id,
1684 person_id: i.postView.creator.id,
1685 added: !i.creatorIsMod_,
1686 auth: myAuthRequired(),
1690 handleAddAdmin(i: PostListing) {
1691 i.setState({ addAdminLoading: true });
1692 i.props.onAddAdmin({
1693 person_id: i.postView.creator.id,
1694 added: !i.creatorIsAdmin_,
1695 auth: myAuthRequired(),
1699 handleShowConfirmTransferCommunity(i: PostListing) {
1700 i.setState({ showConfirmTransferCommunity: true });
1703 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1704 i.setState({ showConfirmTransferCommunity: false });
1707 handleTransferCommunity(i: PostListing) {
1708 i.setState({ transferLoading: true });
1709 i.props.onTransferCommunity({
1710 community_id: i.postView.community.id,
1711 person_id: i.postView.creator.id,
1712 auth: myAuthRequired(),
1716 handleShowConfirmTransferSite(i: PostListing) {
1717 i.setState({ showConfirmTransferSite: true });
1720 handleCancelShowConfirmTransferSite(i: PostListing) {
1721 i.setState({ showConfirmTransferSite: false });
1724 handleImageExpandClick(i: PostListing, event: any) {
1725 event.preventDefault();
1726 i.setState({ imageExpanded: !i.state.imageExpanded });
1729 const auth = myAuth();
1730 if (auth && !i.props.post_view.read) {
1731 i.props.onMarkPostAsRead({
1732 post_id: i.props.post_view.post.id,
1739 handleViewSource(i: PostListing) {
1740 i.setState({ viewSource: !i.state.viewSource });
1743 handleShowAdvanced(i: PostListing) {
1744 i.setState({ showAdvanced: !i.state.showAdvanced });
1748 handleShowMoreMobile(i: PostListing) {
1750 showMoreMobile: !i.state.showMoreMobile,
1751 showAdvanced: !i.state.showAdvanced,
1756 handleShowBody(i: PostListing) {
1757 i.setState({ showBody: !i.state.showBody });
1761 get pointsTippy(): string {
1762 const points = I18NextService.i18n.t("number_of_points", {
1763 count: Number(this.postView.counts.score),
1764 formattedCount: Number(this.postView.counts.score),
1767 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1768 count: Number(this.postView.counts.upvotes),
1769 formattedCount: Number(this.postView.counts.upvotes),
1772 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1773 count: Number(this.postView.counts.downvotes),
1774 formattedCount: Number(this.postView.counts.downvotes),
1777 return `${points} • ${upvotes} • ${downvotes}`;
1780 get canModOnSelf_(): boolean {
1782 this.postView.creator.id,
1783 this.props.moderators,
1790 get canMod_(): boolean {
1792 this.postView.creator.id,
1793 this.props.moderators,
1798 get canAdmin_(): boolean {
1799 return canAdmin(this.postView.creator.id, this.props.admins);
1802 get creatorIsMod_(): boolean {
1803 return isMod(this.postView.creator.id, this.props.moderators);
1806 get creatorIsAdmin_(): boolean {
1807 return isAdmin(this.postView.creator.id, this.props.admins);