1 import { canShare, share } from "@utils/browser";
11 } from "@utils/roles";
12 import classNames from "classnames";
13 import { Component, linkEvent } from "inferno";
14 import { Link } from "inferno-router";
21 CommunityModeratorView,
36 } from "lemmy-js-client";
37 import { getExternalHost, getHttpBase } from "../../env";
38 import { i18n } from "../../i18next";
39 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
40 import { UserService } from "../../services";
56 import { Icon, PurgeWarning, Spinner } from "../common/icon";
57 import { MomentTime } from "../common/moment-time";
58 import { PictrsImage } from "../common/pictrs-image";
59 import { CommunityLink } from "../community/community-link";
60 import { PersonListing } from "../person/person-listing";
61 import { MetadataCard } from "./metadata-card";
62 import { PostForm } from "./post-form";
64 interface PostListingState {
66 showRemoveDialog: boolean;
67 showPurgeDialog: boolean;
69 purgeType?: PurgeType;
70 purgeLoading: boolean;
71 removeReason?: string;
72 showBanDialog: boolean;
74 banExpireDays?: number;
77 showConfirmTransferSite: boolean;
78 showConfirmTransferCommunity: boolean;
79 imageExpanded: boolean;
81 showAdvanced: boolean;
82 showMoreMobile: boolean;
84 showReportDialog: boolean;
85 reportReason?: string;
86 upvoteLoading: boolean;
87 downvoteLoading: boolean;
88 reportLoading: boolean;
89 blockLoading: boolean;
91 deleteLoading: boolean;
92 removeLoading: boolean;
94 featureCommunityLoading: boolean;
95 featureLocalLoading: boolean;
97 addModLoading: boolean;
98 addAdminLoading: boolean;
99 transferLoading: boolean;
102 interface PostListingProps {
104 crossPosts?: PostView[];
105 moderators?: CommunityModeratorView[];
106 admins?: PersonView[];
107 allLanguages: Language[];
108 siteLanguages: number[];
109 showCommunity?: boolean;
112 enableDownvotes?: boolean;
113 enableNsfw?: boolean;
115 onPostEdit(form: EditPost): void;
116 onPostVote(form: CreatePostLike): void;
117 onPostReport(form: CreatePostReport): void;
118 onBlockPerson(form: BlockPerson): void;
119 onLockPost(form: LockPost): void;
120 onDeletePost(form: DeletePost): void;
121 onRemovePost(form: RemovePost): void;
122 onSavePost(form: SavePost): void;
123 onFeaturePost(form: FeaturePost): void;
124 onPurgePerson(form: PurgePerson): void;
125 onPurgePost(form: PurgePost): void;
126 onBanPersonFromCommunity(form: BanFromCommunity): void;
127 onBanPerson(form: BanPerson): void;
128 onAddModToCommunity(form: AddModToCommunity): void;
129 onAddAdmin(form: AddAdmin): void;
130 onTransferCommunity(form: TransferCommunity): void;
133 export class PostListing extends Component<PostListingProps, PostListingState> {
134 state: PostListingState = {
136 showRemoveDialog: false,
137 showPurgeDialog: false,
138 purgeType: PurgeType.Person,
139 showBanDialog: false,
140 banType: BanType.Community,
142 showConfirmTransferSite: false,
143 showConfirmTransferCommunity: false,
144 imageExpanded: false,
147 showMoreMobile: false,
149 showReportDialog: false,
150 upvoteLoading: false,
151 downvoteLoading: false,
153 reportLoading: false,
156 deleteLoading: false,
157 removeLoading: false,
159 featureCommunityLoading: false,
160 featureLocalLoading: false,
162 addModLoading: false,
163 addAdminLoading: false,
164 transferLoading: false,
167 constructor(props: any, context: any) {
168 super(props, context);
170 this.handleEditPost = this.handleEditPost.bind(this);
171 this.handleEditCancel = this.handleEditCancel.bind(this);
174 componentWillReceiveProps(nextProps: PostListingProps) {
175 if (this.props !== nextProps) {
177 upvoteLoading: false,
178 downvoteLoading: false,
180 reportLoading: false,
183 deleteLoading: false,
184 removeLoading: false,
186 featureCommunityLoading: false,
187 featureLocalLoading: false,
189 addModLoading: false,
190 addAdminLoading: false,
191 transferLoading: false,
192 imageExpanded: false,
197 get postView(): PostView {
198 return this.props.post_view;
202 const post = this.postView.post;
205 <div className="post-listing mt-2">
206 {!this.state.showEdit ? (
209 {this.state.imageExpanded && !this.props.hideImage && this.img}
210 {post.url && this.state.showBody && post.embed_title && (
211 <MetadataCard post={post} />
213 {this.showBody && this.body()}
217 post_view={this.postView}
218 crossPosts={this.props.crossPosts}
219 onEdit={this.handleEditPost}
220 onCancel={this.handleEditCancel}
221 enableNsfw={this.props.enableNsfw}
222 enableDownvotes={this.props.enableDownvotes}
223 allLanguages={this.props.allLanguages}
224 siteLanguages={this.props.siteLanguages}
232 const body = this.postView.post.body;
234 <article id="postContent" className="col-12 card my-2 p-2">
235 {this.state.viewSource ? (
238 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
247 return this.imageSrc ? (
249 <div className="offset-sm-3 my-2 d-none d-sm-block">
250 <a href={this.imageSrc} className="d-inline-block">
251 <PictrsImage src={this.imageSrc} />
254 <div className="my-2 d-block d-sm-none">
256 className="d-inline-block"
257 onClick={linkEvent(this, this.handleImageExpandClick)}
259 <PictrsImage src={this.imageSrc} />
268 imgThumb(src: string) {
269 const post_view = this.postView;
275 nsfw={post_view.post.nsfw || post_view.community.nsfw}
280 get imageSrc(): string | undefined {
281 const post = this.postView.post;
282 const url = post.url;
283 const thumbnail = post.thumbnail_url;
285 if (url && isImage(url)) {
286 if (url.includes("pictrs")) {
288 } else if (thumbnail) {
293 } else if (thumbnail) {
301 const post = this.postView.post;
302 const url = post.url;
303 const thumbnail = post.thumbnail_url;
305 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
309 className="text-body d-inline-block position-relative mb-2"
310 data-tippy-content={i18n.t("expand_here")}
311 onClick={linkEvent(this, this.handleImageExpandClick)}
312 aria-label={i18n.t("expand_here")}
314 {this.imgThumb(this.imageSrc)}
315 <Icon icon="image" classes="mini-overlay" />
318 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
321 className="text-body d-inline-block position-relative mb-2"
326 {this.imgThumb(this.imageSrc)}
327 <Icon icon="external-link" classes="mini-overlay" />
331 if (!this.props.hideImage && isVideo(url)) {
333 <div className="embed-responsive embed-responsive-16by9">
339 className="embed-responsive-item"
341 <source src={url} type="video/mp4" />
347 <a className="text-body" href={url} title={url} rel={relTags}>
348 <div className="thumbnail rounded bg-light d-flex justify-content-center">
349 <Icon icon="external-link" classes="d-flex align-items-center" />
357 className="text-body"
358 to={`/post/${post.id}`}
359 title={i18n.t("comments")}
361 <div className="thumbnail rounded bg-light d-flex justify-content-center">
362 <Icon icon="message-square" classes="d-flex align-items-center" />
370 const post_view = this.postView;
372 <ul className="list-inline mb-1 text-muted small mt-2">
373 <li className="list-inline-item">
374 <PersonListing person={post_view.creator} />
376 {this.creatorIsMod_ && (
377 <span className="mx-1 badge">{i18n.t("mod")}</span>
379 {this.creatorIsAdmin_ && (
380 <span className="mx-1 badge">{i18n.t("admin")}</span>
382 {post_view.creator.bot_account && (
383 <span className="mx-1 badge">
384 {i18n.t("bot_account").toLowerCase()}
387 {this.props.showCommunity && (
390 {i18n.t("to")} <CommunityLink community={post_view.community} />
394 {post_view.post.language_id !== 0 && (
395 <span className="mx-1 badge">
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}
418 <div className={`vote-bar col-1 pr-0 small text-center`}>
420 className={`btn-animate btn btn-link p-0 ${
421 this.postView.my_vote == 1 ? "text-info" : "text-muted"
423 onClick={linkEvent(this, this.handleUpvote)}
424 data-tippy-content={i18n.t("upvote")}
425 aria-label={i18n.t("upvote")}
426 aria-pressed={this.postView.my_vote === 1}
428 {this.state.upvoteLoading ? (
431 <Icon icon="arrow-up1" classes="upvote" />
436 className={`unselectable pointer font-weight-bold text-muted px-1 post-score`}
437 data-tippy-content={this.pointsTippy}
439 {numToSI(this.postView.counts.score)}
442 <div className="p-1"></div>
444 {this.props.enableDownvotes && (
446 className={`btn-animate btn btn-link p-0 ${
447 this.postView.my_vote == -1 ? "text-danger" : "text-muted"
449 onClick={linkEvent(this, this.handleDownvote)}
450 data-tippy-content={i18n.t("downvote")}
451 aria-label={i18n.t("downvote")}
452 aria-pressed={this.postView.my_vote === -1}
454 {this.state.downvoteLoading ? (
457 <Icon icon="arrow-down1" classes="downvote" />
466 const post = this.postView.post;
469 className={`d-inline ${
470 !post.featured_community && !post.featured_local
474 to={`/post/${post.id}`}
475 title={i18n.t("comments")}
479 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
486 const post = this.postView.post;
487 const url = post.url;
491 <div className="post-title overflow-hidden">
492 <h5 className="d-inline">
493 {url && this.props.showBody ? (
496 !post.featured_community && !post.featured_local
503 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
509 {(url && isImage(url)) ||
510 (post.thumbnail_url && (
512 className="btn btn-link text-monospace text-muted small d-inline-block"
513 data-tippy-content={i18n.t("expand_here")}
514 onClick={linkEvent(this, this.handleImageExpandClick)}
518 !this.state.imageExpanded ? "plus-square" : "minus-square"
520 classes="icon-inline"
525 <small className="ml-2 badge text-bg-secondary">
531 className="unselectable pointer ml-2 text-muted font-italic"
532 data-tippy-content={i18n.t("deleted")}
534 <Icon icon="trash" classes="icon-inline text-danger" />
539 className="unselectable pointer ml-2 text-muted font-italic"
540 data-tippy-content={i18n.t("locked")}
542 <Icon icon="lock" classes="icon-inline text-danger" />
545 {post.featured_community && (
547 className="unselectable pointer ml-2 text-muted font-italic"
548 data-tippy-content={i18n.t("featured_in_community")}
549 aria-label={i18n.t("featured_in_community")}
551 <Icon icon="pin" classes="icon-inline text-primary" />
554 {post.featured_local && (
556 className="unselectable pointer ml-2 text-muted font-italic"
557 data-tippy-content={i18n.t("featured_in_local")}
558 aria-label={i18n.t("featured_in_local")}
560 <Icon icon="pin" classes="icon-inline text-secondary" />
564 <small className="ml-2 badge text-bg-danger">
569 {url && this.urlLine()}
575 const post = this.postView.post;
576 const url = post.url;
579 <p className="d-flex text-muted align-items-center gap-1 small m-0">
580 {url && !(hostname(url) === getExternalHost()) && (
582 className="text-muted font-italic"
595 const dupes = this.props.crossPosts;
596 return dupes && dupes.length > 0 ? (
597 <ul className="list-inline mb-1 small text-muted">
599 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
601 <li key={pv.post.id} className="list-inline-item mr-2">
602 <Link to={`/post/${pv.post.id}`}>
605 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
616 commentsLine(mobile = false) {
617 const post = this.postView.post;
620 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted font-weight-bold">
621 {this.commentsButton}
624 className="btn btn-sm btn-link"
625 onClick={linkEvent(this, this.handleShare)}
628 <Icon icon="share" inline />
633 className="btn btn-link btn-animate text-muted py-0"
634 title={i18n.t("link")}
637 <Icon icon="fedilink" inline />
640 {mobile && !this.props.viewOnly && this.mobileVotes}
641 {UserService.Instance.myUserInfo &&
642 !this.props.viewOnly &&
648 showPreviewButton() {
649 const post_view = this.postView;
650 const body = post_view.post.body;
654 className="btn btn-link btn-animate text-muted py-0"
655 data-tippy-content={body && mdNoImages.render(body)}
656 data-tippy-allowHtml={true}
657 onClick={linkEvent(this, this.handleShowBody)}
661 classes={classNames("icon-inline mr-1", {
662 "text-success": this.state.showBody,
670 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
671 // Possible enhancement: Make each button a component.
672 const post_view = this.postView;
673 const post = post_view.post;
678 {this.crossPostButton}
681 * If there is a URL, or if the post has a body and we were told not to
682 * show the body, show the MetadataCard/body toggle.
684 {(post.url || (post.body && !this.props.showBody)) &&
685 this.showPreviewButton()}
687 {this.showBody && post_view.post.body && this.viewSourceButton}
689 <div className="dropdown">
691 className="btn btn-link btn-animate text-muted py-0 dropdown-toggle"
692 onClick={linkEvent(this, this.handleShowAdvanced)}
693 data-tippy-content={i18n.t("more")}
694 data-bs-toggle="dropdown"
695 aria-expanded="false"
696 aria-controls="advancedButtonsDropdown"
697 aria-label={i18n.t("more")}
699 <Icon icon="more-vertical" inline />
702 <ul className="dropdown-menu" id="advancedButtonsDropdown">
705 <li>{this.reportButton}</li>
706 <li>{this.blockButton}</li>
710 <li>{this.editButton}</li>
711 <li>{this.deleteButton}</li>
715 {/* Any mod can do these, not limited to hierarchy*/}
716 {(amMod(this.props.moderators) || amAdmin()) && (
719 <hr className="dropdown-divider" />
721 <li>{this.lockButton}</li>
722 {this.featureButtons}
726 {(this.canMod_ || this.canAdmin_) && (
727 <li>{this.modRemoveButton}</li>
735 get commentsButton() {
736 const post_view = this.postView;
739 className="btn btn-link text-muted pl-0 text-muted"
740 title={i18n.t("number_of_comments", {
741 count: Number(post_view.counts.comments),
742 formattedCount: Number(post_view.counts.comments),
744 to={`/post/${post_view.post.id}?scrollToComments=true`}
746 <Icon icon="message-square" classes="mr-1" inline />
747 <span className="mr-2">
748 {i18n.t("number_of_comments", {
749 count: Number(post_view.counts.comments),
750 formattedCount: numToSI(post_view.counts.comments),
753 {this.unreadCount && (
754 <span className="small text-warning">
755 ({this.unreadCount} {i18n.t("new")})
762 get unreadCount(): number | undefined {
763 const pv = this.postView;
764 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
766 : pv.unread_comments;
771 const tippy = showScores()
772 ? { "data-tippy-content": this.pointsTippy }
778 className={`btn-animate btn py-0 px-1 ${
779 this.postView.my_vote === 1 ? "text-info" : "text-muted"
782 onClick={linkEvent(this, this.handleUpvote)}
783 aria-label={i18n.t("upvote")}
784 aria-pressed={this.postView.my_vote === 1}
786 {this.state.upvoteLoading ? (
790 <Icon icon="arrow-up1" classes="icon-inline small" />
792 <span className="ml-2">
793 {numToSI(this.postView.counts.upvotes)}
799 {this.props.enableDownvotes && (
801 className={`ml-2 btn-animate btn py-0 px-1 ${
802 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
804 onClick={linkEvent(this, this.handleDownvote)}
806 aria-label={i18n.t("downvote")}
807 aria-pressed={this.postView.my_vote === -1}
809 {this.state.downvoteLoading ? (
813 <Icon icon="arrow-down1" classes="icon-inline small" />
816 className={classNames("ml-2", {
817 invisible: this.postView.counts.downvotes === 0,
820 {numToSI(this.postView.counts.downvotes)}
833 const saved = this.postView.saved;
834 const label = saved ? i18n.t("unsave") : i18n.t("save");
837 className="btn btn-link btn-animate text-muted py-0"
838 onClick={linkEvent(this, this.handleSavePostClick)}
839 data-tippy-content={label}
842 {this.state.saveLoading ? (
847 classes={classNames({ "text-warning": saved })}
855 get crossPostButton() {
858 className="btn btn-link btn-animate text-muted py-0"
860 /* Empty string properties are required to satisfy type*/
861 pathname: "/create_post",
862 state: { ...this.crossPostParams },
867 title={i18n.t("cross_post")}
868 data-tippy-content={i18n.t("cross_post")}
869 aria-label={i18n.t("cross_post")}
871 <Icon icon="copy" inline />
879 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
880 onClick={linkEvent(this, this.handleShowReportDialog)}
881 aria-label={i18n.t("show_report_dialog")}
883 <Icon classes="mr-1" icon="flag" inline />
884 {i18n.t("create_report")}
892 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
893 onClick={linkEvent(this, this.handleBlockPersonClick)}
894 aria-label={i18n.t("block_user")}
896 {this.state.blockLoading ? (
899 <Icon classes="mr-1" icon="slash" inline />
901 {i18n.t("block_user")}
909 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
910 onClick={linkEvent(this, this.handleEditClick)}
911 aria-label={i18n.t("edit")}
913 <Icon classes="mr-1" icon="edit" inline />
920 const deleted = this.postView.post.deleted;
921 const label = !deleted ? i18n.t("delete") : i18n.t("restore");
924 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
925 onClick={linkEvent(this, this.handleDeleteClick)}
928 {this.state.deleteLoading ? (
934 classes={classNames("mr-1", { "text-danger": deleted })}
944 get viewSourceButton() {
947 className="btn btn-link btn-animate text-muted py-0"
948 onClick={linkEvent(this, this.handleViewSource)}
949 data-tippy-content={i18n.t("view_source")}
950 aria-label={i18n.t("view_source")}
954 classes={classNames({ "text-success": this.state.viewSource })}
962 const locked = this.postView.post.locked;
963 const label = locked ? i18n.t("unlock") : i18n.t("lock");
966 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
967 onClick={linkEvent(this, this.handleModLock)}
970 {this.state.lockLoading ? (
976 classes={classNames("mr-1", { "text-danger": locked })}
986 get featureButtons() {
987 const featuredCommunity = this.postView.post.featured_community;
988 const labelCommunity = featuredCommunity
989 ? i18n.t("unfeature_from_community")
990 : i18n.t("feature_in_community");
992 const featuredLocal = this.postView.post.featured_local;
993 const labelLocal = featuredLocal
994 ? i18n.t("unfeature_from_local")
995 : i18n.t("feature_in_local");
1000 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1001 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
1002 data-tippy-content={labelCommunity}
1003 aria-label={labelCommunity}
1005 {this.state.featureCommunityLoading ? (
1011 classes={classNames("mr-1", {
1012 "text-success": featuredCommunity,
1016 {i18n.t("community")}
1024 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1025 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1026 data-tippy-content={labelLocal}
1027 aria-label={labelLocal}
1029 {this.state.featureLocalLoading ? (
1035 classes={classNames("mr-1", {
1036 "text-success": featuredLocal,
1050 get modRemoveButton() {
1051 const removed = this.postView.post.removed;
1054 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1057 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1060 {/* TODO: Find an icon for this. */}
1061 {this.state.removeLoading ? (
1073 * Mod/Admin actions to be taken against the author.
1077 const post_view = this.postView;
1079 this.state.showAdvanced && (
1083 {!this.creatorIsMod_ &&
1084 (!post_view.creator_banned_from_community ? (
1086 className="btn btn-link btn-animate text-muted py-0"
1089 this.handleModBanFromCommunityShow
1091 aria-label={i18n.t("ban_from_community")}
1093 {i18n.t("ban_from_community")}
1097 className="btn btn-link btn-animate text-muted py-0"
1100 this.handleModBanFromCommunitySubmit
1102 aria-label={i18n.t("unban")}
1104 {this.state.banLoading ? <Spinner /> : i18n.t("unban")}
1107 {!post_view.creator_banned_from_community && (
1109 className="btn btn-link btn-animate text-muted py-0"
1110 onClick={linkEvent(this, this.handleAddModToCommunity)}
1113 ? i18n.t("remove_as_mod")
1114 : i18n.t("appoint_as_mod")
1117 {this.state.addModLoading ? (
1119 ) : this.creatorIsMod_ ? (
1120 i18n.t("remove_as_mod")
1122 i18n.t("appoint_as_mod")
1128 {/* Community creators and admins can transfer community to another mod */}
1129 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1131 this.creatorIsMod_ &&
1132 (!this.state.showConfirmTransferCommunity ? (
1134 className="btn btn-link btn-animate text-muted py-0"
1137 this.handleShowConfirmTransferCommunity
1139 aria-label={i18n.t("transfer_community")}
1141 {i18n.t("transfer_community")}
1146 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1147 aria-label={i18n.t("are_you_sure")}
1149 {i18n.t("are_you_sure")}
1152 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1153 aria-label={i18n.t("yes")}
1154 onClick={linkEvent(this, this.handleTransferCommunity)}
1156 {this.state.transferLoading ? <Spinner /> : i18n.t("yes")}
1159 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1162 this.handleCancelShowConfirmTransferCommunity
1164 aria-label={i18n.t("no")}
1170 {/* Admins can ban from all, and appoint other admins */}
1171 {this.canAdmin_ && (
1173 {!this.creatorIsAdmin_ && (
1175 {!isBanned(post_view.creator) ? (
1177 className="btn btn-link btn-animate text-muted py-0"
1178 onClick={linkEvent(this, this.handleModBanShow)}
1179 aria-label={i18n.t("ban_from_site")}
1181 {i18n.t("ban_from_site")}
1185 className="btn btn-link btn-animate text-muted py-0"
1186 onClick={linkEvent(this, this.handleModBanSubmit)}
1187 aria-label={i18n.t("unban_from_site")}
1189 {this.state.banLoading ? (
1192 i18n.t("unban_from_site")
1197 className="btn btn-link btn-animate text-muted py-0"
1198 onClick={linkEvent(this, this.handlePurgePersonShow)}
1199 aria-label={i18n.t("purge_user")}
1201 {i18n.t("purge_user")}
1204 className="btn btn-link btn-animate text-muted py-0"
1205 onClick={linkEvent(this, this.handlePurgePostShow)}
1206 aria-label={i18n.t("purge_post")}
1208 {i18n.t("purge_post")}
1212 {!isBanned(post_view.creator) && post_view.creator.local && (
1214 className="btn btn-link btn-animate text-muted py-0"
1215 onClick={linkEvent(this, this.handleAddAdmin)}
1217 this.creatorIsAdmin_
1218 ? i18n.t("remove_as_admin")
1219 : i18n.t("appoint_as_admin")
1222 {this.state.addAdminLoading ? (
1224 ) : this.creatorIsAdmin_ ? (
1225 i18n.t("remove_as_admin")
1227 i18n.t("appoint_as_admin")
1238 removeAndBanDialogs() {
1239 const post = this.postView;
1240 const purgeTypeText =
1241 this.state.purgeType == PurgeType.Post
1242 ? i18n.t("purge_post")
1243 : `${i18n.t("purge")} ${post.creator.name}`;
1246 {this.state.showRemoveDialog && (
1248 className="form-inline"
1249 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1251 <label className="sr-only" htmlFor="post-listing-remove-reason">
1256 id="post-listing-remove-reason"
1257 className="form-control mr-2"
1258 placeholder={i18n.t("reason")}
1259 value={this.state.removeReason}
1260 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1264 className="btn btn-secondary"
1265 aria-label={i18n.t("remove_post")}
1267 {this.state.removeLoading ? <Spinner /> : i18n.t("remove_post")}
1271 {this.state.showBanDialog && (
1272 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1273 <div className="form-group row col-12">
1275 className="col-form-label"
1276 htmlFor="post-listing-ban-reason"
1282 id="post-listing-ban-reason"
1283 className="form-control mr-2"
1284 placeholder={i18n.t("reason")}
1285 value={this.state.banReason}
1286 onInput={linkEvent(this, this.handleModBanReasonChange)}
1288 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1293 id={`mod-ban-expires`}
1294 className="form-control mr-2"
1295 placeholder={i18n.t("number_of_days")}
1296 value={this.state.banExpireDays}
1297 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1299 <div className="form-group">
1300 <div className="form-check">
1302 className="form-check-input"
1303 id="mod-ban-remove-data"
1305 checked={this.state.removeData}
1306 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1309 className="form-check-label"
1310 htmlFor="mod-ban-remove-data"
1311 title={i18n.t("remove_content_more")}
1313 {i18n.t("remove_content")}
1318 {/* TODO hold off on expires until later */}
1319 {/* <div class="form-group row"> */}
1320 {/* <label class="col-form-label">Expires</label> */}
1321 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1323 <div className="form-group row">
1326 className="btn btn-secondary"
1327 aria-label={i18n.t("ban")}
1329 {this.state.banLoading ? (
1333 {i18n.t("ban")} {post.creator.name}
1340 {this.state.showReportDialog && (
1342 className="form-inline"
1343 onSubmit={linkEvent(this, this.handleReportSubmit)}
1345 <label className="sr-only" htmlFor="post-report-reason">
1350 id="post-report-reason"
1351 className="form-control mr-2"
1352 placeholder={i18n.t("reason")}
1354 value={this.state.reportReason}
1355 onInput={linkEvent(this, this.handleReportReasonChange)}
1359 className="btn btn-secondary"
1360 aria-label={i18n.t("create_report")}
1362 {this.state.reportLoading ? <Spinner /> : i18n.t("create_report")}
1366 {this.state.showPurgeDialog && (
1368 className="form-inline"
1369 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1372 <label className="sr-only" htmlFor="purge-reason">
1378 className="form-control mr-2"
1379 placeholder={i18n.t("reason")}
1380 value={this.state.purgeReason}
1381 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1383 {this.state.purgeLoading ? (
1388 className="btn btn-secondary"
1389 aria-label={purgeTypeText}
1391 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1401 const post = this.postView.post;
1402 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1403 <div className="row">
1404 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1405 {this.postTitleLine()}
1407 <div className="col-4">
1408 {/* Post body prev or thumbnail */}
1409 {!this.state.imageExpanded && this.thumbnail()}
1413 this.postTitleLine()
1417 showMobilePreview() {
1418 const { body, id } = this.postView.post;
1420 return !this.showBody && body ? (
1421 <Link className="text-body" to={`/post/${id}`}>
1422 <div className="md-div mb-1 preview-lines">{body}</div>
1432 {/* The mobile view*/}
1433 <div className="d-block d-sm-none">
1434 <article className="row post-container">
1435 <div className="col-12">
1436 {this.createdLine()}
1438 {/* If it has a thumbnail, do a right aligned thumbnail */}
1439 {this.mobileThumbnail()}
1441 {/* Show a preview of the post body */}
1442 {this.showMobilePreview()}
1444 {this.commentsLine(true)}
1445 {this.userActionsLine()}
1446 {this.duplicatesLine()}
1447 {this.removeAndBanDialogs()}
1452 {/* The larger view*/}
1453 <div className="d-none d-sm-block">
1454 <article className="row post-container">
1455 {!this.props.viewOnly && this.voteBar()}
1456 <div className="col-sm-2 pr-0 post-media">
1457 <div className="">{this.thumbnail()}</div>
1459 <div className="col-12 col-sm-9">
1460 <div className="row">
1461 <div className="col-12">
1462 {this.postTitleLine()}
1463 {this.createdLine()}
1464 {this.commentsLine()}
1465 {this.duplicatesLine()}
1466 {this.userActionsLine()}
1467 {this.removeAndBanDialogs()}
1477 private get myPost(): boolean {
1479 this.postView.creator.id ==
1480 UserService.Instance.myUserInfo?.local_user_view.person.id
1483 handleEditClick(i: PostListing) {
1484 i.setState({ showEdit: true });
1487 handleEditCancel() {
1488 this.setState({ showEdit: false });
1491 // The actual editing is done in the receive for post
1492 handleEditPost(form: EditPost) {
1493 this.setState({ showEdit: false });
1494 this.props.onPostEdit(form);
1497 handleShare(i: PostListing) {
1498 const { name, body, id } = i.props.post_view.post;
1501 text: body?.slice(0, 50),
1502 url: `${getHttpBase()}/post/${id}`,
1506 handleShowReportDialog(i: PostListing) {
1507 i.setState({ showReportDialog: !i.state.showReportDialog });
1510 handleReportReasonChange(i: PostListing, event: any) {
1511 i.setState({ reportReason: event.target.value });
1514 handleReportSubmit(i: PostListing, event: any) {
1515 event.preventDefault();
1516 i.setState({ reportLoading: true });
1517 i.props.onPostReport({
1518 post_id: i.postView.post.id,
1519 reason: i.state.reportReason ?? "",
1520 auth: myAuthRequired(),
1524 handleBlockPersonClick(i: PostListing) {
1525 i.setState({ blockLoading: true });
1526 i.props.onBlockPerson({
1527 person_id: i.postView.creator.id,
1529 auth: myAuthRequired(),
1533 handleDeleteClick(i: PostListing) {
1534 i.setState({ deleteLoading: true });
1535 i.props.onDeletePost({
1536 post_id: i.postView.post.id,
1537 deleted: !i.postView.post.deleted,
1538 auth: myAuthRequired(),
1542 handleSavePostClick(i: PostListing) {
1543 i.setState({ saveLoading: true });
1544 i.props.onSavePost({
1545 post_id: i.postView.post.id,
1546 save: !i.postView.saved,
1547 auth: myAuthRequired(),
1551 get crossPostParams(): PostFormParams {
1552 const queryParams: PostFormParams = {};
1553 const { name, url } = this.postView.post;
1555 queryParams.name = name;
1558 queryParams.url = url;
1561 const crossPostBody = this.crossPostBody();
1562 if (crossPostBody) {
1563 queryParams.body = crossPostBody;
1569 crossPostBody(): string | undefined {
1570 const post = this.postView.post;
1571 const body = post.body;
1574 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1581 get showBody(): boolean {
1582 return this.props.showBody || this.state.showBody;
1585 handleModRemoveShow(i: PostListing) {
1587 showRemoveDialog: !i.state.showRemoveDialog,
1588 showBanDialog: false,
1592 handleModRemoveReasonChange(i: PostListing, event: any) {
1593 i.setState({ removeReason: event.target.value });
1596 handleModRemoveDataChange(i: PostListing, event: any) {
1597 i.setState({ removeData: event.target.checked });
1600 handleModRemoveSubmit(i: PostListing, event: any) {
1601 event.preventDefault();
1602 i.setState({ removeLoading: true });
1603 i.props.onRemovePost({
1604 post_id: i.postView.post.id,
1605 removed: !i.postView.post.removed,
1606 auth: myAuthRequired(),
1610 handleModLock(i: PostListing) {
1611 i.setState({ lockLoading: true });
1612 i.props.onLockPost({
1613 post_id: i.postView.post.id,
1614 locked: !i.postView.post.locked,
1615 auth: myAuthRequired(),
1619 handleModFeaturePostLocal(i: PostListing) {
1620 i.setState({ featureLocalLoading: true });
1621 i.props.onFeaturePost({
1622 post_id: i.postView.post.id,
1623 featured: !i.postView.post.featured_local,
1624 feature_type: "Local",
1625 auth: myAuthRequired(),
1629 handleModFeaturePostCommunity(i: PostListing) {
1630 i.setState({ featureCommunityLoading: true });
1631 i.props.onFeaturePost({
1632 post_id: i.postView.post.id,
1633 featured: !i.postView.post.featured_community,
1634 feature_type: "Community",
1635 auth: myAuthRequired(),
1639 handleModBanFromCommunityShow(i: PostListing) {
1641 showBanDialog: true,
1642 banType: BanType.Community,
1643 showRemoveDialog: false,
1647 handleModBanShow(i: PostListing) {
1649 showBanDialog: true,
1650 banType: BanType.Site,
1651 showRemoveDialog: false,
1655 handlePurgePersonShow(i: PostListing) {
1657 showPurgeDialog: true,
1658 purgeType: PurgeType.Person,
1659 showRemoveDialog: false,
1663 handlePurgePostShow(i: PostListing) {
1665 showPurgeDialog: true,
1666 purgeType: PurgeType.Post,
1667 showRemoveDialog: false,
1671 handlePurgeReasonChange(i: PostListing, event: any) {
1672 i.setState({ purgeReason: event.target.value });
1675 handlePurgeSubmit(i: PostListing, event: any) {
1676 event.preventDefault();
1677 i.setState({ purgeLoading: true });
1678 if (i.state.purgeType == PurgeType.Person) {
1679 i.props.onPurgePerson({
1680 person_id: i.postView.creator.id,
1681 reason: i.state.purgeReason,
1682 auth: myAuthRequired(),
1684 } else if (i.state.purgeType == PurgeType.Post) {
1685 i.props.onPurgePost({
1686 post_id: i.postView.post.id,
1687 reason: i.state.purgeReason,
1688 auth: myAuthRequired(),
1693 handleModBanReasonChange(i: PostListing, event: any) {
1694 i.setState({ banReason: event.target.value });
1697 handleModBanExpireDaysChange(i: PostListing, event: any) {
1698 i.setState({ banExpireDays: event.target.value });
1701 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1702 i.setState({ banType: BanType.Community });
1703 i.handleModBanBothSubmit(i, event);
1706 handleModBanSubmit(i: PostListing, event: any) {
1707 i.setState({ banType: BanType.Site });
1708 i.handleModBanBothSubmit(i, event);
1711 handleModBanBothSubmit(i: PostListing, event: any) {
1712 event.preventDefault();
1713 i.setState({ banLoading: true });
1715 const ban = !i.props.post_view.creator_banned_from_community;
1716 // If its an unban, restore all their data
1718 i.setState({ removeData: false });
1720 const person_id = i.props.post_view.creator.id;
1721 const remove_data = i.state.removeData;
1722 const reason = i.state.banReason;
1723 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1725 if (i.state.banType == BanType.Community) {
1726 const community_id = i.postView.community.id;
1727 i.props.onBanPersonFromCommunity({
1734 auth: myAuthRequired(),
1737 i.props.onBanPerson({
1743 auth: myAuthRequired(),
1748 handleAddModToCommunity(i: PostListing) {
1749 i.setState({ addModLoading: true });
1750 i.props.onAddModToCommunity({
1751 community_id: i.postView.community.id,
1752 person_id: i.postView.creator.id,
1753 added: !i.creatorIsMod_,
1754 auth: myAuthRequired(),
1758 handleAddAdmin(i: PostListing) {
1759 i.setState({ addAdminLoading: true });
1760 i.props.onAddAdmin({
1761 person_id: i.postView.creator.id,
1762 added: !i.creatorIsAdmin_,
1763 auth: myAuthRequired(),
1767 handleShowConfirmTransferCommunity(i: PostListing) {
1768 i.setState({ showConfirmTransferCommunity: true });
1771 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1772 i.setState({ showConfirmTransferCommunity: false });
1775 handleTransferCommunity(i: PostListing) {
1776 i.setState({ transferLoading: true });
1777 i.props.onTransferCommunity({
1778 community_id: i.postView.community.id,
1779 person_id: i.postView.creator.id,
1780 auth: myAuthRequired(),
1784 handleShowConfirmTransferSite(i: PostListing) {
1785 i.setState({ showConfirmTransferSite: true });
1788 handleCancelShowConfirmTransferSite(i: PostListing) {
1789 i.setState({ showConfirmTransferSite: false });
1792 handleImageExpandClick(i: PostListing, event: any) {
1793 event.preventDefault();
1794 i.setState({ imageExpanded: !i.state.imageExpanded });
1798 handleViewSource(i: PostListing) {
1799 i.setState({ viewSource: !i.state.viewSource });
1802 handleShowAdvanced(i: PostListing) {
1803 i.setState({ showAdvanced: !i.state.showAdvanced });
1807 handleShowMoreMobile(i: PostListing) {
1809 showMoreMobile: !i.state.showMoreMobile,
1810 showAdvanced: !i.state.showAdvanced,
1815 handleShowBody(i: PostListing) {
1816 i.setState({ showBody: !i.state.showBody });
1820 handleUpvote(i: PostListing) {
1821 i.setState({ upvoteLoading: true });
1822 i.props.onPostVote({
1823 post_id: i.postView.post.id,
1824 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1825 auth: myAuthRequired(),
1829 handleDownvote(i: PostListing) {
1830 i.setState({ downvoteLoading: true });
1831 i.props.onPostVote({
1832 post_id: i.postView.post.id,
1833 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1834 auth: myAuthRequired(),
1838 get pointsTippy(): string {
1839 const points = i18n.t("number_of_points", {
1840 count: Number(this.postView.counts.score),
1841 formattedCount: Number(this.postView.counts.score),
1844 const upvotes = i18n.t("number_of_upvotes", {
1845 count: Number(this.postView.counts.upvotes),
1846 formattedCount: Number(this.postView.counts.upvotes),
1849 const downvotes = i18n.t("number_of_downvotes", {
1850 count: Number(this.postView.counts.downvotes),
1851 formattedCount: Number(this.postView.counts.downvotes),
1854 return `${points} • ${upvotes} • ${downvotes}`;
1857 get canModOnSelf_(): boolean {
1859 this.postView.creator.id,
1860 this.props.moderators,
1867 get canMod_(): boolean {
1869 this.postView.creator.id,
1870 this.props.moderators,
1875 get canAdmin_(): boolean {
1876 return canAdmin(this.postView.creator.id, this.props.admins);
1879 get creatorIsMod_(): boolean {
1880 return isMod(this.postView.creator.id, this.props.moderators);
1883 get creatorIsAdmin_(): boolean {
1884 return isAdmin(this.postView.creator.id, this.props.admins);