1 import { getRoleLabelPill, myAuthRequired } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
51 } from "../../interfaces";
52 import { mdToHtml, mdToHtmlInline } from "../../markdown";
53 import { I18NextService, UserService } from "../../services";
54 import { setupTippy } from "../../tippy";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
59 import { CommunityLink } from "../community/community-link";
60 import { PersonListing } from "../person/person-listing";
61 import { MetadataCard } from "./metadata-card";
62 import { PostForm } from "./post-form";
64 interface PostListingState {
66 showRemoveDialog: boolean;
67 showPurgeDialog: boolean;
69 purgeType?: PurgeType;
70 purgeLoading: boolean;
71 removeReason?: string;
72 showBanDialog: boolean;
74 banExpireDays?: number;
77 showConfirmTransferSite: boolean;
78 showConfirmTransferCommunity: boolean;
79 imageExpanded: boolean;
81 showAdvanced: boolean;
82 showMoreMobile: boolean;
84 showReportDialog: boolean;
85 reportReason?: string;
86 reportLoading: boolean;
87 blockLoading: boolean;
89 deleteLoading: boolean;
90 removeLoading: boolean;
92 featureCommunityLoading: boolean;
93 featureLocalLoading: boolean;
95 addModLoading: boolean;
96 addAdminLoading: boolean;
97 transferLoading: boolean;
100 interface PostListingProps {
102 crossPosts?: PostView[];
103 moderators?: CommunityModeratorView[];
104 admins?: PersonView[];
105 allLanguages: Language[];
106 siteLanguages: number[];
107 showCommunity?: boolean;
109 * Controls whether to show both the body *and* the metadata preview card
113 enableDownvotes?: boolean;
114 enableNsfw?: boolean;
116 onPostEdit(form: EditPost): void;
117 onPostVote(form: CreatePostLike): void;
118 onPostReport(form: CreatePostReport): void;
119 onBlockPerson(form: BlockPerson): void;
120 onLockPost(form: LockPost): void;
121 onDeletePost(form: DeletePost): void;
122 onRemovePost(form: RemovePost): void;
123 onSavePost(form: SavePost): void;
124 onFeaturePost(form: FeaturePost): void;
125 onPurgePerson(form: PurgePerson): void;
126 onPurgePost(form: PurgePost): void;
127 onBanPersonFromCommunity(form: BanFromCommunity): void;
128 onBanPerson(form: BanPerson): void;
129 onAddModToCommunity(form: AddModToCommunity): void;
130 onAddAdmin(form: AddAdmin): void;
131 onTransferCommunity(form: TransferCommunity): void;
134 export class PostListing extends Component<PostListingProps, PostListingState> {
135 state: PostListingState = {
137 showRemoveDialog: false,
138 showPurgeDialog: false,
139 purgeType: PurgeType.Person,
140 showBanDialog: false,
141 banType: BanType.Community,
143 showConfirmTransferSite: false,
144 showConfirmTransferCommunity: false,
145 imageExpanded: false,
148 showMoreMobile: false,
150 showReportDialog: false,
152 reportLoading: false,
155 deleteLoading: false,
156 removeLoading: false,
158 featureCommunityLoading: false,
159 featureLocalLoading: false,
161 addModLoading: false,
162 addAdminLoading: false,
163 transferLoading: false,
166 constructor(props: any, context: any) {
167 super(props, context);
169 this.handleEditPost = this.handleEditPost.bind(this);
170 this.handleEditCancel = this.handleEditCancel.bind(this);
173 componentWillReceiveProps(nextProps: PostListingProps) {
174 if (this.props !== nextProps) {
177 reportLoading: false,
180 deleteLoading: false,
181 removeLoading: false,
183 featureCommunityLoading: false,
184 featureLocalLoading: false,
186 addModLoading: false,
187 addAdminLoading: false,
188 transferLoading: false,
193 get postView(): PostView {
194 return this.props.post_view;
198 const post = this.postView.post;
201 <div className="post-listing mt-2">
202 {!this.state.showEdit ? (
205 {this.state.imageExpanded && !this.props.hideImage && this.img}
206 {this.showBody && post.url && post.embed_title && (
207 <MetadataCard post={post} />
209 {this.showBody && this.body()}
213 post_view={this.postView}
214 crossPosts={this.props.crossPosts}
215 onEdit={this.handleEditPost}
216 onCancel={this.handleEditCancel}
217 enableNsfw={this.props.enableNsfw}
218 enableDownvotes={this.props.enableDownvotes}
219 allLanguages={this.props.allLanguages}
220 siteLanguages={this.props.siteLanguages}
228 const body = this.postView.post.body;
230 <article id="postContent" className="col-12 card my-2 p-2">
231 {this.state.viewSource ? (
234 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
246 <div className="offset-sm-3 my-2 d-none d-sm-block">
247 <a href={this.imageSrc} className="d-inline-block">
248 <PictrsImage src={this.imageSrc} />
251 <div className="my-2 d-block d-sm-none">
254 className="p-0 border-0 bg-transparent d-inline-block"
255 onClick={linkEvent(this, this.handleImageExpandClick)}
257 <PictrsImage src={this.imageSrc} />
264 const { post } = this.postView;
265 const { url } = post;
267 // if direct video link
268 if (url && isVideo(url)) {
270 <div className="embed-responsive mt-3">
271 <video muted controls className="embed-responsive-item col-12">
272 <source src={url} type="video/mp4" />
278 // if embedded video link
279 if (url && post.embed_video_url) {
281 <div className="ratio ratio-16x9">
284 className="post-metadata-iframe"
285 src={post.embed_video_url}
286 title={post.embed_title}
295 imgThumb(src: string) {
296 const post_view = this.postView;
302 nsfw={post_view.post.nsfw || post_view.community.nsfw}
307 get imageSrc(): string | undefined {
308 const post = this.postView.post;
309 const url = post.url;
310 const thumbnail = post.thumbnail_url;
312 if (url && isImage(url)) {
313 if (url.includes("pictrs")) {
315 } else if (thumbnail) {
320 } else if (thumbnail) {
328 const post = this.postView.post;
329 const url = post.url;
330 const thumbnail = post.thumbnail_url;
332 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
336 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0 bg-transparent"
337 data-tippy-content={I18NextService.i18n.t("expand_here")}
338 onClick={linkEvent(this, this.handleImageExpandClick)}
339 aria-label={I18NextService.i18n.t("expand_here")}
341 {this.imgThumb(this.imageSrc)}
344 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
348 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
351 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0"
356 {this.imgThumb(this.imageSrc)}
359 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
364 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
367 className="text-body"
371 data-tippy-content={I18NextService.i18n.t("expand_here")}
372 onClick={linkEvent(this, this.handleImageExpandClick)}
373 aria-label={I18NextService.i18n.t("expand_here")}
375 <div className="thumbnail rounded bg-light d-flex justify-content-center">
376 <Icon icon="play" classes="d-flex align-items-center" />
382 <a className="text-body" href={url} title={url} rel={relTags}>
383 <div className="thumbnail rounded bg-light d-flex justify-content-center">
384 <Icon icon="external-link" classes="d-flex align-items-center" />
392 className="text-body"
393 to={`/post/${post.id}`}
394 title={I18NextService.i18n.t("comments")}
396 <div className="thumbnail rounded bg-light d-flex justify-content-center">
397 <Icon icon="message-square" classes="d-flex align-items-center" />
405 const post_view = this.postView;
408 <div className="small mb-1 mb-md-0">
409 <span className="me-1">
410 <PersonListing person={post_view.creator} />
412 {this.creatorIsMod_ &&
414 label: I18NextService.i18n.t("mod"),
415 tooltip: I18NextService.i18n.t("mod"),
416 classes: "text-bg-primary",
418 {this.creatorIsAdmin_ &&
420 label: I18NextService.i18n.t("admin"),
421 tooltip: I18NextService.i18n.t("admin"),
422 classes: "text-bg-danger",
424 {post_view.creator.bot_account &&
426 label: I18NextService.i18n.t("bot_account").toLowerCase(),
427 tooltip: I18NextService.i18n.t("bot_account"),
429 {this.props.showCommunity && (
432 {I18NextService.i18n.t("to")}{" "}
433 <CommunityLink community={post_view.community} />
436 {post_view.post.language_id !== 0 && (
437 <span className="mx-1 badge text-bg-light">
439 this.props.allLanguages.find(
440 lang => lang.id === post_view.post.language_id
447 published={post_view.post.published}
448 updated={post_view.post.updated}
455 const post = this.postView.post;
458 className={`d-inline ${
459 !post.featured_community && !post.featured_local
463 to={`/post/${post.id}`}
464 title={I18NextService.i18n.t("comments")}
468 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
475 const post = this.postView.post;
476 const url = post.url;
480 <div className="post-title overflow-hidden">
481 <h1 className="h5 d-inline">
482 {url && this.props.showBody ? (
485 !post.featured_community && !post.featured_local
492 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
500 * If there is a URL, an embed title, and we were not told to show the
501 * body by the parent component, show the MetadataCard/body toggle.
503 {!this.props.showBody &&
506 this.showPreviewButton()}
509 <small className="ms-2 badge text-bg-secondary">
510 {I18NextService.i18n.t("removed")}
516 className="unselectable pointer ms-2 text-muted fst-italic"
517 data-tippy-content={I18NextService.i18n.t("deleted")}
519 <Icon icon="trash" classes="icon-inline text-danger" />
525 className="unselectable pointer ms-2 text-muted fst-italic"
526 data-tippy-content={I18NextService.i18n.t("locked")}
528 <Icon icon="lock" classes="icon-inline text-danger" />
532 {post.featured_community && (
534 className="unselectable pointer ms-2 text-muted fst-italic"
535 data-tippy-content={I18NextService.i18n.t(
536 "featured_in_community"
538 aria-label={I18NextService.i18n.t("featured_in_community")}
540 <Icon icon="pin" classes="icon-inline text-primary" />
544 {post.featured_local && (
546 className="unselectable pointer ms-2 text-muted fst-italic"
547 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
548 aria-label={I18NextService.i18n.t("featured_in_local")}
550 <Icon icon="pin" classes="icon-inline text-secondary" />
555 <small className="ms-2 badge text-bg-danger">
556 {I18NextService.i18n.t("nsfw")}
560 {url && this.urlLine()}
566 const post = this.postView.post;
567 const url = post.url;
570 <p className="small m-0">
571 {url && !(hostname(url) === getExternalHost()) && (
573 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
586 const dupes = this.props.crossPosts;
587 return dupes && dupes.length > 0 ? (
588 <ul className="list-inline mb-1 small text-muted">
590 <li className="list-inline-item me-2">
591 {I18NextService.i18n.t("cross_posted_to")}
594 <li key={pv.post.id} className="list-inline-item me-2">
595 <Link to={`/post/${pv.post.id}`}>
598 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
609 commentsLine(mobile = false) {
610 const post = this.postView.post;
613 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
614 {this.commentsButton}
617 className="btn btn-sm btn-animate text-muted py-0"
618 onClick={linkEvent(this, this.handleShare)}
621 <Icon icon="share" inline />
626 className="btn btn-sm btn-animate text-muted py-0"
627 title={I18NextService.i18n.t("link")}
630 <Icon icon="fedilink" inline />
633 {mobile && !this.props.viewOnly && (
635 voteContentType={VoteContentType.Post}
636 id={this.postView.post.id}
637 onVote={this.props.onPostVote}
638 enableDownvotes={this.props.enableDownvotes}
639 counts={this.postView.counts}
640 my_vote={this.postView.my_vote}
643 {UserService.Instance.myUserInfo &&
644 !this.props.viewOnly &&
651 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
652 // Possible enhancement: Make each button a component.
653 const post_view = this.postView;
654 const post = post_view.post;
659 {this.crossPostButton}
661 {this.props.showBody && post_view.post.body && this.viewSourceButton}
663 <div className="dropdown">
665 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
666 onClick={linkEvent(this, this.handleShowAdvanced)}
667 data-tippy-content={I18NextService.i18n.t("more")}
668 data-bs-toggle="dropdown"
669 aria-expanded="false"
670 aria-controls={`advancedButtonsDropdown${post.id}`}
671 aria-label={I18NextService.i18n.t("more")}
673 <Icon icon="more-vertical" inline />
677 className="dropdown-menu"
678 id={`advancedButtonsDropdown${post.id}`}
682 <li>{this.reportButton}</li>
683 <li>{this.blockButton}</li>
687 <li>{this.editButton}</li>
688 <li>{this.deleteButton}</li>
692 {/* Any mod can do these, not limited to hierarchy*/}
693 {(amMod(this.props.moderators) || amAdmin()) && (
696 <hr className="dropdown-divider" />
698 <li>{this.lockButton}</li>
699 {this.featureButtons}
703 {(this.canMod_ || this.canAdmin_) && (
704 <li>{this.modRemoveButton}</li>
710 <hr className="dropdown-divider" />
712 {!this.creatorIsMod_ &&
713 (!post_view.creator_banned_from_community ? (
714 <li>{this.modBanFromCommunityButton}</li>
716 <li>{this.modUnbanFromCommunityButton}</li>
718 {!post_view.creator_banned_from_community && (
719 <li>{this.addModToCommunityButton}</li>
724 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
726 this.creatorIsMod_ && <li>{this.transferCommunityButton}</li>}
728 {/* Admins can ban from all, and appoint other admins */}
732 <hr className="dropdown-divider" />
734 {!this.creatorIsAdmin_ && (
736 {!isBanned(post_view.creator) ? (
737 <li>{this.modBanButton}</li>
739 <li>{this.modUnbanButton}</li>
741 <li>{this.purgePersonButton}</li>
742 <li>{this.purgePostButton}</li>
745 {!isBanned(post_view.creator) && post_view.creator.local && (
746 <li>{this.toggleAdminButton}</li>
756 get commentsButton() {
757 const post_view = this.postView;
758 const title = I18NextService.i18n.t("number_of_comments", {
759 count: Number(post_view.counts.comments),
760 formattedCount: Number(post_view.counts.comments),
765 className="btn btn-link btn-sm text-muted ps-0"
767 to={`/post/${post_view.post.id}?scrollToComments=true`}
768 data-tippy-content={title}
770 <Icon icon="message-square" classes="me-1" inline />
771 {post_view.counts.comments}
772 {this.unreadCount && (
775 <span className="fst-italic">
776 ({this.unreadCount} {I18NextService.i18n.t("new")})
784 get unreadCount(): number | undefined {
785 const pv = this.postView;
786 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
788 : pv.unread_comments;
792 const saved = this.postView.saved;
794 ? I18NextService.i18n.t("unsave")
795 : I18NextService.i18n.t("save");
798 className="btn btn-sm btn-animate text-muted py-0"
799 onClick={linkEvent(this, this.handleSavePostClick)}
800 data-tippy-content={label}
803 {this.state.saveLoading ? (
808 classes={classNames({ "text-warning": saved })}
816 get crossPostButton() {
819 className="btn btn-sm btn-animate text-muted py-0"
821 /* Empty string properties are required to satisfy type*/
822 pathname: "/create_post",
823 state: { ...this.crossPostParams },
828 title={I18NextService.i18n.t("cross_post")}
829 data-tippy-content={I18NextService.i18n.t("cross_post")}
830 aria-label={I18NextService.i18n.t("cross_post")}
832 <Icon icon="copy" inline />
840 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
841 onClick={linkEvent(this, this.handleShowReportDialog)}
842 aria-label={I18NextService.i18n.t("show_report_dialog")}
844 <Icon classes="me-1" icon="flag" inline />
845 {I18NextService.i18n.t("create_report")}
853 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
854 onClick={linkEvent(this, this.handleBlockPersonClick)}
855 aria-label={I18NextService.i18n.t("block_user")}
857 {this.state.blockLoading ? (
860 <Icon classes="me-1" icon="slash" inline />
862 {I18NextService.i18n.t("block_user")}
870 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
871 onClick={linkEvent(this, this.handleEditClick)}
872 aria-label={I18NextService.i18n.t("edit")}
874 <Icon classes="me-1" icon="edit" inline />
875 {I18NextService.i18n.t("edit")}
881 const deleted = this.postView.post.deleted;
882 const label = !deleted
883 ? I18NextService.i18n.t("delete")
884 : I18NextService.i18n.t("restore");
887 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
888 onClick={linkEvent(this, this.handleDeleteClick)}
890 {this.state.deleteLoading ? (
896 classes={classNames("me-1", { "text-danger": deleted })}
906 get viewSourceButton() {
909 className="btn btn-sm btn-animate text-muted py-0"
910 onClick={linkEvent(this, this.handleViewSource)}
911 data-tippy-content={I18NextService.i18n.t("view_source")}
912 aria-label={I18NextService.i18n.t("view_source")}
916 classes={classNames({ "text-success": this.state.viewSource })}
924 const locked = this.postView.post.locked;
926 ? I18NextService.i18n.t("unlock")
927 : I18NextService.i18n.t("lock");
930 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
931 onClick={linkEvent(this, this.handleModLock)}
934 {this.state.lockLoading ? (
940 classes={classNames("me-1", { "text-danger": locked })}
943 {capitalizeFirstLetter(label)}
950 get featureButtons() {
951 const featuredCommunity = this.postView.post.featured_community;
952 const labelCommunity = featuredCommunity
953 ? I18NextService.i18n.t("unfeature_from_community")
954 : I18NextService.i18n.t("feature_in_community");
956 const featuredLocal = this.postView.post.featured_local;
957 const labelLocal = featuredLocal
958 ? I18NextService.i18n.t("unfeature_from_local")
959 : I18NextService.i18n.t("feature_in_local");
964 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
965 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
966 data-tippy-content={labelCommunity}
967 aria-label={labelCommunity}
969 {this.state.featureCommunityLoading ? (
975 classes={classNames("me-1", {
976 "text-success": featuredCommunity,
980 {I18NextService.i18n.t("community")}
988 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
989 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
990 data-tippy-content={labelLocal}
991 aria-label={labelLocal}
993 {this.state.featureLocalLoading ? (
999 classes={classNames("me-1", {
1000 "text-success": featuredLocal,
1004 {I18NextService.i18n.t("local")}
1014 get modBanFromCommunityButton() {
1017 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1018 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
1020 {I18NextService.i18n.t("ban_from_community")}
1025 get modUnbanFromCommunityButton() {
1028 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1029 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
1031 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1036 get addModToCommunityButton() {
1039 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1040 onClick={linkEvent(this, this.handleAddModToCommunity)}
1042 {this.state.addModLoading ? (
1044 ) : this.creatorIsMod_ ? (
1045 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_mod"))
1047 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_mod"))
1053 get modBanButton() {
1056 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1057 onClick={linkEvent(this, this.handleModBanShow)}
1059 {capitalizeFirstLetter(I18NextService.i18n.t("ban_from_site"))}
1064 get modUnbanButton() {
1067 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1068 onClick={linkEvent(this, this.handleModBanSubmit)}
1070 {this.state.banLoading ? (
1073 capitalizeFirstLetter(I18NextService.i18n.t("unban_from_site"))
1079 get purgePersonButton() {
1082 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1083 onClick={linkEvent(this, this.handlePurgePersonShow)}
1085 {capitalizeFirstLetter(I18NextService.i18n.t("purge_user"))}
1090 get purgePostButton() {
1093 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1094 onClick={linkEvent(this, this.handlePurgePostShow)}
1096 {capitalizeFirstLetter(I18NextService.i18n.t("purge_post"))}
1101 get toggleAdminButton() {
1104 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1105 onClick={linkEvent(this, this.handleAddAdmin)}
1107 {this.state.addAdminLoading ? (
1109 ) : this.creatorIsAdmin_ ? (
1110 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_admin"))
1112 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_admin"))
1118 get transferCommunityButton() {
1121 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1122 onClick={linkEvent(this, this.handleShowConfirmTransferCommunity)}
1124 {capitalizeFirstLetter(I18NextService.i18n.t("transfer_community"))}
1129 get modRemoveButton() {
1130 const removed = this.postView.post.removed;
1133 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1136 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1139 {/* TODO: Find an icon for this. */}
1140 {this.state.removeLoading ? (
1143 capitalizeFirstLetter(I18NextService.i18n.t("remove_post"))
1146 {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "}
1147 {I18NextService.i18n.t("post")}
1154 removeAndBanDialogs() {
1155 const post = this.postView;
1156 const purgeTypeText =
1157 this.state.purgeType == PurgeType.Post
1158 ? I18NextService.i18n.t("purge_post")
1159 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1162 {this.state.showRemoveDialog && (
1164 className="form-inline"
1165 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1168 className="visually-hidden"
1169 htmlFor="post-listing-remove-reason"
1171 {I18NextService.i18n.t("reason")}
1175 id="post-listing-remove-reason"
1176 className="form-control me-2"
1177 placeholder={I18NextService.i18n.t("reason")}
1178 value={this.state.removeReason}
1179 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1181 <button type="submit" className="btn btn-secondary">
1182 {this.state.removeLoading ? (
1185 I18NextService.i18n.t("remove_post")
1190 {this.state.showConfirmTransferCommunity && (
1192 <button className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0">
1193 {I18NextService.i18n.t("are_you_sure")}
1196 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1197 onClick={linkEvent(this, this.handleTransferCommunity)}
1199 {this.state.transferLoading ? (
1202 I18NextService.i18n.t("yes")
1206 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1209 this.handleCancelShowConfirmTransferCommunity
1211 aria-label={I18NextService.i18n.t("no")}
1213 {I18NextService.i18n.t("no")}
1217 {this.state.showBanDialog && (
1218 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1219 <div className="mb-3 row col-12">
1221 className="col-form-label"
1222 htmlFor="post-listing-ban-reason"
1224 {I18NextService.i18n.t("reason")}
1228 id="post-listing-ban-reason"
1229 className="form-control me-2"
1230 placeholder={I18NextService.i18n.t("reason")}
1231 value={this.state.banReason}
1232 onInput={linkEvent(this, this.handleModBanReasonChange)}
1234 <label className="col-form-label" htmlFor="mod-ban-expires">
1235 {I18NextService.i18n.t("expires")}
1239 id="mod-ban-expires"
1240 className="form-control me-2"
1241 placeholder={I18NextService.i18n.t("number_of_days")}
1242 value={this.state.banExpireDays}
1243 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1245 <div className="input-group mb-3">
1246 <div className="form-check">
1248 className="form-check-input"
1249 id="mod-ban-remove-data"
1251 checked={this.state.removeData}
1252 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1255 className="form-check-label"
1256 htmlFor="mod-ban-remove-data"
1257 title={I18NextService.i18n.t("remove_content_more")}
1259 {I18NextService.i18n.t("remove_content")}
1264 {/* TODO hold off on expires until later */}
1265 {/* <div class="mb-3 row"> */}
1266 {/* <label class="col-form-label">Expires</label> */}
1267 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1269 <div className="mb-3 row">
1270 <button type="submit" className="btn btn-secondary">
1271 {this.state.banLoading ? (
1275 {I18NextService.i18n.t("ban")} {post.creator.name}
1282 {this.state.showReportDialog && (
1284 className="form-inline"
1285 onSubmit={linkEvent(this, this.handleReportSubmit)}
1287 <label className="visually-hidden" htmlFor="post-report-reason">
1288 {I18NextService.i18n.t("reason")}
1292 id="post-report-reason"
1293 className="form-control me-2"
1294 placeholder={I18NextService.i18n.t("reason")}
1296 value={this.state.reportReason}
1297 onInput={linkEvent(this, this.handleReportReasonChange)}
1299 <button type="submit" className="btn btn-secondary">
1300 {this.state.reportLoading ? (
1303 I18NextService.i18n.t("create_report")
1308 {this.state.showPurgeDialog && (
1310 className="form-inline"
1311 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1314 <label className="visually-hidden" htmlFor="purge-reason">
1315 {I18NextService.i18n.t("reason")}
1320 className="form-control me-2"
1321 placeholder={I18NextService.i18n.t("reason")}
1322 value={this.state.purgeReason}
1323 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1325 {this.state.purgeLoading ? (
1328 <button type="submit" className="btn btn-secondary">
1329 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1339 const post = this.postView.post;
1340 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1341 <div className="row">
1342 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1343 {this.postTitleLine()}
1345 <div className="col-4">
1346 {/* Post thumbnail */}
1347 {!this.state.imageExpanded && this.thumbnail()}
1351 this.postTitleLine()
1355 showPreviewButton() {
1359 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1360 onClick={linkEvent(this, this.handleShowBody)}
1363 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1364 classes="icon-inline"
1373 {/* The mobile view*/}
1374 <div className="d-block d-sm-none">
1375 <article className="row post-container">
1376 <div className="col-12">
1377 {this.createdLine()}
1379 {/* If it has a thumbnail, do a right aligned thumbnail */}
1380 {this.mobileThumbnail()}
1382 {this.commentsLine(true)}
1383 {this.duplicatesLine()}
1384 {this.removeAndBanDialogs()}
1389 {/* The larger view*/}
1390 <div className="d-none d-sm-block">
1391 <article className="row post-container">
1392 {!this.props.viewOnly && (
1393 <div className="col flex-grow-0">
1395 voteContentType={VoteContentType.Post}
1396 id={this.postView.post.id}
1397 onVote={this.props.onPostVote}
1398 enableDownvotes={this.props.enableDownvotes}
1399 counts={this.postView.counts}
1400 my_vote={this.postView.my_vote}
1404 <div className="col flex-grow-1">
1405 <div className="row">
1406 <div className="col flex-grow-0 px-0">
1407 <div className="">{this.thumbnail()}</div>
1409 <div className="col flex-grow-1">
1410 {this.postTitleLine()}
1411 {this.createdLine()}
1412 {this.commentsLine()}
1413 {this.duplicatesLine()}
1414 {this.removeAndBanDialogs()}
1424 private get myPost(): boolean {
1426 this.postView.creator.id ==
1427 UserService.Instance.myUserInfo?.local_user_view.person.id
1430 handleEditClick(i: PostListing) {
1431 i.setState({ showEdit: true });
1434 handleEditCancel() {
1435 this.setState({ showEdit: false });
1438 // The actual editing is done in the receive for post
1439 handleEditPost(form: EditPost) {
1440 this.setState({ showEdit: false });
1441 this.props.onPostEdit(form);
1444 handleShare(i: PostListing) {
1445 const { name, body, id } = i.props.post_view.post;
1448 text: body?.slice(0, 50),
1449 url: `${getHttpBase()}/post/${id}`,
1453 handleShowReportDialog(i: PostListing) {
1454 i.setState({ showReportDialog: !i.state.showReportDialog });
1457 handleReportReasonChange(i: PostListing, event: any) {
1458 i.setState({ reportReason: event.target.value });
1461 handleReportSubmit(i: PostListing, event: any) {
1462 event.preventDefault();
1463 i.setState({ reportLoading: true });
1464 i.props.onPostReport({
1465 post_id: i.postView.post.id,
1466 reason: i.state.reportReason ?? "",
1467 auth: myAuthRequired(),
1471 handleBlockPersonClick(i: PostListing) {
1472 i.setState({ blockLoading: true });
1473 i.props.onBlockPerson({
1474 person_id: i.postView.creator.id,
1476 auth: myAuthRequired(),
1480 handleDeleteClick(i: PostListing) {
1481 i.setState({ deleteLoading: true });
1482 i.props.onDeletePost({
1483 post_id: i.postView.post.id,
1484 deleted: !i.postView.post.deleted,
1485 auth: myAuthRequired(),
1489 handleSavePostClick(i: PostListing) {
1490 i.setState({ saveLoading: true });
1491 i.props.onSavePost({
1492 post_id: i.postView.post.id,
1493 save: !i.postView.saved,
1494 auth: myAuthRequired(),
1498 get crossPostParams(): PostFormParams {
1499 const queryParams: PostFormParams = {};
1500 const { name, url } = this.postView.post;
1502 queryParams.name = name;
1505 queryParams.url = url;
1508 const crossPostBody = this.crossPostBody();
1509 if (crossPostBody) {
1510 queryParams.body = crossPostBody;
1516 crossPostBody(): string | undefined {
1517 const post = this.postView.post;
1518 const body = post.body;
1521 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1523 }\n\n${body.replace(/^/gm, "> ")}`
1527 get showBody(): boolean {
1528 return this.props.showBody || this.state.showBody;
1531 handleModRemoveShow(i: PostListing) {
1533 showRemoveDialog: !i.state.showRemoveDialog,
1534 showBanDialog: false,
1538 handleModRemoveReasonChange(i: PostListing, event: any) {
1539 i.setState({ removeReason: event.target.value });
1542 handleModRemoveDataChange(i: PostListing, event: any) {
1543 i.setState({ removeData: event.target.checked });
1546 handleModRemoveSubmit(i: PostListing, event: any) {
1547 event.preventDefault();
1548 i.setState({ removeLoading: true });
1549 i.props.onRemovePost({
1550 post_id: i.postView.post.id,
1551 removed: !i.postView.post.removed,
1552 auth: myAuthRequired(),
1556 handleModLock(i: PostListing) {
1557 i.setState({ lockLoading: true });
1558 i.props.onLockPost({
1559 post_id: i.postView.post.id,
1560 locked: !i.postView.post.locked,
1561 auth: myAuthRequired(),
1565 handleModFeaturePostLocal(i: PostListing) {
1566 i.setState({ featureLocalLoading: true });
1567 i.props.onFeaturePost({
1568 post_id: i.postView.post.id,
1569 featured: !i.postView.post.featured_local,
1570 feature_type: "Local",
1571 auth: myAuthRequired(),
1575 handleModFeaturePostCommunity(i: PostListing) {
1576 i.setState({ featureCommunityLoading: true });
1577 i.props.onFeaturePost({
1578 post_id: i.postView.post.id,
1579 featured: !i.postView.post.featured_community,
1580 feature_type: "Community",
1581 auth: myAuthRequired(),
1585 handleModBanFromCommunityShow(i: PostListing) {
1587 showBanDialog: true,
1588 banType: BanType.Community,
1589 showRemoveDialog: false,
1593 handleModBanShow(i: PostListing) {
1595 showBanDialog: true,
1596 banType: BanType.Site,
1597 showRemoveDialog: false,
1601 handlePurgePersonShow(i: PostListing) {
1603 showPurgeDialog: true,
1604 purgeType: PurgeType.Person,
1605 showRemoveDialog: false,
1609 handlePurgePostShow(i: PostListing) {
1611 showPurgeDialog: true,
1612 purgeType: PurgeType.Post,
1613 showRemoveDialog: false,
1617 handlePurgeReasonChange(i: PostListing, event: any) {
1618 i.setState({ purgeReason: event.target.value });
1621 handlePurgeSubmit(i: PostListing, event: any) {
1622 event.preventDefault();
1623 i.setState({ purgeLoading: true });
1624 if (i.state.purgeType == PurgeType.Person) {
1625 i.props.onPurgePerson({
1626 person_id: i.postView.creator.id,
1627 reason: i.state.purgeReason,
1628 auth: myAuthRequired(),
1630 } else if (i.state.purgeType == PurgeType.Post) {
1631 i.props.onPurgePost({
1632 post_id: i.postView.post.id,
1633 reason: i.state.purgeReason,
1634 auth: myAuthRequired(),
1639 handleModBanReasonChange(i: PostListing, event: any) {
1640 i.setState({ banReason: event.target.value });
1643 handleModBanExpireDaysChange(i: PostListing, event: any) {
1644 i.setState({ banExpireDays: event.target.value });
1647 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1648 i.setState({ banType: BanType.Community });
1649 i.handleModBanBothSubmit(i, event);
1652 handleModBanSubmit(i: PostListing, event: any) {
1653 i.setState({ banType: BanType.Site });
1654 i.handleModBanBothSubmit(i, event);
1657 handleModBanBothSubmit(i: PostListing, event: any) {
1658 event.preventDefault();
1659 i.setState({ banLoading: true });
1661 const ban = !i.props.post_view.creator_banned_from_community;
1662 // If its an unban, restore all their data
1664 i.setState({ removeData: false });
1666 const person_id = i.props.post_view.creator.id;
1667 const remove_data = i.state.removeData;
1668 const reason = i.state.banReason;
1669 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1671 if (i.state.banType == BanType.Community) {
1672 const community_id = i.postView.community.id;
1673 i.props.onBanPersonFromCommunity({
1680 auth: myAuthRequired(),
1683 i.props.onBanPerson({
1689 auth: myAuthRequired(),
1694 handleAddModToCommunity(i: PostListing) {
1695 i.setState({ addModLoading: true });
1696 i.props.onAddModToCommunity({
1697 community_id: i.postView.community.id,
1698 person_id: i.postView.creator.id,
1699 added: !i.creatorIsMod_,
1700 auth: myAuthRequired(),
1704 handleAddAdmin(i: PostListing) {
1705 i.setState({ addAdminLoading: true });
1706 i.props.onAddAdmin({
1707 person_id: i.postView.creator.id,
1708 added: !i.creatorIsAdmin_,
1709 auth: myAuthRequired(),
1713 handleShowConfirmTransferCommunity(i: PostListing) {
1714 i.setState({ showConfirmTransferCommunity: true });
1717 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1718 i.setState({ showConfirmTransferCommunity: false });
1721 handleTransferCommunity(i: PostListing) {
1722 i.setState({ transferLoading: true });
1723 i.props.onTransferCommunity({
1724 community_id: i.postView.community.id,
1725 person_id: i.postView.creator.id,
1726 auth: myAuthRequired(),
1730 handleShowConfirmTransferSite(i: PostListing) {
1731 i.setState({ showConfirmTransferSite: true });
1734 handleCancelShowConfirmTransferSite(i: PostListing) {
1735 i.setState({ showConfirmTransferSite: false });
1738 handleImageExpandClick(i: PostListing, event: any) {
1739 event.preventDefault();
1740 i.setState({ imageExpanded: !i.state.imageExpanded });
1744 handleViewSource(i: PostListing) {
1745 i.setState({ viewSource: !i.state.viewSource });
1748 handleShowAdvanced(i: PostListing) {
1749 i.setState({ showAdvanced: !i.state.showAdvanced });
1753 handleShowMoreMobile(i: PostListing) {
1755 showMoreMobile: !i.state.showMoreMobile,
1756 showAdvanced: !i.state.showAdvanced,
1761 handleShowBody(i: PostListing) {
1762 i.setState({ showBody: !i.state.showBody });
1766 get pointsTippy(): string {
1767 const points = I18NextService.i18n.t("number_of_points", {
1768 count: Number(this.postView.counts.score),
1769 formattedCount: Number(this.postView.counts.score),
1772 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1773 count: Number(this.postView.counts.upvotes),
1774 formattedCount: Number(this.postView.counts.upvotes),
1777 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1778 count: Number(this.postView.counts.downvotes),
1779 formattedCount: Number(this.postView.counts.downvotes),
1782 return `${points} • ${upvotes} • ${downvotes}`;
1785 get canModOnSelf_(): boolean {
1787 this.postView.creator.id,
1788 this.props.moderators,
1795 get canMod_(): boolean {
1797 this.postView.creator.id,
1798 this.props.moderators,
1803 get canAdmin_(): boolean {
1804 return canAdmin(this.postView.creator.id, this.props.admins);
1807 get creatorIsMod_(): boolean {
1808 return isMod(this.postView.creator.id, this.props.moderators);
1811 get creatorIsAdmin_(): boolean {
1812 return isAdmin(this.postView.creator.id, this.props.admins);