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";
46 import { BanType, PostFormParams, PurgeType } 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 reportLoading: boolean;
82 blockLoading: boolean;
84 deleteLoading: boolean;
85 removeLoading: boolean;
87 featureCommunityLoading: boolean;
88 featureLocalLoading: boolean;
90 addModLoading: boolean;
91 addAdminLoading: boolean;
92 transferLoading: boolean;
95 interface PostListingProps {
97 crossPosts?: PostView[];
98 moderators?: CommunityModeratorView[];
99 admins?: PersonView[];
100 allLanguages: Language[];
101 siteLanguages: number[];
102 showCommunity?: boolean;
105 enableDownvotes?: boolean;
106 enableNsfw?: boolean;
108 onPostEdit(form: EditPost): void;
109 onPostVote(form: CreatePostLike): void;
110 onPostReport(form: CreatePostReport): void;
111 onBlockPerson(form: BlockPerson): void;
112 onLockPost(form: LockPost): void;
113 onDeletePost(form: DeletePost): void;
114 onRemovePost(form: RemovePost): void;
115 onSavePost(form: SavePost): void;
116 onFeaturePost(form: FeaturePost): void;
117 onPurgePerson(form: PurgePerson): void;
118 onPurgePost(form: PurgePost): void;
119 onBanPersonFromCommunity(form: BanFromCommunity): void;
120 onBanPerson(form: BanPerson): void;
121 onAddModToCommunity(form: AddModToCommunity): void;
122 onAddAdmin(form: AddAdmin): void;
123 onTransferCommunity(form: TransferCommunity): void;
126 export class PostListing extends Component<PostListingProps, PostListingState> {
127 state: PostListingState = {
129 showRemoveDialog: false,
130 showPurgeDialog: false,
131 purgeType: PurgeType.Person,
132 showBanDialog: false,
133 banType: BanType.Community,
135 showConfirmTransferSite: false,
136 showConfirmTransferCommunity: false,
137 imageExpanded: false,
140 showMoreMobile: false,
142 showReportDialog: false,
144 reportLoading: false,
147 deleteLoading: false,
148 removeLoading: false,
150 featureCommunityLoading: false,
151 featureLocalLoading: false,
153 addModLoading: false,
154 addAdminLoading: false,
155 transferLoading: false,
158 constructor(props: any, context: any) {
159 super(props, context);
161 this.handleEditPost = this.handleEditPost.bind(this);
162 this.handleEditCancel = this.handleEditCancel.bind(this);
165 componentWillReceiveProps(nextProps: PostListingProps) {
166 if (this.props !== nextProps) {
169 reportLoading: false,
172 deleteLoading: false,
173 removeLoading: false,
175 featureCommunityLoading: false,
176 featureLocalLoading: false,
178 addModLoading: false,
179 addAdminLoading: false,
180 transferLoading: false,
181 imageExpanded: false,
186 get postView(): PostView {
187 return this.props.post_view;
191 const post = this.postView.post;
194 <div className="post-listing mt-2">
195 {!this.state.showEdit ? (
198 {this.state.imageExpanded && !this.props.hideImage && this.img}
199 {post.url && this.state.showBody && post.embed_title && (
200 <MetadataCard post={post} />
202 {this.showBody && this.body()}
206 post_view={this.postView}
207 crossPosts={this.props.crossPosts}
208 onEdit={this.handleEditPost}
209 onCancel={this.handleEditCancel}
210 enableNsfw={this.props.enableNsfw}
211 enableDownvotes={this.props.enableDownvotes}
212 allLanguages={this.props.allLanguages}
213 siteLanguages={this.props.siteLanguages}
221 const body = this.postView.post.body;
223 <article id="postContent" className="col-12 card my-2 p-2">
224 {this.state.viewSource ? (
227 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
239 <div className="offset-sm-3 my-2 d-none d-sm-block">
240 <a href={this.imageSrc} className="d-inline-block">
241 <PictrsImage src={this.imageSrc} />
244 <div className="my-2 d-block d-sm-none">
246 className="d-inline-block"
247 onClick={linkEvent(this, this.handleImageExpandClick)}
249 <PictrsImage src={this.imageSrc} />
256 const { post } = this.postView;
257 const { url } = post;
259 if (url && isVideo(url)) {
261 <div className="embed-responsive mt-3">
262 <video muted controls className="embed-responsive-item col-12">
263 <source src={url} type="video/mp4" />
272 imgThumb(src: string) {
273 const post_view = this.postView;
279 nsfw={post_view.post.nsfw || post_view.community.nsfw}
284 get imageSrc(): string | undefined {
285 const post = this.postView.post;
286 const url = post.url;
287 const thumbnail = post.thumbnail_url;
289 if (url && isImage(url)) {
290 if (url.includes("pictrs")) {
292 } else if (thumbnail) {
297 } else if (thumbnail) {
305 const post = this.postView.post;
306 const url = post.url;
307 const thumbnail = post.thumbnail_url;
309 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
313 className="text-body d-inline-block position-relative mb-2"
314 data-tippy-content={I18NextService.i18n.t("expand_here")}
315 onClick={linkEvent(this, this.handleImageExpandClick)}
316 aria-label={I18NextService.i18n.t("expand_here")}
318 {this.imgThumb(this.imageSrc)}
319 <Icon icon="image" classes="mini-overlay" />
322 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
325 className="text-body d-inline-block position-relative mb-2"
330 {this.imgThumb(this.imageSrc)}
331 <Icon icon="external-link" classes="mini-overlay" />
335 if (!this.props.hideImage && isVideo(url)) {
338 className="text-body"
342 data-tippy-content={I18NextService.i18n.t("expand_here")}
343 onClick={linkEvent(this, this.handleImageExpandClick)}
344 aria-label={I18NextService.i18n.t("expand_here")}
346 <div className="thumbnail rounded bg-light d-flex justify-content-center">
347 <Icon icon="play" classes="d-flex align-items-center" />
353 <a className="text-body" href={url} title={url} rel={relTags}>
354 <div className="thumbnail rounded bg-light d-flex justify-content-center">
355 <Icon icon="external-link" classes="d-flex align-items-center" />
363 className="text-body"
364 to={`/post/${post.id}`}
365 title={I18NextService.i18n.t("comments")}
367 <div className="thumbnail rounded bg-light d-flex justify-content-center">
368 <Icon icon="message-square" classes="d-flex align-items-center" />
376 const post_view = this.postView;
378 <span className="small">
379 <PersonListing person={post_view.creator} />
380 {this.creatorIsMod_ && (
381 <span className="mx-1 badge text-bg-light">
382 {I18NextService.i18n.t("mod")}
385 {this.creatorIsAdmin_ && (
386 <span className="mx-1 badge text-bg-light">
387 {I18NextService.i18n.t("admin")}
390 {post_view.creator.bot_account && (
391 <span className="mx-1 badge text-bg-light">
392 {I18NextService.i18n.t("bot_account").toLowerCase()}
395 {this.props.showCommunity && (
398 {I18NextService.i18n.t("to")}{" "}
399 <CommunityLink community={post_view.community} />
402 {post_view.post.language_id !== 0 && (
403 <span className="mx-1 badge text-bg-light">
405 this.props.allLanguages.find(
406 lang => lang.id === post_view.post.language_id
413 published={post_view.post.published}
414 updated={post_view.post.updated}
421 const post = this.postView.post;
424 className={`d-inline ${
425 !post.featured_community && !post.featured_local
429 to={`/post/${post.id}`}
430 title={I18NextService.i18n.t("comments")}
434 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
441 const post = this.postView.post;
442 const url = post.url;
446 <div className="post-title overflow-hidden">
447 <h5 className="d-inline">
448 {url && this.props.showBody ? (
451 !post.featured_community && !post.featured_local
458 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
464 {(url && isImage(url)) ||
465 (post.thumbnail_url && (
467 className="btn btn-sm text-monospace text-muted d-inline-block"
468 data-tippy-content={I18NextService.i18n.t("expand_here")}
469 onClick={linkEvent(this, this.handleImageExpandClick)}
473 !this.state.imageExpanded ? "plus-square" : "minus-square"
475 classes="icon-inline"
480 <small className="ms-2 badge text-bg-secondary">
481 {I18NextService.i18n.t("removed")}
486 className="unselectable pointer ms-2 text-muted font-italic"
487 data-tippy-content={I18NextService.i18n.t("deleted")}
489 <Icon icon="trash" classes="icon-inline text-danger" />
494 className="unselectable pointer ms-2 text-muted font-italic"
495 data-tippy-content={I18NextService.i18n.t("locked")}
497 <Icon icon="lock" classes="icon-inline text-danger" />
500 {post.featured_community && (
502 className="unselectable pointer ms-2 text-muted font-italic"
503 data-tippy-content={I18NextService.i18n.t(
504 "featured_in_community"
506 aria-label={I18NextService.i18n.t("featured_in_community")}
508 <Icon icon="pin" classes="icon-inline text-primary" />
511 {post.featured_local && (
513 className="unselectable pointer ms-2 text-muted font-italic"
514 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
515 aria-label={I18NextService.i18n.t("featured_in_local")}
517 <Icon icon="pin" classes="icon-inline text-secondary" />
521 <small className="ms-2 badge text-bg-danger">
522 {I18NextService.i18n.t("nsfw")}
526 {url && this.urlLine()}
532 const post = this.postView.post;
533 const url = post.url;
536 <p className="d-flex text-muted align-items-center gap-1 small m-0">
537 {url && !(hostname(url) === getExternalHost()) && (
539 className="text-muted font-italic"
552 const dupes = this.props.crossPosts;
553 return dupes && dupes.length > 0 ? (
554 <ul className="list-inline mb-1 small text-muted">
556 <li className="list-inline-item me-2">
557 {I18NextService.i18n.t("cross_posted_to")}
560 <li key={pv.post.id} className="list-inline-item me-2">
561 <Link to={`/post/${pv.post.id}`}>
564 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
575 commentsLine(mobile = false) {
576 const post = this.postView.post;
579 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
580 {this.commentsButton}
583 className="btn btn-sm btn-animate text-muted py-0"
584 onClick={linkEvent(this, this.handleShare)}
587 <Icon icon="share" inline />
592 className="btn btn-sm btn-animate text-muted py-0"
593 title={I18NextService.i18n.t("link")}
596 <Icon icon="fedilink" inline />
599 {mobile && !this.props.viewOnly && (
601 id={this.postView.post.id}
602 onVote={this.props.onPostVote}
604 enableDownvotes={this.props.enableDownvotes}
605 counts={this.postView.counts}
606 my_vote={this.postView.my_vote}
609 {UserService.Instance.myUserInfo &&
610 !this.props.viewOnly &&
616 showPreviewButton() {
617 const post_view = this.postView;
618 const body = post_view.post.body;
622 className="btn btn-sm btn-animate text-muted py-0"
623 data-tippy-content={body && mdNoImages.render(body)}
624 data-tippy-allowHtml={true}
625 onClick={linkEvent(this, this.handleShowBody)}
629 classes={classNames("icon-inline me-1", {
630 "text-success": this.state.showBody,
638 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
639 // Possible enhancement: Make each button a component.
640 const post_view = this.postView;
641 const post = post_view.post;
646 {this.crossPostButton}
649 * If there is a URL, or if the post has a body and we were told not to
650 * show the body, show the MetadataCard/body toggle.
652 {(post.url || (post.body && !this.props.showBody)) &&
653 this.showPreviewButton()}
655 {this.showBody && post_view.post.body && this.viewSourceButton}
657 <div className="dropdown">
659 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
660 onClick={linkEvent(this, this.handleShowAdvanced)}
661 data-tippy-content={I18NextService.i18n.t("more")}
662 data-bs-toggle="dropdown"
663 aria-expanded="false"
664 aria-controls="advancedButtonsDropdown"
665 aria-label={I18NextService.i18n.t("more")}
667 <Icon icon="more-vertical" inline />
670 <ul className="dropdown-menu" id="advancedButtonsDropdown">
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 <Icon icon="message-square" classes="me-1" inline />
718 {post_view.counts.comments}
719 {this.unreadCount && (
720 <span className="text-muted fst-italic">
721 ({this.unreadCount} {I18NextService.i18n.t("new")})
728 get unreadCount(): number | undefined {
729 const pv = this.postView;
730 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
732 : pv.unread_comments;
736 const saved = this.postView.saved;
738 ? I18NextService.i18n.t("unsave")
739 : I18NextService.i18n.t("save");
742 className="btn btn-sm btn-animate text-muted py-0"
743 onClick={linkEvent(this, this.handleSavePostClick)}
744 data-tippy-content={label}
747 {this.state.saveLoading ? (
752 classes={classNames({ "text-warning": saved })}
760 get crossPostButton() {
763 className="btn btn-sm btn-animate text-muted py-0"
765 /* Empty string properties are required to satisfy type*/
766 pathname: "/create_post",
767 state: { ...this.crossPostParams },
772 title={I18NextService.i18n.t("cross_post")}
773 data-tippy-content={I18NextService.i18n.t("cross_post")}
774 aria-label={I18NextService.i18n.t("cross_post")}
776 <Icon icon="copy" inline />
784 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
785 onClick={linkEvent(this, this.handleShowReportDialog)}
786 aria-label={I18NextService.i18n.t("show_report_dialog")}
788 <Icon classes="me-1" icon="flag" inline />
789 {I18NextService.i18n.t("create_report")}
797 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
798 onClick={linkEvent(this, this.handleBlockPersonClick)}
799 aria-label={I18NextService.i18n.t("block_user")}
801 {this.state.blockLoading ? (
804 <Icon classes="me-1" icon="slash" inline />
806 {I18NextService.i18n.t("block_user")}
814 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
815 onClick={linkEvent(this, this.handleEditClick)}
816 aria-label={I18NextService.i18n.t("edit")}
818 <Icon classes="me-1" icon="edit" inline />
819 {I18NextService.i18n.t("edit")}
825 const deleted = this.postView.post.deleted;
826 const label = !deleted
827 ? I18NextService.i18n.t("delete")
828 : I18NextService.i18n.t("restore");
831 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
832 onClick={linkEvent(this, this.handleDeleteClick)}
834 {this.state.deleteLoading ? (
840 classes={classNames("me-1", { "text-danger": deleted })}
850 get viewSourceButton() {
853 className="btn btn-sm btn-animate text-muted py-0"
854 onClick={linkEvent(this, this.handleViewSource)}
855 data-tippy-content={I18NextService.i18n.t("view_source")}
856 aria-label={I18NextService.i18n.t("view_source")}
860 classes={classNames({ "text-success": this.state.viewSource })}
868 const locked = this.postView.post.locked;
870 ? I18NextService.i18n.t("unlock")
871 : I18NextService.i18n.t("lock");
874 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
875 onClick={linkEvent(this, this.handleModLock)}
878 {this.state.lockLoading ? (
884 classes={classNames("me-1", { "text-danger": locked })}
887 {capitalizeFirstLetter(label)}
894 get featureButtons() {
895 const featuredCommunity = this.postView.post.featured_community;
896 const labelCommunity = featuredCommunity
897 ? I18NextService.i18n.t("unfeature_from_community")
898 : I18NextService.i18n.t("feature_in_community");
900 const featuredLocal = this.postView.post.featured_local;
901 const labelLocal = featuredLocal
902 ? I18NextService.i18n.t("unfeature_from_local")
903 : I18NextService.i18n.t("feature_in_local");
908 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
909 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
910 data-tippy-content={labelCommunity}
911 aria-label={labelCommunity}
913 {this.state.featureCommunityLoading ? (
919 classes={classNames("me-1", {
920 "text-success": featuredCommunity,
924 {I18NextService.i18n.t("community")}
932 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
933 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
934 data-tippy-content={labelLocal}
935 aria-label={labelLocal}
937 {this.state.featureLocalLoading ? (
943 classes={classNames("me-1", {
944 "text-success": featuredLocal,
948 {I18NextService.i18n.t("local")}
958 get modRemoveButton() {
959 const removed = this.postView.post.removed;
962 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
965 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
968 {/* TODO: Find an icon for this. */}
969 {this.state.removeLoading ? (
972 I18NextService.i18n.t("remove")
974 I18NextService.i18n.t("restore")
981 * Mod/Admin actions to be taken against the author.
985 const post_view = this.postView;
987 this.state.showAdvanced && (
988 <div className="mt-3">
991 {!this.creatorIsMod_ &&
992 (!post_view.creator_banned_from_community ? (
994 className="btn btn-link btn-animate text-muted py-0"
997 this.handleModBanFromCommunityShow
999 aria-label={I18NextService.i18n.t("ban_from_community")}
1001 {I18NextService.i18n.t("ban_from_community")}
1005 className="btn btn-link btn-animate text-muted py-0"
1008 this.handleModBanFromCommunitySubmit
1010 aria-label={I18NextService.i18n.t("unban")}
1012 {this.state.banLoading ? (
1015 I18NextService.i18n.t("unban")
1019 {!post_view.creator_banned_from_community && (
1021 className="btn btn-link btn-animate text-muted py-0"
1022 onClick={linkEvent(this, this.handleAddModToCommunity)}
1025 ? I18NextService.i18n.t("remove_as_mod")
1026 : I18NextService.i18n.t("appoint_as_mod")
1029 {this.state.addModLoading ? (
1031 ) : this.creatorIsMod_ ? (
1032 I18NextService.i18n.t("remove_as_mod")
1034 I18NextService.i18n.t("appoint_as_mod")
1040 {/* Community creators and admins can transfer community to another mod */}
1041 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1043 this.creatorIsMod_ &&
1044 (!this.state.showConfirmTransferCommunity ? (
1046 className="btn btn-link btn-animate text-muted py-0"
1049 this.handleShowConfirmTransferCommunity
1051 aria-label={I18NextService.i18n.t("transfer_community")}
1053 {I18NextService.i18n.t("transfer_community")}
1058 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1059 aria-label={I18NextService.i18n.t("are_you_sure")}
1061 {I18NextService.i18n.t("are_you_sure")}
1064 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1065 aria-label={I18NextService.i18n.t("yes")}
1066 onClick={linkEvent(this, this.handleTransferCommunity)}
1068 {this.state.transferLoading ? (
1071 I18NextService.i18n.t("yes")
1075 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1078 this.handleCancelShowConfirmTransferCommunity
1080 aria-label={I18NextService.i18n.t("no")}
1082 {I18NextService.i18n.t("no")}
1086 {/* Admins can ban from all, and appoint other admins */}
1087 {this.canAdmin_ && (
1089 {!this.creatorIsAdmin_ && (
1091 {!isBanned(post_view.creator) ? (
1093 className="btn btn-link btn-animate text-muted py-0"
1094 onClick={linkEvent(this, this.handleModBanShow)}
1095 aria-label={I18NextService.i18n.t("ban_from_site")}
1097 {I18NextService.i18n.t("ban_from_site")}
1101 className="btn btn-link btn-animate text-muted py-0"
1102 onClick={linkEvent(this, this.handleModBanSubmit)}
1103 aria-label={I18NextService.i18n.t("unban_from_site")}
1105 {this.state.banLoading ? (
1108 I18NextService.i18n.t("unban_from_site")
1113 className="btn btn-link btn-animate text-muted py-0"
1114 onClick={linkEvent(this, this.handlePurgePersonShow)}
1115 aria-label={I18NextService.i18n.t("purge_user")}
1117 {I18NextService.i18n.t("purge_user")}
1120 className="btn btn-link btn-animate text-muted py-0"
1121 onClick={linkEvent(this, this.handlePurgePostShow)}
1122 aria-label={I18NextService.i18n.t("purge_post")}
1124 {I18NextService.i18n.t("purge_post")}
1128 {!isBanned(post_view.creator) && post_view.creator.local && (
1130 className="btn btn-link btn-animate text-muted py-0"
1131 onClick={linkEvent(this, this.handleAddAdmin)}
1133 this.creatorIsAdmin_
1134 ? I18NextService.i18n.t("remove_as_admin")
1135 : I18NextService.i18n.t("appoint_as_admin")
1138 {this.state.addAdminLoading ? (
1140 ) : this.creatorIsAdmin_ ? (
1141 I18NextService.i18n.t("remove_as_admin")
1143 I18NextService.i18n.t("appoint_as_admin")
1154 removeAndBanDialogs() {
1155 const post = this.postView;
1156 const purgeTypeText =
1157 this.state.purgeType == PurgeType.Post
1158 ? I18NextService.i18n.t("purge_post")
1159 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1162 {this.state.showRemoveDialog && (
1164 className="form-inline"
1165 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1168 className="visually-hidden"
1169 htmlFor="post-listing-remove-reason"
1171 {I18NextService.i18n.t("reason")}
1175 id="post-listing-remove-reason"
1176 className="form-control me-2"
1177 placeholder={I18NextService.i18n.t("reason")}
1178 value={this.state.removeReason}
1179 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1183 className="btn btn-secondary"
1184 aria-label={I18NextService.i18n.t("remove_post")}
1186 {this.state.removeLoading ? (
1189 I18NextService.i18n.t("remove_post")
1194 {this.state.showBanDialog && (
1195 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1196 <div className="mb-3 row col-12">
1198 className="col-form-label"
1199 htmlFor="post-listing-ban-reason"
1201 {I18NextService.i18n.t("reason")}
1205 id="post-listing-ban-reason"
1206 className="form-control me-2"
1207 placeholder={I18NextService.i18n.t("reason")}
1208 value={this.state.banReason}
1209 onInput={linkEvent(this, this.handleModBanReasonChange)}
1211 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1212 {I18NextService.i18n.t("expires")}
1216 id={`mod-ban-expires`}
1217 className="form-control me-2"
1218 placeholder={I18NextService.i18n.t("number_of_days")}
1219 value={this.state.banExpireDays}
1220 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1222 <div className="input-group mb-3">
1223 <div className="form-check">
1225 className="form-check-input"
1226 id="mod-ban-remove-data"
1228 checked={this.state.removeData}
1229 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1232 className="form-check-label"
1233 htmlFor="mod-ban-remove-data"
1234 title={I18NextService.i18n.t("remove_content_more")}
1236 {I18NextService.i18n.t("remove_content")}
1241 {/* TODO hold off on expires until later */}
1242 {/* <div class="mb-3 row"> */}
1243 {/* <label class="col-form-label">Expires</label> */}
1244 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1246 <div className="mb-3 row">
1249 className="btn btn-secondary"
1250 aria-label={I18NextService.i18n.t("ban")}
1252 {this.state.banLoading ? (
1256 {I18NextService.i18n.t("ban")} {post.creator.name}
1263 {this.state.showReportDialog && (
1265 className="form-inline"
1266 onSubmit={linkEvent(this, this.handleReportSubmit)}
1268 <label className="visually-hidden" htmlFor="post-report-reason">
1269 {I18NextService.i18n.t("reason")}
1273 id="post-report-reason"
1274 className="form-control me-2"
1275 placeholder={I18NextService.i18n.t("reason")}
1277 value={this.state.reportReason}
1278 onInput={linkEvent(this, this.handleReportReasonChange)}
1282 className="btn btn-secondary"
1283 aria-label={I18NextService.i18n.t("create_report")}
1285 {this.state.reportLoading ? (
1288 I18NextService.i18n.t("create_report")
1293 {this.state.showPurgeDialog && (
1295 className="form-inline"
1296 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1299 <label className="visually-hidden" htmlFor="purge-reason">
1300 {I18NextService.i18n.t("reason")}
1305 className="form-control me-2"
1306 placeholder={I18NextService.i18n.t("reason")}
1307 value={this.state.purgeReason}
1308 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1310 {this.state.purgeLoading ? (
1315 className="btn btn-secondary"
1316 aria-label={purgeTypeText}
1318 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1328 const post = this.postView.post;
1329 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1330 <div className="row">
1331 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1332 {this.postTitleLine()}
1334 <div className="col-4">
1335 {/* Post thumbnail */}
1336 {!this.state.imageExpanded && this.thumbnail()}
1340 this.postTitleLine()
1345 const { body, id } = this.postView.post;
1347 return !this.showBody && body ? (
1348 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1349 <div className="md-div mb-1 preview-lines">{body}</div>
1359 {/* The mobile view*/}
1360 <div className="d-block d-sm-none">
1361 <article className="row post-container">
1362 <div className="col-12">
1363 {this.createdLine()}
1365 {/* If it has a thumbnail, do a right aligned thumbnail */}
1366 {this.mobileThumbnail()}
1368 {/* Show a preview of the post body */}
1369 {this.showBodyPreview()}
1371 {this.commentsLine(true)}
1372 {this.userActionsLine()}
1373 {this.duplicatesLine()}
1374 {this.removeAndBanDialogs()}
1379 {/* The larger view*/}
1380 <div className="d-none d-sm-block">
1381 <article className="row post-container">
1382 {!this.props.viewOnly && (
1384 id={this.postView.post.id}
1385 onVote={this.props.onPostVote}
1387 enableDownvotes={this.props.enableDownvotes}
1388 counts={this.postView.counts}
1389 my_vote={this.postView.my_vote}
1392 <div className="col-sm-2 pe-0 post-media">
1393 <div className="">{this.thumbnail()}</div>
1395 <div className="col-12 col-sm-9">
1396 <div className="row">
1397 <div className="col-12">
1398 {this.postTitleLine()}
1399 {this.createdLine()}
1400 {this.showBodyPreview()}
1401 {this.commentsLine()}
1402 {this.duplicatesLine()}
1403 {this.userActionsLine()}
1404 {this.removeAndBanDialogs()}
1414 private get myPost(): boolean {
1416 this.postView.creator.id ==
1417 UserService.Instance.myUserInfo?.local_user_view.person.id
1420 handleEditClick(i: PostListing) {
1421 i.setState({ showEdit: true });
1424 handleEditCancel() {
1425 this.setState({ showEdit: false });
1428 // The actual editing is done in the receive for post
1429 handleEditPost(form: EditPost) {
1430 this.setState({ showEdit: false });
1431 this.props.onPostEdit(form);
1434 handleShare(i: PostListing) {
1435 const { name, body, id } = i.props.post_view.post;
1438 text: body?.slice(0, 50),
1439 url: `${getHttpBase()}/post/${id}`,
1443 handleShowReportDialog(i: PostListing) {
1444 i.setState({ showReportDialog: !i.state.showReportDialog });
1447 handleReportReasonChange(i: PostListing, event: any) {
1448 i.setState({ reportReason: event.target.value });
1451 handleReportSubmit(i: PostListing, event: any) {
1452 event.preventDefault();
1453 i.setState({ reportLoading: true });
1454 i.props.onPostReport({
1455 post_id: i.postView.post.id,
1456 reason: i.state.reportReason ?? "",
1457 auth: myAuthRequired(),
1461 handleBlockPersonClick(i: PostListing) {
1462 i.setState({ blockLoading: true });
1463 i.props.onBlockPerson({
1464 person_id: i.postView.creator.id,
1466 auth: myAuthRequired(),
1470 handleDeleteClick(i: PostListing) {
1471 i.setState({ deleteLoading: true });
1472 i.props.onDeletePost({
1473 post_id: i.postView.post.id,
1474 deleted: !i.postView.post.deleted,
1475 auth: myAuthRequired(),
1479 handleSavePostClick(i: PostListing) {
1480 i.setState({ saveLoading: true });
1481 i.props.onSavePost({
1482 post_id: i.postView.post.id,
1483 save: !i.postView.saved,
1484 auth: myAuthRequired(),
1488 get crossPostParams(): PostFormParams {
1489 const queryParams: PostFormParams = {};
1490 const { name, url } = this.postView.post;
1492 queryParams.name = name;
1495 queryParams.url = url;
1498 const crossPostBody = this.crossPostBody();
1499 if (crossPostBody) {
1500 queryParams.body = crossPostBody;
1506 crossPostBody(): string | undefined {
1507 const post = this.postView.post;
1508 const body = post.body;
1511 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1513 }\n\n${body.replace(/^/gm, "> ")}`
1517 get showBody(): boolean {
1518 return this.props.showBody || this.state.showBody;
1521 handleModRemoveShow(i: PostListing) {
1523 showRemoveDialog: !i.state.showRemoveDialog,
1524 showBanDialog: false,
1528 handleModRemoveReasonChange(i: PostListing, event: any) {
1529 i.setState({ removeReason: event.target.value });
1532 handleModRemoveDataChange(i: PostListing, event: any) {
1533 i.setState({ removeData: event.target.checked });
1536 handleModRemoveSubmit(i: PostListing, event: any) {
1537 event.preventDefault();
1538 i.setState({ removeLoading: true });
1539 i.props.onRemovePost({
1540 post_id: i.postView.post.id,
1541 removed: !i.postView.post.removed,
1542 auth: myAuthRequired(),
1546 handleModLock(i: PostListing) {
1547 i.setState({ lockLoading: true });
1548 i.props.onLockPost({
1549 post_id: i.postView.post.id,
1550 locked: !i.postView.post.locked,
1551 auth: myAuthRequired(),
1555 handleModFeaturePostLocal(i: PostListing) {
1556 i.setState({ featureLocalLoading: true });
1557 i.props.onFeaturePost({
1558 post_id: i.postView.post.id,
1559 featured: !i.postView.post.featured_local,
1560 feature_type: "Local",
1561 auth: myAuthRequired(),
1565 handleModFeaturePostCommunity(i: PostListing) {
1566 i.setState({ featureCommunityLoading: true });
1567 i.props.onFeaturePost({
1568 post_id: i.postView.post.id,
1569 featured: !i.postView.post.featured_community,
1570 feature_type: "Community",
1571 auth: myAuthRequired(),
1575 handleModBanFromCommunityShow(i: PostListing) {
1577 showBanDialog: true,
1578 banType: BanType.Community,
1579 showRemoveDialog: false,
1583 handleModBanShow(i: PostListing) {
1585 showBanDialog: true,
1586 banType: BanType.Site,
1587 showRemoveDialog: false,
1591 handlePurgePersonShow(i: PostListing) {
1593 showPurgeDialog: true,
1594 purgeType: PurgeType.Person,
1595 showRemoveDialog: false,
1599 handlePurgePostShow(i: PostListing) {
1601 showPurgeDialog: true,
1602 purgeType: PurgeType.Post,
1603 showRemoveDialog: false,
1607 handlePurgeReasonChange(i: PostListing, event: any) {
1608 i.setState({ purgeReason: event.target.value });
1611 handlePurgeSubmit(i: PostListing, event: any) {
1612 event.preventDefault();
1613 i.setState({ purgeLoading: true });
1614 if (i.state.purgeType == PurgeType.Person) {
1615 i.props.onPurgePerson({
1616 person_id: i.postView.creator.id,
1617 reason: i.state.purgeReason,
1618 auth: myAuthRequired(),
1620 } else if (i.state.purgeType == PurgeType.Post) {
1621 i.props.onPurgePost({
1622 post_id: i.postView.post.id,
1623 reason: i.state.purgeReason,
1624 auth: myAuthRequired(),
1629 handleModBanReasonChange(i: PostListing, event: any) {
1630 i.setState({ banReason: event.target.value });
1633 handleModBanExpireDaysChange(i: PostListing, event: any) {
1634 i.setState({ banExpireDays: event.target.value });
1637 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1638 i.setState({ banType: BanType.Community });
1639 i.handleModBanBothSubmit(i, event);
1642 handleModBanSubmit(i: PostListing, event: any) {
1643 i.setState({ banType: BanType.Site });
1644 i.handleModBanBothSubmit(i, event);
1647 handleModBanBothSubmit(i: PostListing, event: any) {
1648 event.preventDefault();
1649 i.setState({ banLoading: true });
1651 const ban = !i.props.post_view.creator_banned_from_community;
1652 // If its an unban, restore all their data
1654 i.setState({ removeData: false });
1656 const person_id = i.props.post_view.creator.id;
1657 const remove_data = i.state.removeData;
1658 const reason = i.state.banReason;
1659 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1661 if (i.state.banType == BanType.Community) {
1662 const community_id = i.postView.community.id;
1663 i.props.onBanPersonFromCommunity({
1670 auth: myAuthRequired(),
1673 i.props.onBanPerson({
1679 auth: myAuthRequired(),
1684 handleAddModToCommunity(i: PostListing) {
1685 i.setState({ addModLoading: true });
1686 i.props.onAddModToCommunity({
1687 community_id: i.postView.community.id,
1688 person_id: i.postView.creator.id,
1689 added: !i.creatorIsMod_,
1690 auth: myAuthRequired(),
1694 handleAddAdmin(i: PostListing) {
1695 i.setState({ addAdminLoading: true });
1696 i.props.onAddAdmin({
1697 person_id: i.postView.creator.id,
1698 added: !i.creatorIsAdmin_,
1699 auth: myAuthRequired(),
1703 handleShowConfirmTransferCommunity(i: PostListing) {
1704 i.setState({ showConfirmTransferCommunity: true });
1707 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1708 i.setState({ showConfirmTransferCommunity: false });
1711 handleTransferCommunity(i: PostListing) {
1712 i.setState({ transferLoading: true });
1713 i.props.onTransferCommunity({
1714 community_id: i.postView.community.id,
1715 person_id: i.postView.creator.id,
1716 auth: myAuthRequired(),
1720 handleShowConfirmTransferSite(i: PostListing) {
1721 i.setState({ showConfirmTransferSite: true });
1724 handleCancelShowConfirmTransferSite(i: PostListing) {
1725 i.setState({ showConfirmTransferSite: false });
1728 handleImageExpandClick(i: PostListing, event: any) {
1729 event.preventDefault();
1730 i.setState({ imageExpanded: !i.state.imageExpanded });
1734 handleViewSource(i: PostListing) {
1735 i.setState({ viewSource: !i.state.viewSource });
1738 handleShowAdvanced(i: PostListing) {
1739 i.setState({ showAdvanced: !i.state.showAdvanced });
1743 handleShowMoreMobile(i: PostListing) {
1745 showMoreMobile: !i.state.showMoreMobile,
1746 showAdvanced: !i.state.showAdvanced,
1751 handleShowBody(i: PostListing) {
1752 i.setState({ showBody: !i.state.showBody });
1756 get pointsTippy(): string {
1757 const points = I18NextService.i18n.t("number_of_points", {
1758 count: Number(this.postView.counts.score),
1759 formattedCount: Number(this.postView.counts.score),
1762 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1763 count: Number(this.postView.counts.upvotes),
1764 formattedCount: Number(this.postView.counts.upvotes),
1767 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1768 count: Number(this.postView.counts.downvotes),
1769 formattedCount: Number(this.postView.counts.downvotes),
1772 return `${points} • ${upvotes} • ${downvotes}`;
1775 get canModOnSelf_(): boolean {
1777 this.postView.creator.id,
1778 this.props.moderators,
1785 get canMod_(): boolean {
1787 this.postView.creator.id,
1788 this.props.moderators,
1793 get canAdmin_(): boolean {
1794 return canAdmin(this.postView.creator.id, this.props.admins);
1797 get creatorIsMod_(): boolean {
1798 return isMod(this.postView.creator.id, this.props.moderators);
1801 get creatorIsAdmin_(): boolean {
1802 return isAdmin(this.postView.creator.id, this.props.admins);