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 get postView(): PostView {
171 return this.props.post_view;
175 const post = this.postView.post;
178 <div className="post-listing mt-2">
179 {!this.state.showEdit ? (
182 {this.state.imageExpanded && !this.props.hideImage && this.img}
183 {post.url && this.state.showBody && post.embed_title && (
184 <MetadataCard post={post} />
186 {this.showBody && this.body()}
190 post_view={this.postView}
191 crossPosts={this.props.crossPosts}
192 onEdit={this.handleEditPost}
193 onCancel={this.handleEditCancel}
194 enableNsfw={this.props.enableNsfw}
195 enableDownvotes={this.props.enableDownvotes}
196 allLanguages={this.props.allLanguages}
197 siteLanguages={this.props.siteLanguages}
205 const body = this.postView.post.body;
207 <article id="postContent" className="col-12 card my-2 p-2">
208 {this.state.viewSource ? (
211 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
223 <div className="offset-sm-3 my-2 d-none d-sm-block">
224 <a href={this.imageSrc} className="d-inline-block">
225 <PictrsImage src={this.imageSrc} />
228 <div className="my-2 d-block d-sm-none">
231 className="p-0 border-0 bg-transparent d-inline-block"
232 onClick={linkEvent(this, this.handleImageExpandClick)}
234 <PictrsImage src={this.imageSrc} />
241 const { post } = this.postView;
242 const { url } = post;
244 // if direct video link
245 if (url && isVideo(url)) {
247 <div className="embed-responsive mt-3">
248 <video muted controls className="embed-responsive-item col-12">
249 <source src={url} type="video/mp4" />
255 // if embedded video link
256 if (url && post.embed_video_url) {
258 <div className="ratio ratio-16x9">
261 className="post-metadata-iframe"
262 src={post.embed_video_url}
263 title={post.embed_title}
272 imgThumb(src: string) {
273 const post_view = this.postView;
279 nsfw={post_view.post.nsfw || post_view.community.nsfw}
284 get imageSrc(): string | undefined {
285 const post = this.postView.post;
286 const url = post.url;
287 const thumbnail = post.thumbnail_url;
289 if (url && isImage(url)) {
290 if (url.includes("pictrs")) {
292 } else if (thumbnail) {
297 } else if (thumbnail) {
305 const post = this.postView.post;
306 const url = post.url;
307 const thumbnail = post.thumbnail_url;
309 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
313 className="text-body d-inline-block position-relative mb-2"
314 data-tippy-content={I18NextService.i18n.t("expand_here")}
315 onClick={linkEvent(this, this.handleImageExpandClick)}
316 aria-label={I18NextService.i18n.t("expand_here")}
318 {this.imgThumb(this.imageSrc)}
319 <Icon icon="image" classes="mini-overlay" />
322 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
325 className="text-body d-inline-block position-relative mb-2"
330 {this.imgThumb(this.imageSrc)}
331 <Icon icon="external-link" classes="mini-overlay" />
335 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
338 className="text-body"
342 data-tippy-content={I18NextService.i18n.t("expand_here")}
343 onClick={linkEvent(this, this.handleImageExpandClick)}
344 aria-label={I18NextService.i18n.t("expand_here")}
346 <div className="thumbnail rounded bg-light d-flex justify-content-center">
347 <Icon icon="play" classes="d-flex align-items-center" />
353 <a className="text-body" href={url} title={url} rel={relTags}>
354 <div className="thumbnail rounded bg-light d-flex justify-content-center">
355 <Icon icon="external-link" classes="d-flex align-items-center" />
363 className="text-body"
364 to={`/post/${post.id}`}
365 title={I18NextService.i18n.t("comments")}
367 <div className="thumbnail rounded bg-light d-flex justify-content-center">
368 <Icon icon="message-square" classes="d-flex align-items-center" />
376 const post_view = this.postView;
378 <span className="small">
379 <PersonListing person={post_view.creator} muted={true} />
380 {this.creatorIsMod_ && (
381 <span className="mx-1 badge text-bg-light">
382 {I18NextService.i18n.t("mod")}
385 {this.creatorIsAdmin_ && (
386 <span className="mx-1 badge text-bg-light">
387 {I18NextService.i18n.t("admin")}
390 {post_view.creator.bot_account && (
391 <span className="mx-1 badge text-bg-light">
392 {I18NextService.i18n.t("bot_account").toLowerCase()}
395 {this.props.showCommunity && (
398 {I18NextService.i18n.t("to")}{" "}
399 <CommunityLink community={post_view.community} />
402 {post_view.post.language_id !== 0 && (
403 <span className="mx-1 badge text-bg-light">
405 this.props.allLanguages.find(
406 lang => lang.id === post_view.post.language_id
413 published={post_view.post.published}
414 updated={post_view.post.updated}
421 const post = this.postView.post;
424 className={`d-inline ${
425 !post.featured_community && !post.featured_local
429 to={`/post/${post.id}`}
430 title={I18NextService.i18n.t("comments")}
434 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
441 const post = this.postView.post;
442 const url = post.url;
446 <div className="post-title overflow-hidden">
447 <h5 className="d-inline">
448 {url && this.props.showBody ? (
451 !post.featured_community && !post.featured_local
458 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
464 {(url && isImage(url)) ||
465 (post.thumbnail_url && (
467 className="btn btn-sm text-monospace text-muted d-inline-block"
468 data-tippy-content={I18NextService.i18n.t("expand_here")}
469 onClick={linkEvent(this, this.handleImageExpandClick)}
473 !this.state.imageExpanded ? "plus-square" : "minus-square"
475 classes="icon-inline"
480 <small className="ms-2 badge text-bg-secondary">
481 {I18NextService.i18n.t("removed")}
486 className="unselectable pointer ms-2 text-muted fst-italic"
487 data-tippy-content={I18NextService.i18n.t("deleted")}
489 <Icon icon="trash" classes="icon-inline text-danger" />
494 className="unselectable pointer ms-2 text-muted fst-italic"
495 data-tippy-content={I18NextService.i18n.t("locked")}
497 <Icon icon="lock" classes="icon-inline text-danger" />
500 {post.featured_community && (
502 className="unselectable pointer ms-2 text-muted fst-italic"
503 data-tippy-content={I18NextService.i18n.t(
504 "featured_in_community"
506 aria-label={I18NextService.i18n.t("featured_in_community")}
508 <Icon icon="pin" classes="icon-inline text-primary" />
511 {post.featured_local && (
513 className="unselectable pointer ms-2 text-muted fst-italic"
514 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
515 aria-label={I18NextService.i18n.t("featured_in_local")}
517 <Icon icon="pin" classes="icon-inline text-secondary" />
521 <small className="ms-2 badge text-bg-danger">
522 {I18NextService.i18n.t("nsfw")}
526 {url && this.urlLine()}
532 const post = this.postView.post;
533 const url = post.url;
536 <p className="small m-0">
537 {url && !(hostname(url) === getExternalHost()) && (
539 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
552 const dupes = this.props.crossPosts;
553 return dupes && dupes.length > 0 ? (
554 <ul className="list-inline mb-1 small text-muted">
556 <li className="list-inline-item me-2">
557 {I18NextService.i18n.t("cross_posted_to")}
560 <li key={pv.post.id} className="list-inline-item me-2">
561 <Link to={`/post/${pv.post.id}`}>
564 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
575 commentsLine(mobile = false) {
576 const post = this.postView.post;
579 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
580 {this.commentsButton}
583 className="btn btn-sm btn-animate text-muted py-0"
584 onClick={linkEvent(this, this.handleShare)}
587 <Icon icon="share" inline />
592 className="btn btn-sm btn-animate text-muted py-0"
593 title={I18NextService.i18n.t("link")}
596 <Icon icon="fedilink" inline />
599 {mobile && !this.props.viewOnly && (
601 voteContentType={VoteContentType.Post}
602 id={this.postView.post.id}
603 onVote={this.props.onPostVote}
604 enableDownvotes={this.props.enableDownvotes}
605 counts={this.postView.counts}
606 my_vote={this.postView.my_vote}
609 {UserService.Instance.myUserInfo &&
610 !this.props.viewOnly &&
616 showPreviewButton() {
617 const post_view = this.postView;
618 const body = post_view.post.body;
622 className="btn btn-sm btn-animate text-muted py-0"
623 data-tippy-content={body && mdNoImages.render(body)}
624 data-tippy-allowHtml={true}
625 onClick={linkEvent(this, this.handleShowBody)}
629 classes={classNames("icon-inline me-1", {
630 "text-success": this.state.showBody,
638 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
639 // Possible enhancement: Make each button a component.
640 const post_view = this.postView;
641 const post = post_view.post;
646 {this.crossPostButton}
649 * If there is a URL, or if the post has a body and we were told not to
650 * show the body, show the MetadataCard/body toggle.
652 {(post.url || (post.body && !this.props.showBody)) &&
653 this.showPreviewButton()}
655 {this.showBody && post_view.post.body && this.viewSourceButton}
657 <div className="dropdown">
659 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
660 onClick={linkEvent(this, this.handleShowAdvanced)}
661 data-tippy-content={I18NextService.i18n.t("more")}
662 data-bs-toggle="dropdown"
663 aria-expanded="false"
664 aria-controls={`advancedButtonsDropdown${post.id}`}
665 aria-label={I18NextService.i18n.t("more")}
667 <Icon icon="more-vertical" inline />
671 className="dropdown-menu"
672 id={`advancedButtonsDropdown${post.id}`}
676 <li>{this.reportButton}</li>
677 <li>{this.blockButton}</li>
681 <li>{this.editButton}</li>
682 <li>{this.deleteButton}</li>
686 {/* Any mod can do these, not limited to hierarchy*/}
687 {(amMod(this.props.moderators) || amAdmin()) && (
690 <hr className="dropdown-divider" />
692 <li>{this.lockButton}</li>
693 {this.featureButtons}
697 {(this.canMod_ || this.canAdmin_) && (
698 <li>{this.modRemoveButton}</li>
706 get commentsButton() {
707 const post_view = this.postView;
708 const title = I18NextService.i18n.t("number_of_comments", {
709 count: Number(post_view.counts.comments),
710 formattedCount: Number(post_view.counts.comments),
715 className="btn btn-link btn-sm text-muted ps-0"
717 to={`/post/${post_view.post.id}?scrollToComments=true`}
718 data-tippy-content={title}
720 <Icon icon="message-square" classes="me-1" inline />
721 {post_view.counts.comments}
722 {this.unreadCount && (
725 <span className="fst-italic">
726 ({this.unreadCount} {I18NextService.i18n.t("new")})
734 get unreadCount(): number | undefined {
735 const pv = this.postView;
736 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
738 : pv.unread_comments;
742 const saved = this.postView.saved;
744 ? I18NextService.i18n.t("unsave")
745 : I18NextService.i18n.t("save");
748 className="btn btn-sm btn-animate text-muted py-0"
749 onClick={linkEvent(this, this.handleSavePostClick)}
750 data-tippy-content={label}
753 {this.state.saveLoading ? (
758 classes={classNames({ "text-warning": saved })}
766 get crossPostButton() {
769 className="btn btn-sm btn-animate text-muted py-0"
771 /* Empty string properties are required to satisfy type*/
772 pathname: "/create_post",
773 state: { ...this.crossPostParams },
778 title={I18NextService.i18n.t("cross_post")}
779 data-tippy-content={I18NextService.i18n.t("cross_post")}
780 aria-label={I18NextService.i18n.t("cross_post")}
782 <Icon icon="copy" inline />
790 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
791 onClick={linkEvent(this, this.handleShowReportDialog)}
792 aria-label={I18NextService.i18n.t("show_report_dialog")}
794 <Icon classes="me-1" icon="flag" inline />
795 {I18NextService.i18n.t("create_report")}
803 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
804 onClick={linkEvent(this, this.handleBlockPersonClick)}
805 aria-label={I18NextService.i18n.t("block_user")}
807 {this.state.blockLoading ? (
810 <Icon classes="me-1" icon="slash" inline />
812 {I18NextService.i18n.t("block_user")}
820 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
821 onClick={linkEvent(this, this.handleEditClick)}
822 aria-label={I18NextService.i18n.t("edit")}
824 <Icon classes="me-1" icon="edit" inline />
825 {I18NextService.i18n.t("edit")}
831 const deleted = this.postView.post.deleted;
832 const label = !deleted
833 ? I18NextService.i18n.t("delete")
834 : I18NextService.i18n.t("restore");
837 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
838 onClick={linkEvent(this, this.handleDeleteClick)}
840 {this.state.deleteLoading ? (
846 classes={classNames("me-1", { "text-danger": deleted })}
856 get viewSourceButton() {
859 className="btn btn-sm btn-animate text-muted py-0"
860 onClick={linkEvent(this, this.handleViewSource)}
861 data-tippy-content={I18NextService.i18n.t("view_source")}
862 aria-label={I18NextService.i18n.t("view_source")}
866 classes={classNames({ "text-success": this.state.viewSource })}
874 const locked = this.postView.post.locked;
876 ? I18NextService.i18n.t("unlock")
877 : I18NextService.i18n.t("lock");
880 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
881 onClick={linkEvent(this, this.handleModLock)}
884 {this.state.lockLoading ? (
890 classes={classNames("me-1", { "text-danger": locked })}
893 {capitalizeFirstLetter(label)}
900 get featureButtons() {
901 const featuredCommunity = this.postView.post.featured_community;
902 const labelCommunity = featuredCommunity
903 ? I18NextService.i18n.t("unfeature_from_community")
904 : I18NextService.i18n.t("feature_in_community");
906 const featuredLocal = this.postView.post.featured_local;
907 const labelLocal = featuredLocal
908 ? I18NextService.i18n.t("unfeature_from_local")
909 : I18NextService.i18n.t("feature_in_local");
914 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
915 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
916 data-tippy-content={labelCommunity}
917 aria-label={labelCommunity}
919 {this.state.featureCommunityLoading ? (
925 classes={classNames("me-1", {
926 "text-success": featuredCommunity,
930 {I18NextService.i18n.t("community")}
938 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
939 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
940 data-tippy-content={labelLocal}
941 aria-label={labelLocal}
943 {this.state.featureLocalLoading ? (
949 classes={classNames("me-1", {
950 "text-success": featuredLocal,
954 {I18NextService.i18n.t("local")}
964 get modRemoveButton() {
965 const removed = this.postView.post.removed;
968 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
971 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
974 {/* TODO: Find an icon for this. */}
975 {this.state.removeLoading ? (
978 I18NextService.i18n.t("remove")
980 I18NextService.i18n.t("restore")
987 * Mod/Admin actions to be taken against the author.
991 const post_view = this.postView;
993 this.state.showAdvanced && (
994 <div className="mt-3">
997 {!this.creatorIsMod_ &&
998 (!post_view.creator_banned_from_community ? (
1000 className="btn btn-link btn-animate text-muted py-0"
1003 this.handleModBanFromCommunityShow
1005 aria-label={I18NextService.i18n.t("ban_from_community")}
1007 {I18NextService.i18n.t("ban_from_community")}
1011 className="btn btn-link btn-animate text-muted py-0"
1014 this.handleModBanFromCommunitySubmit
1016 aria-label={I18NextService.i18n.t("unban")}
1018 {this.state.banLoading ? (
1021 I18NextService.i18n.t("unban")
1025 {!post_view.creator_banned_from_community && (
1027 className="btn btn-link btn-animate text-muted py-0"
1028 onClick={linkEvent(this, this.handleAddModToCommunity)}
1031 ? I18NextService.i18n.t("remove_as_mod")
1032 : I18NextService.i18n.t("appoint_as_mod")
1035 {this.state.addModLoading ? (
1037 ) : this.creatorIsMod_ ? (
1038 I18NextService.i18n.t("remove_as_mod")
1040 I18NextService.i18n.t("appoint_as_mod")
1046 {/* Community creators and admins can transfer community to another mod */}
1047 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1049 this.creatorIsMod_ &&
1050 (!this.state.showConfirmTransferCommunity ? (
1052 className="btn btn-link btn-animate text-muted py-0"
1055 this.handleShowConfirmTransferCommunity
1057 aria-label={I18NextService.i18n.t("transfer_community")}
1059 {I18NextService.i18n.t("transfer_community")}
1064 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1065 aria-label={I18NextService.i18n.t("are_you_sure")}
1067 {I18NextService.i18n.t("are_you_sure")}
1070 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1071 aria-label={I18NextService.i18n.t("yes")}
1072 onClick={linkEvent(this, this.handleTransferCommunity)}
1074 {this.state.transferLoading ? (
1077 I18NextService.i18n.t("yes")
1081 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1084 this.handleCancelShowConfirmTransferCommunity
1086 aria-label={I18NextService.i18n.t("no")}
1088 {I18NextService.i18n.t("no")}
1092 {/* Admins can ban from all, and appoint other admins */}
1093 {this.canAdmin_ && (
1095 {!this.creatorIsAdmin_ && (
1097 {!isBanned(post_view.creator) ? (
1099 className="btn btn-link btn-animate text-muted py-0"
1100 onClick={linkEvent(this, this.handleModBanShow)}
1101 aria-label={I18NextService.i18n.t("ban_from_site")}
1103 {I18NextService.i18n.t("ban_from_site")}
1107 className="btn btn-link btn-animate text-muted py-0"
1108 onClick={linkEvent(this, this.handleModBanSubmit)}
1109 aria-label={I18NextService.i18n.t("unban_from_site")}
1111 {this.state.banLoading ? (
1114 I18NextService.i18n.t("unban_from_site")
1119 className="btn btn-link btn-animate text-muted py-0"
1120 onClick={linkEvent(this, this.handlePurgePersonShow)}
1121 aria-label={I18NextService.i18n.t("purge_user")}
1123 {I18NextService.i18n.t("purge_user")}
1126 className="btn btn-link btn-animate text-muted py-0"
1127 onClick={linkEvent(this, this.handlePurgePostShow)}
1128 aria-label={I18NextService.i18n.t("purge_post")}
1130 {I18NextService.i18n.t("purge_post")}
1134 {!isBanned(post_view.creator) && post_view.creator.local && (
1136 className="btn btn-link btn-animate text-muted py-0"
1137 onClick={linkEvent(this, this.handleAddAdmin)}
1139 this.creatorIsAdmin_
1140 ? I18NextService.i18n.t("remove_as_admin")
1141 : I18NextService.i18n.t("appoint_as_admin")
1144 {this.state.addAdminLoading ? (
1146 ) : this.creatorIsAdmin_ ? (
1147 I18NextService.i18n.t("remove_as_admin")
1149 I18NextService.i18n.t("appoint_as_admin")
1160 removeAndBanDialogs() {
1161 const post = this.postView;
1162 const purgeTypeText =
1163 this.state.purgeType == PurgeType.Post
1164 ? I18NextService.i18n.t("purge_post")
1165 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1168 {this.state.showRemoveDialog && (
1170 className="form-inline"
1171 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1174 className="visually-hidden"
1175 htmlFor="post-listing-remove-reason"
1177 {I18NextService.i18n.t("reason")}
1181 id="post-listing-remove-reason"
1182 className="form-control me-2"
1183 placeholder={I18NextService.i18n.t("reason")}
1184 value={this.state.removeReason}
1185 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1189 className="btn btn-secondary"
1190 aria-label={I18NextService.i18n.t("remove_post")}
1192 {this.state.removeLoading ? (
1195 I18NextService.i18n.t("remove_post")
1200 {this.state.showBanDialog && (
1201 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1202 <div className="mb-3 row col-12">
1204 className="col-form-label"
1205 htmlFor="post-listing-ban-reason"
1207 {I18NextService.i18n.t("reason")}
1211 id="post-listing-ban-reason"
1212 className="form-control me-2"
1213 placeholder={I18NextService.i18n.t("reason")}
1214 value={this.state.banReason}
1215 onInput={linkEvent(this, this.handleModBanReasonChange)}
1217 <label className="col-form-label" htmlFor="mod-ban-expires">
1218 {I18NextService.i18n.t("expires")}
1222 id="mod-ban-expires"
1223 className="form-control me-2"
1224 placeholder={I18NextService.i18n.t("number_of_days")}
1225 value={this.state.banExpireDays}
1226 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1228 <div className="input-group mb-3">
1229 <div className="form-check">
1231 className="form-check-input"
1232 id="mod-ban-remove-data"
1234 checked={this.state.removeData}
1235 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1238 className="form-check-label"
1239 htmlFor="mod-ban-remove-data"
1240 title={I18NextService.i18n.t("remove_content_more")}
1242 {I18NextService.i18n.t("remove_content")}
1247 {/* TODO hold off on expires until later */}
1248 {/* <div class="mb-3 row"> */}
1249 {/* <label class="col-form-label">Expires</label> */}
1250 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1252 <div className="mb-3 row">
1255 className="btn btn-secondary"
1256 aria-label={I18NextService.i18n.t("ban")}
1258 {this.state.banLoading ? (
1262 {I18NextService.i18n.t("ban")} {post.creator.name}
1269 {this.state.showReportDialog && (
1271 className="form-inline"
1272 onSubmit={linkEvent(this, this.handleReportSubmit)}
1274 <label className="visually-hidden" htmlFor="post-report-reason">
1275 {I18NextService.i18n.t("reason")}
1279 id="post-report-reason"
1280 className="form-control me-2"
1281 placeholder={I18NextService.i18n.t("reason")}
1283 value={this.state.reportReason}
1284 onInput={linkEvent(this, this.handleReportReasonChange)}
1288 className="btn btn-secondary"
1289 aria-label={I18NextService.i18n.t("create_report")}
1291 {this.state.reportLoading ? (
1294 I18NextService.i18n.t("create_report")
1299 {this.state.showPurgeDialog && (
1301 className="form-inline"
1302 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1305 <label className="visually-hidden" htmlFor="purge-reason">
1306 {I18NextService.i18n.t("reason")}
1311 className="form-control me-2"
1312 placeholder={I18NextService.i18n.t("reason")}
1313 value={this.state.purgeReason}
1314 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1316 {this.state.purgeLoading ? (
1321 className="btn btn-secondary"
1322 aria-label={purgeTypeText}
1324 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1334 const post = this.postView.post;
1335 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1336 <div className="row">
1337 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1338 {this.postTitleLine()}
1340 <div className="col-4">
1341 {/* Post thumbnail */}
1342 {!this.state.imageExpanded && this.thumbnail()}
1346 this.postTitleLine()
1351 const { body, id } = this.postView.post;
1353 return !this.showBody && body ? (
1354 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1355 <div className="md-div mb-1 preview-lines">{body}</div>
1365 {/* The mobile view*/}
1366 <div className="d-block d-sm-none">
1367 <article className="row post-container">
1368 <div className="col-12">
1369 {this.createdLine()}
1371 {/* If it has a thumbnail, do a right aligned thumbnail */}
1372 {this.mobileThumbnail()}
1374 {/* Show a preview of the post body */}
1375 {this.showBodyPreview()}
1377 {this.commentsLine(true)}
1378 {this.userActionsLine()}
1379 {this.duplicatesLine()}
1380 {this.removeAndBanDialogs()}
1385 {/* The larger view*/}
1386 <div className="d-none d-sm-block">
1387 <article className="row post-container">
1388 {!this.props.viewOnly && (
1390 voteContentType={VoteContentType.Post}
1391 id={this.postView.post.id}
1392 onVote={this.props.onPostVote}
1393 enableDownvotes={this.props.enableDownvotes}
1394 counts={this.postView.counts}
1395 my_vote={this.postView.my_vote}
1398 <div className="col-sm-2 pe-0 post-media">
1399 <div className="">{this.thumbnail()}</div>
1401 <div className="col-12 col-sm-9">
1402 <div className="row">
1403 <div className="col-12">
1404 {this.postTitleLine()}
1405 {this.createdLine()}
1406 {this.showBodyPreview()}
1407 {this.commentsLine()}
1408 {this.duplicatesLine()}
1409 {this.userActionsLine()}
1410 {this.removeAndBanDialogs()}
1420 private get myPost(): boolean {
1422 this.postView.creator.id ==
1423 UserService.Instance.myUserInfo?.local_user_view.person.id
1426 handleEditClick(i: PostListing) {
1427 i.setState({ showEdit: true });
1430 handleEditCancel() {
1431 this.setState({ showEdit: false });
1434 // The actual editing is done in the receive for post
1435 handleEditPost(form: EditPost) {
1436 this.setState({ showEdit: false });
1437 this.props.onPostEdit(form);
1440 handleShare(i: PostListing) {
1441 const { name, body, id } = i.props.post_view.post;
1444 text: body?.slice(0, 50),
1445 url: `${getHttpBase()}/post/${id}`,
1449 handleShowReportDialog(i: PostListing) {
1450 i.setState({ showReportDialog: !i.state.showReportDialog });
1453 handleReportReasonChange(i: PostListing, event: any) {
1454 i.setState({ reportReason: event.target.value });
1457 handleReportSubmit(i: PostListing, event: any) {
1458 event.preventDefault();
1459 i.setState({ reportLoading: true });
1460 i.props.onPostReport({
1461 post_id: i.postView.post.id,
1462 reason: i.state.reportReason ?? "",
1463 auth: myAuthRequired(),
1467 handleBlockPersonClick(i: PostListing) {
1468 i.setState({ blockLoading: true });
1469 i.props.onBlockPerson({
1470 person_id: i.postView.creator.id,
1472 auth: myAuthRequired(),
1476 handleDeleteClick(i: PostListing) {
1477 i.setState({ deleteLoading: true });
1478 i.props.onDeletePost({
1479 post_id: i.postView.post.id,
1480 deleted: !i.postView.post.deleted,
1481 auth: myAuthRequired(),
1485 handleSavePostClick(i: PostListing) {
1486 i.setState({ saveLoading: true });
1487 i.props.onSavePost({
1488 post_id: i.postView.post.id,
1489 save: !i.postView.saved,
1490 auth: myAuthRequired(),
1494 get crossPostParams(): PostFormParams {
1495 const queryParams: PostFormParams = {};
1496 const { name, url } = this.postView.post;
1498 queryParams.name = name;
1501 queryParams.url = url;
1504 const crossPostBody = this.crossPostBody();
1505 if (crossPostBody) {
1506 queryParams.body = crossPostBody;
1512 crossPostBody(): string | undefined {
1513 const post = this.postView.post;
1514 const body = post.body;
1517 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1519 }\n\n${body.replace(/^/gm, "> ")}`
1523 get showBody(): boolean {
1524 return this.props.showBody || this.state.showBody;
1527 handleModRemoveShow(i: PostListing) {
1529 showRemoveDialog: !i.state.showRemoveDialog,
1530 showBanDialog: false,
1534 handleModRemoveReasonChange(i: PostListing, event: any) {
1535 i.setState({ removeReason: event.target.value });
1538 handleModRemoveDataChange(i: PostListing, event: any) {
1539 i.setState({ removeData: event.target.checked });
1542 handleModRemoveSubmit(i: PostListing, event: any) {
1543 event.preventDefault();
1544 i.setState({ removeLoading: true });
1545 i.props.onRemovePost({
1546 post_id: i.postView.post.id,
1547 removed: !i.postView.post.removed,
1548 auth: myAuthRequired(),
1552 handleModLock(i: PostListing) {
1553 i.setState({ lockLoading: true });
1554 i.props.onLockPost({
1555 post_id: i.postView.post.id,
1556 locked: !i.postView.post.locked,
1557 auth: myAuthRequired(),
1561 handleModFeaturePostLocal(i: PostListing) {
1562 i.setState({ featureLocalLoading: true });
1563 i.props.onFeaturePost({
1564 post_id: i.postView.post.id,
1565 featured: !i.postView.post.featured_local,
1566 feature_type: "Local",
1567 auth: myAuthRequired(),
1571 handleModFeaturePostCommunity(i: PostListing) {
1572 i.setState({ featureCommunityLoading: true });
1573 i.props.onFeaturePost({
1574 post_id: i.postView.post.id,
1575 featured: !i.postView.post.featured_community,
1576 feature_type: "Community",
1577 auth: myAuthRequired(),
1581 handleModBanFromCommunityShow(i: PostListing) {
1583 showBanDialog: true,
1584 banType: BanType.Community,
1585 showRemoveDialog: false,
1589 handleModBanShow(i: PostListing) {
1591 showBanDialog: true,
1592 banType: BanType.Site,
1593 showRemoveDialog: false,
1597 handlePurgePersonShow(i: PostListing) {
1599 showPurgeDialog: true,
1600 purgeType: PurgeType.Person,
1601 showRemoveDialog: false,
1605 handlePurgePostShow(i: PostListing) {
1607 showPurgeDialog: true,
1608 purgeType: PurgeType.Post,
1609 showRemoveDialog: false,
1613 handlePurgeReasonChange(i: PostListing, event: any) {
1614 i.setState({ purgeReason: event.target.value });
1617 handlePurgeSubmit(i: PostListing, event: any) {
1618 event.preventDefault();
1619 i.setState({ purgeLoading: true });
1620 if (i.state.purgeType == PurgeType.Person) {
1621 i.props.onPurgePerson({
1622 person_id: i.postView.creator.id,
1623 reason: i.state.purgeReason,
1624 auth: myAuthRequired(),
1626 } else if (i.state.purgeType == PurgeType.Post) {
1627 i.props.onPurgePost({
1628 post_id: i.postView.post.id,
1629 reason: i.state.purgeReason,
1630 auth: myAuthRequired(),
1635 handleModBanReasonChange(i: PostListing, event: any) {
1636 i.setState({ banReason: event.target.value });
1639 handleModBanExpireDaysChange(i: PostListing, event: any) {
1640 i.setState({ banExpireDays: event.target.value });
1643 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1644 i.setState({ banType: BanType.Community });
1645 i.handleModBanBothSubmit(i, event);
1648 handleModBanSubmit(i: PostListing, event: any) {
1649 i.setState({ banType: BanType.Site });
1650 i.handleModBanBothSubmit(i, event);
1653 handleModBanBothSubmit(i: PostListing, event: any) {
1654 event.preventDefault();
1655 i.setState({ banLoading: true });
1657 const ban = !i.props.post_view.creator_banned_from_community;
1658 // If its an unban, restore all their data
1660 i.setState({ removeData: false });
1662 const person_id = i.props.post_view.creator.id;
1663 const remove_data = i.state.removeData;
1664 const reason = i.state.banReason;
1665 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1667 if (i.state.banType == BanType.Community) {
1668 const community_id = i.postView.community.id;
1669 i.props.onBanPersonFromCommunity({
1676 auth: myAuthRequired(),
1679 i.props.onBanPerson({
1685 auth: myAuthRequired(),
1690 handleAddModToCommunity(i: PostListing) {
1691 i.setState({ addModLoading: true });
1692 i.props.onAddModToCommunity({
1693 community_id: i.postView.community.id,
1694 person_id: i.postView.creator.id,
1695 added: !i.creatorIsMod_,
1696 auth: myAuthRequired(),
1700 handleAddAdmin(i: PostListing) {
1701 i.setState({ addAdminLoading: true });
1702 i.props.onAddAdmin({
1703 person_id: i.postView.creator.id,
1704 added: !i.creatorIsAdmin_,
1705 auth: myAuthRequired(),
1709 handleShowConfirmTransferCommunity(i: PostListing) {
1710 i.setState({ showConfirmTransferCommunity: true });
1713 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1714 i.setState({ showConfirmTransferCommunity: false });
1717 handleTransferCommunity(i: PostListing) {
1718 i.setState({ transferLoading: true });
1719 i.props.onTransferCommunity({
1720 community_id: i.postView.community.id,
1721 person_id: i.postView.creator.id,
1722 auth: myAuthRequired(),
1726 handleShowConfirmTransferSite(i: PostListing) {
1727 i.setState({ showConfirmTransferSite: true });
1730 handleCancelShowConfirmTransferSite(i: PostListing) {
1731 i.setState({ showConfirmTransferSite: false });
1734 handleImageExpandClick(i: PostListing, event: any) {
1735 event.preventDefault();
1736 i.setState({ imageExpanded: !i.state.imageExpanded });
1740 handleViewSource(i: PostListing) {
1741 i.setState({ viewSource: !i.state.viewSource });
1744 handleShowAdvanced(i: PostListing) {
1745 i.setState({ showAdvanced: !i.state.showAdvanced });
1749 handleShowMoreMobile(i: PostListing) {
1751 showMoreMobile: !i.state.showMoreMobile,
1752 showAdvanced: !i.state.showAdvanced,
1757 handleShowBody(i: PostListing) {
1758 i.setState({ showBody: !i.state.showBody });
1762 get pointsTippy(): string {
1763 const points = I18NextService.i18n.t("number_of_points", {
1764 count: Number(this.postView.counts.score),
1765 formattedCount: Number(this.postView.counts.score),
1768 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1769 count: Number(this.postView.counts.upvotes),
1770 formattedCount: Number(this.postView.counts.upvotes),
1773 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1774 count: Number(this.postView.counts.downvotes),
1775 formattedCount: Number(this.postView.counts.downvotes),
1778 return `${points} • ${upvotes} • ${downvotes}`;
1781 get canModOnSelf_(): boolean {
1783 this.postView.creator.id,
1784 this.props.moderators,
1791 get canMod_(): boolean {
1793 this.postView.creator.id,
1794 this.props.moderators,
1799 get canAdmin_(): boolean {
1800 return canAdmin(this.postView.creator.id, this.props.admins);
1803 get creatorIsMod_(): boolean {
1804 return isMod(this.postView.creator.id, this.props.moderators);
1807 get creatorIsAdmin_(): boolean {
1808 return isAdmin(this.postView.creator.id, this.props.admins);