1 import { myAuthRequired } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
51 } from "../../interfaces";
52 import { mdNoImages, 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 smallAvatars?: boolean;
111 enableDownvotes?: boolean;
112 enableNsfw?: boolean;
114 onPostEdit(form: EditPost): void;
115 onPostVote(form: CreatePostLike): void;
116 onPostReport(form: CreatePostReport): void;
117 onBlockPerson(form: BlockPerson): void;
118 onLockPost(form: LockPost): void;
119 onDeletePost(form: DeletePost): void;
120 onRemovePost(form: RemovePost): void;
121 onSavePost(form: SavePost): void;
122 onFeaturePost(form: FeaturePost): void;
123 onPurgePerson(form: PurgePerson): void;
124 onPurgePost(form: PurgePost): void;
125 onBanPersonFromCommunity(form: BanFromCommunity): void;
126 onBanPerson(form: BanPerson): void;
127 onAddModToCommunity(form: AddModToCommunity): void;
128 onAddAdmin(form: AddAdmin): void;
129 onTransferCommunity(form: TransferCommunity): void;
132 export class PostListing extends Component<PostListingProps, PostListingState> {
133 state: PostListingState = {
135 showRemoveDialog: false,
136 showPurgeDialog: false,
137 purgeType: PurgeType.Person,
138 showBanDialog: false,
139 banType: BanType.Community,
141 showConfirmTransferSite: false,
142 showConfirmTransferCommunity: false,
143 imageExpanded: false,
146 showMoreMobile: false,
148 showReportDialog: false,
150 reportLoading: false,
153 deleteLoading: false,
154 removeLoading: false,
156 featureCommunityLoading: false,
157 featureLocalLoading: false,
159 addModLoading: false,
160 addAdminLoading: false,
161 transferLoading: false,
164 constructor(props: any, context: any) {
165 super(props, context);
167 this.handleEditPost = this.handleEditPost.bind(this);
168 this.handleEditCancel = this.handleEditCancel.bind(this);
171 componentWillReceiveProps(nextProps: PostListingProps) {
172 if (this.props !== nextProps) {
175 reportLoading: false,
178 deleteLoading: false,
179 removeLoading: false,
181 featureCommunityLoading: false,
182 featureLocalLoading: false,
184 addModLoading: false,
185 addAdminLoading: false,
186 transferLoading: false,
187 imageExpanded: false,
192 get postView(): PostView {
193 return this.props.post_view;
197 const post = this.postView.post;
200 <div className="post-listing mt-2">
201 {!this.state.showEdit ? (
204 {this.state.imageExpanded && !this.props.hideImage && this.img}
205 {post.url && this.state.showBody && post.embed_title && (
206 <MetadataCard post={post} />
208 {this.showBody && this.body()}
212 post_view={this.postView}
213 crossPosts={this.props.crossPosts}
214 onEdit={this.handleEditPost}
215 onCancel={this.handleEditCancel}
216 enableNsfw={this.props.enableNsfw}
217 enableDownvotes={this.props.enableDownvotes}
218 allLanguages={this.props.allLanguages}
219 siteLanguages={this.props.siteLanguages}
227 const body = this.postView.post.body;
229 <article id="postContent" className="col-12 card my-2 p-2">
230 {this.state.viewSource ? (
233 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
245 <div className="offset-sm-3 my-2 d-none d-sm-block">
246 <a href={this.imageSrc} className="d-inline-block">
247 <PictrsImage src={this.imageSrc} />
250 <div className="my-2 d-block d-sm-none">
253 className="p-0 border-0 bg-transparent d-inline-block"
254 onClick={linkEvent(this, this.handleImageExpandClick)}
256 <PictrsImage src={this.imageSrc} />
263 const { post } = this.postView;
264 const { url } = post;
266 // if direct video link
267 if (url && isVideo(url)) {
269 <div className="embed-responsive mt-3">
270 <video muted controls className="embed-responsive-item col-12">
271 <source src={url} type="video/mp4" />
277 // if embedded video link
278 if (url && post.embed_video_url) {
280 <div className="ratio ratio-16x9">
283 className="post-metadata-iframe"
284 src={post.embed_video_url}
285 title={post.embed_title}
294 imgThumb(src: string) {
295 const post_view = this.postView;
301 nsfw={post_view.post.nsfw || post_view.community.nsfw}
306 get imageSrc(): string | undefined {
307 const post = this.postView.post;
308 const url = post.url;
309 const thumbnail = post.thumbnail_url;
311 if (url && isImage(url)) {
312 if (url.includes("pictrs")) {
314 } else if (thumbnail) {
319 } else if (thumbnail) {
327 const post = this.postView.post;
328 const url = post.url;
329 const thumbnail = post.thumbnail_url;
331 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
335 className="text-body d-inline-block position-relative mb-2"
336 data-tippy-content={I18NextService.i18n.t("expand_here")}
337 onClick={linkEvent(this, this.handleImageExpandClick)}
338 aria-label={I18NextService.i18n.t("expand_here")}
340 {this.imgThumb(this.imageSrc)}
341 <Icon icon="image" classes="mini-overlay" />
344 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
347 className="text-body d-inline-block position-relative mb-2"
352 {this.imgThumb(this.imageSrc)}
353 <Icon icon="external-link" classes="mini-overlay" />
357 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
360 className="text-body"
364 data-tippy-content={I18NextService.i18n.t("expand_here")}
365 onClick={linkEvent(this, this.handleImageExpandClick)}
366 aria-label={I18NextService.i18n.t("expand_here")}
368 <div className="thumbnail rounded bg-light d-flex justify-content-center">
369 <Icon icon="play" classes="d-flex align-items-center" />
375 <a className="text-body" href={url} title={url} rel={relTags}>
376 <div className="thumbnail rounded bg-light d-flex justify-content-center">
377 <Icon icon="external-link" classes="d-flex align-items-center" />
385 className="text-body"
386 to={`/post/${post.id}`}
387 title={I18NextService.i18n.t("comments")}
389 <div className="thumbnail rounded bg-light d-flex justify-content-center">
390 <Icon icon="message-square" classes="d-flex align-items-center" />
398 const post_view = this.postView;
400 <span className="small">
401 <PersonListing person={post_view.creator} />
402 {this.creatorIsMod_ && (
403 <span className="mx-1 badge text-bg-light">
404 {I18NextService.i18n.t("mod")}
407 {this.creatorIsAdmin_ && (
408 <span className="mx-1 badge text-bg-light">
409 {I18NextService.i18n.t("admin")}
412 {post_view.creator.bot_account && (
413 <span className="mx-1 badge text-bg-light">
414 {I18NextService.i18n.t("bot_account").toLowerCase()}
417 {this.props.showCommunity && (
420 {I18NextService.i18n.t("to")}{" "}
421 <CommunityLink community={post_view.community} />
424 {post_view.post.language_id !== 0 && (
425 <span className="mx-1 badge text-bg-light">
427 this.props.allLanguages.find(
428 lang => lang.id === post_view.post.language_id
435 published={post_view.post.published}
436 updated={post_view.post.updated}
443 const post = this.postView.post;
446 className={`d-inline ${
447 !post.featured_community && !post.featured_local
451 to={`/post/${post.id}`}
452 title={I18NextService.i18n.t("comments")}
456 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
463 const post = this.postView.post;
464 const url = post.url;
468 <div className="post-title overflow-hidden">
469 <h5 className="d-inline">
470 {url && this.props.showBody ? (
473 !post.featured_community && !post.featured_local
480 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
488 <small className="ms-2 badge text-bg-secondary">
489 {I18NextService.i18n.t("removed")}
495 className="unselectable pointer ms-2 text-muted fst-italic"
496 data-tippy-content={I18NextService.i18n.t("deleted")}
498 <Icon icon="trash" classes="icon-inline text-danger" />
504 className="unselectable pointer ms-2 text-muted fst-italic"
505 data-tippy-content={I18NextService.i18n.t("locked")}
507 <Icon icon="lock" classes="icon-inline text-danger" />
511 {post.featured_community && (
513 className="unselectable pointer ms-2 text-muted fst-italic"
514 data-tippy-content={I18NextService.i18n.t(
515 "featured_in_community"
517 aria-label={I18NextService.i18n.t("featured_in_community")}
519 <Icon icon="pin" classes="icon-inline text-primary" />
523 {post.featured_local && (
525 className="unselectable pointer ms-2 text-muted fst-italic"
526 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
527 aria-label={I18NextService.i18n.t("featured_in_local")}
529 <Icon icon="pin" classes="icon-inline text-secondary" />
534 <small className="ms-2 badge text-bg-danger">
535 {I18NextService.i18n.t("nsfw")}
539 {url && this.urlLine()}
545 const post = this.postView.post;
546 const url = post.url;
549 <p className="small m-0">
550 {url && !(hostname(url) === getExternalHost()) && (
552 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
565 const dupes = this.props.crossPosts;
566 return dupes && dupes.length > 0 ? (
567 <ul className="list-inline mb-1 small text-muted">
569 <li className="list-inline-item me-2">
570 {I18NextService.i18n.t("cross_posted_to")}
573 <li key={pv.post.id} className="list-inline-item me-2">
574 <Link to={`/post/${pv.post.id}`}>
577 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
588 commentsLine(mobile = false) {
589 const post = this.postView.post;
592 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
593 {this.commentsButton}
596 className="btn btn-sm btn-animate text-muted py-0"
597 onClick={linkEvent(this, this.handleShare)}
600 <Icon icon="share" inline />
605 className="btn btn-sm btn-animate text-muted py-0"
606 title={I18NextService.i18n.t("link")}
609 <Icon icon="fedilink" inline />
612 {mobile && !this.props.viewOnly && (
614 voteContentType={VoteContentType.Post}
615 id={this.postView.post.id}
616 onVote={this.props.onPostVote}
617 enableDownvotes={this.props.enableDownvotes}
618 counts={this.postView.counts}
619 my_vote={this.postView.my_vote}
622 {UserService.Instance.myUserInfo &&
623 !this.props.viewOnly &&
629 showPreviewButton() {
630 const post_view = this.postView;
631 const body = post_view.post.body;
635 className="btn btn-sm btn-animate text-muted py-0"
636 data-tippy-content={body && mdNoImages.render(body)}
637 data-tippy-allowHtml={true}
638 onClick={linkEvent(this, this.handleShowBody)}
642 classes={classNames("icon-inline me-1", {
643 "text-success": this.state.showBody,
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}
662 * If there is a URL, or if the post has a body and we were told not to
663 * show the body, show the MetadataCard/body toggle.
665 {(post.url || (post.body && !this.props.showBody)) &&
666 this.showPreviewButton()}
668 {this.showBody && post_view.post.body && this.viewSourceButton}
670 <div className="dropdown">
672 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
673 onClick={linkEvent(this, this.handleShowAdvanced)}
674 data-tippy-content={I18NextService.i18n.t("more")}
675 data-bs-toggle="dropdown"
676 aria-expanded="false"
677 aria-controls={`advancedButtonsDropdown${post.id}`}
678 aria-label={I18NextService.i18n.t("more")}
680 <Icon icon="more-vertical" inline />
684 className="dropdown-menu"
685 id={`advancedButtonsDropdown${post.id}`}
689 <li>{this.reportButton}</li>
690 <li>{this.blockButton}</li>
694 <li>{this.editButton}</li>
695 <li>{this.deleteButton}</li>
699 {/* Any mod can do these, not limited to hierarchy*/}
700 {(amMod(this.props.moderators) || amAdmin()) && (
703 <hr className="dropdown-divider" />
705 <li>{this.lockButton}</li>
706 {this.featureButtons}
710 {(this.canMod_ || this.canAdmin_) && (
711 <li>{this.modRemoveButton}</li>
719 get commentsButton() {
720 const post_view = this.postView;
721 const title = I18NextService.i18n.t("number_of_comments", {
722 count: Number(post_view.counts.comments),
723 formattedCount: Number(post_view.counts.comments),
728 className="btn btn-link btn-sm text-muted ps-0"
730 to={`/post/${post_view.post.id}?scrollToComments=true`}
731 data-tippy-content={title}
733 <Icon icon="message-square" classes="me-1" inline />
734 {post_view.counts.comments}
735 {this.unreadCount && (
738 <span className="fst-italic">
739 ({this.unreadCount} {I18NextService.i18n.t("new")})
747 get unreadCount(): number | undefined {
748 const pv = this.postView;
749 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
751 : pv.unread_comments;
755 const saved = this.postView.saved;
757 ? I18NextService.i18n.t("unsave")
758 : I18NextService.i18n.t("save");
761 className="btn btn-sm btn-animate text-muted py-0"
762 onClick={linkEvent(this, this.handleSavePostClick)}
763 data-tippy-content={label}
766 {this.state.saveLoading ? (
771 classes={classNames({ "text-warning": saved })}
779 get crossPostButton() {
782 className="btn btn-sm btn-animate text-muted py-0"
784 /* Empty string properties are required to satisfy type*/
785 pathname: "/create_post",
786 state: { ...this.crossPostParams },
791 title={I18NextService.i18n.t("cross_post")}
792 data-tippy-content={I18NextService.i18n.t("cross_post")}
793 aria-label={I18NextService.i18n.t("cross_post")}
795 <Icon icon="copy" inline />
803 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
804 onClick={linkEvent(this, this.handleShowReportDialog)}
805 aria-label={I18NextService.i18n.t("show_report_dialog")}
807 <Icon classes="me-1" icon="flag" inline />
808 {I18NextService.i18n.t("create_report")}
816 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
817 onClick={linkEvent(this, this.handleBlockPersonClick)}
818 aria-label={I18NextService.i18n.t("block_user")}
820 {this.state.blockLoading ? (
823 <Icon classes="me-1" icon="slash" inline />
825 {I18NextService.i18n.t("block_user")}
833 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
834 onClick={linkEvent(this, this.handleEditClick)}
835 aria-label={I18NextService.i18n.t("edit")}
837 <Icon classes="me-1" icon="edit" inline />
838 {I18NextService.i18n.t("edit")}
844 const deleted = this.postView.post.deleted;
845 const label = !deleted
846 ? I18NextService.i18n.t("delete")
847 : I18NextService.i18n.t("restore");
850 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
851 onClick={linkEvent(this, this.handleDeleteClick)}
853 {this.state.deleteLoading ? (
859 classes={classNames("me-1", { "text-danger": deleted })}
869 get viewSourceButton() {
872 className="btn btn-sm btn-animate text-muted py-0"
873 onClick={linkEvent(this, this.handleViewSource)}
874 data-tippy-content={I18NextService.i18n.t("view_source")}
875 aria-label={I18NextService.i18n.t("view_source")}
879 classes={classNames({ "text-success": this.state.viewSource })}
887 const locked = this.postView.post.locked;
889 ? I18NextService.i18n.t("unlock")
890 : I18NextService.i18n.t("lock");
893 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
894 onClick={linkEvent(this, this.handleModLock)}
897 {this.state.lockLoading ? (
903 classes={classNames("me-1", { "text-danger": locked })}
906 {capitalizeFirstLetter(label)}
913 get featureButtons() {
914 const featuredCommunity = this.postView.post.featured_community;
915 const labelCommunity = featuredCommunity
916 ? I18NextService.i18n.t("unfeature_from_community")
917 : I18NextService.i18n.t("feature_in_community");
919 const featuredLocal = this.postView.post.featured_local;
920 const labelLocal = featuredLocal
921 ? I18NextService.i18n.t("unfeature_from_local")
922 : I18NextService.i18n.t("feature_in_local");
927 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
928 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
929 data-tippy-content={labelCommunity}
930 aria-label={labelCommunity}
932 {this.state.featureCommunityLoading ? (
938 classes={classNames("me-1", {
939 "text-success": featuredCommunity,
943 {I18NextService.i18n.t("community")}
951 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
952 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
953 data-tippy-content={labelLocal}
954 aria-label={labelLocal}
956 {this.state.featureLocalLoading ? (
962 classes={classNames("me-1", {
963 "text-success": featuredLocal,
967 {I18NextService.i18n.t("local")}
977 get modBanFromCommunityButton() {
980 className="btn btn-link btn-animate text-muted py-0"
981 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
982 aria-label={I18NextService.i18n.t("ban_from_community")}
984 {I18NextService.i18n.t("ban_from_community")}
989 get modUnbanFromCommunityButton() {
992 className="btn btn-link btn-animate text-muted py-0"
993 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
994 aria-label={I18NextService.i18n.t("unban")}
996 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1001 get addModToCommunityButton() {
1004 className="btn btn-link btn-animate text-muted py-0"
1005 onClick={linkEvent(this, this.handleAddModToCommunity)}
1008 ? I18NextService.i18n.t("remove_as_mod")
1009 : I18NextService.i18n.t("appoint_as_mod")
1012 {this.state.addModLoading ? (
1014 ) : this.creatorIsMod_ ? (
1015 I18NextService.i18n.t("remove_as_mod")
1017 I18NextService.i18n.t("appoint_as_mod")
1023 get modBanButton() {
1026 className="btn btn-link btn-animate text-muted py-0"
1027 onClick={linkEvent(this, this.handleModBanShow)}
1028 aria-label={I18NextService.i18n.t("ban_from_site")}
1030 {I18NextService.i18n.t("ban_from_site")}
1035 get modUnbanButton() {
1038 className="btn btn-link btn-animate text-muted py-0"
1039 onClick={linkEvent(this, this.handleModBanSubmit)}
1040 aria-label={I18NextService.i18n.t("unban_from_site")}
1042 {this.state.banLoading ? (
1045 I18NextService.i18n.t("unban_from_site")
1051 get purgePersonButton() {
1054 className="btn btn-link btn-animate text-muted py-0"
1055 onClick={linkEvent(this, this.handlePurgePersonShow)}
1056 aria-label={I18NextService.i18n.t("purge_user")}
1058 {I18NextService.i18n.t("purge_user")}
1063 get purgePostButton() {
1066 className="btn btn-link btn-animate text-muted py-0"
1067 onClick={linkEvent(this, this.handlePurgePostShow)}
1068 aria-label={I18NextService.i18n.t("purge_post")}
1070 {I18NextService.i18n.t("purge_post")}
1075 get toggleAdminButton() {
1078 className="btn btn-link btn-animate text-muted py-0"
1079 onClick={linkEvent(this, this.handleAddAdmin)}
1081 {this.state.addAdminLoading ? (
1083 ) : this.creatorIsAdmin_ ? (
1084 I18NextService.i18n.t("remove_as_admin")
1086 I18NextService.i18n.t("appoint_as_admin")
1092 get modRemoveButton() {
1093 const removed = this.postView.post.removed;
1096 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1099 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1102 {/* TODO: Find an icon for this. */}
1103 {this.state.removeLoading ? (
1106 I18NextService.i18n.t("remove")
1108 I18NextService.i18n.t("restore")
1115 * Mod/Admin actions to be taken against the author.
1119 const post_view = this.postView;
1121 this.state.showAdvanced && (
1122 <div className="mt-3">
1125 {!this.creatorIsMod_ &&
1126 (!post_view.creator_banned_from_community
1127 ? this.modBanFromCommunityButton
1128 : this.modUnbanFromCommunityButton)}
1129 {!post_view.creator_banned_from_community &&
1130 this.addModToCommunityButton}
1134 {/* Community creators and admins can transfer community to another mod */}
1135 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1137 this.creatorIsMod_ &&
1138 (!this.state.showConfirmTransferCommunity ? (
1140 className="btn btn-link btn-animate text-muted py-0"
1143 this.handleShowConfirmTransferCommunity
1145 aria-label={I18NextService.i18n.t("transfer_community")}
1147 {I18NextService.i18n.t("transfer_community")}
1152 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1153 aria-label={I18NextService.i18n.t("are_you_sure")}
1155 {I18NextService.i18n.t("are_you_sure")}
1158 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1159 aria-label={I18NextService.i18n.t("yes")}
1160 onClick={linkEvent(this, this.handleTransferCommunity)}
1162 {this.state.transferLoading ? (
1165 I18NextService.i18n.t("yes")
1169 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1172 this.handleCancelShowConfirmTransferCommunity
1174 aria-label={I18NextService.i18n.t("no")}
1176 {I18NextService.i18n.t("no")}
1180 {/* Admins can ban from all, and appoint other admins */}
1181 {this.canAdmin_ && (
1183 {!this.creatorIsAdmin_ && (
1185 {!isBanned(post_view.creator)
1187 : this.modUnbanButton}
1188 {this.purgePersonButton}
1189 {this.purgePostButton}
1192 {!isBanned(post_view.creator) &&
1193 post_view.creator.local &&
1194 this.toggleAdminButton}
1202 removeAndBanDialogs() {
1203 const post = this.postView;
1204 const purgeTypeText =
1205 this.state.purgeType == PurgeType.Post
1206 ? I18NextService.i18n.t("purge_post")
1207 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1210 {this.state.showRemoveDialog && (
1212 className="form-inline"
1213 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1216 className="visually-hidden"
1217 htmlFor="post-listing-remove-reason"
1219 {I18NextService.i18n.t("reason")}
1223 id="post-listing-remove-reason"
1224 className="form-control me-2"
1225 placeholder={I18NextService.i18n.t("reason")}
1226 value={this.state.removeReason}
1227 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1231 className="btn btn-secondary"
1232 aria-label={I18NextService.i18n.t("remove_post")}
1234 {this.state.removeLoading ? (
1237 I18NextService.i18n.t("remove_post")
1242 {this.state.showBanDialog && (
1243 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1244 <div className="mb-3 row col-12">
1246 className="col-form-label"
1247 htmlFor="post-listing-ban-reason"
1249 {I18NextService.i18n.t("reason")}
1253 id="post-listing-ban-reason"
1254 className="form-control me-2"
1255 placeholder={I18NextService.i18n.t("reason")}
1256 value={this.state.banReason}
1257 onInput={linkEvent(this, this.handleModBanReasonChange)}
1259 <label className="col-form-label" htmlFor="mod-ban-expires">
1260 {I18NextService.i18n.t("expires")}
1264 id="mod-ban-expires"
1265 className="form-control me-2"
1266 placeholder={I18NextService.i18n.t("number_of_days")}
1267 value={this.state.banExpireDays}
1268 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1270 <div className="input-group mb-3">
1271 <div className="form-check">
1273 className="form-check-input"
1274 id="mod-ban-remove-data"
1276 checked={this.state.removeData}
1277 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1280 className="form-check-label"
1281 htmlFor="mod-ban-remove-data"
1282 title={I18NextService.i18n.t("remove_content_more")}
1284 {I18NextService.i18n.t("remove_content")}
1289 {/* TODO hold off on expires until later */}
1290 {/* <div class="mb-3 row"> */}
1291 {/* <label class="col-form-label">Expires</label> */}
1292 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1294 <div className="mb-3 row">
1297 className="btn btn-secondary"
1298 aria-label={I18NextService.i18n.t("ban")}
1300 {this.state.banLoading ? (
1304 {I18NextService.i18n.t("ban")} {post.creator.name}
1311 {this.state.showReportDialog && (
1313 className="form-inline"
1314 onSubmit={linkEvent(this, this.handleReportSubmit)}
1316 <label className="visually-hidden" htmlFor="post-report-reason">
1317 {I18NextService.i18n.t("reason")}
1321 id="post-report-reason"
1322 className="form-control me-2"
1323 placeholder={I18NextService.i18n.t("reason")}
1325 value={this.state.reportReason}
1326 onInput={linkEvent(this, this.handleReportReasonChange)}
1330 className="btn btn-secondary"
1331 aria-label={I18NextService.i18n.t("create_report")}
1333 {this.state.reportLoading ? (
1336 I18NextService.i18n.t("create_report")
1341 {this.state.showPurgeDialog && (
1343 className="form-inline"
1344 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1347 <label className="visually-hidden" htmlFor="purge-reason">
1348 {I18NextService.i18n.t("reason")}
1353 className="form-control me-2"
1354 placeholder={I18NextService.i18n.t("reason")}
1355 value={this.state.purgeReason}
1356 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1358 {this.state.purgeLoading ? (
1363 className="btn btn-secondary"
1364 aria-label={purgeTypeText}
1366 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1376 const post = this.postView.post;
1377 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1378 <div className="row">
1379 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1380 {this.postTitleLine()}
1382 <div className="col-4">
1383 {/* Post thumbnail */}
1384 {!this.state.imageExpanded && this.thumbnail()}
1388 this.postTitleLine()
1393 const { body, id } = this.postView.post;
1395 return !this.showBody && body ? (
1396 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1397 <div className="md-div mb-1 preview-lines">{body}</div>
1407 {/* The mobile view*/}
1408 <div className="d-block d-sm-none">
1409 <article className="row post-container">
1410 <div className="col-12">
1411 {this.createdLine()}
1413 {/* If it has a thumbnail, do a right aligned thumbnail */}
1414 {this.mobileThumbnail()}
1416 {/* Show a preview of the post body */}
1417 {this.showBodyPreview()}
1419 {this.commentsLine(true)}
1420 {this.userActionsLine()}
1421 {this.duplicatesLine()}
1422 {this.removeAndBanDialogs()}
1427 {/* The larger view*/}
1428 <div className="d-none d-sm-block">
1429 <article className="row post-container">
1430 {!this.props.viewOnly && (
1432 voteContentType={VoteContentType.Post}
1433 id={this.postView.post.id}
1434 onVote={this.props.onPostVote}
1435 enableDownvotes={this.props.enableDownvotes}
1436 counts={this.postView.counts}
1437 my_vote={this.postView.my_vote}
1440 <div className="col-sm-2 pe-0 post-media">
1441 <div className="">{this.thumbnail()}</div>
1443 <div className="col-12 col-sm-9">
1444 <div className="row">
1445 <div className="col-12">
1446 {this.postTitleLine()}
1447 {this.createdLine()}
1448 {this.showBodyPreview()}
1449 {this.commentsLine()}
1450 {this.duplicatesLine()}
1451 {this.userActionsLine()}
1452 {this.removeAndBanDialogs()}
1462 private get myPost(): boolean {
1464 this.postView.creator.id ==
1465 UserService.Instance.myUserInfo?.local_user_view.person.id
1468 handleEditClick(i: PostListing) {
1469 i.setState({ showEdit: true });
1472 handleEditCancel() {
1473 this.setState({ showEdit: false });
1476 // The actual editing is done in the receive for post
1477 handleEditPost(form: EditPost) {
1478 this.setState({ showEdit: false });
1479 this.props.onPostEdit(form);
1482 handleShare(i: PostListing) {
1483 const { name, body, id } = i.props.post_view.post;
1486 text: body?.slice(0, 50),
1487 url: `${getHttpBase()}/post/${id}`,
1491 handleShowReportDialog(i: PostListing) {
1492 i.setState({ showReportDialog: !i.state.showReportDialog });
1495 handleReportReasonChange(i: PostListing, event: any) {
1496 i.setState({ reportReason: event.target.value });
1499 handleReportSubmit(i: PostListing, event: any) {
1500 event.preventDefault();
1501 i.setState({ reportLoading: true });
1502 i.props.onPostReport({
1503 post_id: i.postView.post.id,
1504 reason: i.state.reportReason ?? "",
1505 auth: myAuthRequired(),
1509 handleBlockPersonClick(i: PostListing) {
1510 i.setState({ blockLoading: true });
1511 i.props.onBlockPerson({
1512 person_id: i.postView.creator.id,
1514 auth: myAuthRequired(),
1518 handleDeleteClick(i: PostListing) {
1519 i.setState({ deleteLoading: true });
1520 i.props.onDeletePost({
1521 post_id: i.postView.post.id,
1522 deleted: !i.postView.post.deleted,
1523 auth: myAuthRequired(),
1527 handleSavePostClick(i: PostListing) {
1528 i.setState({ saveLoading: true });
1529 i.props.onSavePost({
1530 post_id: i.postView.post.id,
1531 save: !i.postView.saved,
1532 auth: myAuthRequired(),
1536 get crossPostParams(): PostFormParams {
1537 const queryParams: PostFormParams = {};
1538 const { name, url } = this.postView.post;
1540 queryParams.name = name;
1543 queryParams.url = url;
1546 const crossPostBody = this.crossPostBody();
1547 if (crossPostBody) {
1548 queryParams.body = crossPostBody;
1554 crossPostBody(): string | undefined {
1555 const post = this.postView.post;
1556 const body = post.body;
1559 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1561 }\n\n${body.replace(/^/gm, "> ")}`
1565 get showBody(): boolean {
1566 return this.props.showBody || this.state.showBody;
1569 handleModRemoveShow(i: PostListing) {
1571 showRemoveDialog: !i.state.showRemoveDialog,
1572 showBanDialog: false,
1576 handleModRemoveReasonChange(i: PostListing, event: any) {
1577 i.setState({ removeReason: event.target.value });
1580 handleModRemoveDataChange(i: PostListing, event: any) {
1581 i.setState({ removeData: event.target.checked });
1584 handleModRemoveSubmit(i: PostListing, event: any) {
1585 event.preventDefault();
1586 i.setState({ removeLoading: true });
1587 i.props.onRemovePost({
1588 post_id: i.postView.post.id,
1589 removed: !i.postView.post.removed,
1590 auth: myAuthRequired(),
1594 handleModLock(i: PostListing) {
1595 i.setState({ lockLoading: true });
1596 i.props.onLockPost({
1597 post_id: i.postView.post.id,
1598 locked: !i.postView.post.locked,
1599 auth: myAuthRequired(),
1603 handleModFeaturePostLocal(i: PostListing) {
1604 i.setState({ featureLocalLoading: true });
1605 i.props.onFeaturePost({
1606 post_id: i.postView.post.id,
1607 featured: !i.postView.post.featured_local,
1608 feature_type: "Local",
1609 auth: myAuthRequired(),
1613 handleModFeaturePostCommunity(i: PostListing) {
1614 i.setState({ featureCommunityLoading: true });
1615 i.props.onFeaturePost({
1616 post_id: i.postView.post.id,
1617 featured: !i.postView.post.featured_community,
1618 feature_type: "Community",
1619 auth: myAuthRequired(),
1623 handleModBanFromCommunityShow(i: PostListing) {
1625 showBanDialog: true,
1626 banType: BanType.Community,
1627 showRemoveDialog: false,
1631 handleModBanShow(i: PostListing) {
1633 showBanDialog: true,
1634 banType: BanType.Site,
1635 showRemoveDialog: false,
1639 handlePurgePersonShow(i: PostListing) {
1641 showPurgeDialog: true,
1642 purgeType: PurgeType.Person,
1643 showRemoveDialog: false,
1647 handlePurgePostShow(i: PostListing) {
1649 showPurgeDialog: true,
1650 purgeType: PurgeType.Post,
1651 showRemoveDialog: false,
1655 handlePurgeReasonChange(i: PostListing, event: any) {
1656 i.setState({ purgeReason: event.target.value });
1659 handlePurgeSubmit(i: PostListing, event: any) {
1660 event.preventDefault();
1661 i.setState({ purgeLoading: true });
1662 if (i.state.purgeType == PurgeType.Person) {
1663 i.props.onPurgePerson({
1664 person_id: i.postView.creator.id,
1665 reason: i.state.purgeReason,
1666 auth: myAuthRequired(),
1668 } else if (i.state.purgeType == PurgeType.Post) {
1669 i.props.onPurgePost({
1670 post_id: i.postView.post.id,
1671 reason: i.state.purgeReason,
1672 auth: myAuthRequired(),
1677 handleModBanReasonChange(i: PostListing, event: any) {
1678 i.setState({ banReason: event.target.value });
1681 handleModBanExpireDaysChange(i: PostListing, event: any) {
1682 i.setState({ banExpireDays: event.target.value });
1685 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1686 i.setState({ banType: BanType.Community });
1687 i.handleModBanBothSubmit(i, event);
1690 handleModBanSubmit(i: PostListing, event: any) {
1691 i.setState({ banType: BanType.Site });
1692 i.handleModBanBothSubmit(i, event);
1695 handleModBanBothSubmit(i: PostListing, event: any) {
1696 event.preventDefault();
1697 i.setState({ banLoading: true });
1699 const ban = !i.props.post_view.creator_banned_from_community;
1700 // If its an unban, restore all their data
1702 i.setState({ removeData: false });
1704 const person_id = i.props.post_view.creator.id;
1705 const remove_data = i.state.removeData;
1706 const reason = i.state.banReason;
1707 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1709 if (i.state.banType == BanType.Community) {
1710 const community_id = i.postView.community.id;
1711 i.props.onBanPersonFromCommunity({
1718 auth: myAuthRequired(),
1721 i.props.onBanPerson({
1727 auth: myAuthRequired(),
1732 handleAddModToCommunity(i: PostListing) {
1733 i.setState({ addModLoading: true });
1734 i.props.onAddModToCommunity({
1735 community_id: i.postView.community.id,
1736 person_id: i.postView.creator.id,
1737 added: !i.creatorIsMod_,
1738 auth: myAuthRequired(),
1742 handleAddAdmin(i: PostListing) {
1743 i.setState({ addAdminLoading: true });
1744 i.props.onAddAdmin({
1745 person_id: i.postView.creator.id,
1746 added: !i.creatorIsAdmin_,
1747 auth: myAuthRequired(),
1751 handleShowConfirmTransferCommunity(i: PostListing) {
1752 i.setState({ showConfirmTransferCommunity: true });
1755 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1756 i.setState({ showConfirmTransferCommunity: false });
1759 handleTransferCommunity(i: PostListing) {
1760 i.setState({ transferLoading: true });
1761 i.props.onTransferCommunity({
1762 community_id: i.postView.community.id,
1763 person_id: i.postView.creator.id,
1764 auth: myAuthRequired(),
1768 handleShowConfirmTransferSite(i: PostListing) {
1769 i.setState({ showConfirmTransferSite: true });
1772 handleCancelShowConfirmTransferSite(i: PostListing) {
1773 i.setState({ showConfirmTransferSite: false });
1776 handleImageExpandClick(i: PostListing, event: any) {
1777 event.preventDefault();
1778 i.setState({ imageExpanded: !i.state.imageExpanded });
1782 handleViewSource(i: PostListing) {
1783 i.setState({ viewSource: !i.state.viewSource });
1786 handleShowAdvanced(i: PostListing) {
1787 i.setState({ showAdvanced: !i.state.showAdvanced });
1791 handleShowMoreMobile(i: PostListing) {
1793 showMoreMobile: !i.state.showMoreMobile,
1794 showAdvanced: !i.state.showAdvanced,
1799 handleShowBody(i: PostListing) {
1800 i.setState({ showBody: !i.state.showBody });
1804 get pointsTippy(): string {
1805 const points = I18NextService.i18n.t("number_of_points", {
1806 count: Number(this.postView.counts.score),
1807 formattedCount: Number(this.postView.counts.score),
1810 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1811 count: Number(this.postView.counts.upvotes),
1812 formattedCount: Number(this.postView.counts.upvotes),
1815 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1816 count: Number(this.postView.counts.downvotes),
1817 formattedCount: Number(this.postView.counts.downvotes),
1820 return `${points} • ${upvotes} • ${downvotes}`;
1823 get canModOnSelf_(): boolean {
1825 this.postView.creator.id,
1826 this.props.moderators,
1833 get canMod_(): boolean {
1835 this.postView.creator.id,
1836 this.props.moderators,
1841 get canAdmin_(): boolean {
1842 return canAdmin(this.postView.creator.id, this.props.admins);
1845 get creatorIsMod_(): boolean {
1846 return isMod(this.postView.creator.id, this.props.moderators);
1849 get creatorIsAdmin_(): boolean {
1850 return isAdmin(this.postView.creator.id, this.props.admins);