1 import { myAuthRequired } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
51 } from "../../interfaces";
52 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
53 import { I18NextService, UserService } from "../../services";
54 import { setupTippy } from "../../tippy";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
59 import { CommunityLink } from "../community/community-link";
60 import { PersonListing } from "../person/person-listing";
61 import { MetadataCard } from "./metadata-card";
62 import { PostForm } from "./post-form";
64 interface PostListingState {
66 showRemoveDialog: boolean;
67 showPurgeDialog: boolean;
69 purgeType?: PurgeType;
70 purgeLoading: boolean;
71 removeReason?: string;
72 showBanDialog: boolean;
74 banExpireDays?: number;
77 showConfirmTransferSite: boolean;
78 showConfirmTransferCommunity: boolean;
79 imageExpanded: boolean;
81 showAdvanced: boolean;
82 showMoreMobile: boolean;
84 showReportDialog: boolean;
85 reportReason?: string;
86 reportLoading: boolean;
87 blockLoading: boolean;
89 deleteLoading: boolean;
90 removeLoading: boolean;
92 featureCommunityLoading: boolean;
93 featureLocalLoading: boolean;
95 addModLoading: boolean;
96 addAdminLoading: boolean;
97 transferLoading: boolean;
100 interface PostListingProps {
102 crossPosts?: PostView[];
103 moderators?: CommunityModeratorView[];
104 admins?: PersonView[];
105 allLanguages: Language[];
106 siteLanguages: number[];
107 showCommunity?: boolean;
110 enableDownvotes?: boolean;
111 enableNsfw?: boolean;
113 onPostEdit(form: EditPost): void;
114 onPostVote(form: CreatePostLike): void;
115 onPostReport(form: CreatePostReport): void;
116 onBlockPerson(form: BlockPerson): void;
117 onLockPost(form: LockPost): void;
118 onDeletePost(form: DeletePost): void;
119 onRemovePost(form: RemovePost): void;
120 onSavePost(form: SavePost): void;
121 onFeaturePost(form: FeaturePost): void;
122 onPurgePerson(form: PurgePerson): void;
123 onPurgePost(form: PurgePost): void;
124 onBanPersonFromCommunity(form: BanFromCommunity): void;
125 onBanPerson(form: BanPerson): void;
126 onAddModToCommunity(form: AddModToCommunity): void;
127 onAddAdmin(form: AddAdmin): void;
128 onTransferCommunity(form: TransferCommunity): void;
131 export class PostListing extends Component<PostListingProps, PostListingState> {
132 state: PostListingState = {
134 showRemoveDialog: false,
135 showPurgeDialog: false,
136 purgeType: PurgeType.Person,
137 showBanDialog: false,
138 banType: BanType.Community,
140 showConfirmTransferSite: false,
141 showConfirmTransferCommunity: false,
142 imageExpanded: false,
145 showMoreMobile: false,
147 showReportDialog: false,
149 reportLoading: false,
152 deleteLoading: false,
153 removeLoading: false,
155 featureCommunityLoading: false,
156 featureLocalLoading: false,
158 addModLoading: false,
159 addAdminLoading: false,
160 transferLoading: false,
163 constructor(props: any, context: any) {
164 super(props, context);
166 this.handleEditPost = this.handleEditPost.bind(this);
167 this.handleEditCancel = this.handleEditCancel.bind(this);
170 componentWillReceiveProps(nextProps: PostListingProps) {
171 if (this.props !== nextProps) {
174 reportLoading: false,
177 deleteLoading: false,
178 removeLoading: false,
180 featureCommunityLoading: false,
181 featureLocalLoading: false,
183 addModLoading: false,
184 addAdminLoading: false,
185 transferLoading: false,
186 imageExpanded: false,
191 get postView(): PostView {
192 return this.props.post_view;
196 const post = this.postView.post;
199 <div className="post-listing mt-2">
200 {!this.state.showEdit ? (
203 {this.state.imageExpanded && !this.props.hideImage && this.img}
204 {post.url && this.state.showBody && post.embed_title && (
205 <MetadataCard post={post} />
207 {this.showBody && this.body()}
211 post_view={this.postView}
212 crossPosts={this.props.crossPosts}
213 onEdit={this.handleEditPost}
214 onCancel={this.handleEditCancel}
215 enableNsfw={this.props.enableNsfw}
216 enableDownvotes={this.props.enableDownvotes}
217 allLanguages={this.props.allLanguages}
218 siteLanguages={this.props.siteLanguages}
226 const body = this.postView.post.body;
228 <article id="postContent" className="col-12 card my-2 p-2">
229 {this.state.viewSource ? (
232 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
244 <div className="offset-sm-3 my-2 d-none d-sm-block">
245 <a href={this.imageSrc} className="d-inline-block">
246 <PictrsImage src={this.imageSrc} />
249 <div className="my-2 d-block d-sm-none">
252 className="p-0 border-0 bg-transparent d-inline-block"
253 onClick={linkEvent(this, this.handleImageExpandClick)}
255 <PictrsImage src={this.imageSrc} />
262 const { post } = this.postView;
263 const { url } = post;
265 // if direct video link
266 if (url && isVideo(url)) {
268 <div className="embed-responsive mt-3">
269 <video muted controls className="embed-responsive-item col-12">
270 <source src={url} type="video/mp4" />
276 // if embedded video link
277 if (url && post.embed_video_url) {
279 <div className="ratio ratio-16x9">
282 className="post-metadata-iframe"
283 src={post.embed_video_url}
284 title={post.embed_title}
293 imgThumb(src: string) {
294 const post_view = this.postView;
300 nsfw={post_view.post.nsfw || post_view.community.nsfw}
305 get imageSrc(): string | undefined {
306 const post = this.postView.post;
307 const url = post.url;
308 const thumbnail = post.thumbnail_url;
310 if (url && isImage(url)) {
311 if (url.includes("pictrs")) {
313 } else if (thumbnail) {
318 } else if (thumbnail) {
326 const post = this.postView.post;
327 const url = post.url;
328 const thumbnail = post.thumbnail_url;
330 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
334 className="text-body d-inline-block position-relative mb-2"
335 data-tippy-content={I18NextService.i18n.t("expand_here")}
336 onClick={linkEvent(this, this.handleImageExpandClick)}
337 aria-label={I18NextService.i18n.t("expand_here")}
339 {this.imgThumb(this.imageSrc)}
340 <Icon icon="image" classes="mini-overlay" />
343 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
346 className="text-body d-inline-block position-relative mb-2"
351 {this.imgThumb(this.imageSrc)}
352 <Icon icon="external-link" classes="mini-overlay" />
356 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
359 className="text-body"
363 data-tippy-content={I18NextService.i18n.t("expand_here")}
364 onClick={linkEvent(this, this.handleImageExpandClick)}
365 aria-label={I18NextService.i18n.t("expand_here")}
367 <div className="thumbnail rounded bg-light d-flex justify-content-center">
368 <Icon icon="play" classes="d-flex align-items-center" />
374 <a className="text-body" href={url} title={url} rel={relTags}>
375 <div className="thumbnail rounded bg-light d-flex justify-content-center">
376 <Icon icon="external-link" classes="d-flex align-items-center" />
384 className="text-body"
385 to={`/post/${post.id}`}
386 title={I18NextService.i18n.t("comments")}
388 <div className="thumbnail rounded bg-light d-flex justify-content-center">
389 <Icon icon="message-square" classes="d-flex align-items-center" />
397 const post_view = this.postView;
399 <span className="small">
400 <PersonListing person={post_view.creator} />
401 {this.creatorIsMod_ && (
402 <span className="mx-1 badge text-bg-light">
403 {I18NextService.i18n.t("mod")}
406 {this.creatorIsAdmin_ && (
407 <span className="mx-1 badge text-bg-light">
408 {I18NextService.i18n.t("admin")}
411 {post_view.creator.bot_account && (
412 <span className="mx-1 badge text-bg-light">
413 {I18NextService.i18n.t("bot_account").toLowerCase()}
416 {this.props.showCommunity && (
419 {I18NextService.i18n.t("to")}{" "}
420 <CommunityLink community={post_view.community} />
423 {post_view.post.language_id !== 0 && (
424 <span className="mx-1 badge text-bg-light">
426 this.props.allLanguages.find(
427 lang => lang.id === post_view.post.language_id
434 published={post_view.post.published}
435 updated={post_view.post.updated}
442 const post = this.postView.post;
445 className={`d-inline ${
446 !post.featured_community && !post.featured_local
450 to={`/post/${post.id}`}
451 title={I18NextService.i18n.t("comments")}
455 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
462 const post = this.postView.post;
463 const url = post.url;
467 <div className="post-title overflow-hidden">
468 <h5 className="d-inline">
469 {url && this.props.showBody ? (
472 !post.featured_community && !post.featured_local
479 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
485 {(url && isImage(url)) ||
486 (post.thumbnail_url && (
488 className="btn btn-sm text-monospace text-muted d-inline-block"
489 data-tippy-content={I18NextService.i18n.t("expand_here")}
490 onClick={linkEvent(this, this.handleImageExpandClick)}
494 !this.state.imageExpanded ? "plus-square" : "minus-square"
496 classes="icon-inline"
501 <small className="ms-2 badge text-bg-secondary">
502 {I18NextService.i18n.t("removed")}
507 className="unselectable pointer ms-2 text-muted fst-italic"
508 data-tippy-content={I18NextService.i18n.t("deleted")}
510 <Icon icon="trash" classes="icon-inline text-danger" />
515 className="unselectable pointer ms-2 text-muted fst-italic"
516 data-tippy-content={I18NextService.i18n.t("locked")}
518 <Icon icon="lock" classes="icon-inline text-danger" />
521 {post.featured_community && (
523 className="unselectable pointer ms-2 text-muted fst-italic"
524 data-tippy-content={I18NextService.i18n.t(
525 "featured_in_community"
527 aria-label={I18NextService.i18n.t("featured_in_community")}
529 <Icon icon="pin" classes="icon-inline text-primary" />
532 {post.featured_local && (
534 className="unselectable pointer ms-2 text-muted fst-italic"
535 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
536 aria-label={I18NextService.i18n.t("featured_in_local")}
538 <Icon icon="pin" classes="icon-inline text-secondary" />
542 <small className="ms-2 badge text-bg-danger">
543 {I18NextService.i18n.t("nsfw")}
547 {url && this.urlLine()}
553 const post = this.postView.post;
554 const url = post.url;
557 <p className="d-flex text-muted align-items-center gap-1 small m-0">
558 {url && !(hostname(url) === getExternalHost()) && (
560 className="text-muted fst-italic"
573 const dupes = this.props.crossPosts;
574 return dupes && dupes.length > 0 ? (
575 <ul className="list-inline mb-1 small text-muted">
577 <li className="list-inline-item me-2">
578 {I18NextService.i18n.t("cross_posted_to")}
581 <li key={pv.post.id} className="list-inline-item me-2">
582 <Link to={`/post/${pv.post.id}`}>
585 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
596 commentsLine(mobile = false) {
597 const post = this.postView.post;
600 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
601 {this.commentsButton}
604 className="btn btn-sm btn-animate text-muted py-0"
605 onClick={linkEvent(this, this.handleShare)}
608 <Icon icon="share" inline />
613 className="btn btn-sm btn-animate text-muted py-0"
614 title={I18NextService.i18n.t("link")}
617 <Icon icon="fedilink" inline />
620 {mobile && !this.props.viewOnly && (
622 voteContentType={VoteContentType.Post}
623 id={this.postView.post.id}
624 onVote={this.props.onPostVote}
625 enableDownvotes={this.props.enableDownvotes}
626 counts={this.postView.counts}
627 my_vote={this.postView.my_vote}
630 {UserService.Instance.myUserInfo &&
631 !this.props.viewOnly &&
637 showPreviewButton() {
638 const post_view = this.postView;
639 const body = post_view.post.body;
643 className="btn btn-sm btn-animate text-muted py-0"
644 data-tippy-content={body && mdNoImages.render(body)}
645 data-tippy-allowHtml={true}
646 onClick={linkEvent(this, this.handleShowBody)}
650 classes={classNames("icon-inline me-1", {
651 "text-success": this.state.showBody,
659 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
660 // Possible enhancement: Make each button a component.
661 const post_view = this.postView;
662 const post = post_view.post;
667 {this.crossPostButton}
670 * If there is a URL, or if the post has a body and we were told not to
671 * show the body, show the MetadataCard/body toggle.
673 {(post.url || (post.body && !this.props.showBody)) &&
674 this.showPreviewButton()}
676 {this.showBody && post_view.post.body && this.viewSourceButton}
678 <div className="dropdown">
680 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
681 onClick={linkEvent(this, this.handleShowAdvanced)}
682 data-tippy-content={I18NextService.i18n.t("more")}
683 data-bs-toggle="dropdown"
684 aria-expanded="false"
685 aria-controls={`advancedButtonsDropdown${post.id}`}
686 aria-label={I18NextService.i18n.t("more")}
688 <Icon icon="more-vertical" inline />
692 className="dropdown-menu"
693 id={`advancedButtonsDropdown${post.id}`}
697 <li>{this.reportButton}</li>
698 <li>{this.blockButton}</li>
702 <li>{this.editButton}</li>
703 <li>{this.deleteButton}</li>
707 {/* Any mod can do these, not limited to hierarchy*/}
708 {(amMod(this.props.moderators) || amAdmin()) && (
711 <hr className="dropdown-divider" />
713 <li>{this.lockButton}</li>
714 {this.featureButtons}
718 {(this.canMod_ || this.canAdmin_) && (
719 <li>{this.modRemoveButton}</li>
727 get commentsButton() {
728 const post_view = this.postView;
729 const title = I18NextService.i18n.t("number_of_comments", {
730 count: Number(post_view.counts.comments),
731 formattedCount: Number(post_view.counts.comments),
736 className="btn btn-link btn-sm text-muted ps-0"
738 to={`/post/${post_view.post.id}?scrollToComments=true`}
739 data-tippy-content={title}
741 <Icon icon="message-square" classes="me-1" inline />
742 {post_view.counts.comments}
743 {this.unreadCount && (
746 <span className="fst-italic">
747 ({this.unreadCount} {I18NextService.i18n.t("new")})
755 get unreadCount(): number | undefined {
756 const pv = this.postView;
757 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
759 : pv.unread_comments;
763 const saved = this.postView.saved;
765 ? I18NextService.i18n.t("unsave")
766 : I18NextService.i18n.t("save");
769 className="btn btn-sm btn-animate text-muted py-0"
770 onClick={linkEvent(this, this.handleSavePostClick)}
771 data-tippy-content={label}
774 {this.state.saveLoading ? (
779 classes={classNames({ "text-warning": saved })}
787 get crossPostButton() {
790 className="btn btn-sm btn-animate text-muted py-0"
792 /* Empty string properties are required to satisfy type*/
793 pathname: "/create_post",
794 state: { ...this.crossPostParams },
799 title={I18NextService.i18n.t("cross_post")}
800 data-tippy-content={I18NextService.i18n.t("cross_post")}
801 aria-label={I18NextService.i18n.t("cross_post")}
803 <Icon icon="copy" inline />
811 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
812 onClick={linkEvent(this, this.handleShowReportDialog)}
813 aria-label={I18NextService.i18n.t("show_report_dialog")}
815 <Icon classes="me-1" icon="flag" inline />
816 {I18NextService.i18n.t("create_report")}
824 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
825 onClick={linkEvent(this, this.handleBlockPersonClick)}
826 aria-label={I18NextService.i18n.t("block_user")}
828 {this.state.blockLoading ? (
831 <Icon classes="me-1" icon="slash" inline />
833 {I18NextService.i18n.t("block_user")}
841 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
842 onClick={linkEvent(this, this.handleEditClick)}
843 aria-label={I18NextService.i18n.t("edit")}
845 <Icon classes="me-1" icon="edit" inline />
846 {I18NextService.i18n.t("edit")}
852 const deleted = this.postView.post.deleted;
853 const label = !deleted
854 ? I18NextService.i18n.t("delete")
855 : I18NextService.i18n.t("restore");
858 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
859 onClick={linkEvent(this, this.handleDeleteClick)}
861 {this.state.deleteLoading ? (
867 classes={classNames("me-1", { "text-danger": deleted })}
877 get viewSourceButton() {
880 className="btn btn-sm btn-animate text-muted py-0"
881 onClick={linkEvent(this, this.handleViewSource)}
882 data-tippy-content={I18NextService.i18n.t("view_source")}
883 aria-label={I18NextService.i18n.t("view_source")}
887 classes={classNames({ "text-success": this.state.viewSource })}
895 const locked = this.postView.post.locked;
897 ? I18NextService.i18n.t("unlock")
898 : I18NextService.i18n.t("lock");
901 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
902 onClick={linkEvent(this, this.handleModLock)}
905 {this.state.lockLoading ? (
911 classes={classNames("me-1", { "text-danger": locked })}
914 {capitalizeFirstLetter(label)}
921 get featureButtons() {
922 const featuredCommunity = this.postView.post.featured_community;
923 const labelCommunity = featuredCommunity
924 ? I18NextService.i18n.t("unfeature_from_community")
925 : I18NextService.i18n.t("feature_in_community");
927 const featuredLocal = this.postView.post.featured_local;
928 const labelLocal = featuredLocal
929 ? I18NextService.i18n.t("unfeature_from_local")
930 : I18NextService.i18n.t("feature_in_local");
935 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
936 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
937 data-tippy-content={labelCommunity}
938 aria-label={labelCommunity}
940 {this.state.featureCommunityLoading ? (
946 classes={classNames("me-1", {
947 "text-success": featuredCommunity,
951 {I18NextService.i18n.t("community")}
959 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
960 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
961 data-tippy-content={labelLocal}
962 aria-label={labelLocal}
964 {this.state.featureLocalLoading ? (
970 classes={classNames("me-1", {
971 "text-success": featuredLocal,
975 {I18NextService.i18n.t("local")}
985 get modBanFromCommunityButton() {
988 className="btn btn-link btn-animate text-muted py-0"
989 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
990 aria-label={I18NextService.i18n.t("ban_from_community")}
992 {I18NextService.i18n.t("ban_from_community")}
997 get modUnbanFromCommunityButton() {
1000 className="btn btn-link btn-animate text-muted py-0"
1001 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
1002 aria-label={I18NextService.i18n.t("unban")}
1004 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1009 get addModToCommunityButton() {
1012 className="btn btn-link btn-animate text-muted py-0"
1013 onClick={linkEvent(this, this.handleAddModToCommunity)}
1016 ? I18NextService.i18n.t("remove_as_mod")
1017 : I18NextService.i18n.t("appoint_as_mod")
1020 {this.state.addModLoading ? (
1022 ) : this.creatorIsMod_ ? (
1023 I18NextService.i18n.t("remove_as_mod")
1025 I18NextService.i18n.t("appoint_as_mod")
1031 get modBanButton() {
1034 className="btn btn-link btn-animate text-muted py-0"
1035 onClick={linkEvent(this, this.handleModBanShow)}
1036 aria-label={I18NextService.i18n.t("ban_from_site")}
1038 {I18NextService.i18n.t("ban_from_site")}
1043 get modUnbanButton() {
1046 className="btn btn-link btn-animate text-muted py-0"
1047 onClick={linkEvent(this, this.handleModBanSubmit)}
1048 aria-label={I18NextService.i18n.t("unban_from_site")}
1050 {this.state.banLoading ? (
1053 I18NextService.i18n.t("unban_from_site")
1059 get purgePersonButton() {
1062 className="btn btn-link btn-animate text-muted py-0"
1063 onClick={linkEvent(this, this.handlePurgePersonShow)}
1064 aria-label={I18NextService.i18n.t("purge_user")}
1066 {I18NextService.i18n.t("purge_user")}
1071 get purgePostButton() {
1074 className="btn btn-link btn-animate text-muted py-0"
1075 onClick={linkEvent(this, this.handlePurgePostShow)}
1076 aria-label={I18NextService.i18n.t("purge_post")}
1078 {I18NextService.i18n.t("purge_post")}
1083 get toggleAdminButton() {
1086 className="btn btn-link btn-animate text-muted py-0"
1087 onClick={linkEvent(this, this.handleAddAdmin)}
1089 {this.state.addAdminLoading ? (
1091 ) : this.creatorIsAdmin_ ? (
1092 I18NextService.i18n.t("remove_as_admin")
1094 I18NextService.i18n.t("appoint_as_admin")
1100 get modRemoveButton() {
1101 const removed = this.postView.post.removed;
1104 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1107 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1110 {/* TODO: Find an icon for this. */}
1111 {this.state.removeLoading ? (
1114 I18NextService.i18n.t("remove")
1116 I18NextService.i18n.t("restore")
1123 * Mod/Admin actions to be taken against the author.
1127 const post_view = this.postView;
1129 this.state.showAdvanced && (
1130 <div className="mt-3 user-actions-line">
1133 {!this.creatorIsMod_ &&
1134 (!post_view.creator_banned_from_community ? (
1135 <li>{this.modBanFromCommunityButton}</li>
1137 <li>{this.modUnbanFromCommunityButton}</li>
1139 {!post_view.creator_banned_from_community && (
1140 <li>{this.addModToCommunityButton}</li>
1145 {/* Community creators and admins can transfer community to another mod */}
1146 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1148 this.creatorIsMod_ &&
1149 (!this.state.showConfirmTransferCommunity ? (
1151 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1154 this.handleShowConfirmTransferCommunity
1156 aria-label={I18NextService.i18n.t("transfer_community")}
1158 {I18NextService.i18n.t("transfer_community")}
1163 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1164 aria-label={I18NextService.i18n.t("are_you_sure")}
1166 {I18NextService.i18n.t("are_you_sure")}
1169 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1170 aria-label={I18NextService.i18n.t("yes")}
1171 onClick={linkEvent(this, this.handleTransferCommunity)}
1173 {this.state.transferLoading ? (
1176 I18NextService.i18n.t("yes")
1180 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1183 this.handleCancelShowConfirmTransferCommunity
1185 aria-label={I18NextService.i18n.t("no")}
1187 {I18NextService.i18n.t("no")}
1191 {/* Admins can ban from all, and appoint other admins */}
1192 {this.canAdmin_ && (
1194 {!this.creatorIsAdmin_ && (
1196 {!isBanned(post_view.creator)
1198 : this.modUnbanButton}
1199 {this.purgePersonButton}
1200 {this.purgePostButton}
1203 {!isBanned(post_view.creator) &&
1204 post_view.creator.local &&
1205 this.toggleAdminButton}
1213 removeAndBanDialogs() {
1214 const post = this.postView;
1215 const purgeTypeText =
1216 this.state.purgeType == PurgeType.Post
1217 ? I18NextService.i18n.t("purge_post")
1218 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1221 {this.state.showRemoveDialog && (
1223 className="form-inline"
1224 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1227 className="visually-hidden"
1228 htmlFor="post-listing-remove-reason"
1230 {I18NextService.i18n.t("reason")}
1234 id="post-listing-remove-reason"
1235 className="form-control me-2"
1236 placeholder={I18NextService.i18n.t("reason")}
1237 value={this.state.removeReason}
1238 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1242 className="btn btn-secondary"
1243 aria-label={I18NextService.i18n.t("remove_post")}
1245 {this.state.removeLoading ? (
1248 I18NextService.i18n.t("remove_post")
1253 {this.state.showBanDialog && (
1254 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1255 <div className="mb-3 row col-12">
1257 className="col-form-label"
1258 htmlFor="post-listing-ban-reason"
1260 {I18NextService.i18n.t("reason")}
1264 id="post-listing-ban-reason"
1265 className="form-control me-2"
1266 placeholder={I18NextService.i18n.t("reason")}
1267 value={this.state.banReason}
1268 onInput={linkEvent(this, this.handleModBanReasonChange)}
1270 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1271 {I18NextService.i18n.t("expires")}
1275 id={`mod-ban-expires`}
1276 className="form-control me-2"
1277 placeholder={I18NextService.i18n.t("number_of_days")}
1278 value={this.state.banExpireDays}
1279 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1281 <div className="input-group mb-3">
1282 <div className="form-check">
1284 className="form-check-input"
1285 id="mod-ban-remove-data"
1287 checked={this.state.removeData}
1288 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1291 className="form-check-label"
1292 htmlFor="mod-ban-remove-data"
1293 title={I18NextService.i18n.t("remove_content_more")}
1295 {I18NextService.i18n.t("remove_content")}
1300 {/* TODO hold off on expires until later */}
1301 {/* <div class="mb-3 row"> */}
1302 {/* <label class="col-form-label">Expires</label> */}
1303 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1305 <div className="mb-3 row">
1308 className="btn btn-secondary"
1309 aria-label={I18NextService.i18n.t("ban")}
1311 {this.state.banLoading ? (
1315 {I18NextService.i18n.t("ban")} {post.creator.name}
1322 {this.state.showReportDialog && (
1324 className="form-inline"
1325 onSubmit={linkEvent(this, this.handleReportSubmit)}
1327 <label className="visually-hidden" htmlFor="post-report-reason">
1328 {I18NextService.i18n.t("reason")}
1332 id="post-report-reason"
1333 className="form-control me-2"
1334 placeholder={I18NextService.i18n.t("reason")}
1336 value={this.state.reportReason}
1337 onInput={linkEvent(this, this.handleReportReasonChange)}
1341 className="btn btn-secondary"
1342 aria-label={I18NextService.i18n.t("create_report")}
1344 {this.state.reportLoading ? (
1347 I18NextService.i18n.t("create_report")
1352 {this.state.showPurgeDialog && (
1354 className="form-inline"
1355 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1358 <label className="visually-hidden" htmlFor="purge-reason">
1359 {I18NextService.i18n.t("reason")}
1364 className="form-control me-2"
1365 placeholder={I18NextService.i18n.t("reason")}
1366 value={this.state.purgeReason}
1367 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1369 {this.state.purgeLoading ? (
1374 className="btn btn-secondary"
1375 aria-label={purgeTypeText}
1377 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1387 const post = this.postView.post;
1388 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1389 <div className="row">
1390 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1391 {this.postTitleLine()}
1393 <div className="col-4">
1394 {/* Post thumbnail */}
1395 {!this.state.imageExpanded && this.thumbnail()}
1399 this.postTitleLine()
1404 const { body, id } = this.postView.post;
1406 return !this.showBody && body ? (
1407 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1408 <div className="md-div mb-1 preview-lines">{body}</div>
1418 {/* The mobile view*/}
1419 <div className="d-block d-sm-none">
1420 <article className="row post-container">
1421 <div className="col-12">
1422 {this.createdLine()}
1424 {/* If it has a thumbnail, do a right aligned thumbnail */}
1425 {this.mobileThumbnail()}
1427 {/* Show a preview of the post body */}
1428 {this.showBodyPreview()}
1430 {this.commentsLine(true)}
1431 {this.userActionsLine()}
1432 {this.duplicatesLine()}
1433 {this.removeAndBanDialogs()}
1438 {/* The larger view*/}
1439 <div className="d-none d-sm-block">
1440 <article className="row post-container">
1441 {!this.props.viewOnly && (
1443 voteContentType={VoteContentType.Post}
1444 id={this.postView.post.id}
1445 onVote={this.props.onPostVote}
1446 enableDownvotes={this.props.enableDownvotes}
1447 counts={this.postView.counts}
1448 my_vote={this.postView.my_vote}
1451 <div className="col-sm-2 pe-0 post-media">
1452 <div className="">{this.thumbnail()}</div>
1454 <div className="col-12 col-sm-9">
1455 <div className="row">
1456 <div className="col-12">
1457 {this.postTitleLine()}
1458 {this.createdLine()}
1459 {this.showBodyPreview()}
1460 {this.commentsLine()}
1461 {this.duplicatesLine()}
1462 {this.userActionsLine()}
1463 {this.removeAndBanDialogs()}
1473 private get myPost(): boolean {
1475 this.postView.creator.id ==
1476 UserService.Instance.myUserInfo?.local_user_view.person.id
1479 handleEditClick(i: PostListing) {
1480 i.setState({ showEdit: true });
1483 handleEditCancel() {
1484 this.setState({ showEdit: false });
1487 // The actual editing is done in the receive for post
1488 handleEditPost(form: EditPost) {
1489 this.setState({ showEdit: false });
1490 this.props.onPostEdit(form);
1493 handleShare(i: PostListing) {
1494 const { name, body, id } = i.props.post_view.post;
1497 text: body?.slice(0, 50),
1498 url: `${getHttpBase()}/post/${id}`,
1502 handleShowReportDialog(i: PostListing) {
1503 i.setState({ showReportDialog: !i.state.showReportDialog });
1506 handleReportReasonChange(i: PostListing, event: any) {
1507 i.setState({ reportReason: event.target.value });
1510 handleReportSubmit(i: PostListing, event: any) {
1511 event.preventDefault();
1512 i.setState({ reportLoading: true });
1513 i.props.onPostReport({
1514 post_id: i.postView.post.id,
1515 reason: i.state.reportReason ?? "",
1516 auth: myAuthRequired(),
1520 handleBlockPersonClick(i: PostListing) {
1521 i.setState({ blockLoading: true });
1522 i.props.onBlockPerson({
1523 person_id: i.postView.creator.id,
1525 auth: myAuthRequired(),
1529 handleDeleteClick(i: PostListing) {
1530 i.setState({ deleteLoading: true });
1531 i.props.onDeletePost({
1532 post_id: i.postView.post.id,
1533 deleted: !i.postView.post.deleted,
1534 auth: myAuthRequired(),
1538 handleSavePostClick(i: PostListing) {
1539 i.setState({ saveLoading: true });
1540 i.props.onSavePost({
1541 post_id: i.postView.post.id,
1542 save: !i.postView.saved,
1543 auth: myAuthRequired(),
1547 get crossPostParams(): PostFormParams {
1548 const queryParams: PostFormParams = {};
1549 const { name, url } = this.postView.post;
1551 queryParams.name = name;
1554 queryParams.url = url;
1557 const crossPostBody = this.crossPostBody();
1558 if (crossPostBody) {
1559 queryParams.body = crossPostBody;
1565 crossPostBody(): string | undefined {
1566 const post = this.postView.post;
1567 const body = post.body;
1570 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1572 }\n\n${body.replace(/^/gm, "> ")}`
1576 get showBody(): boolean {
1577 return this.props.showBody || this.state.showBody;
1580 handleModRemoveShow(i: PostListing) {
1582 showRemoveDialog: !i.state.showRemoveDialog,
1583 showBanDialog: false,
1587 handleModRemoveReasonChange(i: PostListing, event: any) {
1588 i.setState({ removeReason: event.target.value });
1591 handleModRemoveDataChange(i: PostListing, event: any) {
1592 i.setState({ removeData: event.target.checked });
1595 handleModRemoveSubmit(i: PostListing, event: any) {
1596 event.preventDefault();
1597 i.setState({ removeLoading: true });
1598 i.props.onRemovePost({
1599 post_id: i.postView.post.id,
1600 removed: !i.postView.post.removed,
1601 auth: myAuthRequired(),
1605 handleModLock(i: PostListing) {
1606 i.setState({ lockLoading: true });
1607 i.props.onLockPost({
1608 post_id: i.postView.post.id,
1609 locked: !i.postView.post.locked,
1610 auth: myAuthRequired(),
1614 handleModFeaturePostLocal(i: PostListing) {
1615 i.setState({ featureLocalLoading: true });
1616 i.props.onFeaturePost({
1617 post_id: i.postView.post.id,
1618 featured: !i.postView.post.featured_local,
1619 feature_type: "Local",
1620 auth: myAuthRequired(),
1624 handleModFeaturePostCommunity(i: PostListing) {
1625 i.setState({ featureCommunityLoading: true });
1626 i.props.onFeaturePost({
1627 post_id: i.postView.post.id,
1628 featured: !i.postView.post.featured_community,
1629 feature_type: "Community",
1630 auth: myAuthRequired(),
1634 handleModBanFromCommunityShow(i: PostListing) {
1636 showBanDialog: true,
1637 banType: BanType.Community,
1638 showRemoveDialog: false,
1642 handleModBanShow(i: PostListing) {
1644 showBanDialog: true,
1645 banType: BanType.Site,
1646 showRemoveDialog: false,
1650 handlePurgePersonShow(i: PostListing) {
1652 showPurgeDialog: true,
1653 purgeType: PurgeType.Person,
1654 showRemoveDialog: false,
1658 handlePurgePostShow(i: PostListing) {
1660 showPurgeDialog: true,
1661 purgeType: PurgeType.Post,
1662 showRemoveDialog: false,
1666 handlePurgeReasonChange(i: PostListing, event: any) {
1667 i.setState({ purgeReason: event.target.value });
1670 handlePurgeSubmit(i: PostListing, event: any) {
1671 event.preventDefault();
1672 i.setState({ purgeLoading: true });
1673 if (i.state.purgeType == PurgeType.Person) {
1674 i.props.onPurgePerson({
1675 person_id: i.postView.creator.id,
1676 reason: i.state.purgeReason,
1677 auth: myAuthRequired(),
1679 } else if (i.state.purgeType == PurgeType.Post) {
1680 i.props.onPurgePost({
1681 post_id: i.postView.post.id,
1682 reason: i.state.purgeReason,
1683 auth: myAuthRequired(),
1688 handleModBanReasonChange(i: PostListing, event: any) {
1689 i.setState({ banReason: event.target.value });
1692 handleModBanExpireDaysChange(i: PostListing, event: any) {
1693 i.setState({ banExpireDays: event.target.value });
1696 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1697 i.setState({ banType: BanType.Community });
1698 i.handleModBanBothSubmit(i, event);
1701 handleModBanSubmit(i: PostListing, event: any) {
1702 i.setState({ banType: BanType.Site });
1703 i.handleModBanBothSubmit(i, event);
1706 handleModBanBothSubmit(i: PostListing, event: any) {
1707 event.preventDefault();
1708 i.setState({ banLoading: true });
1710 const ban = !i.props.post_view.creator_banned_from_community;
1711 // If its an unban, restore all their data
1713 i.setState({ removeData: false });
1715 const person_id = i.props.post_view.creator.id;
1716 const remove_data = i.state.removeData;
1717 const reason = i.state.banReason;
1718 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1720 if (i.state.banType == BanType.Community) {
1721 const community_id = i.postView.community.id;
1722 i.props.onBanPersonFromCommunity({
1729 auth: myAuthRequired(),
1732 i.props.onBanPerson({
1738 auth: myAuthRequired(),
1743 handleAddModToCommunity(i: PostListing) {
1744 i.setState({ addModLoading: true });
1745 i.props.onAddModToCommunity({
1746 community_id: i.postView.community.id,
1747 person_id: i.postView.creator.id,
1748 added: !i.creatorIsMod_,
1749 auth: myAuthRequired(),
1753 handleAddAdmin(i: PostListing) {
1754 i.setState({ addAdminLoading: true });
1755 i.props.onAddAdmin({
1756 person_id: i.postView.creator.id,
1757 added: !i.creatorIsAdmin_,
1758 auth: myAuthRequired(),
1762 handleShowConfirmTransferCommunity(i: PostListing) {
1763 i.setState({ showConfirmTransferCommunity: true });
1766 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1767 i.setState({ showConfirmTransferCommunity: false });
1770 handleTransferCommunity(i: PostListing) {
1771 i.setState({ transferLoading: true });
1772 i.props.onTransferCommunity({
1773 community_id: i.postView.community.id,
1774 person_id: i.postView.creator.id,
1775 auth: myAuthRequired(),
1779 handleShowConfirmTransferSite(i: PostListing) {
1780 i.setState({ showConfirmTransferSite: true });
1783 handleCancelShowConfirmTransferSite(i: PostListing) {
1784 i.setState({ showConfirmTransferSite: false });
1787 handleImageExpandClick(i: PostListing, event: any) {
1788 event.preventDefault();
1789 i.setState({ imageExpanded: !i.state.imageExpanded });
1793 handleViewSource(i: PostListing) {
1794 i.setState({ viewSource: !i.state.viewSource });
1797 handleShowAdvanced(i: PostListing) {
1798 i.setState({ showAdvanced: !i.state.showAdvanced });
1802 handleShowMoreMobile(i: PostListing) {
1804 showMoreMobile: !i.state.showMoreMobile,
1805 showAdvanced: !i.state.showAdvanced,
1810 handleShowBody(i: PostListing) {
1811 i.setState({ showBody: !i.state.showBody });
1815 get pointsTippy(): string {
1816 const points = I18NextService.i18n.t("number_of_points", {
1817 count: Number(this.postView.counts.score),
1818 formattedCount: Number(this.postView.counts.score),
1821 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1822 count: Number(this.postView.counts.upvotes),
1823 formattedCount: Number(this.postView.counts.upvotes),
1826 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1827 count: Number(this.postView.counts.downvotes),
1828 formattedCount: Number(this.postView.counts.downvotes),
1831 return `${points} • ${upvotes} • ${downvotes}`;
1834 get canModOnSelf_(): boolean {
1836 this.postView.creator.id,
1837 this.props.moderators,
1844 get canMod_(): boolean {
1846 this.postView.creator.id,
1847 this.props.moderators,
1852 get canAdmin_(): boolean {
1853 return canAdmin(this.postView.creator.id, this.props.admins);
1856 get creatorIsMod_(): boolean {
1857 return isMod(this.postView.creator.id, this.props.moderators);
1860 get creatorIsAdmin_(): boolean {
1861 return isAdmin(this.postView.creator.id, this.props.admins);