1 import { myAuthRequired, newVote, showScores } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { futureDaysToUnixTime, hostname, numToSI } from "@utils/helpers";
4 import { isImage, isVideo } from "@utils/media";
14 } from "@utils/roles";
15 import classNames from "classnames";
16 import { Component, linkEvent } from "inferno";
17 import { Link } from "inferno-router";
24 CommunityModeratorView,
39 } from "lemmy-js-client";
40 import { relTags } from "../../config";
41 import { getExternalHost, getHttpBase } from "../../env";
42 import { i18n } from "../../i18next";
43 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
44 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
45 import { UserService } from "../../services";
46 import { setupTippy } from "../../tippy";
47 import { Icon, PurgeWarning, Spinner } from "../common/icon";
48 import { MomentTime } from "../common/moment-time";
49 import { PictrsImage } from "../common/pictrs-image";
50 import { CommunityLink } from "../community/community-link";
51 import { PersonListing } from "../person/person-listing";
52 import { MetadataCard } from "./metadata-card";
53 import { PostForm } from "./post-form";
55 interface PostListingState {
57 showRemoveDialog: boolean;
58 showPurgeDialog: boolean;
60 purgeType?: PurgeType;
61 purgeLoading: boolean;
62 removeReason?: string;
63 showBanDialog: boolean;
65 banExpireDays?: number;
68 showConfirmTransferSite: boolean;
69 showConfirmTransferCommunity: boolean;
70 imageExpanded: boolean;
72 showAdvanced: boolean;
73 showMoreMobile: boolean;
75 showReportDialog: boolean;
76 reportReason?: string;
77 upvoteLoading: boolean;
78 downvoteLoading: boolean;
79 reportLoading: boolean;
80 blockLoading: boolean;
82 deleteLoading: boolean;
83 removeLoading: boolean;
85 featureCommunityLoading: boolean;
86 featureLocalLoading: boolean;
88 addModLoading: boolean;
89 addAdminLoading: boolean;
90 transferLoading: boolean;
93 interface PostListingProps {
95 crossPosts?: PostView[];
96 moderators?: CommunityModeratorView[];
97 admins?: PersonView[];
98 allLanguages: Language[];
99 siteLanguages: number[];
100 showCommunity?: boolean;
103 enableDownvotes?: boolean;
104 enableNsfw?: boolean;
106 onPostEdit(form: EditPost): void;
107 onPostVote(form: CreatePostLike): void;
108 onPostReport(form: CreatePostReport): void;
109 onBlockPerson(form: BlockPerson): void;
110 onLockPost(form: LockPost): void;
111 onDeletePost(form: DeletePost): void;
112 onRemovePost(form: RemovePost): void;
113 onSavePost(form: SavePost): void;
114 onFeaturePost(form: FeaturePost): void;
115 onPurgePerson(form: PurgePerson): void;
116 onPurgePost(form: PurgePost): void;
117 onBanPersonFromCommunity(form: BanFromCommunity): void;
118 onBanPerson(form: BanPerson): void;
119 onAddModToCommunity(form: AddModToCommunity): void;
120 onAddAdmin(form: AddAdmin): void;
121 onTransferCommunity(form: TransferCommunity): void;
124 export class PostListing extends Component<PostListingProps, PostListingState> {
125 state: PostListingState = {
127 showRemoveDialog: false,
128 showPurgeDialog: false,
129 purgeType: PurgeType.Person,
130 showBanDialog: false,
131 banType: BanType.Community,
133 showConfirmTransferSite: false,
134 showConfirmTransferCommunity: false,
135 imageExpanded: false,
138 showMoreMobile: false,
140 showReportDialog: false,
141 upvoteLoading: false,
142 downvoteLoading: 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) {
168 upvoteLoading: false,
169 downvoteLoading: false,
171 reportLoading: false,
174 deleteLoading: false,
175 removeLoading: false,
177 featureCommunityLoading: false,
178 featureLocalLoading: false,
180 addModLoading: false,
181 addAdminLoading: false,
182 transferLoading: false,
183 imageExpanded: false,
188 get postView(): PostView {
189 return this.props.post_view;
193 const post = this.postView.post;
196 <div className="post-listing mt-2">
197 {!this.state.showEdit ? (
200 {this.state.imageExpanded && !this.props.hideImage && this.img}
201 {post.url && this.state.showBody && post.embed_title && (
202 <MetadataCard post={post} />
204 {this.showBody && this.body()}
208 post_view={this.postView}
209 crossPosts={this.props.crossPosts}
210 onEdit={this.handleEditPost}
211 onCancel={this.handleEditCancel}
212 enableNsfw={this.props.enableNsfw}
213 enableDownvotes={this.props.enableDownvotes}
214 allLanguages={this.props.allLanguages}
215 siteLanguages={this.props.siteLanguages}
223 const body = this.postView.post.body;
225 <article id="postContent" className="col-12 card my-2 p-2">
226 {this.state.viewSource ? (
229 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
238 return this.imageSrc ? (
240 <div className="offset-sm-3 my-2 d-none d-sm-block">
241 <a href={this.imageSrc} className="d-inline-block">
242 <PictrsImage src={this.imageSrc} />
245 <div className="my-2 d-block d-sm-none">
247 className="d-inline-block"
248 onClick={linkEvent(this, this.handleImageExpandClick)}
250 <PictrsImage src={this.imageSrc} />
259 imgThumb(src: string) {
260 const post_view = this.postView;
266 nsfw={post_view.post.nsfw || post_view.community.nsfw}
271 get imageSrc(): string | undefined {
272 const post = this.postView.post;
273 const url = post.url;
274 const thumbnail = post.thumbnail_url;
276 if (url && isImage(url)) {
277 if (url.includes("pictrs")) {
279 } else if (thumbnail) {
284 } else if (thumbnail) {
292 const post = this.postView.post;
293 const url = post.url;
294 const thumbnail = post.thumbnail_url;
296 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
300 className="text-body d-inline-block position-relative mb-2"
301 data-tippy-content={i18n.t("expand_here")}
302 onClick={linkEvent(this, this.handleImageExpandClick)}
303 aria-label={i18n.t("expand_here")}
305 {this.imgThumb(this.imageSrc)}
306 <Icon icon="image" classes="mini-overlay" />
309 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
312 className="text-body d-inline-block position-relative mb-2"
317 {this.imgThumb(this.imageSrc)}
318 <Icon icon="external-link" classes="mini-overlay" />
322 if (!this.props.hideImage && isVideo(url)) {
324 <div className="embed-responsive embed-responsive-16by9">
330 className="embed-responsive-item"
332 <source src={url} type="video/mp4" />
338 <a className="text-body" href={url} title={url} rel={relTags}>
339 <div className="thumbnail rounded bg-light d-flex justify-content-center">
340 <Icon icon="external-link" classes="d-flex align-items-center" />
348 className="text-body"
349 to={`/post/${post.id}`}
350 title={i18n.t("comments")}
352 <div className="thumbnail rounded bg-light d-flex justify-content-center">
353 <Icon icon="message-square" classes="d-flex align-items-center" />
361 const post_view = this.postView;
363 <ul className="list-inline mb-1 text-muted small mt-2">
364 <li className="list-inline-item">
365 <PersonListing person={post_view.creator} />
367 {this.creatorIsMod_ && (
368 <span className="mx-1 badge text-bg-light">{i18n.t("mod")}</span>
370 {this.creatorIsAdmin_ && (
371 <span className="mx-1 badge text-bg-light">{i18n.t("admin")}</span>
373 {post_view.creator.bot_account && (
374 <span className="mx-1 badge text-bg-light">
375 {i18n.t("bot_account").toLowerCase()}
378 {this.props.showCommunity && (
381 {i18n.t("to")} <CommunityLink community={post_view.community} />
385 {post_view.post.language_id !== 0 && (
386 <span className="mx-1 badge text-bg-light">
388 this.props.allLanguages.find(
389 lang => lang.id === post_view.post.language_id
394 <li className="list-inline-item">•</li>
395 <li className="list-inline-item">
398 published={post_view.post.published}
399 updated={post_view.post.updated}
409 <div className={`vote-bar col-1 pe-0 small text-center`}>
411 className={`btn-animate btn btn-link p-0 ${
412 this.postView.my_vote == 1 ? "text-info" : "text-muted"
414 onClick={linkEvent(this, this.handleUpvote)}
415 data-tippy-content={i18n.t("upvote")}
416 aria-label={i18n.t("upvote")}
417 aria-pressed={this.postView.my_vote === 1}
419 {this.state.upvoteLoading ? (
422 <Icon icon="arrow-up1" classes="upvote" />
427 className={`unselectable pointer text-muted px-1 post-score`}
428 data-tippy-content={this.pointsTippy}
430 {numToSI(this.postView.counts.score)}
433 <div className="p-1"></div>
435 {this.props.enableDownvotes && (
437 className={`btn-animate btn btn-link p-0 ${
438 this.postView.my_vote == -1 ? "text-danger" : "text-muted"
440 onClick={linkEvent(this, this.handleDownvote)}
441 data-tippy-content={i18n.t("downvote")}
442 aria-label={i18n.t("downvote")}
443 aria-pressed={this.postView.my_vote === -1}
445 {this.state.downvoteLoading ? (
448 <Icon icon="arrow-down1" classes="downvote" />
457 const post = this.postView.post;
460 className={`d-inline ${
461 !post.featured_community && !post.featured_local
465 to={`/post/${post.id}`}
466 title={i18n.t("comments")}
470 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
477 const post = this.postView.post;
478 const url = post.url;
482 <div className="post-title overflow-hidden">
483 <h5 className="d-inline">
484 {url && this.props.showBody ? (
487 !post.featured_community && !post.featured_local
494 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
500 {(url && isImage(url)) ||
501 (post.thumbnail_url && (
503 className="btn btn-sm text-monospace text-muted d-inline-block"
504 data-tippy-content={i18n.t("expand_here")}
505 onClick={linkEvent(this, this.handleImageExpandClick)}
509 !this.state.imageExpanded ? "plus-square" : "minus-square"
511 classes="icon-inline"
516 <small className="ms-2 badge text-bg-secondary">
522 className="unselectable pointer ms-2 text-muted font-italic"
523 data-tippy-content={i18n.t("deleted")}
525 <Icon icon="trash" classes="icon-inline text-danger" />
530 className="unselectable pointer ms-2 text-muted font-italic"
531 data-tippy-content={i18n.t("locked")}
533 <Icon icon="lock" classes="icon-inline text-danger" />
536 {post.featured_community && (
538 className="unselectable pointer ms-2 text-muted font-italic"
539 data-tippy-content={i18n.t("featured_in_community")}
540 aria-label={i18n.t("featured_in_community")}
542 <Icon icon="pin" classes="icon-inline text-primary" />
545 {post.featured_local && (
547 className="unselectable pointer ms-2 text-muted font-italic"
548 data-tippy-content={i18n.t("featured_in_local")}
549 aria-label={i18n.t("featured_in_local")}
551 <Icon icon="pin" classes="icon-inline text-secondary" />
555 <small className="ms-2 badge text-bg-danger">
560 {url && this.urlLine()}
566 const post = this.postView.post;
567 const url = post.url;
570 <p className="d-flex text-muted align-items-center gap-1 small m-0">
571 {url && !(hostname(url) === getExternalHost()) && (
573 className="text-muted font-italic"
586 const dupes = this.props.crossPosts;
587 return dupes && dupes.length > 0 ? (
588 <ul className="list-inline mb-1 small text-muted">
590 <li className="list-inline-item me-2">{i18n.t("cross_posted_to")}</li>
592 <li key={pv.post.id} className="list-inline-item me-2">
593 <Link to={`/post/${pv.post.id}`}>
596 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
607 commentsLine(mobile = false) {
608 const post = this.postView.post;
611 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
612 {this.commentsButton}
615 className="btn btn-sm btn-animate text-muted py-0"
616 onClick={linkEvent(this, this.handleShare)}
619 <Icon icon="share" inline />
624 className="btn btn-sm btn-animate text-muted py-0"
625 title={i18n.t("link")}
628 <Icon icon="fedilink" inline />
631 {mobile && !this.props.viewOnly && this.mobileVotes}
632 {UserService.Instance.myUserInfo &&
633 !this.props.viewOnly &&
639 showPreviewButton() {
640 const post_view = this.postView;
641 const body = post_view.post.body;
645 className="btn btn-sm btn-animate text-muted py-0"
646 data-tippy-content={body && mdNoImages.render(body)}
647 data-tippy-allowHtml={true}
648 onClick={linkEvent(this, this.handleShowBody)}
652 classes={classNames("icon-inline me-1", {
653 "text-success": this.state.showBody,
661 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
662 // Possible enhancement: Make each button a component.
663 const post_view = this.postView;
664 const post = post_view.post;
669 {this.crossPostButton}
672 * If there is a URL, or if the post has a body and we were told not to
673 * show the body, show the MetadataCard/body toggle.
675 {(post.url || (post.body && !this.props.showBody)) &&
676 this.showPreviewButton()}
678 {this.showBody && post_view.post.body && this.viewSourceButton}
680 <div className="dropdown">
682 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
683 onClick={linkEvent(this, this.handleShowAdvanced)}
684 data-tippy-content={i18n.t("more")}
685 data-bs-toggle="dropdown"
686 aria-expanded="false"
687 aria-controls="advancedButtonsDropdown"
688 aria-label={i18n.t("more")}
690 <Icon icon="more-vertical" inline />
693 <ul className="dropdown-menu" id="advancedButtonsDropdown">
696 <li>{this.reportButton}</li>
697 <li>{this.blockButton}</li>
701 <li>{this.editButton}</li>
702 <li>{this.deleteButton}</li>
706 {/* Any mod can do these, not limited to hierarchy*/}
707 {(amMod(this.props.moderators) || amAdmin()) && (
710 <hr className="dropdown-divider" />
712 <li>{this.lockButton}</li>
713 {this.featureButtons}
717 {(this.canMod_ || this.canAdmin_) && (
718 <li>{this.modRemoveButton}</li>
726 get commentsButton() {
727 const post_view = this.postView;
728 const title = i18n.t("number_of_comments", {
729 count: Number(post_view.counts.comments),
730 formattedCount: Number(post_view.counts.comments),
735 className="btn btn-link btn-sm text-muted ps-0"
737 to={`/post/${post_view.post.id}?scrollToComments=true`}
738 data-tippy-content={title}
740 <span className="me-1">
741 <Icon icon="message-square" classes="me-1" inline />
742 {post_view.counts.comments}
744 {this.unreadCount && (
745 <span className="text-muted fst-italic">
746 ({this.unreadCount} {i18n.t("new")})
753 get unreadCount(): number | undefined {
754 const pv = this.postView;
755 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
757 : pv.unread_comments;
762 const tippy = showScores()
763 ? { "data-tippy-content": this.pointsTippy }
769 className={`btn-animate btn py-0 px-1 ${
770 this.postView.my_vote === 1 ? "text-info" : "text-muted"
773 onClick={linkEvent(this, this.handleUpvote)}
774 aria-label={i18n.t("upvote")}
775 aria-pressed={this.postView.my_vote === 1}
777 {this.state.upvoteLoading ? (
781 <Icon icon="arrow-up1" classes="icon-inline small" />
783 <span className="ms-2">
784 {numToSI(this.postView.counts.upvotes)}
790 {this.props.enableDownvotes && (
792 className={`ms-2 btn-animate btn py-0 px-1 ${
793 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
795 onClick={linkEvent(this, this.handleDownvote)}
797 aria-label={i18n.t("downvote")}
798 aria-pressed={this.postView.my_vote === -1}
800 {this.state.downvoteLoading ? (
804 <Icon icon="arrow-down1" classes="icon-inline small" />
807 className={classNames("ms-2", {
808 invisible: this.postView.counts.downvotes === 0,
811 {numToSI(this.postView.counts.downvotes)}
824 const saved = this.postView.saved;
825 const label = saved ? i18n.t("unsave") : i18n.t("save");
828 className="btn btn-sm btn-animate text-muted py-0"
829 onClick={linkEvent(this, this.handleSavePostClick)}
830 data-tippy-content={label}
833 {this.state.saveLoading ? (
838 classes={classNames({ "text-warning": saved })}
846 get crossPostButton() {
849 className="btn btn-sm btn-animate text-muted py-0"
851 /* Empty string properties are required to satisfy type*/
852 pathname: "/create_post",
853 state: { ...this.crossPostParams },
858 title={i18n.t("cross_post")}
859 data-tippy-content={i18n.t("cross_post")}
860 aria-label={i18n.t("cross_post")}
862 <Icon icon="copy" inline />
870 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
871 onClick={linkEvent(this, this.handleShowReportDialog)}
872 aria-label={i18n.t("show_report_dialog")}
874 <Icon classes="me-1" icon="flag" inline />
875 {i18n.t("create_report")}
883 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
884 onClick={linkEvent(this, this.handleBlockPersonClick)}
885 aria-label={i18n.t("block_user")}
887 {this.state.blockLoading ? (
890 <Icon classes="me-1" icon="slash" inline />
892 {i18n.t("block_user")}
900 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
901 onClick={linkEvent(this, this.handleEditClick)}
902 aria-label={i18n.t("edit")}
904 <Icon classes="me-1" icon="edit" inline />
911 const deleted = this.postView.post.deleted;
912 const label = !deleted ? i18n.t("delete") : i18n.t("restore");
915 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
916 onClick={linkEvent(this, this.handleDeleteClick)}
919 {this.state.deleteLoading ? (
925 classes={classNames("me-1", { "text-danger": deleted })}
935 get viewSourceButton() {
938 className="btn btn-sm btn-animate text-muted py-0"
939 onClick={linkEvent(this, this.handleViewSource)}
940 data-tippy-content={i18n.t("view_source")}
941 aria-label={i18n.t("view_source")}
945 classes={classNames({ "text-success": this.state.viewSource })}
953 const locked = this.postView.post.locked;
954 const label = locked ? i18n.t("unlock") : i18n.t("lock");
957 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
958 onClick={linkEvent(this, this.handleModLock)}
961 {this.state.lockLoading ? (
967 classes={classNames("me-1", { "text-danger": locked })}
977 get featureButtons() {
978 const featuredCommunity = this.postView.post.featured_community;
979 const labelCommunity = featuredCommunity
980 ? i18n.t("unfeature_from_community")
981 : i18n.t("feature_in_community");
983 const featuredLocal = this.postView.post.featured_local;
984 const labelLocal = featuredLocal
985 ? i18n.t("unfeature_from_local")
986 : i18n.t("feature_in_local");
991 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
992 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
993 data-tippy-content={labelCommunity}
994 aria-label={labelCommunity}
996 {this.state.featureCommunityLoading ? (
1002 classes={classNames("me-1", {
1003 "text-success": featuredCommunity,
1007 {i18n.t("community")}
1015 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1016 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1017 data-tippy-content={labelLocal}
1018 aria-label={labelLocal}
1020 {this.state.featureLocalLoading ? (
1026 classes={classNames("me-1", {
1027 "text-success": featuredLocal,
1041 get modRemoveButton() {
1042 const removed = this.postView.post.removed;
1045 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1048 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1051 {/* TODO: Find an icon for this. */}
1052 {this.state.removeLoading ? (
1064 * Mod/Admin actions to be taken against the author.
1068 const post_view = this.postView;
1070 this.state.showAdvanced && (
1074 {!this.creatorIsMod_ &&
1075 (!post_view.creator_banned_from_community ? (
1077 className="btn btn-link btn-animate text-muted py-0"
1080 this.handleModBanFromCommunityShow
1082 aria-label={i18n.t("ban_from_community")}
1084 {i18n.t("ban_from_community")}
1088 className="btn btn-link btn-animate text-muted py-0"
1091 this.handleModBanFromCommunitySubmit
1093 aria-label={i18n.t("unban")}
1095 {this.state.banLoading ? <Spinner /> : i18n.t("unban")}
1098 {!post_view.creator_banned_from_community && (
1100 className="btn btn-link btn-animate text-muted py-0"
1101 onClick={linkEvent(this, this.handleAddModToCommunity)}
1104 ? i18n.t("remove_as_mod")
1105 : i18n.t("appoint_as_mod")
1108 {this.state.addModLoading ? (
1110 ) : this.creatorIsMod_ ? (
1111 i18n.t("remove_as_mod")
1113 i18n.t("appoint_as_mod")
1119 {/* Community creators and admins can transfer community to another mod */}
1120 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1122 this.creatorIsMod_ &&
1123 (!this.state.showConfirmTransferCommunity ? (
1125 className="btn btn-link btn-animate text-muted py-0"
1128 this.handleShowConfirmTransferCommunity
1130 aria-label={i18n.t("transfer_community")}
1132 {i18n.t("transfer_community")}
1137 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1138 aria-label={i18n.t("are_you_sure")}
1140 {i18n.t("are_you_sure")}
1143 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1144 aria-label={i18n.t("yes")}
1145 onClick={linkEvent(this, this.handleTransferCommunity)}
1147 {this.state.transferLoading ? <Spinner /> : i18n.t("yes")}
1150 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1153 this.handleCancelShowConfirmTransferCommunity
1155 aria-label={i18n.t("no")}
1161 {/* Admins can ban from all, and appoint other admins */}
1162 {this.canAdmin_ && (
1164 {!this.creatorIsAdmin_ && (
1166 {!isBanned(post_view.creator) ? (
1168 className="btn btn-link btn-animate text-muted py-0"
1169 onClick={linkEvent(this, this.handleModBanShow)}
1170 aria-label={i18n.t("ban_from_site")}
1172 {i18n.t("ban_from_site")}
1176 className="btn btn-link btn-animate text-muted py-0"
1177 onClick={linkEvent(this, this.handleModBanSubmit)}
1178 aria-label={i18n.t("unban_from_site")}
1180 {this.state.banLoading ? (
1183 i18n.t("unban_from_site")
1188 className="btn btn-link btn-animate text-muted py-0"
1189 onClick={linkEvent(this, this.handlePurgePersonShow)}
1190 aria-label={i18n.t("purge_user")}
1192 {i18n.t("purge_user")}
1195 className="btn btn-link btn-animate text-muted py-0"
1196 onClick={linkEvent(this, this.handlePurgePostShow)}
1197 aria-label={i18n.t("purge_post")}
1199 {i18n.t("purge_post")}
1203 {!isBanned(post_view.creator) && post_view.creator.local && (
1205 className="btn btn-link btn-animate text-muted py-0"
1206 onClick={linkEvent(this, this.handleAddAdmin)}
1208 this.creatorIsAdmin_
1209 ? i18n.t("remove_as_admin")
1210 : i18n.t("appoint_as_admin")
1213 {this.state.addAdminLoading ? (
1215 ) : this.creatorIsAdmin_ ? (
1216 i18n.t("remove_as_admin")
1218 i18n.t("appoint_as_admin")
1229 removeAndBanDialogs() {
1230 const post = this.postView;
1231 const purgeTypeText =
1232 this.state.purgeType == PurgeType.Post
1233 ? i18n.t("purge_post")
1234 : `${i18n.t("purge")} ${post.creator.name}`;
1237 {this.state.showRemoveDialog && (
1239 className="form-inline"
1240 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1243 className="visually-hidden"
1244 htmlFor="post-listing-remove-reason"
1250 id="post-listing-remove-reason"
1251 className="form-control me-2"
1252 placeholder={i18n.t("reason")}
1253 value={this.state.removeReason}
1254 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1258 className="btn btn-secondary"
1259 aria-label={i18n.t("remove_post")}
1261 {this.state.removeLoading ? <Spinner /> : i18n.t("remove_post")}
1265 {this.state.showBanDialog && (
1266 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1267 <div className="mb-3 row col-12">
1269 className="col-form-label"
1270 htmlFor="post-listing-ban-reason"
1276 id="post-listing-ban-reason"
1277 className="form-control me-2"
1278 placeholder={i18n.t("reason")}
1279 value={this.state.banReason}
1280 onInput={linkEvent(this, this.handleModBanReasonChange)}
1282 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1287 id={`mod-ban-expires`}
1288 className="form-control me-2"
1289 placeholder={i18n.t("number_of_days")}
1290 value={this.state.banExpireDays}
1291 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1293 <div className="input-group mb-3">
1294 <div className="form-check">
1296 className="form-check-input"
1297 id="mod-ban-remove-data"
1299 checked={this.state.removeData}
1300 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1303 className="form-check-label"
1304 htmlFor="mod-ban-remove-data"
1305 title={i18n.t("remove_content_more")}
1307 {i18n.t("remove_content")}
1312 {/* TODO hold off on expires until later */}
1313 {/* <div class="mb-3 row"> */}
1314 {/* <label class="col-form-label">Expires</label> */}
1315 {/* <input type="date" class="form-control me-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1317 <div className="mb-3 row">
1320 className="btn btn-secondary"
1321 aria-label={i18n.t("ban")}
1323 {this.state.banLoading ? (
1327 {i18n.t("ban")} {post.creator.name}
1334 {this.state.showReportDialog && (
1336 className="form-inline"
1337 onSubmit={linkEvent(this, this.handleReportSubmit)}
1339 <label className="visually-hidden" htmlFor="post-report-reason">
1344 id="post-report-reason"
1345 className="form-control me-2"
1346 placeholder={i18n.t("reason")}
1348 value={this.state.reportReason}
1349 onInput={linkEvent(this, this.handleReportReasonChange)}
1353 className="btn btn-secondary"
1354 aria-label={i18n.t("create_report")}
1356 {this.state.reportLoading ? <Spinner /> : i18n.t("create_report")}
1360 {this.state.showPurgeDialog && (
1362 className="form-inline"
1363 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1366 <label className="visually-hidden" htmlFor="purge-reason">
1372 className="form-control me-2"
1373 placeholder={i18n.t("reason")}
1374 value={this.state.purgeReason}
1375 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1377 {this.state.purgeLoading ? (
1382 className="btn btn-secondary"
1383 aria-label={purgeTypeText}
1385 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1395 const post = this.postView.post;
1396 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1397 <div className="row">
1398 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1399 {this.postTitleLine()}
1401 <div className="col-4">
1402 {/* Post body prev or thumbnail */}
1403 {!this.state.imageExpanded && this.thumbnail()}
1407 this.postTitleLine()
1411 showMobilePreview() {
1412 const { body, id } = this.postView.post;
1414 return !this.showBody && body ? (
1415 <Link className="text-body" to={`/post/${id}`}>
1416 <div className="md-div mb-1 preview-lines">{body}</div>
1426 {/* The mobile view*/}
1427 <div className="d-block d-sm-none">
1428 <article className="row post-container">
1429 <div className="col-12">
1430 {this.createdLine()}
1432 {/* If it has a thumbnail, do a right aligned thumbnail */}
1433 {this.mobileThumbnail()}
1435 {/* Show a preview of the post body */}
1436 {this.showMobilePreview()}
1438 {this.commentsLine(true)}
1439 {this.userActionsLine()}
1440 {this.duplicatesLine()}
1441 {this.removeAndBanDialogs()}
1446 {/* The larger view*/}
1447 <div className="d-none d-sm-block">
1448 <article className="row post-container">
1449 {!this.props.viewOnly && this.voteBar()}
1450 <div className="col-sm-2 pe-0 post-media">
1451 <div className="">{this.thumbnail()}</div>
1453 <div className="col-12 col-sm-9">
1454 <div className="row">
1455 <div className="col-12">
1456 {this.postTitleLine()}
1457 {this.createdLine()}
1458 {this.commentsLine()}
1459 {this.duplicatesLine()}
1460 {this.userActionsLine()}
1461 {this.removeAndBanDialogs()}
1471 private get myPost(): boolean {
1473 this.postView.creator.id ==
1474 UserService.Instance.myUserInfo?.local_user_view.person.id
1477 handleEditClick(i: PostListing) {
1478 i.setState({ showEdit: true });
1481 handleEditCancel() {
1482 this.setState({ showEdit: false });
1485 // The actual editing is done in the receive for post
1486 handleEditPost(form: EditPost) {
1487 this.setState({ showEdit: false });
1488 this.props.onPostEdit(form);
1491 handleShare(i: PostListing) {
1492 const { name, body, id } = i.props.post_view.post;
1495 text: body?.slice(0, 50),
1496 url: `${getHttpBase()}/post/${id}`,
1500 handleShowReportDialog(i: PostListing) {
1501 i.setState({ showReportDialog: !i.state.showReportDialog });
1504 handleReportReasonChange(i: PostListing, event: any) {
1505 i.setState({ reportReason: event.target.value });
1508 handleReportSubmit(i: PostListing, event: any) {
1509 event.preventDefault();
1510 i.setState({ reportLoading: true });
1511 i.props.onPostReport({
1512 post_id: i.postView.post.id,
1513 reason: i.state.reportReason ?? "",
1514 auth: myAuthRequired(),
1518 handleBlockPersonClick(i: PostListing) {
1519 i.setState({ blockLoading: true });
1520 i.props.onBlockPerson({
1521 person_id: i.postView.creator.id,
1523 auth: myAuthRequired(),
1527 handleDeleteClick(i: PostListing) {
1528 i.setState({ deleteLoading: true });
1529 i.props.onDeletePost({
1530 post_id: i.postView.post.id,
1531 deleted: !i.postView.post.deleted,
1532 auth: myAuthRequired(),
1536 handleSavePostClick(i: PostListing) {
1537 i.setState({ saveLoading: true });
1538 i.props.onSavePost({
1539 post_id: i.postView.post.id,
1540 save: !i.postView.saved,
1541 auth: myAuthRequired(),
1545 get crossPostParams(): PostFormParams {
1546 const queryParams: PostFormParams = {};
1547 const { name, url } = this.postView.post;
1549 queryParams.name = name;
1552 queryParams.url = url;
1555 const crossPostBody = this.crossPostBody();
1556 if (crossPostBody) {
1557 queryParams.body = crossPostBody;
1563 crossPostBody(): string | undefined {
1564 const post = this.postView.post;
1565 const body = post.body;
1568 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1575 get showBody(): boolean {
1576 return this.props.showBody || this.state.showBody;
1579 handleModRemoveShow(i: PostListing) {
1581 showRemoveDialog: !i.state.showRemoveDialog,
1582 showBanDialog: false,
1586 handleModRemoveReasonChange(i: PostListing, event: any) {
1587 i.setState({ removeReason: event.target.value });
1590 handleModRemoveDataChange(i: PostListing, event: any) {
1591 i.setState({ removeData: event.target.checked });
1594 handleModRemoveSubmit(i: PostListing, event: any) {
1595 event.preventDefault();
1596 i.setState({ removeLoading: true });
1597 i.props.onRemovePost({
1598 post_id: i.postView.post.id,
1599 removed: !i.postView.post.removed,
1600 auth: myAuthRequired(),
1604 handleModLock(i: PostListing) {
1605 i.setState({ lockLoading: true });
1606 i.props.onLockPost({
1607 post_id: i.postView.post.id,
1608 locked: !i.postView.post.locked,
1609 auth: myAuthRequired(),
1613 handleModFeaturePostLocal(i: PostListing) {
1614 i.setState({ featureLocalLoading: true });
1615 i.props.onFeaturePost({
1616 post_id: i.postView.post.id,
1617 featured: !i.postView.post.featured_local,
1618 feature_type: "Local",
1619 auth: myAuthRequired(),
1623 handleModFeaturePostCommunity(i: PostListing) {
1624 i.setState({ featureCommunityLoading: true });
1625 i.props.onFeaturePost({
1626 post_id: i.postView.post.id,
1627 featured: !i.postView.post.featured_community,
1628 feature_type: "Community",
1629 auth: myAuthRequired(),
1633 handleModBanFromCommunityShow(i: PostListing) {
1635 showBanDialog: true,
1636 banType: BanType.Community,
1637 showRemoveDialog: false,
1641 handleModBanShow(i: PostListing) {
1643 showBanDialog: true,
1644 banType: BanType.Site,
1645 showRemoveDialog: false,
1649 handlePurgePersonShow(i: PostListing) {
1651 showPurgeDialog: true,
1652 purgeType: PurgeType.Person,
1653 showRemoveDialog: false,
1657 handlePurgePostShow(i: PostListing) {
1659 showPurgeDialog: true,
1660 purgeType: PurgeType.Post,
1661 showRemoveDialog: false,
1665 handlePurgeReasonChange(i: PostListing, event: any) {
1666 i.setState({ purgeReason: event.target.value });
1669 handlePurgeSubmit(i: PostListing, event: any) {
1670 event.preventDefault();
1671 i.setState({ purgeLoading: true });
1672 if (i.state.purgeType == PurgeType.Person) {
1673 i.props.onPurgePerson({
1674 person_id: i.postView.creator.id,
1675 reason: i.state.purgeReason,
1676 auth: myAuthRequired(),
1678 } else if (i.state.purgeType == PurgeType.Post) {
1679 i.props.onPurgePost({
1680 post_id: i.postView.post.id,
1681 reason: i.state.purgeReason,
1682 auth: myAuthRequired(),
1687 handleModBanReasonChange(i: PostListing, event: any) {
1688 i.setState({ banReason: event.target.value });
1691 handleModBanExpireDaysChange(i: PostListing, event: any) {
1692 i.setState({ banExpireDays: event.target.value });
1695 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1696 i.setState({ banType: BanType.Community });
1697 i.handleModBanBothSubmit(i, event);
1700 handleModBanSubmit(i: PostListing, event: any) {
1701 i.setState({ banType: BanType.Site });
1702 i.handleModBanBothSubmit(i, event);
1705 handleModBanBothSubmit(i: PostListing, event: any) {
1706 event.preventDefault();
1707 i.setState({ banLoading: true });
1709 const ban = !i.props.post_view.creator_banned_from_community;
1710 // If its an unban, restore all their data
1712 i.setState({ removeData: false });
1714 const person_id = i.props.post_view.creator.id;
1715 const remove_data = i.state.removeData;
1716 const reason = i.state.banReason;
1717 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1719 if (i.state.banType == BanType.Community) {
1720 const community_id = i.postView.community.id;
1721 i.props.onBanPersonFromCommunity({
1728 auth: myAuthRequired(),
1731 i.props.onBanPerson({
1737 auth: myAuthRequired(),
1742 handleAddModToCommunity(i: PostListing) {
1743 i.setState({ addModLoading: true });
1744 i.props.onAddModToCommunity({
1745 community_id: i.postView.community.id,
1746 person_id: i.postView.creator.id,
1747 added: !i.creatorIsMod_,
1748 auth: myAuthRequired(),
1752 handleAddAdmin(i: PostListing) {
1753 i.setState({ addAdminLoading: true });
1754 i.props.onAddAdmin({
1755 person_id: i.postView.creator.id,
1756 added: !i.creatorIsAdmin_,
1757 auth: myAuthRequired(),
1761 handleShowConfirmTransferCommunity(i: PostListing) {
1762 i.setState({ showConfirmTransferCommunity: true });
1765 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1766 i.setState({ showConfirmTransferCommunity: false });
1769 handleTransferCommunity(i: PostListing) {
1770 i.setState({ transferLoading: true });
1771 i.props.onTransferCommunity({
1772 community_id: i.postView.community.id,
1773 person_id: i.postView.creator.id,
1774 auth: myAuthRequired(),
1778 handleShowConfirmTransferSite(i: PostListing) {
1779 i.setState({ showConfirmTransferSite: true });
1782 handleCancelShowConfirmTransferSite(i: PostListing) {
1783 i.setState({ showConfirmTransferSite: false });
1786 handleImageExpandClick(i: PostListing, event: any) {
1787 event.preventDefault();
1788 i.setState({ imageExpanded: !i.state.imageExpanded });
1792 handleViewSource(i: PostListing) {
1793 i.setState({ viewSource: !i.state.viewSource });
1796 handleShowAdvanced(i: PostListing) {
1797 i.setState({ showAdvanced: !i.state.showAdvanced });
1801 handleShowMoreMobile(i: PostListing) {
1803 showMoreMobile: !i.state.showMoreMobile,
1804 showAdvanced: !i.state.showAdvanced,
1809 handleShowBody(i: PostListing) {
1810 i.setState({ showBody: !i.state.showBody });
1814 handleUpvote(i: PostListing) {
1815 i.setState({ upvoteLoading: true });
1816 i.props.onPostVote({
1817 post_id: i.postView.post.id,
1818 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1819 auth: myAuthRequired(),
1823 handleDownvote(i: PostListing) {
1824 i.setState({ downvoteLoading: true });
1825 i.props.onPostVote({
1826 post_id: i.postView.post.id,
1827 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1828 auth: myAuthRequired(),
1832 get pointsTippy(): string {
1833 const points = i18n.t("number_of_points", {
1834 count: Number(this.postView.counts.score),
1835 formattedCount: Number(this.postView.counts.score),
1838 const upvotes = i18n.t("number_of_upvotes", {
1839 count: Number(this.postView.counts.upvotes),
1840 formattedCount: Number(this.postView.counts.upvotes),
1843 const downvotes = i18n.t("number_of_downvotes", {
1844 count: Number(this.postView.counts.downvotes),
1845 formattedCount: Number(this.postView.counts.downvotes),
1848 return `${points} • ${upvotes} • ${downvotes}`;
1851 get canModOnSelf_(): boolean {
1853 this.postView.creator.id,
1854 this.props.moderators,
1861 get canMod_(): boolean {
1863 this.postView.creator.id,
1864 this.props.moderators,
1869 get canAdmin_(): boolean {
1870 return canAdmin(this.postView.creator.id, this.props.admins);
1873 get creatorIsMod_(): boolean {
1874 return isMod(this.postView.creator.id, this.props.moderators);
1877 get creatorIsAdmin_(): boolean {
1878 return isAdmin(this.postView.creator.id, this.props.admins);