1 import { myAuthRequired, newVote } 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";
46 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
47 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
48 import { I18NextService, UserService } from "../../services";
49 import { setupTippy } from "../../tippy";
50 import { Icon, PurgeWarning, Spinner } from "../common/icon";
51 import { MomentTime } from "../common/moment-time";
52 import { PictrsImage } from "../common/pictrs-image";
53 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
54 import { CommunityLink } from "../community/community-link";
55 import { PersonListing } from "../person/person-listing";
56 import { MetadataCard } from "./metadata-card";
57 import { PostForm } from "./post-form";
59 interface PostListingState {
61 showRemoveDialog: boolean;
62 showPurgeDialog: boolean;
64 purgeType?: PurgeType;
65 purgeLoading: boolean;
66 removeReason?: string;
67 showBanDialog: boolean;
69 banExpireDays?: number;
72 showConfirmTransferSite: boolean;
73 showConfirmTransferCommunity: boolean;
74 imageExpanded: boolean;
76 showAdvanced: boolean;
77 showMoreMobile: boolean;
79 showReportDialog: boolean;
80 reportReason?: string;
81 upvoteLoading: boolean;
82 downvoteLoading: boolean;
83 reportLoading: boolean;
84 blockLoading: boolean;
86 deleteLoading: boolean;
87 removeLoading: boolean;
89 featureCommunityLoading: boolean;
90 featureLocalLoading: boolean;
92 addModLoading: boolean;
93 addAdminLoading: boolean;
94 transferLoading: boolean;
97 interface PostListingProps {
99 crossPosts?: PostView[];
100 moderators?: CommunityModeratorView[];
101 admins?: PersonView[];
102 allLanguages: Language[];
103 siteLanguages: number[];
104 showCommunity?: boolean;
107 enableDownvotes?: boolean;
108 enableNsfw?: boolean;
110 onPostEdit(form: EditPost): void;
111 onPostVote(form: CreatePostLike): void;
112 onPostReport(form: CreatePostReport): void;
113 onBlockPerson(form: BlockPerson): void;
114 onLockPost(form: LockPost): void;
115 onDeletePost(form: DeletePost): void;
116 onRemovePost(form: RemovePost): void;
117 onSavePost(form: SavePost): void;
118 onFeaturePost(form: FeaturePost): void;
119 onPurgePerson(form: PurgePerson): void;
120 onPurgePost(form: PurgePost): void;
121 onBanPersonFromCommunity(form: BanFromCommunity): void;
122 onBanPerson(form: BanPerson): void;
123 onAddModToCommunity(form: AddModToCommunity): void;
124 onAddAdmin(form: AddAdmin): void;
125 onTransferCommunity(form: TransferCommunity): void;
128 export class PostListing extends Component<PostListingProps, PostListingState> {
129 state: PostListingState = {
131 showRemoveDialog: false,
132 showPurgeDialog: false,
133 purgeType: PurgeType.Person,
134 showBanDialog: false,
135 banType: BanType.Community,
137 showConfirmTransferSite: false,
138 showConfirmTransferCommunity: false,
139 imageExpanded: false,
142 showMoreMobile: false,
144 showReportDialog: false,
145 upvoteLoading: false,
146 downvoteLoading: false,
148 reportLoading: false,
151 deleteLoading: false,
152 removeLoading: false,
154 featureCommunityLoading: false,
155 featureLocalLoading: false,
157 addModLoading: false,
158 addAdminLoading: false,
159 transferLoading: false,
162 constructor(props: any, context: any) {
163 super(props, context);
165 this.handleEditPost = this.handleEditPost.bind(this);
166 this.handleEditCancel = this.handleEditCancel.bind(this);
169 componentWillReceiveProps(nextProps: PostListingProps) {
170 if (this.props !== nextProps) {
172 upvoteLoading: false,
173 downvoteLoading: false,
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)} />
242 return this.imageSrc ? (
244 <div className="offset-sm-3 my-2 d-none d-sm-block">
245 <a href={this.imageSrc} className="d-inline-block">
246 <PictrsImage src={this.imageSrc} />
249 <div className="my-2 d-block d-sm-none">
251 className="d-inline-block"
252 onClick={linkEvent(this, this.handleImageExpandClick)}
254 <PictrsImage src={this.imageSrc} />
263 imgThumb(src: string) {
264 const post_view = this.postView;
270 nsfw={post_view.post.nsfw || post_view.community.nsfw}
275 get imageSrc(): string | undefined {
276 const post = this.postView.post;
277 const url = post.url;
278 const thumbnail = post.thumbnail_url;
280 if (url && isImage(url)) {
281 if (url.includes("pictrs")) {
283 } else if (thumbnail) {
288 } else if (thumbnail) {
296 const post = this.postView.post;
297 const url = post.url;
298 const thumbnail = post.thumbnail_url;
300 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
304 className="text-body d-inline-block position-relative mb-2"
305 data-tippy-content={I18NextService.i18n.t("expand_here")}
306 onClick={linkEvent(this, this.handleImageExpandClick)}
307 aria-label={I18NextService.i18n.t("expand_here")}
309 {this.imgThumb(this.imageSrc)}
310 <Icon icon="image" classes="mini-overlay" />
313 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
316 className="text-body d-inline-block position-relative mb-2"
321 {this.imgThumb(this.imageSrc)}
322 <Icon icon="external-link" classes="mini-overlay" />
326 if (!this.props.hideImage && isVideo(url)) {
328 <div className="embed-responsive embed-responsive-16by9">
334 className="embed-responsive-item"
336 <source src={url} type="video/mp4" />
342 <a className="text-body" href={url} title={url} rel={relTags}>
343 <div className="thumbnail rounded bg-light d-flex justify-content-center">
344 <Icon icon="external-link" classes="d-flex align-items-center" />
352 className="text-body"
353 to={`/post/${post.id}`}
354 title={I18NextService.i18n.t("comments")}
356 <div className="thumbnail rounded bg-light d-flex justify-content-center">
357 <Icon icon="message-square" classes="d-flex align-items-center" />
365 const post_view = this.postView;
367 <ul className="list-inline mb-1 text-muted small mt-2">
368 <li className="list-inline-item">
369 <PersonListing person={post_view.creator} />
371 {this.creatorIsMod_ && (
372 <span className="mx-1 badge text-bg-light">
373 {I18NextService.i18n.t("mod")}
376 {this.creatorIsAdmin_ && (
377 <span className="mx-1 badge text-bg-light">
378 {I18NextService.i18n.t("admin")}
381 {post_view.creator.bot_account && (
382 <span className="mx-1 badge text-bg-light">
383 {I18NextService.i18n.t("bot_account").toLowerCase()}
386 {this.props.showCommunity && (
389 {I18NextService.i18n.t("to")}{" "}
390 <CommunityLink community={post_view.community} />
394 {post_view.post.language_id !== 0 && (
395 <span className="mx-1 badge text-bg-light">
397 this.props.allLanguages.find(
398 lang => lang.id === post_view.post.language_id
403 <li className="list-inline-item">•</li>
404 <li className="list-inline-item">
407 published={post_view.post.published}
408 updated={post_view.post.updated}
417 const post = this.postView.post;
420 className={`d-inline ${
421 !post.featured_community && !post.featured_local
425 to={`/post/${post.id}`}
426 title={I18NextService.i18n.t("comments")}
430 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
437 const post = this.postView.post;
438 const url = post.url;
442 <div className="post-title overflow-hidden">
443 <h5 className="d-inline">
444 {url && this.props.showBody ? (
447 !post.featured_community && !post.featured_local
454 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
460 {(url && isImage(url)) ||
461 (post.thumbnail_url && (
463 className="btn btn-sm text-monospace text-muted d-inline-block"
464 data-tippy-content={I18NextService.i18n.t("expand_here")}
465 onClick={linkEvent(this, this.handleImageExpandClick)}
469 !this.state.imageExpanded ? "plus-square" : "minus-square"
471 classes="icon-inline"
476 <small className="ms-2 badge text-bg-secondary">
477 {I18NextService.i18n.t("removed")}
482 className="unselectable pointer ms-2 text-muted font-italic"
483 data-tippy-content={I18NextService.i18n.t("deleted")}
485 <Icon icon="trash" classes="icon-inline text-danger" />
490 className="unselectable pointer ms-2 text-muted font-italic"
491 data-tippy-content={I18NextService.i18n.t("locked")}
493 <Icon icon="lock" classes="icon-inline text-danger" />
496 {post.featured_community && (
498 className="unselectable pointer ms-2 text-muted font-italic"
499 data-tippy-content={I18NextService.i18n.t(
500 "featured_in_community"
502 aria-label={I18NextService.i18n.t("featured_in_community")}
504 <Icon icon="pin" classes="icon-inline text-primary" />
507 {post.featured_local && (
509 className="unselectable pointer ms-2 text-muted font-italic"
510 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
511 aria-label={I18NextService.i18n.t("featured_in_local")}
513 <Icon icon="pin" classes="icon-inline text-secondary" />
517 <small className="ms-2 badge text-bg-danger">
518 {I18NextService.i18n.t("nsfw")}
522 {url && this.urlLine()}
528 const post = this.postView.post;
529 const url = post.url;
532 <p className="d-flex text-muted align-items-center gap-1 small m-0">
533 {url && !(hostname(url) === getExternalHost()) && (
535 className="text-muted font-italic"
548 const dupes = this.props.crossPosts;
549 return dupes && dupes.length > 0 ? (
550 <ul className="list-inline mb-1 small text-muted">
552 <li className="list-inline-item me-2">
553 {I18NextService.i18n.t("cross_posted_to")}
556 <li key={pv.post.id} className="list-inline-item me-2">
557 <Link to={`/post/${pv.post.id}`}>
560 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
571 commentsLine(mobile = false) {
572 const post = this.postView.post;
575 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
576 {this.commentsButton}
579 className="btn btn-sm btn-animate text-muted py-0"
580 onClick={linkEvent(this, this.handleShare)}
583 <Icon icon="share" inline />
588 className="btn btn-sm btn-animate text-muted py-0"
589 title={I18NextService.i18n.t("link")}
592 <Icon icon="fedilink" inline />
595 {mobile && !this.props.viewOnly && (
598 enableDownvotes={this.props.enableDownvotes}
599 handleUpvote={this.handleUpvote}
600 handleDownvote={this.handleDownvote}
601 counts={this.postView.counts}
602 my_vote={this.postView.my_vote}
605 {UserService.Instance.myUserInfo &&
606 !this.props.viewOnly &&
612 showPreviewButton() {
613 const post_view = this.postView;
614 const body = post_view.post.body;
618 className="btn btn-sm btn-animate text-muted py-0"
619 data-tippy-content={body && mdNoImages.render(body)}
620 data-tippy-allowHtml={true}
621 onClick={linkEvent(this, this.handleShowBody)}
625 classes={classNames("icon-inline me-1", {
626 "text-success": this.state.showBody,
634 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
635 // Possible enhancement: Make each button a component.
636 const post_view = this.postView;
637 const post = post_view.post;
644 * If there is a URL, or if the post has a body and we were told not to
645 * show the body, show the MetadataCard/body toggle.
647 {(post.url || (post.body && !this.props.showBody)) &&
648 this.showPreviewButton()}
650 {this.showBody && post_view.post.body && this.viewSourceButton}
652 <div className="dropdown">
654 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
655 onClick={linkEvent(this, this.handleShowAdvanced)}
656 data-tippy-content={I18NextService.i18n.t("more")}
657 data-bs-toggle="dropdown"
658 aria-expanded="false"
659 aria-controls="advancedButtonsDropdown"
660 aria-label={I18NextService.i18n.t("more")}
662 <Icon icon="more-vertical" inline />
665 <ul className="dropdown-menu" id="advancedButtonsDropdown">
666 <li>{this.crossPostButton}</li>
668 <hr className="dropdown-divider" />
673 <li>{this.reportButton}</li>
674 <li>{this.blockButton}</li>
678 <li>{this.editButton}</li>
679 <li>{this.deleteButton}</li>
683 {/* Any mod can do these, not limited to hierarchy*/}
684 {(amMod(this.props.moderators) || amAdmin()) && (
687 <hr className="dropdown-divider" />
689 <li>{this.lockButton}</li>
690 {this.featureButtons}
694 {(this.canMod_ || this.canAdmin_) && (
695 <li>{this.modRemoveButton}</li>
703 get commentsButton() {
704 const post_view = this.postView;
705 const title = I18NextService.i18n.t("number_of_comments", {
706 count: Number(post_view.counts.comments),
707 formattedCount: Number(post_view.counts.comments),
712 className="btn btn-link btn-sm text-muted ps-0"
714 to={`/post/${post_view.post.id}?scrollToComments=true`}
715 data-tippy-content={title}
717 <span className="me-1">
718 <Icon icon="message-square" classes="me-1" inline />
719 {post_view.counts.comments}
721 {this.unreadCount && (
722 <span className="text-muted fst-italic">
723 ({this.unreadCount} {I18NextService.i18n.t("new")})
730 get unreadCount(): number | undefined {
731 const pv = this.postView;
732 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
734 : pv.unread_comments;
738 const saved = this.postView.saved;
740 ? I18NextService.i18n.t("unsave")
741 : I18NextService.i18n.t("save");
744 className="btn btn-sm btn-animate text-muted py-0"
745 onClick={linkEvent(this, this.handleSavePostClick)}
746 data-tippy-content={label}
749 {this.state.saveLoading ? (
754 classes={classNames({ "text-warning": saved })}
762 get crossPostButton() {
765 className="btn btn-sm d-flex align-items-center rounded-0 dropdown-item"
767 /* Empty string properties are required to satisfy type*/
768 pathname: "/create_post",
769 state: { ...this.crossPostParams },
774 title={I18NextService.i18n.t("cross_post")}
775 data-tippy-content={I18NextService.i18n.t("cross_post")}
776 aria-label={I18NextService.i18n.t("cross_post")}
778 <Icon classes="me-1" icon="copy" inline />
779 {I18NextService.i18n.t("cross_post")}
787 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
788 onClick={linkEvent(this, this.handleShowReportDialog)}
789 aria-label={I18NextService.i18n.t("show_report_dialog")}
791 <Icon classes="me-1" icon="flag" inline />
792 {I18NextService.i18n.t("create_report")}
800 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
801 onClick={linkEvent(this, this.handleBlockPersonClick)}
802 aria-label={I18NextService.i18n.t("block_user")}
804 {this.state.blockLoading ? (
807 <Icon classes="me-1" icon="slash" inline />
809 {I18NextService.i18n.t("block_user")}
817 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
818 onClick={linkEvent(this, this.handleEditClick)}
819 aria-label={I18NextService.i18n.t("edit")}
821 <Icon classes="me-1" icon="edit" inline />
822 {I18NextService.i18n.t("edit")}
828 const deleted = this.postView.post.deleted;
829 const label = !deleted
830 ? I18NextService.i18n.t("delete")
831 : I18NextService.i18n.t("restore");
834 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
835 onClick={linkEvent(this, this.handleDeleteClick)}
837 {this.state.deleteLoading ? (
843 classes={classNames("me-1", { "text-danger": deleted })}
853 get viewSourceButton() {
856 className="btn btn-sm btn-animate text-muted py-0"
857 onClick={linkEvent(this, this.handleViewSource)}
858 data-tippy-content={I18NextService.i18n.t("view_source")}
859 aria-label={I18NextService.i18n.t("view_source")}
863 classes={classNames({ "text-success": this.state.viewSource })}
871 const locked = this.postView.post.locked;
873 ? I18NextService.i18n.t("unlock")
874 : I18NextService.i18n.t("lock");
877 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
878 onClick={linkEvent(this, this.handleModLock)}
881 {this.state.lockLoading ? (
887 classes={classNames("me-1", { "text-danger": locked })}
890 {capitalizeFirstLetter(label)}
897 get featureButtons() {
898 const featuredCommunity = this.postView.post.featured_community;
899 const labelCommunity = featuredCommunity
900 ? I18NextService.i18n.t("unfeature_from_community")
901 : I18NextService.i18n.t("feature_in_community");
903 const featuredLocal = this.postView.post.featured_local;
904 const labelLocal = featuredLocal
905 ? I18NextService.i18n.t("unfeature_from_local")
906 : I18NextService.i18n.t("feature_in_local");
911 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
912 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
913 data-tippy-content={labelCommunity}
914 aria-label={labelCommunity}
916 {this.state.featureCommunityLoading ? (
922 classes={classNames("me-1", {
923 "text-success": featuredCommunity,
927 {I18NextService.i18n.t("community")}
935 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
936 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
937 data-tippy-content={labelLocal}
938 aria-label={labelLocal}
940 {this.state.featureLocalLoading ? (
946 classes={classNames("me-1", {
947 "text-success": featuredLocal,
951 {I18NextService.i18n.t("local")}
961 get modRemoveButton() {
962 const removed = this.postView.post.removed;
965 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
968 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
971 {/* TODO: Find an icon for this. */}
972 {this.state.removeLoading ? (
975 I18NextService.i18n.t("remove")
977 I18NextService.i18n.t("restore")
984 * Mod/Admin actions to be taken against the author.
988 const post_view = this.postView;
990 this.state.showAdvanced && (
994 {!this.creatorIsMod_ &&
995 (!post_view.creator_banned_from_community ? (
997 className="btn btn-link btn-animate text-muted py-0"
1000 this.handleModBanFromCommunityShow
1002 aria-label={I18NextService.i18n.t("ban_from_community")}
1004 {I18NextService.i18n.t("ban_from_community")}
1008 className="btn btn-link btn-animate text-muted py-0"
1011 this.handleModBanFromCommunitySubmit
1013 aria-label={I18NextService.i18n.t("unban")}
1015 {this.state.banLoading ? (
1018 I18NextService.i18n.t("unban")
1022 {!post_view.creator_banned_from_community && (
1024 className="btn btn-link btn-animate text-muted py-0"
1025 onClick={linkEvent(this, this.handleAddModToCommunity)}
1028 ? I18NextService.i18n.t("remove_as_mod")
1029 : I18NextService.i18n.t("appoint_as_mod")
1032 {this.state.addModLoading ? (
1034 ) : this.creatorIsMod_ ? (
1035 I18NextService.i18n.t("remove_as_mod")
1037 I18NextService.i18n.t("appoint_as_mod")
1043 {/* Community creators and admins can transfer community to another mod */}
1044 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1046 this.creatorIsMod_ &&
1047 (!this.state.showConfirmTransferCommunity ? (
1049 className="btn btn-link btn-animate text-muted py-0"
1052 this.handleShowConfirmTransferCommunity
1054 aria-label={I18NextService.i18n.t("transfer_community")}
1056 {I18NextService.i18n.t("transfer_community")}
1061 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1062 aria-label={I18NextService.i18n.t("are_you_sure")}
1064 {I18NextService.i18n.t("are_you_sure")}
1067 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1068 aria-label={I18NextService.i18n.t("yes")}
1069 onClick={linkEvent(this, this.handleTransferCommunity)}
1071 {this.state.transferLoading ? (
1074 I18NextService.i18n.t("yes")
1078 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1081 this.handleCancelShowConfirmTransferCommunity
1083 aria-label={I18NextService.i18n.t("no")}
1085 {I18NextService.i18n.t("no")}
1089 {/* Admins can ban from all, and appoint other admins */}
1090 {this.canAdmin_ && (
1092 {!this.creatorIsAdmin_ && (
1094 {!isBanned(post_view.creator) ? (
1096 className="btn btn-link btn-animate text-muted py-0"
1097 onClick={linkEvent(this, this.handleModBanShow)}
1098 aria-label={I18NextService.i18n.t("ban_from_site")}
1100 {I18NextService.i18n.t("ban_from_site")}
1104 className="btn btn-link btn-animate text-muted py-0"
1105 onClick={linkEvent(this, this.handleModBanSubmit)}
1106 aria-label={I18NextService.i18n.t("unban_from_site")}
1108 {this.state.banLoading ? (
1111 I18NextService.i18n.t("unban_from_site")
1116 className="btn btn-link btn-animate text-muted py-0"
1117 onClick={linkEvent(this, this.handlePurgePersonShow)}
1118 aria-label={I18NextService.i18n.t("purge_user")}
1120 {I18NextService.i18n.t("purge_user")}
1123 className="btn btn-link btn-animate text-muted py-0"
1124 onClick={linkEvent(this, this.handlePurgePostShow)}
1125 aria-label={I18NextService.i18n.t("purge_post")}
1127 {I18NextService.i18n.t("purge_post")}
1131 {!isBanned(post_view.creator) && post_view.creator.local && (
1133 className="btn btn-link btn-animate text-muted py-0"
1134 onClick={linkEvent(this, this.handleAddAdmin)}
1136 this.creatorIsAdmin_
1137 ? I18NextService.i18n.t("remove_as_admin")
1138 : I18NextService.i18n.t("appoint_as_admin")
1141 {this.state.addAdminLoading ? (
1143 ) : this.creatorIsAdmin_ ? (
1144 I18NextService.i18n.t("remove_as_admin")
1146 I18NextService.i18n.t("appoint_as_admin")
1157 removeAndBanDialogs() {
1158 const post = this.postView;
1159 const purgeTypeText =
1160 this.state.purgeType == PurgeType.Post
1161 ? I18NextService.i18n.t("purge_post")
1162 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1165 {this.state.showRemoveDialog && (
1167 className="form-inline"
1168 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1171 className="visually-hidden"
1172 htmlFor="post-listing-remove-reason"
1174 {I18NextService.i18n.t("reason")}
1178 id="post-listing-remove-reason"
1179 className="form-control me-2"
1180 placeholder={I18NextService.i18n.t("reason")}
1181 value={this.state.removeReason}
1182 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1186 className="btn btn-secondary"
1187 aria-label={I18NextService.i18n.t("remove_post")}
1189 {this.state.removeLoading ? (
1192 I18NextService.i18n.t("remove_post")
1197 {this.state.showBanDialog && (
1198 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1199 <div className="mb-3 row col-12">
1201 className="col-form-label"
1202 htmlFor="post-listing-ban-reason"
1204 {I18NextService.i18n.t("reason")}
1208 id="post-listing-ban-reason"
1209 className="form-control me-2"
1210 placeholder={I18NextService.i18n.t("reason")}
1211 value={this.state.banReason}
1212 onInput={linkEvent(this, this.handleModBanReasonChange)}
1214 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1215 {I18NextService.i18n.t("expires")}
1219 id={`mod-ban-expires`}
1220 className="form-control me-2"
1221 placeholder={I18NextService.i18n.t("number_of_days")}
1222 value={this.state.banExpireDays}
1223 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1225 <div className="input-group mb-3">
1226 <div className="form-check">
1228 className="form-check-input"
1229 id="mod-ban-remove-data"
1231 checked={this.state.removeData}
1232 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1235 className="form-check-label"
1236 htmlFor="mod-ban-remove-data"
1237 title={I18NextService.i18n.t("remove_content_more")}
1239 {I18NextService.i18n.t("remove_content")}
1244 {/* TODO hold off on expires until later */}
1245 {/* <div class="mb-3 row"> */}
1246 {/* <label class="col-form-label">Expires</label> */}
1247 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1249 <div className="mb-3 row">
1252 className="btn btn-secondary"
1253 aria-label={I18NextService.i18n.t("ban")}
1255 {this.state.banLoading ? (
1259 {I18NextService.i18n.t("ban")} {post.creator.name}
1266 {this.state.showReportDialog && (
1268 className="form-inline"
1269 onSubmit={linkEvent(this, this.handleReportSubmit)}
1271 <label className="visually-hidden" htmlFor="post-report-reason">
1272 {I18NextService.i18n.t("reason")}
1276 id="post-report-reason"
1277 className="form-control me-2"
1278 placeholder={I18NextService.i18n.t("reason")}
1280 value={this.state.reportReason}
1281 onInput={linkEvent(this, this.handleReportReasonChange)}
1285 className="btn btn-secondary"
1286 aria-label={I18NextService.i18n.t("create_report")}
1288 {this.state.reportLoading ? (
1291 I18NextService.i18n.t("create_report")
1296 {this.state.showPurgeDialog && (
1298 className="form-inline"
1299 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1302 <label className="visually-hidden" htmlFor="purge-reason">
1303 {I18NextService.i18n.t("reason")}
1308 className="form-control me-2"
1309 placeholder={I18NextService.i18n.t("reason")}
1310 value={this.state.purgeReason}
1311 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1313 {this.state.purgeLoading ? (
1318 className="btn btn-secondary"
1319 aria-label={purgeTypeText}
1321 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1331 const post = this.postView.post;
1332 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1333 <div className="row">
1334 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1335 {this.postTitleLine()}
1337 <div className="col-4">
1338 {/* Post thumbnail */}
1339 {!this.state.imageExpanded && this.thumbnail()}
1343 this.postTitleLine()
1348 const { body, id } = this.postView.post;
1350 return !this.showBody && body ? (
1351 <Link className="text-body" to={`/post/${id}`}>
1352 <div className="md-div mb-1 preview-lines">{body}</div>
1362 {/* The mobile view*/}
1363 <div className="d-block d-sm-none">
1364 <article className="row post-container">
1365 <div className="col-12">
1366 {this.createdLine()}
1368 {/* If it has a thumbnail, do a right aligned thumbnail */}
1369 {this.mobileThumbnail()}
1371 <div className="mt-2">
1372 {this.bodyPreview()}
1373 {this.commentsLine(true)}
1375 {this.userActionsLine()}
1376 {this.duplicatesLine()}
1377 {this.removeAndBanDialogs()}
1382 {/* The larger view*/}
1383 <div className="d-none d-sm-block">
1384 <article className="row post-container">
1385 {!this.props.viewOnly && (
1388 enableDownvotes={this.props.enableDownvotes}
1389 handleUpvote={this.handleUpvote}
1390 handleDownvote={this.handleDownvote}
1391 counts={this.postView.counts}
1392 my_vote={this.postView.my_vote}
1395 <div className="col-sm-2 pe-0 post-media">
1396 <div className="">{this.thumbnail()}</div>
1398 <div className="col-12 col-sm-9">
1399 <div className="row">
1400 <div className="col-12">
1401 {this.postTitleLine()}
1402 {this.createdLine()}
1403 {this.bodyPreview()}
1404 {this.commentsLine()}
1405 {this.duplicatesLine()}
1406 {this.userActionsLine()}
1407 {this.removeAndBanDialogs()}
1417 private get myPost(): boolean {
1419 this.postView.creator.id ==
1420 UserService.Instance.myUserInfo?.local_user_view.person.id
1423 handleEditClick(i: PostListing) {
1424 i.setState({ showEdit: true });
1427 handleEditCancel() {
1428 this.setState({ showEdit: false });
1431 // The actual editing is done in the receive for post
1432 handleEditPost(form: EditPost) {
1433 this.setState({ showEdit: false });
1434 this.props.onPostEdit(form);
1437 handleShare(i: PostListing) {
1438 const { name, body, id } = i.props.post_view.post;
1441 text: body?.slice(0, 50),
1442 url: `${getHttpBase()}/post/${id}`,
1446 handleShowReportDialog(i: PostListing) {
1447 i.setState({ showReportDialog: !i.state.showReportDialog });
1450 handleReportReasonChange(i: PostListing, event: any) {
1451 i.setState({ reportReason: event.target.value });
1454 handleReportSubmit(i: PostListing, event: any) {
1455 event.preventDefault();
1456 i.setState({ reportLoading: true });
1457 i.props.onPostReport({
1458 post_id: i.postView.post.id,
1459 reason: i.state.reportReason ?? "",
1460 auth: myAuthRequired(),
1464 handleBlockPersonClick(i: PostListing) {
1465 i.setState({ blockLoading: true });
1466 i.props.onBlockPerson({
1467 person_id: i.postView.creator.id,
1469 auth: myAuthRequired(),
1473 handleDeleteClick(i: PostListing) {
1474 i.setState({ deleteLoading: true });
1475 i.props.onDeletePost({
1476 post_id: i.postView.post.id,
1477 deleted: !i.postView.post.deleted,
1478 auth: myAuthRequired(),
1482 handleSavePostClick(i: PostListing) {
1483 i.setState({ saveLoading: true });
1484 i.props.onSavePost({
1485 post_id: i.postView.post.id,
1486 save: !i.postView.saved,
1487 auth: myAuthRequired(),
1491 get crossPostParams(): PostFormParams {
1492 const queryParams: PostFormParams = {};
1493 const { name, url } = this.postView.post;
1495 queryParams.name = name;
1498 queryParams.url = url;
1501 const crossPostBody = this.crossPostBody();
1502 if (crossPostBody) {
1503 queryParams.body = crossPostBody;
1509 crossPostBody(): string | undefined {
1510 const post = this.postView.post;
1511 const body = post.body;
1514 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1516 }\n\n${body.replace(/^/gm, "> ")}`
1520 get showBody(): boolean {
1521 return this.props.showBody || this.state.showBody;
1524 handleModRemoveShow(i: PostListing) {
1526 showRemoveDialog: !i.state.showRemoveDialog,
1527 showBanDialog: false,
1531 handleModRemoveReasonChange(i: PostListing, event: any) {
1532 i.setState({ removeReason: event.target.value });
1535 handleModRemoveDataChange(i: PostListing, event: any) {
1536 i.setState({ removeData: event.target.checked });
1539 handleModRemoveSubmit(i: PostListing, event: any) {
1540 event.preventDefault();
1541 i.setState({ removeLoading: true });
1542 i.props.onRemovePost({
1543 post_id: i.postView.post.id,
1544 removed: !i.postView.post.removed,
1545 auth: myAuthRequired(),
1549 handleModLock(i: PostListing) {
1550 i.setState({ lockLoading: true });
1551 i.props.onLockPost({
1552 post_id: i.postView.post.id,
1553 locked: !i.postView.post.locked,
1554 auth: myAuthRequired(),
1558 handleModFeaturePostLocal(i: PostListing) {
1559 i.setState({ featureLocalLoading: true });
1560 i.props.onFeaturePost({
1561 post_id: i.postView.post.id,
1562 featured: !i.postView.post.featured_local,
1563 feature_type: "Local",
1564 auth: myAuthRequired(),
1568 handleModFeaturePostCommunity(i: PostListing) {
1569 i.setState({ featureCommunityLoading: true });
1570 i.props.onFeaturePost({
1571 post_id: i.postView.post.id,
1572 featured: !i.postView.post.featured_community,
1573 feature_type: "Community",
1574 auth: myAuthRequired(),
1578 handleModBanFromCommunityShow(i: PostListing) {
1580 showBanDialog: true,
1581 banType: BanType.Community,
1582 showRemoveDialog: false,
1586 handleModBanShow(i: PostListing) {
1588 showBanDialog: true,
1589 banType: BanType.Site,
1590 showRemoveDialog: false,
1594 handlePurgePersonShow(i: PostListing) {
1596 showPurgeDialog: true,
1597 purgeType: PurgeType.Person,
1598 showRemoveDialog: false,
1602 handlePurgePostShow(i: PostListing) {
1604 showPurgeDialog: true,
1605 purgeType: PurgeType.Post,
1606 showRemoveDialog: false,
1610 handlePurgeReasonChange(i: PostListing, event: any) {
1611 i.setState({ purgeReason: event.target.value });
1614 handlePurgeSubmit(i: PostListing, event: any) {
1615 event.preventDefault();
1616 i.setState({ purgeLoading: true });
1617 if (i.state.purgeType == PurgeType.Person) {
1618 i.props.onPurgePerson({
1619 person_id: i.postView.creator.id,
1620 reason: i.state.purgeReason,
1621 auth: myAuthRequired(),
1623 } else if (i.state.purgeType == PurgeType.Post) {
1624 i.props.onPurgePost({
1625 post_id: i.postView.post.id,
1626 reason: i.state.purgeReason,
1627 auth: myAuthRequired(),
1632 handleModBanReasonChange(i: PostListing, event: any) {
1633 i.setState({ banReason: event.target.value });
1636 handleModBanExpireDaysChange(i: PostListing, event: any) {
1637 i.setState({ banExpireDays: event.target.value });
1640 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1641 i.setState({ banType: BanType.Community });
1642 i.handleModBanBothSubmit(i, event);
1645 handleModBanSubmit(i: PostListing, event: any) {
1646 i.setState({ banType: BanType.Site });
1647 i.handleModBanBothSubmit(i, event);
1650 handleModBanBothSubmit(i: PostListing, event: any) {
1651 event.preventDefault();
1652 i.setState({ banLoading: true });
1654 const ban = !i.props.post_view.creator_banned_from_community;
1655 // If its an unban, restore all their data
1657 i.setState({ removeData: false });
1659 const person_id = i.props.post_view.creator.id;
1660 const remove_data = i.state.removeData;
1661 const reason = i.state.banReason;
1662 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1664 if (i.state.banType == BanType.Community) {
1665 const community_id = i.postView.community.id;
1666 i.props.onBanPersonFromCommunity({
1673 auth: myAuthRequired(),
1676 i.props.onBanPerson({
1682 auth: myAuthRequired(),
1687 handleAddModToCommunity(i: PostListing) {
1688 i.setState({ addModLoading: true });
1689 i.props.onAddModToCommunity({
1690 community_id: i.postView.community.id,
1691 person_id: i.postView.creator.id,
1692 added: !i.creatorIsMod_,
1693 auth: myAuthRequired(),
1697 handleAddAdmin(i: PostListing) {
1698 i.setState({ addAdminLoading: true });
1699 i.props.onAddAdmin({
1700 person_id: i.postView.creator.id,
1701 added: !i.creatorIsAdmin_,
1702 auth: myAuthRequired(),
1706 handleShowConfirmTransferCommunity(i: PostListing) {
1707 i.setState({ showConfirmTransferCommunity: true });
1710 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1711 i.setState({ showConfirmTransferCommunity: false });
1714 handleTransferCommunity(i: PostListing) {
1715 i.setState({ transferLoading: true });
1716 i.props.onTransferCommunity({
1717 community_id: i.postView.community.id,
1718 person_id: i.postView.creator.id,
1719 auth: myAuthRequired(),
1723 handleShowConfirmTransferSite(i: PostListing) {
1724 i.setState({ showConfirmTransferSite: true });
1727 handleCancelShowConfirmTransferSite(i: PostListing) {
1728 i.setState({ showConfirmTransferSite: false });
1731 handleImageExpandClick(i: PostListing, event: any) {
1732 event.preventDefault();
1733 i.setState({ imageExpanded: !i.state.imageExpanded });
1737 handleViewSource(i: PostListing) {
1738 i.setState({ viewSource: !i.state.viewSource });
1741 handleShowAdvanced(i: PostListing) {
1742 i.setState({ showAdvanced: !i.state.showAdvanced });
1746 handleShowMoreMobile(i: PostListing) {
1748 showMoreMobile: !i.state.showMoreMobile,
1749 showAdvanced: !i.state.showAdvanced,
1754 handleShowBody(i: PostListing) {
1755 i.setState({ showBody: !i.state.showBody });
1759 handleUpvote(i: PostListing) {
1760 i.setState({ upvoteLoading: true });
1761 i.props.onPostVote({
1762 post_id: i.postView.post.id,
1763 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1764 auth: myAuthRequired(),
1768 handleDownvote(i: PostListing) {
1769 i.setState({ downvoteLoading: true });
1770 i.props.onPostVote({
1771 post_id: i.postView.post.id,
1772 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1773 auth: myAuthRequired(),
1777 get pointsTippy(): string {
1778 const points = I18NextService.i18n.t("number_of_points", {
1779 count: Number(this.postView.counts.score),
1780 formattedCount: Number(this.postView.counts.score),
1783 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1784 count: Number(this.postView.counts.upvotes),
1785 formattedCount: Number(this.postView.counts.upvotes),
1788 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1789 count: Number(this.postView.counts.downvotes),
1790 formattedCount: Number(this.postView.counts.downvotes),
1793 return `${points} • ${upvotes} • ${downvotes}`;
1796 get canModOnSelf_(): boolean {
1798 this.postView.creator.id,
1799 this.props.moderators,
1806 get canMod_(): boolean {
1808 this.postView.creator.id,
1809 this.props.moderators,
1814 get canAdmin_(): boolean {
1815 return canAdmin(this.postView.creator.id, this.props.admins);
1818 get creatorIsMod_(): boolean {
1819 return isMod(this.postView.creator.id, this.props.moderators);
1822 get creatorIsAdmin_(): boolean {
1823 return isAdmin(this.postView.creator.id, this.props.admins);