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"
352 target={this.linkTarget}
354 {this.imgThumb(this.imageSrc)}
357 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
362 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
365 className="text-body"
369 data-tippy-content={I18NextService.i18n.t("expand_here")}
370 onClick={linkEvent(this, this.handleImageExpandClick)}
371 aria-label={I18NextService.i18n.t("expand_here")}
372 target={this.linkTarget}
374 <div className="thumbnail rounded bg-light d-flex justify-content-center">
375 <Icon icon="play" classes="d-flex align-items-center" />
382 className="text-body"
386 target={this.linkTarget}
388 <div className="thumbnail rounded bg-light d-flex justify-content-center">
389 <Icon icon="external-link" classes="d-flex align-items-center" />
397 className="text-body"
398 to={`/post/${post.id}`}
399 title={I18NextService.i18n.t("comments")}
400 target={this.linkTarget}
402 <div className="thumbnail rounded bg-light d-flex justify-content-center">
403 <Icon icon="message-square" classes="d-flex align-items-center" />
411 const post_view = this.postView;
414 <div className="small mb-1 mb-md-0">
415 <PersonListing person={post_view.creator} />
418 isMod={this.creatorIsMod_}
419 isAdmin={this.creatorIsAdmin_}
420 isBot={post_view.creator.bot_account}
422 {this.props.showCommunity && (
425 {I18NextService.i18n.t("to")}{" "}
426 <CommunityLink community={post_view.community} />
429 {post_view.post.language_id !== 0 && (
430 <span className="mx-1 badge text-bg-light">
432 this.props.allLanguages.find(
433 lang => lang.id === post_view.post.language_id,
440 published={post_view.post.published}
441 updated={post_view.post.updated}
448 const post = this.postView.post;
451 className={`d-inline ${
452 !post.featured_community && !post.featured_local
456 to={`/post/${post.id}`}
457 title={I18NextService.i18n.t("comments")}
461 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
468 const post = this.postView.post;
469 const url = post.url;
473 <div className="post-title">
474 <h1 className="h5 d-inline text-break">
475 {url && this.props.showBody ? (
478 !post.featured_community && !post.featured_local
485 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
493 * If there is (a) a URL and an embed title, or (b) a post body, and
494 * we were not told to show the body by the parent component, show the
495 * MetadataCard/body toggle.
497 {!this.props.showBody &&
498 ((post.url && post.embed_title) || post.body) &&
499 this.showPreviewButton()}
502 <small className="ms-2 badge text-bg-secondary">
503 {I18NextService.i18n.t("removed")}
509 className="unselectable pointer ms-2 text-muted fst-italic"
510 data-tippy-content={I18NextService.i18n.t("deleted")}
512 <Icon icon="trash" classes="icon-inline text-danger" />
518 className="unselectable pointer ms-2 text-muted fst-italic"
519 data-tippy-content={I18NextService.i18n.t("locked")}
521 <Icon icon="lock" classes="icon-inline text-danger" />
525 {post.featured_community && (
527 className="unselectable pointer ms-2 text-muted fst-italic"
528 data-tippy-content={I18NextService.i18n.t(
529 "featured_in_community",
531 aria-label={I18NextService.i18n.t("featured_in_community")}
533 <Icon icon="pin" classes="icon-inline text-primary" />
537 {post.featured_local && (
539 className="unselectable pointer ms-2 text-muted fst-italic"
540 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
541 aria-label={I18NextService.i18n.t("featured_in_local")}
543 <Icon icon="pin" classes="icon-inline text-secondary" />
548 <small className="ms-2 badge text-bg-danger">
549 {I18NextService.i18n.t("nsfw")}
553 {url && this.urlLine()}
559 const post = this.postView.post;
560 const url = post.url;
563 <p className="small m-0">
564 {url && !(hostname(url) === getExternalHost()) && (
566 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
579 const dupes = this.props.crossPosts;
580 return dupes && dupes.length > 0 ? (
581 <ul className="list-inline mb-1 small text-muted">
583 <li className="list-inline-item me-2">
584 {I18NextService.i18n.t("cross_posted_to")}
587 <li key={pv.post.id} className="list-inline-item me-2">
588 <Link to={`/post/${pv.post.id}`}>
591 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
602 commentsLine(mobile = false) {
603 const post = this.postView.post;
606 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
607 {this.commentsButton}
610 className="btn btn-sm btn-link btn-animate text-muted py-0"
611 onClick={linkEvent(this, this.handleShare)}
614 <Icon icon="share" inline />
619 className="btn btn-sm btn-link btn-animate text-muted py-0"
620 title={I18NextService.i18n.t("link")}
623 <Icon icon="fedilink" inline />
626 {mobile && !this.props.viewOnly && (
628 voteContentType={VoteContentType.Post}
629 id={this.postView.post.id}
630 onVote={this.props.onPostVote}
631 enableDownvotes={this.props.enableDownvotes}
632 counts={this.postView.counts}
633 my_vote={this.postView.my_vote}
636 {UserService.Instance.myUserInfo &&
637 !this.props.viewOnly &&
644 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
645 // Possible enhancement: Make each button a component.
646 const post_view = this.postView;
647 const post = post_view.post;
652 {this.crossPostButton}
654 {this.props.showBody && post_view.post.body && this.viewSourceButton}
656 <div className="dropdown">
658 className="btn btn-sm btn-link 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${post.id}`}
664 aria-label={I18NextService.i18n.t("more")}
666 <Icon icon="more-vertical" inline />
670 className="dropdown-menu"
671 id={`advancedButtonsDropdown${post.id}`}
675 <li>{this.reportButton}</li>
676 <li>{this.blockButton}</li>
680 <li>{this.editButton}</li>
681 <li>{this.deleteButton}</li>
685 {/* Any mod can do these, not limited to hierarchy*/}
686 {(amMod(this.props.moderators) || amAdmin()) && (
689 <hr className="dropdown-divider" />
691 <li>{this.lockButton}</li>
692 {this.featureButtons}
696 {(this.canMod_ || this.canAdmin_) && (
697 <li>{this.modRemoveButton}</li>
703 <hr className="dropdown-divider" />
705 {!this.creatorIsMod_ &&
706 (!post_view.creator_banned_from_community ? (
707 <li>{this.modBanFromCommunityButton}</li>
709 <li>{this.modUnbanFromCommunityButton}</li>
711 {!post_view.creator_banned_from_community && (
712 <li>{this.addModToCommunityButton}</li>
717 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
719 this.creatorIsMod_ && <li>{this.transferCommunityButton}</li>}
721 {/* Admins can ban from all, and appoint other admins */}
725 <hr className="dropdown-divider" />
727 {!this.creatorIsAdmin_ && (
729 {!isBanned(post_view.creator) ? (
730 <li>{this.modBanButton}</li>
732 <li>{this.modUnbanButton}</li>
734 <li>{this.purgePersonButton}</li>
735 <li>{this.purgePostButton}</li>
738 {!isBanned(post_view.creator) && post_view.creator.local && (
739 <li>{this.toggleAdminButton}</li>
749 public get linkTarget(): string {
750 return UserService.Instance.myUserInfo?.local_user_view.local_user
751 .open_links_in_new_tab
753 : // _self is the default target on links when the field is not specified
757 get commentsButton() {
758 const post_view = this.postView;
759 const title = I18NextService.i18n.t("number_of_comments", {
760 count: Number(post_view.counts.comments),
761 formattedCount: Number(post_view.counts.comments),
766 className="btn btn-link btn-sm text-muted ps-0"
768 to={`/post/${post_view.post.id}?scrollToComments=true`}
769 data-tippy-content={title}
770 target={this.linkTarget}
772 <Icon icon="message-square" classes="me-1" inline />
773 {post_view.counts.comments}
774 {this.unreadCount && (
777 <span className="fst-italic">
778 ({this.unreadCount} {I18NextService.i18n.t("new")})
786 get unreadCount(): number | undefined {
787 const pv = this.postView;
788 return pv.unread_comments === pv.counts.comments || pv.unread_comments === 0
790 : pv.unread_comments;
794 const saved = this.postView.saved;
796 ? I18NextService.i18n.t("unsave")
797 : I18NextService.i18n.t("save");
800 className="btn btn-sm btn-link btn-animate text-muted py-0"
801 onClick={linkEvent(this, this.handleSavePostClick)}
802 data-tippy-content={label}
805 {this.state.saveLoading ? (
810 classes={classNames({ "text-warning": saved })}
818 get crossPostButton() {
821 className="btn btn-sm btn-link btn-animate text-muted py-0"
823 /* Empty string properties are required to satisfy type*/
824 pathname: "/create_post",
825 state: { ...this.crossPostParams },
830 title={I18NextService.i18n.t("cross_post")}
831 data-tippy-content={I18NextService.i18n.t("cross_post")}
832 aria-label={I18NextService.i18n.t("cross_post")}
834 <Icon icon="copy" inline />
842 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
843 onClick={linkEvent(this, this.handleShowReportDialog)}
844 aria-label={I18NextService.i18n.t("show_report_dialog")}
846 <Icon classes="me-1" icon="flag" inline />
847 {I18NextService.i18n.t("create_report")}
855 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
856 onClick={linkEvent(this, this.handleBlockPersonClick)}
857 aria-label={I18NextService.i18n.t("block_user")}
859 {this.state.blockLoading ? (
862 <Icon classes="me-1" icon="slash" inline />
864 {I18NextService.i18n.t("block_user")}
872 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
873 onClick={linkEvent(this, this.handleEditClick)}
874 aria-label={I18NextService.i18n.t("edit")}
876 <Icon classes="me-1" icon="edit" inline />
877 {I18NextService.i18n.t("edit")}
883 const deleted = this.postView.post.deleted;
884 const label = !deleted
885 ? I18NextService.i18n.t("delete")
886 : I18NextService.i18n.t("restore");
889 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
890 onClick={linkEvent(this, this.handleDeleteClick)}
892 {this.state.deleteLoading ? (
898 classes={classNames("me-1", { "text-danger": deleted })}
908 get viewSourceButton() {
911 className="btn btn-sm btn-link btn-animate text-muted py-0"
912 onClick={linkEvent(this, this.handleViewSource)}
913 data-tippy-content={I18NextService.i18n.t("view_source")}
914 aria-label={I18NextService.i18n.t("view_source")}
918 classes={classNames({ "text-success": this.state.viewSource })}
926 const locked = this.postView.post.locked;
928 ? I18NextService.i18n.t("unlock")
929 : I18NextService.i18n.t("lock");
932 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
933 onClick={linkEvent(this, this.handleModLock)}
936 {this.state.lockLoading ? (
942 classes={classNames("me-1", { "text-danger": locked })}
945 {capitalizeFirstLetter(label)}
952 get featureButtons() {
953 const featuredCommunity = this.postView.post.featured_community;
954 const labelCommunity = featuredCommunity
955 ? I18NextService.i18n.t("unfeature_from_community")
956 : I18NextService.i18n.t("feature_in_community");
958 const featuredLocal = this.postView.post.featured_local;
959 const labelLocal = featuredLocal
960 ? I18NextService.i18n.t("unfeature_from_local")
961 : I18NextService.i18n.t("feature_in_local");
966 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
967 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
968 data-tippy-content={labelCommunity}
969 aria-label={labelCommunity}
971 {this.state.featureCommunityLoading ? (
977 classes={classNames("me-1", {
978 "text-success": featuredCommunity,
982 {I18NextService.i18n.t("community")}
990 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
991 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
992 data-tippy-content={labelLocal}
993 aria-label={labelLocal}
995 {this.state.featureLocalLoading ? (
1001 classes={classNames("me-1", {
1002 "text-success": featuredLocal,
1006 {I18NextService.i18n.t("local")}
1016 get modBanFromCommunityButton() {
1019 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1020 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
1022 {I18NextService.i18n.t("ban_from_community")}
1027 get modUnbanFromCommunityButton() {
1030 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1031 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
1033 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1038 get addModToCommunityButton() {
1041 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1042 onClick={linkEvent(this, this.handleAddModToCommunity)}
1044 {this.state.addModLoading ? (
1046 ) : this.creatorIsMod_ ? (
1047 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_mod"))
1049 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_mod"))
1055 get modBanButton() {
1058 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1059 onClick={linkEvent(this, this.handleModBanShow)}
1061 {capitalizeFirstLetter(I18NextService.i18n.t("ban_from_site"))}
1066 get modUnbanButton() {
1069 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1070 onClick={linkEvent(this, this.handleModBanSubmit)}
1072 {this.state.banLoading ? (
1075 capitalizeFirstLetter(I18NextService.i18n.t("unban_from_site"))
1081 get purgePersonButton() {
1084 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1085 onClick={linkEvent(this, this.handlePurgePersonShow)}
1087 {capitalizeFirstLetter(I18NextService.i18n.t("purge_user"))}
1092 get purgePostButton() {
1095 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1096 onClick={linkEvent(this, this.handlePurgePostShow)}
1098 {capitalizeFirstLetter(I18NextService.i18n.t("purge_post"))}
1103 get toggleAdminButton() {
1106 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1107 onClick={linkEvent(this, this.handleAddAdmin)}
1109 {this.state.addAdminLoading ? (
1111 ) : this.creatorIsAdmin_ ? (
1112 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_admin"))
1114 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_admin"))
1120 get transferCommunityButton() {
1123 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1124 onClick={linkEvent(this, this.handleShowConfirmTransferCommunity)}
1126 {capitalizeFirstLetter(I18NextService.i18n.t("transfer_community"))}
1131 get modRemoveButton() {
1132 const removed = this.postView.post.removed;
1135 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1138 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit,
1141 {/* TODO: Find an icon for this. */}
1142 {this.state.removeLoading ? (
1145 capitalizeFirstLetter(I18NextService.i18n.t("remove_post"))
1148 {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "}
1149 {I18NextService.i18n.t("post")}
1156 removeAndBanDialogs() {
1157 const post = this.postView;
1158 const purgeTypeText =
1159 this.state.purgeType === PurgeType.Post
1160 ? I18NextService.i18n.t("purge_post")
1161 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1164 {this.state.showRemoveDialog && (
1166 className="form-inline"
1167 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1170 className="visually-hidden"
1171 htmlFor="post-listing-remove-reason"
1173 {I18NextService.i18n.t("reason")}
1177 id="post-listing-remove-reason"
1178 className="form-control me-2"
1179 placeholder={I18NextService.i18n.t("reason")}
1180 value={this.state.removeReason}
1181 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1183 <button type="submit" className="btn btn-secondary">
1184 {this.state.removeLoading ? (
1187 I18NextService.i18n.t("remove_post")
1192 {this.state.showConfirmTransferCommunity && (
1194 <button className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0">
1195 {I18NextService.i18n.t("are_you_sure")}
1198 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1199 onClick={linkEvent(this, this.handleTransferCommunity)}
1201 {this.state.transferLoading ? (
1204 I18NextService.i18n.t("yes")
1208 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1211 this.handleCancelShowConfirmTransferCommunity,
1213 aria-label={I18NextService.i18n.t("no")}
1215 {I18NextService.i18n.t("no")}
1219 {this.state.showBanDialog && (
1220 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1221 <div className="mb-3 row col-12">
1223 className="col-form-label"
1224 htmlFor="post-listing-ban-reason"
1226 {I18NextService.i18n.t("reason")}
1230 id="post-listing-ban-reason"
1231 className="form-control me-2"
1232 placeholder={I18NextService.i18n.t("reason")}
1233 value={this.state.banReason}
1234 onInput={linkEvent(this, this.handleModBanReasonChange)}
1236 <label className="col-form-label" htmlFor="mod-ban-expires">
1237 {I18NextService.i18n.t("expires")}
1241 id="mod-ban-expires"
1242 className="form-control me-2"
1243 placeholder={I18NextService.i18n.t("number_of_days")}
1244 value={this.state.banExpireDays}
1245 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1247 <div className="input-group mb-3">
1248 <div className="form-check">
1250 className="form-check-input"
1251 id="mod-ban-remove-data"
1253 checked={this.state.removeData}
1254 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1257 className="form-check-label"
1258 htmlFor="mod-ban-remove-data"
1259 title={I18NextService.i18n.t("remove_content_more")}
1261 {I18NextService.i18n.t("remove_content")}
1266 {/* TODO hold off on expires until later */}
1267 {/* <div class="mb-3 row"> */}
1268 {/* <label class="col-form-label">Expires</label> */}
1269 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1271 <div className="mb-3 row">
1272 <button type="submit" className="btn btn-secondary">
1273 {this.state.banLoading ? (
1277 {I18NextService.i18n.t("ban")} {post.creator.name}
1284 {this.state.showReportDialog && (
1286 className="form-inline"
1287 onSubmit={linkEvent(this, this.handleReportSubmit)}
1289 <label className="visually-hidden" htmlFor="post-report-reason">
1290 {I18NextService.i18n.t("reason")}
1294 id="post-report-reason"
1295 className="form-control me-2"
1296 placeholder={I18NextService.i18n.t("reason")}
1298 value={this.state.reportReason}
1299 onInput={linkEvent(this, this.handleReportReasonChange)}
1301 <button type="submit" className="btn btn-secondary">
1302 {this.state.reportLoading ? (
1305 I18NextService.i18n.t("create_report")
1310 {this.state.showPurgeDialog && (
1312 className="form-inline"
1313 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1316 <label className="visually-hidden" htmlFor="purge-reason">
1317 {I18NextService.i18n.t("reason")}
1322 className="form-control me-2"
1323 placeholder={I18NextService.i18n.t("reason")}
1324 value={this.state.purgeReason}
1325 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1327 {this.state.purgeLoading ? (
1330 <button type="submit" className="btn btn-secondary">
1331 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1341 const post = this.postView.post;
1342 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1343 <div className="row">
1344 <div className={`${this.state.imageExpanded ? "col-12" : "col-9"}`}>
1345 {this.postTitleLine()}
1347 <div className="col-3 mobile-thumbnail-container">
1348 {/* Post thumbnail */}
1349 {!this.state.imageExpanded && this.thumbnail()}
1353 this.postTitleLine()
1357 showPreviewButton() {
1361 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1362 onClick={linkEvent(this, this.handleShowBody)}
1365 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1366 classes="icon-inline"
1375 {/* The mobile view*/}
1376 <div className="d-block d-sm-none">
1377 <article className="row post-container">
1378 <div className="col-12">
1379 {this.createdLine()}
1381 {/* If it has a thumbnail, do a right aligned thumbnail */}
1382 {this.mobileThumbnail()}
1384 {this.commentsLine(true)}
1385 {this.duplicatesLine()}
1386 {this.removeAndBanDialogs()}
1391 {/* The larger view*/}
1392 <div className="d-none d-sm-block">
1393 <article className="row post-container">
1394 {!this.props.viewOnly && (
1395 <div className="col flex-grow-0">
1397 voteContentType={VoteContentType.Post}
1398 id={this.postView.post.id}
1399 onVote={this.props.onPostVote}
1400 enableDownvotes={this.props.enableDownvotes}
1401 counts={this.postView.counts}
1402 my_vote={this.postView.my_vote}
1406 <div className="col flex-grow-1">
1407 <div className="row">
1408 <div className="col flex-grow-0 px-0">
1409 <div className="">{this.thumbnail()}</div>
1411 <div className="col flex-grow-1">
1412 {this.postTitleLine()}
1413 {this.createdLine()}
1414 {this.commentsLine()}
1415 {this.duplicatesLine()}
1416 {this.removeAndBanDialogs()}
1426 private get myPost(): boolean {
1428 this.postView.creator.id ===
1429 UserService.Instance.myUserInfo?.local_user_view.person.id
1433 handleEditClick(i: PostListing) {
1434 i.setState({ showEdit: true });
1437 handleEditCancel() {
1438 this.setState({ showEdit: false });
1441 // The actual editing is done in the receive for post
1442 handleEditPost(form: EditPost) {
1443 this.setState({ showEdit: false });
1444 this.props.onPostEdit(form);
1447 handleShare(i: PostListing) {
1448 const { name, body, id } = i.props.post_view.post;
1451 text: body?.slice(0, 50),
1452 url: `${getHttpBase()}/post/${id}`,
1456 handleShowReportDialog(i: PostListing) {
1457 i.setState({ showReportDialog: !i.state.showReportDialog });
1460 handleReportReasonChange(i: PostListing, event: any) {
1461 i.setState({ reportReason: event.target.value });
1464 handleReportSubmit(i: PostListing, event: any) {
1465 event.preventDefault();
1466 i.setState({ reportLoading: true });
1467 i.props.onPostReport({
1468 post_id: i.postView.post.id,
1469 reason: i.state.reportReason ?? "",
1470 auth: myAuthRequired(),
1474 handleBlockPersonClick(i: PostListing) {
1475 i.setState({ blockLoading: true });
1476 i.props.onBlockPerson({
1477 person_id: i.postView.creator.id,
1479 auth: myAuthRequired(),
1483 handleDeleteClick(i: PostListing) {
1484 i.setState({ deleteLoading: true });
1485 i.props.onDeletePost({
1486 post_id: i.postView.post.id,
1487 deleted: !i.postView.post.deleted,
1488 auth: myAuthRequired(),
1492 handleSavePostClick(i: PostListing) {
1493 i.setState({ saveLoading: true });
1494 i.props.onSavePost({
1495 post_id: i.postView.post.id,
1496 save: !i.postView.saved,
1497 auth: myAuthRequired(),
1501 get crossPostParams(): PostFormParams {
1502 const queryParams: PostFormParams = {};
1503 const { name, url } = this.postView.post;
1505 queryParams.name = name;
1508 queryParams.url = url;
1511 const crossPostBody = this.crossPostBody();
1512 if (crossPostBody) {
1513 queryParams.body = crossPostBody;
1519 crossPostBody(): string | undefined {
1520 const post = this.postView.post;
1521 const body = post.body;
1524 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1526 }\n\n${body.replace(/^/gm, "> ")}`
1530 get showBody(): boolean {
1531 return this.props.showBody || this.state.showBody;
1534 handleModRemoveShow(i: PostListing) {
1536 showRemoveDialog: !i.state.showRemoveDialog,
1537 showBanDialog: false,
1541 handleModRemoveReasonChange(i: PostListing, event: any) {
1542 i.setState({ removeReason: event.target.value });
1545 handleModRemoveDataChange(i: PostListing, event: any) {
1546 i.setState({ removeData: event.target.checked });
1549 handleModRemoveSubmit(i: PostListing, event: any) {
1550 event.preventDefault();
1551 i.setState({ removeLoading: true });
1552 i.props.onRemovePost({
1553 post_id: i.postView.post.id,
1554 removed: !i.postView.post.removed,
1555 auth: myAuthRequired(),
1556 reason: i.state.removeReason,
1560 handleModLock(i: PostListing) {
1561 i.setState({ lockLoading: true });
1562 i.props.onLockPost({
1563 post_id: i.postView.post.id,
1564 locked: !i.postView.post.locked,
1565 auth: myAuthRequired(),
1569 handleModFeaturePostLocal(i: PostListing) {
1570 i.setState({ featureLocalLoading: true });
1571 i.props.onFeaturePost({
1572 post_id: i.postView.post.id,
1573 featured: !i.postView.post.featured_local,
1574 feature_type: "Local",
1575 auth: myAuthRequired(),
1579 handleModFeaturePostCommunity(i: PostListing) {
1580 i.setState({ featureCommunityLoading: true });
1581 i.props.onFeaturePost({
1582 post_id: i.postView.post.id,
1583 featured: !i.postView.post.featured_community,
1584 feature_type: "Community",
1585 auth: myAuthRequired(),
1589 handleModBanFromCommunityShow(i: PostListing) {
1591 showBanDialog: true,
1592 banType: BanType.Community,
1593 showRemoveDialog: false,
1597 handleModBanShow(i: PostListing) {
1599 showBanDialog: true,
1600 banType: BanType.Site,
1601 showRemoveDialog: false,
1605 handlePurgePersonShow(i: PostListing) {
1607 showPurgeDialog: true,
1608 purgeType: PurgeType.Person,
1609 showRemoveDialog: false,
1613 handlePurgePostShow(i: PostListing) {
1615 showPurgeDialog: true,
1616 purgeType: PurgeType.Post,
1617 showRemoveDialog: false,
1621 handlePurgeReasonChange(i: PostListing, event: any) {
1622 i.setState({ purgeReason: event.target.value });
1625 handlePurgeSubmit(i: PostListing, event: any) {
1626 event.preventDefault();
1627 i.setState({ purgeLoading: true });
1628 if (i.state.purgeType === PurgeType.Person) {
1629 i.props.onPurgePerson({
1630 person_id: i.postView.creator.id,
1631 reason: i.state.purgeReason,
1632 auth: myAuthRequired(),
1634 } else if (i.state.purgeType === PurgeType.Post) {
1635 i.props.onPurgePost({
1636 post_id: i.postView.post.id,
1637 reason: i.state.purgeReason,
1638 auth: myAuthRequired(),
1643 handleModBanReasonChange(i: PostListing, event: any) {
1644 i.setState({ banReason: event.target.value });
1647 handleModBanExpireDaysChange(i: PostListing, event: any) {
1648 i.setState({ banExpireDays: event.target.value });
1651 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1652 i.setState({ banType: BanType.Community });
1653 i.handleModBanBothSubmit(i, event);
1656 handleModBanSubmit(i: PostListing, event: any) {
1657 i.setState({ banType: BanType.Site });
1658 i.handleModBanBothSubmit(i, event);
1661 handleModBanBothSubmit(i: PostListing, event: any) {
1662 event.preventDefault();
1663 i.setState({ banLoading: true });
1665 const ban = !i.props.post_view.creator_banned_from_community;
1666 // If its an unban, restore all their data
1667 if (ban === false) {
1668 i.setState({ removeData: false });
1670 const person_id = i.props.post_view.creator.id;
1671 const remove_data = i.state.removeData;
1672 const reason = i.state.banReason;
1673 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1675 if (i.state.banType === BanType.Community) {
1676 const community_id = i.postView.community.id;
1677 i.props.onBanPersonFromCommunity({
1684 auth: myAuthRequired(),
1687 i.props.onBanPerson({
1693 auth: myAuthRequired(),
1698 handleAddModToCommunity(i: PostListing) {
1699 i.setState({ addModLoading: true });
1700 i.props.onAddModToCommunity({
1701 community_id: i.postView.community.id,
1702 person_id: i.postView.creator.id,
1703 added: !i.creatorIsMod_,
1704 auth: myAuthRequired(),
1708 handleAddAdmin(i: PostListing) {
1709 i.setState({ addAdminLoading: true });
1710 i.props.onAddAdmin({
1711 person_id: i.postView.creator.id,
1712 added: !i.creatorIsAdmin_,
1713 auth: myAuthRequired(),
1717 handleShowConfirmTransferCommunity(i: PostListing) {
1718 i.setState({ showConfirmTransferCommunity: true });
1721 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1722 i.setState({ showConfirmTransferCommunity: false });
1725 handleTransferCommunity(i: PostListing) {
1726 i.setState({ transferLoading: true });
1727 i.props.onTransferCommunity({
1728 community_id: i.postView.community.id,
1729 person_id: i.postView.creator.id,
1730 auth: myAuthRequired(),
1734 handleShowConfirmTransferSite(i: PostListing) {
1735 i.setState({ showConfirmTransferSite: true });
1738 handleCancelShowConfirmTransferSite(i: PostListing) {
1739 i.setState({ showConfirmTransferSite: false });
1742 handleImageExpandClick(i: PostListing, event: any) {
1743 event.preventDefault();
1744 i.setState({ imageExpanded: !i.state.imageExpanded });
1747 const auth = myAuth();
1748 if (auth && !i.props.post_view.read) {
1749 i.props.onMarkPostAsRead({
1750 post_id: i.props.post_view.post.id,
1757 handleViewSource(i: PostListing) {
1758 i.setState({ viewSource: !i.state.viewSource });
1761 handleShowAdvanced(i: PostListing) {
1762 i.setState({ showAdvanced: !i.state.showAdvanced });
1766 handleShowMoreMobile(i: PostListing) {
1768 showMoreMobile: !i.state.showMoreMobile,
1769 showAdvanced: !i.state.showAdvanced,
1774 handleShowBody(i: PostListing) {
1775 i.setState({ showBody: !i.state.showBody });
1779 get pointsTippy(): string {
1780 const points = I18NextService.i18n.t("number_of_points", {
1781 count: Number(this.postView.counts.score),
1782 formattedCount: Number(this.postView.counts.score),
1785 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1786 count: Number(this.postView.counts.upvotes),
1787 formattedCount: Number(this.postView.counts.upvotes),
1790 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1791 count: Number(this.postView.counts.downvotes),
1792 formattedCount: Number(this.postView.counts.downvotes),
1795 return `${points} • ${upvotes} • ${downvotes}`;
1798 get canModOnSelf_(): boolean {
1800 this.postView.creator.id,
1801 this.props.moderators,
1808 get canMod_(): boolean {
1810 this.postView.creator.id,
1811 this.props.moderators,
1816 get canAdmin_(): boolean {
1817 return canAdmin(this.postView.creator.id, this.props.admins);
1820 get creatorIsMod_(): boolean {
1821 return isMod(this.postView.creator.id, this.props.moderators);
1824 get creatorIsAdmin_(): boolean {
1825 return isAdmin(this.postView.creator.id, this.props.admins);