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="d-inline-block position-relative mb-2 p-0 border-0"
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="text-body d-inline-block position-relative mb-2"
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;
407 <div className="small">
408 <span className="me-1">
409 <PersonListing person={post_view.creator} />
411 {this.creatorIsMod_ &&
413 label: I18NextService.i18n.t("mod"),
414 tooltip: I18NextService.i18n.t("mod"),
415 classes: "text-bg-primary",
417 {this.creatorIsAdmin_ &&
419 label: I18NextService.i18n.t("admin"),
420 tooltip: I18NextService.i18n.t("admin"),
421 classes: "text-bg-danger",
423 {post_view.creator.bot_account &&
425 label: I18NextService.i18n.t("bot_account").toLowerCase(),
426 tooltip: I18NextService.i18n.t("bot_account"),
428 {this.props.showCommunity && (
431 {I18NextService.i18n.t("to")}{" "}
432 <CommunityLink community={post_view.community} />
435 {post_view.post.language_id !== 0 && (
436 <span className="mx-1 badge text-bg-light">
438 this.props.allLanguages.find(
439 lang => lang.id === post_view.post.language_id
446 published={post_view.post.published}
447 updated={post_view.post.updated}
454 const post = this.postView.post;
457 className={`d-inline ${
458 !post.featured_community && !post.featured_local
462 to={`/post/${post.id}`}
463 title={I18NextService.i18n.t("comments")}
467 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
474 const post = this.postView.post;
475 const url = post.url;
479 <div className="post-title overflow-hidden">
480 <h5 className="d-inline">
481 {url && this.props.showBody ? (
484 !post.featured_community && !post.featured_local
491 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
499 * If there is a URL, an embed title, and we were not told to show the
500 * body by the parent component, show the MetadataCard/body toggle.
502 {!this.props.showBody &&
505 this.showPreviewButton()}
508 <small className="ms-2 badge text-bg-secondary">
509 {I18NextService.i18n.t("removed")}
515 className="unselectable pointer ms-2 text-muted fst-italic"
516 data-tippy-content={I18NextService.i18n.t("deleted")}
518 <Icon icon="trash" classes="icon-inline text-danger" />
524 className="unselectable pointer ms-2 text-muted fst-italic"
525 data-tippy-content={I18NextService.i18n.t("locked")}
527 <Icon icon="lock" classes="icon-inline text-danger" />
531 {post.featured_community && (
533 className="unselectable pointer ms-2 text-muted fst-italic"
534 data-tippy-content={I18NextService.i18n.t(
535 "featured_in_community"
537 aria-label={I18NextService.i18n.t("featured_in_community")}
539 <Icon icon="pin" classes="icon-inline text-primary" />
543 {post.featured_local && (
545 className="unselectable pointer ms-2 text-muted fst-italic"
546 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
547 aria-label={I18NextService.i18n.t("featured_in_local")}
549 <Icon icon="pin" classes="icon-inline text-secondary" />
554 <small className="ms-2 badge text-bg-danger">
555 {I18NextService.i18n.t("nsfw")}
559 {url && this.urlLine()}
565 const post = this.postView.post;
566 const url = post.url;
569 <p className="small m-0">
570 {url && !(hostname(url) === getExternalHost()) && (
572 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
585 const dupes = this.props.crossPosts;
586 return dupes && dupes.length > 0 ? (
587 <ul className="list-inline mb-1 small text-muted">
589 <li className="list-inline-item me-2">
590 {I18NextService.i18n.t("cross_posted_to")}
593 <li key={pv.post.id} className="list-inline-item me-2">
594 <Link to={`/post/${pv.post.id}`}>
597 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
608 commentsLine(mobile = false) {
609 const post = this.postView.post;
612 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
613 {this.commentsButton}
616 className="btn btn-sm btn-animate text-muted py-0"
617 onClick={linkEvent(this, this.handleShare)}
620 <Icon icon="share" inline />
625 className="btn btn-sm btn-animate text-muted py-0"
626 title={I18NextService.i18n.t("link")}
629 <Icon icon="fedilink" inline />
632 {mobile && !this.props.viewOnly && (
634 voteContentType={VoteContentType.Post}
635 id={this.postView.post.id}
636 onVote={this.props.onPostVote}
637 enableDownvotes={this.props.enableDownvotes}
638 counts={this.postView.counts}
639 my_vote={this.postView.my_vote}
642 {UserService.Instance.myUserInfo &&
643 !this.props.viewOnly &&
650 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
651 // Possible enhancement: Make each button a component.
652 const post_view = this.postView;
653 const post = post_view.post;
658 {this.crossPostButton}
660 {this.props.showBody && post_view.post.body && this.viewSourceButton}
662 <div className="dropdown">
664 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
665 onClick={linkEvent(this, this.handleShowAdvanced)}
666 data-tippy-content={I18NextService.i18n.t("more")}
667 data-bs-toggle="dropdown"
668 aria-expanded="false"
669 aria-controls={`advancedButtonsDropdown${post.id}`}
670 aria-label={I18NextService.i18n.t("more")}
672 <Icon icon="more-vertical" inline />
676 className="dropdown-menu"
677 id={`advancedButtonsDropdown${post.id}`}
681 <li>{this.reportButton}</li>
682 <li>{this.blockButton}</li>
686 <li>{this.editButton}</li>
687 <li>{this.deleteButton}</li>
691 {/* Any mod can do these, not limited to hierarchy*/}
692 {(amMod(this.props.moderators) || amAdmin()) && (
695 <hr className="dropdown-divider" />
697 <li>{this.lockButton}</li>
698 {this.featureButtons}
702 {(this.canMod_ || this.canAdmin_) && (
703 <li>{this.modRemoveButton}</li>
711 get commentsButton() {
712 const post_view = this.postView;
713 const title = I18NextService.i18n.t("number_of_comments", {
714 count: Number(post_view.counts.comments),
715 formattedCount: Number(post_view.counts.comments),
720 className="btn btn-link btn-sm text-muted ps-0"
722 to={`/post/${post_view.post.id}?scrollToComments=true`}
723 data-tippy-content={title}
725 <Icon icon="message-square" classes="me-1" inline />
726 {post_view.counts.comments}
727 {this.unreadCount && (
730 <span className="fst-italic">
731 ({this.unreadCount} {I18NextService.i18n.t("new")})
739 get unreadCount(): number | undefined {
740 const pv = this.postView;
741 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
743 : pv.unread_comments;
747 const saved = this.postView.saved;
749 ? I18NextService.i18n.t("unsave")
750 : I18NextService.i18n.t("save");
753 className="btn btn-sm btn-animate text-muted py-0"
754 onClick={linkEvent(this, this.handleSavePostClick)}
755 data-tippy-content={label}
758 {this.state.saveLoading ? (
763 classes={classNames({ "text-warning": saved })}
771 get crossPostButton() {
774 className="btn btn-sm btn-animate text-muted py-0"
776 /* Empty string properties are required to satisfy type*/
777 pathname: "/create_post",
778 state: { ...this.crossPostParams },
783 title={I18NextService.i18n.t("cross_post")}
784 data-tippy-content={I18NextService.i18n.t("cross_post")}
785 aria-label={I18NextService.i18n.t("cross_post")}
787 <Icon icon="copy" inline />
795 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
796 onClick={linkEvent(this, this.handleShowReportDialog)}
797 aria-label={I18NextService.i18n.t("show_report_dialog")}
799 <Icon classes="me-1" icon="flag" inline />
800 {I18NextService.i18n.t("create_report")}
808 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
809 onClick={linkEvent(this, this.handleBlockPersonClick)}
810 aria-label={I18NextService.i18n.t("block_user")}
812 {this.state.blockLoading ? (
815 <Icon classes="me-1" icon="slash" inline />
817 {I18NextService.i18n.t("block_user")}
825 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
826 onClick={linkEvent(this, this.handleEditClick)}
827 aria-label={I18NextService.i18n.t("edit")}
829 <Icon classes="me-1" icon="edit" inline />
830 {I18NextService.i18n.t("edit")}
836 const deleted = this.postView.post.deleted;
837 const label = !deleted
838 ? I18NextService.i18n.t("delete")
839 : I18NextService.i18n.t("restore");
842 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
843 onClick={linkEvent(this, this.handleDeleteClick)}
845 {this.state.deleteLoading ? (
851 classes={classNames("me-1", { "text-danger": deleted })}
861 get viewSourceButton() {
864 className="btn btn-sm btn-animate text-muted py-0"
865 onClick={linkEvent(this, this.handleViewSource)}
866 data-tippy-content={I18NextService.i18n.t("view_source")}
867 aria-label={I18NextService.i18n.t("view_source")}
871 classes={classNames({ "text-success": this.state.viewSource })}
879 const locked = this.postView.post.locked;
881 ? I18NextService.i18n.t("unlock")
882 : I18NextService.i18n.t("lock");
885 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
886 onClick={linkEvent(this, this.handleModLock)}
889 {this.state.lockLoading ? (
895 classes={classNames("me-1", { "text-danger": locked })}
898 {capitalizeFirstLetter(label)}
905 get featureButtons() {
906 const featuredCommunity = this.postView.post.featured_community;
907 const labelCommunity = featuredCommunity
908 ? I18NextService.i18n.t("unfeature_from_community")
909 : I18NextService.i18n.t("feature_in_community");
911 const featuredLocal = this.postView.post.featured_local;
912 const labelLocal = featuredLocal
913 ? I18NextService.i18n.t("unfeature_from_local")
914 : I18NextService.i18n.t("feature_in_local");
919 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
920 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
921 data-tippy-content={labelCommunity}
922 aria-label={labelCommunity}
924 {this.state.featureCommunityLoading ? (
930 classes={classNames("me-1", {
931 "text-success": featuredCommunity,
935 {I18NextService.i18n.t("community")}
943 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
944 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
945 data-tippy-content={labelLocal}
946 aria-label={labelLocal}
948 {this.state.featureLocalLoading ? (
954 classes={classNames("me-1", {
955 "text-success": featuredLocal,
959 {I18NextService.i18n.t("local")}
969 get modBanFromCommunityButton() {
972 className="btn btn-link btn-animate text-muted py-0"
973 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
974 aria-label={I18NextService.i18n.t("ban_from_community")}
976 {I18NextService.i18n.t("ban_from_community")}
981 get modUnbanFromCommunityButton() {
984 className="btn btn-link btn-animate text-muted py-0"
985 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
986 aria-label={I18NextService.i18n.t("unban")}
988 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
993 get addModToCommunityButton() {
996 className="btn btn-link btn-animate text-muted py-0"
997 onClick={linkEvent(this, this.handleAddModToCommunity)}
1000 ? I18NextService.i18n.t("remove_as_mod")
1001 : I18NextService.i18n.t("appoint_as_mod")
1004 {this.state.addModLoading ? (
1006 ) : this.creatorIsMod_ ? (
1007 I18NextService.i18n.t("remove_as_mod")
1009 I18NextService.i18n.t("appoint_as_mod")
1015 get modBanButton() {
1018 className="btn btn-link btn-animate text-muted py-0"
1019 onClick={linkEvent(this, this.handleModBanShow)}
1020 aria-label={I18NextService.i18n.t("ban_from_site")}
1022 {I18NextService.i18n.t("ban_from_site")}
1027 get modUnbanButton() {
1030 className="btn btn-link btn-animate text-muted py-0"
1031 onClick={linkEvent(this, this.handleModBanSubmit)}
1032 aria-label={I18NextService.i18n.t("unban_from_site")}
1034 {this.state.banLoading ? (
1037 I18NextService.i18n.t("unban_from_site")
1043 get purgePersonButton() {
1046 className="btn btn-link btn-animate text-muted py-0"
1047 onClick={linkEvent(this, this.handlePurgePersonShow)}
1048 aria-label={I18NextService.i18n.t("purge_user")}
1050 {I18NextService.i18n.t("purge_user")}
1055 get purgePostButton() {
1058 className="btn btn-link btn-animate text-muted py-0"
1059 onClick={linkEvent(this, this.handlePurgePostShow)}
1060 aria-label={I18NextService.i18n.t("purge_post")}
1062 {I18NextService.i18n.t("purge_post")}
1067 get toggleAdminButton() {
1070 className="btn btn-link btn-animate text-muted py-0"
1071 onClick={linkEvent(this, this.handleAddAdmin)}
1073 {this.state.addAdminLoading ? (
1075 ) : this.creatorIsAdmin_ ? (
1076 I18NextService.i18n.t("remove_as_admin")
1078 I18NextService.i18n.t("appoint_as_admin")
1084 get modRemoveButton() {
1085 const removed = this.postView.post.removed;
1088 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1091 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1094 {/* TODO: Find an icon for this. */}
1095 {this.state.removeLoading ? (
1098 I18NextService.i18n.t("remove")
1100 I18NextService.i18n.t("restore")
1107 * Mod/Admin actions to be taken against the author.
1111 const post_view = this.postView;
1113 this.state.showAdvanced && (
1114 <div className="mt-3">
1117 {!this.creatorIsMod_ &&
1118 (!post_view.creator_banned_from_community
1119 ? this.modBanFromCommunityButton
1120 : this.modUnbanFromCommunityButton)}
1121 {!post_view.creator_banned_from_community &&
1122 this.addModToCommunityButton}
1126 {/* Community creators and admins can transfer community to another mod */}
1127 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1129 this.creatorIsMod_ &&
1130 (!this.state.showConfirmTransferCommunity ? (
1132 className="btn btn-link btn-animate text-muted py-0"
1135 this.handleShowConfirmTransferCommunity
1137 aria-label={I18NextService.i18n.t("transfer_community")}
1139 {I18NextService.i18n.t("transfer_community")}
1144 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1145 aria-label={I18NextService.i18n.t("are_you_sure")}
1147 {I18NextService.i18n.t("are_you_sure")}
1150 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1151 aria-label={I18NextService.i18n.t("yes")}
1152 onClick={linkEvent(this, this.handleTransferCommunity)}
1154 {this.state.transferLoading ? (
1157 I18NextService.i18n.t("yes")
1161 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1164 this.handleCancelShowConfirmTransferCommunity
1166 aria-label={I18NextService.i18n.t("no")}
1168 {I18NextService.i18n.t("no")}
1172 {/* Admins can ban from all, and appoint other admins */}
1173 {this.canAdmin_ && (
1175 {!this.creatorIsAdmin_ && (
1177 {!isBanned(post_view.creator)
1179 : this.modUnbanButton}
1180 {this.purgePersonButton}
1181 {this.purgePostButton}
1184 {!isBanned(post_view.creator) &&
1185 post_view.creator.local &&
1186 this.toggleAdminButton}
1194 removeAndBanDialogs() {
1195 const post = this.postView;
1196 const purgeTypeText =
1197 this.state.purgeType == PurgeType.Post
1198 ? I18NextService.i18n.t("purge_post")
1199 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1202 {this.state.showRemoveDialog && (
1204 className="form-inline"
1205 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1208 className="visually-hidden"
1209 htmlFor="post-listing-remove-reason"
1211 {I18NextService.i18n.t("reason")}
1215 id="post-listing-remove-reason"
1216 className="form-control me-2"
1217 placeholder={I18NextService.i18n.t("reason")}
1218 value={this.state.removeReason}
1219 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1223 className="btn btn-secondary"
1224 aria-label={I18NextService.i18n.t("remove_post")}
1226 {this.state.removeLoading ? (
1229 I18NextService.i18n.t("remove_post")
1234 {this.state.showBanDialog && (
1235 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1236 <div className="mb-3 row col-12">
1238 className="col-form-label"
1239 htmlFor="post-listing-ban-reason"
1241 {I18NextService.i18n.t("reason")}
1245 id="post-listing-ban-reason"
1246 className="form-control me-2"
1247 placeholder={I18NextService.i18n.t("reason")}
1248 value={this.state.banReason}
1249 onInput={linkEvent(this, this.handleModBanReasonChange)}
1251 <label className="col-form-label" htmlFor="mod-ban-expires">
1252 {I18NextService.i18n.t("expires")}
1256 id="mod-ban-expires"
1257 className="form-control me-2"
1258 placeholder={I18NextService.i18n.t("number_of_days")}
1259 value={this.state.banExpireDays}
1260 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1262 <div className="input-group mb-3">
1263 <div className="form-check">
1265 className="form-check-input"
1266 id="mod-ban-remove-data"
1268 checked={this.state.removeData}
1269 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1272 className="form-check-label"
1273 htmlFor="mod-ban-remove-data"
1274 title={I18NextService.i18n.t("remove_content_more")}
1276 {I18NextService.i18n.t("remove_content")}
1281 {/* TODO hold off on expires until later */}
1282 {/* <div class="mb-3 row"> */}
1283 {/* <label class="col-form-label">Expires</label> */}
1284 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1286 <div className="mb-3 row">
1289 className="btn btn-secondary"
1290 aria-label={I18NextService.i18n.t("ban")}
1292 {this.state.banLoading ? (
1296 {I18NextService.i18n.t("ban")} {post.creator.name}
1303 {this.state.showReportDialog && (
1305 className="form-inline"
1306 onSubmit={linkEvent(this, this.handleReportSubmit)}
1308 <label className="visually-hidden" htmlFor="post-report-reason">
1309 {I18NextService.i18n.t("reason")}
1313 id="post-report-reason"
1314 className="form-control me-2"
1315 placeholder={I18NextService.i18n.t("reason")}
1317 value={this.state.reportReason}
1318 onInput={linkEvent(this, this.handleReportReasonChange)}
1322 className="btn btn-secondary"
1323 aria-label={I18NextService.i18n.t("create_report")}
1325 {this.state.reportLoading ? (
1328 I18NextService.i18n.t("create_report")
1333 {this.state.showPurgeDialog && (
1335 className="form-inline"
1336 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1339 <label className="visually-hidden" htmlFor="purge-reason">
1340 {I18NextService.i18n.t("reason")}
1345 className="form-control me-2"
1346 placeholder={I18NextService.i18n.t("reason")}
1347 value={this.state.purgeReason}
1348 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1350 {this.state.purgeLoading ? (
1355 className="btn btn-secondary"
1356 aria-label={purgeTypeText}
1358 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1368 const post = this.postView.post;
1369 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1370 <div className="row">
1371 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1372 {this.postTitleLine()}
1374 <div className="col-4">
1375 {/* Post thumbnail */}
1376 {!this.state.imageExpanded && this.thumbnail()}
1380 this.postTitleLine()
1384 showPreviewButton() {
1388 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1389 onClick={linkEvent(this, this.handleShowBody)}
1392 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1393 classes="icon-inline"
1402 {/* The mobile view*/}
1403 <div className="d-block d-sm-none">
1404 <article className="row post-container">
1405 <div className="col-12">
1406 {this.createdLine()}
1408 {/* If it has a thumbnail, do a right aligned thumbnail */}
1409 {this.mobileThumbnail()}
1411 {this.commentsLine(true)}
1412 {this.userActionsLine()}
1413 {this.duplicatesLine()}
1414 {this.removeAndBanDialogs()}
1419 {/* The larger view*/}
1420 <div className="d-none d-sm-block">
1421 <article className="row post-container">
1422 {!this.props.viewOnly && (
1423 <div className="col flex-grow-0">
1425 voteContentType={VoteContentType.Post}
1426 id={this.postView.post.id}
1427 onVote={this.props.onPostVote}
1428 enableDownvotes={this.props.enableDownvotes}
1429 counts={this.postView.counts}
1430 my_vote={this.postView.my_vote}
1434 <div className="col flex-grow-1">
1435 <div className="row">
1436 <div className="col-sm-3 col-lg-2 pe-0 post-media">
1437 <div className="">{this.thumbnail()}</div>
1439 <div className="col-12 col-sm-9 col-lg-10">
1440 {this.postTitleLine()}
1441 {this.createdLine()}
1442 {this.commentsLine()}
1443 {this.duplicatesLine()}
1444 {this.userActionsLine()}
1445 {this.removeAndBanDialogs()}
1455 private get myPost(): boolean {
1457 this.postView.creator.id ==
1458 UserService.Instance.myUserInfo?.local_user_view.person.id
1461 handleEditClick(i: PostListing) {
1462 i.setState({ showEdit: true });
1465 handleEditCancel() {
1466 this.setState({ showEdit: false });
1469 // The actual editing is done in the receive for post
1470 handleEditPost(form: EditPost) {
1471 this.setState({ showEdit: false });
1472 this.props.onPostEdit(form);
1475 handleShare(i: PostListing) {
1476 const { name, body, id } = i.props.post_view.post;
1479 text: body?.slice(0, 50),
1480 url: `${getHttpBase()}/post/${id}`,
1484 handleShowReportDialog(i: PostListing) {
1485 i.setState({ showReportDialog: !i.state.showReportDialog });
1488 handleReportReasonChange(i: PostListing, event: any) {
1489 i.setState({ reportReason: event.target.value });
1492 handleReportSubmit(i: PostListing, event: any) {
1493 event.preventDefault();
1494 i.setState({ reportLoading: true });
1495 i.props.onPostReport({
1496 post_id: i.postView.post.id,
1497 reason: i.state.reportReason ?? "",
1498 auth: myAuthRequired(),
1502 handleBlockPersonClick(i: PostListing) {
1503 i.setState({ blockLoading: true });
1504 i.props.onBlockPerson({
1505 person_id: i.postView.creator.id,
1507 auth: myAuthRequired(),
1511 handleDeleteClick(i: PostListing) {
1512 i.setState({ deleteLoading: true });
1513 i.props.onDeletePost({
1514 post_id: i.postView.post.id,
1515 deleted: !i.postView.post.deleted,
1516 auth: myAuthRequired(),
1520 handleSavePostClick(i: PostListing) {
1521 i.setState({ saveLoading: true });
1522 i.props.onSavePost({
1523 post_id: i.postView.post.id,
1524 save: !i.postView.saved,
1525 auth: myAuthRequired(),
1529 get crossPostParams(): PostFormParams {
1530 const queryParams: PostFormParams = {};
1531 const { name, url } = this.postView.post;
1533 queryParams.name = name;
1536 queryParams.url = url;
1539 const crossPostBody = this.crossPostBody();
1540 if (crossPostBody) {
1541 queryParams.body = crossPostBody;
1547 crossPostBody(): string | undefined {
1548 const post = this.postView.post;
1549 const body = post.body;
1552 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1554 }\n\n${body.replace(/^/gm, "> ")}`
1558 get showBody(): boolean {
1559 return this.props.showBody || this.state.showBody;
1562 handleModRemoveShow(i: PostListing) {
1564 showRemoveDialog: !i.state.showRemoveDialog,
1565 showBanDialog: false,
1569 handleModRemoveReasonChange(i: PostListing, event: any) {
1570 i.setState({ removeReason: event.target.value });
1573 handleModRemoveDataChange(i: PostListing, event: any) {
1574 i.setState({ removeData: event.target.checked });
1577 handleModRemoveSubmit(i: PostListing, event: any) {
1578 event.preventDefault();
1579 i.setState({ removeLoading: true });
1580 i.props.onRemovePost({
1581 post_id: i.postView.post.id,
1582 removed: !i.postView.post.removed,
1583 auth: myAuthRequired(),
1587 handleModLock(i: PostListing) {
1588 i.setState({ lockLoading: true });
1589 i.props.onLockPost({
1590 post_id: i.postView.post.id,
1591 locked: !i.postView.post.locked,
1592 auth: myAuthRequired(),
1596 handleModFeaturePostLocal(i: PostListing) {
1597 i.setState({ featureLocalLoading: true });
1598 i.props.onFeaturePost({
1599 post_id: i.postView.post.id,
1600 featured: !i.postView.post.featured_local,
1601 feature_type: "Local",
1602 auth: myAuthRequired(),
1606 handleModFeaturePostCommunity(i: PostListing) {
1607 i.setState({ featureCommunityLoading: true });
1608 i.props.onFeaturePost({
1609 post_id: i.postView.post.id,
1610 featured: !i.postView.post.featured_community,
1611 feature_type: "Community",
1612 auth: myAuthRequired(),
1616 handleModBanFromCommunityShow(i: PostListing) {
1618 showBanDialog: true,
1619 banType: BanType.Community,
1620 showRemoveDialog: false,
1624 handleModBanShow(i: PostListing) {
1626 showBanDialog: true,
1627 banType: BanType.Site,
1628 showRemoveDialog: false,
1632 handlePurgePersonShow(i: PostListing) {
1634 showPurgeDialog: true,
1635 purgeType: PurgeType.Person,
1636 showRemoveDialog: false,
1640 handlePurgePostShow(i: PostListing) {
1642 showPurgeDialog: true,
1643 purgeType: PurgeType.Post,
1644 showRemoveDialog: false,
1648 handlePurgeReasonChange(i: PostListing, event: any) {
1649 i.setState({ purgeReason: event.target.value });
1652 handlePurgeSubmit(i: PostListing, event: any) {
1653 event.preventDefault();
1654 i.setState({ purgeLoading: true });
1655 if (i.state.purgeType == PurgeType.Person) {
1656 i.props.onPurgePerson({
1657 person_id: i.postView.creator.id,
1658 reason: i.state.purgeReason,
1659 auth: myAuthRequired(),
1661 } else if (i.state.purgeType == PurgeType.Post) {
1662 i.props.onPurgePost({
1663 post_id: i.postView.post.id,
1664 reason: i.state.purgeReason,
1665 auth: myAuthRequired(),
1670 handleModBanReasonChange(i: PostListing, event: any) {
1671 i.setState({ banReason: event.target.value });
1674 handleModBanExpireDaysChange(i: PostListing, event: any) {
1675 i.setState({ banExpireDays: event.target.value });
1678 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1679 i.setState({ banType: BanType.Community });
1680 i.handleModBanBothSubmit(i, event);
1683 handleModBanSubmit(i: PostListing, event: any) {
1684 i.setState({ banType: BanType.Site });
1685 i.handleModBanBothSubmit(i, event);
1688 handleModBanBothSubmit(i: PostListing, event: any) {
1689 event.preventDefault();
1690 i.setState({ banLoading: true });
1692 const ban = !i.props.post_view.creator_banned_from_community;
1693 // If its an unban, restore all their data
1695 i.setState({ removeData: false });
1697 const person_id = i.props.post_view.creator.id;
1698 const remove_data = i.state.removeData;
1699 const reason = i.state.banReason;
1700 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1702 if (i.state.banType == BanType.Community) {
1703 const community_id = i.postView.community.id;
1704 i.props.onBanPersonFromCommunity({
1711 auth: myAuthRequired(),
1714 i.props.onBanPerson({
1720 auth: myAuthRequired(),
1725 handleAddModToCommunity(i: PostListing) {
1726 i.setState({ addModLoading: true });
1727 i.props.onAddModToCommunity({
1728 community_id: i.postView.community.id,
1729 person_id: i.postView.creator.id,
1730 added: !i.creatorIsMod_,
1731 auth: myAuthRequired(),
1735 handleAddAdmin(i: PostListing) {
1736 i.setState({ addAdminLoading: true });
1737 i.props.onAddAdmin({
1738 person_id: i.postView.creator.id,
1739 added: !i.creatorIsAdmin_,
1740 auth: myAuthRequired(),
1744 handleShowConfirmTransferCommunity(i: PostListing) {
1745 i.setState({ showConfirmTransferCommunity: true });
1748 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1749 i.setState({ showConfirmTransferCommunity: false });
1752 handleTransferCommunity(i: PostListing) {
1753 i.setState({ transferLoading: true });
1754 i.props.onTransferCommunity({
1755 community_id: i.postView.community.id,
1756 person_id: i.postView.creator.id,
1757 auth: myAuthRequired(),
1761 handleShowConfirmTransferSite(i: PostListing) {
1762 i.setState({ showConfirmTransferSite: true });
1765 handleCancelShowConfirmTransferSite(i: PostListing) {
1766 i.setState({ showConfirmTransferSite: false });
1769 handleImageExpandClick(i: PostListing, event: any) {
1770 event.preventDefault();
1771 i.setState({ imageExpanded: !i.state.imageExpanded });
1775 handleViewSource(i: PostListing) {
1776 i.setState({ viewSource: !i.state.viewSource });
1779 handleShowAdvanced(i: PostListing) {
1780 i.setState({ showAdvanced: !i.state.showAdvanced });
1784 handleShowMoreMobile(i: PostListing) {
1786 showMoreMobile: !i.state.showMoreMobile,
1787 showAdvanced: !i.state.showAdvanced,
1792 handleShowBody(i: PostListing) {
1793 i.setState({ showBody: !i.state.showBody });
1797 get pointsTippy(): string {
1798 const points = I18NextService.i18n.t("number_of_points", {
1799 count: Number(this.postView.counts.score),
1800 formattedCount: Number(this.postView.counts.score),
1803 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1804 count: Number(this.postView.counts.upvotes),
1805 formattedCount: Number(this.postView.counts.upvotes),
1808 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1809 count: Number(this.postView.counts.downvotes),
1810 formattedCount: Number(this.postView.counts.downvotes),
1813 return `${points} • ${upvotes} • ${downvotes}`;
1816 get canModOnSelf_(): boolean {
1818 this.postView.creator.id,
1819 this.props.moderators,
1826 get canMod_(): boolean {
1828 this.postView.creator.id,
1829 this.props.moderators,
1834 get canAdmin_(): boolean {
1835 return canAdmin(this.postView.creator.id, this.props.admins);
1838 get creatorIsMod_(): boolean {
1839 return isMod(this.postView.creator.id, this.props.moderators);
1842 get creatorIsAdmin_(): boolean {
1843 return isAdmin(this.postView.creator.id, this.props.admins);