1 import { myAuth, 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,
45 } from "lemmy-js-client";
46 import { relTags } from "../../config";
52 } from "../../interfaces";
53 import { mdToHtml, mdToHtmlInline } from "../../markdown";
54 import { I18NextService, UserService } from "../../services";
55 import { setupTippy } from "../../tippy";
56 import { Icon, PurgeWarning, Spinner } from "../common/icon";
57 import { MomentTime } from "../common/moment-time";
58 import { PictrsImage } from "../common/pictrs-image";
59 import { UserBadges } from "../common/user-badges";
60 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
61 import { CommunityLink } from "../community/community-link";
62 import { PersonListing } from "../person/person-listing";
63 import { MetadataCard } from "./metadata-card";
64 import { PostForm } from "./post-form";
66 interface PostListingState {
68 showRemoveDialog: boolean;
69 showPurgeDialog: boolean;
71 purgeType?: PurgeType;
72 purgeLoading: boolean;
73 removeReason?: string;
74 showBanDialog: boolean;
76 banExpireDays?: number;
79 showConfirmTransferSite: boolean;
80 showConfirmTransferCommunity: boolean;
81 imageExpanded: boolean;
83 showAdvanced: boolean;
84 showMoreMobile: boolean;
86 showReportDialog: boolean;
87 reportReason?: string;
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;
111 * Controls whether to show both the body *and* the metadata preview card
115 enableDownvotes?: boolean;
116 enableNsfw?: boolean;
118 onPostEdit(form: EditPost): void;
119 onPostVote(form: CreatePostLike): void;
120 onPostReport(form: CreatePostReport): void;
121 onBlockPerson(form: BlockPerson): void;
122 onLockPost(form: LockPost): void;
123 onDeletePost(form: DeletePost): void;
124 onRemovePost(form: RemovePost): void;
125 onSavePost(form: SavePost): void;
126 onFeaturePost(form: FeaturePost): void;
127 onPurgePerson(form: PurgePerson): void;
128 onPurgePost(form: PurgePost): void;
129 onBanPersonFromCommunity(form: BanFromCommunity): void;
130 onBanPerson(form: BanPerson): void;
131 onAddModToCommunity(form: AddModToCommunity): void;
132 onAddAdmin(form: AddAdmin): void;
133 onTransferCommunity(form: TransferCommunity): void;
134 onMarkPostAsRead(form: MarkPostAsRead): void;
137 export class PostListing extends Component<PostListingProps, PostListingState> {
138 state: PostListingState = {
140 showRemoveDialog: false,
141 showPurgeDialog: false,
142 purgeType: PurgeType.Person,
143 showBanDialog: false,
144 banType: BanType.Community,
146 showConfirmTransferSite: false,
147 showConfirmTransferCommunity: false,
148 imageExpanded: false,
151 showMoreMobile: false,
153 showReportDialog: false,
155 reportLoading: false,
158 deleteLoading: false,
159 removeLoading: false,
161 featureCommunityLoading: false,
162 featureLocalLoading: false,
164 addModLoading: false,
165 addAdminLoading: false,
166 transferLoading: false,
169 constructor(props: any, context: any) {
170 super(props, context);
172 if (UserService.Instance.myUserInfo) {
173 this.state.imageExpanded =
174 UserService.Instance.myUserInfo.local_user_view.local_user.auto_expand;
177 this.handleEditPost = this.handleEditPost.bind(this);
178 this.handleEditCancel = this.handleEditCancel.bind(this);
181 componentWillReceiveProps(nextProps: PostListingProps) {
182 if (this.props !== nextProps) {
185 reportLoading: false,
188 deleteLoading: false,
189 removeLoading: false,
191 featureCommunityLoading: false,
192 featureLocalLoading: false,
194 addModLoading: false,
195 addAdminLoading: false,
196 transferLoading: false,
201 get postView(): PostView {
202 return this.props.post_view;
206 const post = this.postView.post;
209 <div className="post-listing mt-2">
210 {!this.state.showEdit ? (
213 {this.state.imageExpanded && !this.props.hideImage && this.img}
214 {this.showBody && post.url && post.embed_title && (
215 <MetadataCard post={post} />
217 {this.showBody && this.body()}
221 post_view={this.postView}
222 crossPosts={this.props.crossPosts}
223 onEdit={this.handleEditPost}
224 onCancel={this.handleEditCancel}
225 enableNsfw={this.props.enableNsfw}
226 enableDownvotes={this.props.enableDownvotes}
227 allLanguages={this.props.allLanguages}
228 siteLanguages={this.props.siteLanguages}
236 const body = this.postView.post.body;
238 <article id="postContent" className="col-12 card my-2 p-2">
239 {this.state.viewSource ? (
242 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
254 <div className="offset-sm-3 my-2 d-none d-sm-block">
255 <a href={this.imageSrc} className="d-inline-block">
256 <PictrsImage src={this.imageSrc} />
259 <div className="my-2 d-block d-sm-none">
262 className="p-0 border-0 bg-transparent d-inline-block"
263 onClick={linkEvent(this, this.handleImageExpandClick)}
265 <PictrsImage src={this.imageSrc} />
272 const { post } = this.postView;
273 const { url } = post;
275 // if direct video link
276 if (url && isVideo(url)) {
278 <div className="embed-responsive mt-3">
279 <video muted controls className="embed-responsive-item col-12">
280 <source src={url} type="video/mp4" />
286 // if embedded video link
287 if (url && post.embed_video_url) {
289 <div className="ratio ratio-16x9">
292 className="post-metadata-iframe"
293 src={post.embed_video_url}
294 title={post.embed_title}
303 imgThumb(src: string) {
304 const post_view = this.postView;
311 nsfw={post_view.post.nsfw || post_view.community.nsfw}
316 get imageSrc(): string | undefined {
317 const post = this.postView.post;
318 const url = post.url;
319 const thumbnail = post.thumbnail_url;
323 } else if (url && isImage(url)) {
331 const post = this.postView.post;
332 const url = post.url;
333 const thumbnail = post.thumbnail_url;
335 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
339 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0 bg-transparent"
340 data-tippy-content={I18NextService.i18n.t("expand_here")}
341 onClick={linkEvent(this, this.handleImageExpandClick)}
342 aria-label={I18NextService.i18n.t("expand_here")}
344 {this.imgThumb(this.imageSrc)}
347 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
351 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
354 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0"
358 target={this.linkTarget}
360 {this.imgThumb(this.imageSrc)}
363 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
368 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
371 className="text-body"
375 data-tippy-content={I18NextService.i18n.t("expand_here")}
376 onClick={linkEvent(this, this.handleImageExpandClick)}
377 aria-label={I18NextService.i18n.t("expand_here")}
378 target={this.linkTarget}
380 <div className="thumbnail rounded bg-light d-flex justify-content-center">
381 <Icon icon="play" classes="d-flex align-items-center" />
388 className="text-body"
392 target={this.linkTarget}
394 <div className="thumbnail rounded bg-light d-flex justify-content-center">
395 <Icon icon="external-link" classes="d-flex align-items-center" />
403 className="text-body"
404 to={`/post/${post.id}`}
405 title={I18NextService.i18n.t("comments")}
406 target={this.linkTarget}
408 <div className="thumbnail rounded bg-light d-flex justify-content-center">
409 <Icon icon="message-square" classes="d-flex align-items-center" />
417 const post_view = this.postView;
420 <div className="small mb-1 mb-md-0">
421 <PersonListing person={post_view.creator} />
424 isMod={this.creatorIsMod_}
425 isAdmin={this.creatorIsAdmin_}
426 isBot={post_view.creator.bot_account}
428 {this.props.showCommunity && (
431 {I18NextService.i18n.t("to")}{" "}
432 <CommunityLink community={post_view.community} />
435 {post_view.post.language_id !== 0 && (
436 <span className="mx-1 badge text-bg-light">
438 this.props.allLanguages.find(
439 lang => lang.id === post_view.post.language_id,
446 published={post_view.post.published}
447 updated={post_view.post.updated}
454 const post = this.postView.post;
457 className={`d-inline ${
458 !post.featured_community && !post.featured_local
462 to={`/post/${post.id}`}
463 title={I18NextService.i18n.t("comments")}
467 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
474 const post = this.postView.post;
475 const url = post.url;
479 <div className="post-title">
480 <h1 className="h5 d-inline text-break">
481 {url && this.props.showBody ? (
484 !post.featured_community && !post.featured_local
491 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
499 * If there is (a) a URL and an embed title, or (b) a post body, and
500 * we were not told to show the body by the parent component, show the
501 * MetadataCard/body toggle.
503 {!this.props.showBody &&
504 ((post.url && post.embed_title) || post.body) &&
505 this.showPreviewButton()}
508 <small className="ms-2 badge text-bg-secondary">
509 {I18NextService.i18n.t("removed")}
515 className="unselectable pointer ms-2 text-muted fst-italic"
516 data-tippy-content={I18NextService.i18n.t("deleted")}
518 <Icon icon="trash" classes="icon-inline text-danger" />
524 className="unselectable pointer ms-2 text-muted fst-italic"
525 data-tippy-content={I18NextService.i18n.t("locked")}
527 <Icon icon="lock" classes="icon-inline text-danger" />
531 {post.featured_community && (
533 className="unselectable pointer ms-2 text-muted fst-italic"
534 data-tippy-content={I18NextService.i18n.t(
535 "featured_in_community",
537 aria-label={I18NextService.i18n.t("featured_in_community")}
539 <Icon icon="pin" classes="icon-inline text-primary" />
543 {post.featured_local && (
545 className="unselectable pointer ms-2 text-muted fst-italic"
546 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
547 aria-label={I18NextService.i18n.t("featured_in_local")}
549 <Icon icon="pin" classes="icon-inline text-secondary" />
554 <small className="ms-2 badge text-bg-danger">
555 {I18NextService.i18n.t("nsfw")}
559 {url && this.urlLine()}
565 const post = this.postView.post;
566 const url = post.url;
569 <p className="small m-0">
570 {url && !(hostname(url) === getExternalHost()) && (
572 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
585 const dupes = this.props.crossPosts;
586 return dupes && dupes.length > 0 ? (
587 <ul className="list-inline mb-1 small text-muted">
589 <li className="list-inline-item me-2">
590 {I18NextService.i18n.t("cross_posted_to")}
593 <li key={pv.post.id} className="list-inline-item me-2">
594 <Link to={`/post/${pv.post.id}`}>
597 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
608 commentsLine(mobile = false) {
609 const post = this.postView.post;
612 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
613 {this.commentsButton}
616 className="btn btn-sm btn-link btn-animate text-muted py-0"
617 onClick={linkEvent(this, this.handleShare)}
620 <Icon icon="share" inline />
625 className="btn btn-sm btn-link btn-animate text-muted py-0"
626 title={I18NextService.i18n.t("link")}
629 <Icon icon="fedilink" inline />
632 {mobile && !this.props.viewOnly && (
634 voteContentType={VoteContentType.Post}
635 id={this.postView.post.id}
636 onVote={this.props.onPostVote}
637 enableDownvotes={this.props.enableDownvotes}
638 counts={this.postView.counts}
639 my_vote={this.postView.my_vote}
642 {UserService.Instance.myUserInfo &&
643 !this.props.viewOnly &&
650 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
651 // Possible enhancement: Make each button a component.
652 const post_view = this.postView;
653 const post = post_view.post;
658 {this.crossPostButton}
660 {this.props.showBody && post_view.post.body && this.viewSourceButton}
662 <div className="dropdown">
664 className="btn btn-sm btn-link btn-animate text-muted py-0 dropdown-toggle"
665 onClick={linkEvent(this, this.handleShowAdvanced)}
666 data-tippy-content={I18NextService.i18n.t("more")}
667 data-bs-toggle="dropdown"
668 aria-expanded="false"
669 aria-controls={`advancedButtonsDropdown${post.id}`}
670 aria-label={I18NextService.i18n.t("more")}
672 <Icon icon="more-vertical" inline />
676 className="dropdown-menu"
677 id={`advancedButtonsDropdown${post.id}`}
681 <li>{this.reportButton}</li>
682 <li>{this.blockButton}</li>
686 <li>{this.editButton}</li>
687 <li>{this.deleteButton}</li>
691 {/* Any mod can do these, not limited to hierarchy*/}
692 {(amMod(this.props.moderators) || amAdmin()) && (
695 <hr className="dropdown-divider" />
697 <li>{this.lockButton}</li>
698 {this.featureButtons}
702 {(this.canMod_ || this.canAdmin_) && (
703 <li>{this.modRemoveButton}</li>
709 <hr className="dropdown-divider" />
711 {!this.creatorIsMod_ &&
712 (!post_view.creator_banned_from_community ? (
713 <li>{this.modBanFromCommunityButton}</li>
715 <li>{this.modUnbanFromCommunityButton}</li>
717 {!post_view.creator_banned_from_community && (
718 <li>{this.addModToCommunityButton}</li>
723 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
725 this.creatorIsMod_ && <li>{this.transferCommunityButton}</li>}
727 {/* Admins can ban from all, and appoint other admins */}
731 <hr className="dropdown-divider" />
733 {!this.creatorIsAdmin_ && (
735 {!isBanned(post_view.creator) ? (
736 <li>{this.modBanButton}</li>
738 <li>{this.modUnbanButton}</li>
740 <li>{this.purgePersonButton}</li>
741 <li>{this.purgePostButton}</li>
744 {!isBanned(post_view.creator) && post_view.creator.local && (
745 <li>{this.toggleAdminButton}</li>
755 public get linkTarget(): string {
756 return UserService.Instance.myUserInfo?.local_user_view.local_user
757 .open_links_in_new_tab
759 : // _self is the default target on links when the field is not specified
763 get commentsButton() {
764 const post_view = this.postView;
765 const title = I18NextService.i18n.t("number_of_comments", {
766 count: Number(post_view.counts.comments),
767 formattedCount: Number(post_view.counts.comments),
772 className="btn btn-link btn-sm text-muted ps-0"
774 to={`/post/${post_view.post.id}?scrollToComments=true`}
775 data-tippy-content={title}
776 target={this.linkTarget}
778 <Icon icon="message-square" classes="me-1" inline />
779 {post_view.counts.comments}
780 {this.unreadCount && (
783 <span className="fst-italic">
784 ({this.unreadCount} {I18NextService.i18n.t("new")})
792 get unreadCount(): number | undefined {
793 const pv = this.postView;
794 return pv.unread_comments === pv.counts.comments || pv.unread_comments === 0
796 : pv.unread_comments;
800 const saved = this.postView.saved;
802 ? I18NextService.i18n.t("unsave")
803 : I18NextService.i18n.t("save");
806 className="btn btn-sm btn-link btn-animate text-muted py-0"
807 onClick={linkEvent(this, this.handleSavePostClick)}
808 data-tippy-content={label}
811 {this.state.saveLoading ? (
816 classes={classNames({ "text-warning": saved })}
824 get crossPostButton() {
827 className="btn btn-sm btn-link btn-animate text-muted py-0"
829 /* Empty string properties are required to satisfy type*/
830 pathname: "/create_post",
831 state: { ...this.crossPostParams },
836 title={I18NextService.i18n.t("cross_post")}
837 data-tippy-content={I18NextService.i18n.t("cross_post")}
838 aria-label={I18NextService.i18n.t("cross_post")}
840 <Icon icon="copy" inline />
848 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
849 onClick={linkEvent(this, this.handleShowReportDialog)}
850 aria-label={I18NextService.i18n.t("show_report_dialog")}
852 <Icon classes="me-1" icon="flag" inline />
853 {I18NextService.i18n.t("create_report")}
861 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
862 onClick={linkEvent(this, this.handleBlockPersonClick)}
863 aria-label={I18NextService.i18n.t("block_user")}
865 {this.state.blockLoading ? (
868 <Icon classes="me-1" icon="slash" inline />
870 {I18NextService.i18n.t("block_user")}
878 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
879 onClick={linkEvent(this, this.handleEditClick)}
880 aria-label={I18NextService.i18n.t("edit")}
882 <Icon classes="me-1" icon="edit" inline />
883 {I18NextService.i18n.t("edit")}
889 const deleted = this.postView.post.deleted;
890 const label = !deleted
891 ? I18NextService.i18n.t("delete")
892 : I18NextService.i18n.t("restore");
895 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
896 onClick={linkEvent(this, this.handleDeleteClick)}
898 {this.state.deleteLoading ? (
904 classes={classNames("me-1", { "text-danger": deleted })}
914 get viewSourceButton() {
917 className="btn btn-sm btn-link btn-animate text-muted py-0"
918 onClick={linkEvent(this, this.handleViewSource)}
919 data-tippy-content={I18NextService.i18n.t("view_source")}
920 aria-label={I18NextService.i18n.t("view_source")}
924 classes={classNames({ "text-success": this.state.viewSource })}
932 const locked = this.postView.post.locked;
934 ? I18NextService.i18n.t("unlock")
935 : I18NextService.i18n.t("lock");
938 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
939 onClick={linkEvent(this, this.handleModLock)}
942 {this.state.lockLoading ? (
948 classes={classNames("me-1", { "text-danger": locked })}
951 {capitalizeFirstLetter(label)}
958 get featureButtons() {
959 const featuredCommunity = this.postView.post.featured_community;
960 const labelCommunity = featuredCommunity
961 ? I18NextService.i18n.t("unfeature_from_community")
962 : I18NextService.i18n.t("feature_in_community");
964 const featuredLocal = this.postView.post.featured_local;
965 const labelLocal = featuredLocal
966 ? I18NextService.i18n.t("unfeature_from_local")
967 : I18NextService.i18n.t("feature_in_local");
972 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
973 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
974 data-tippy-content={labelCommunity}
975 aria-label={labelCommunity}
977 {this.state.featureCommunityLoading ? (
983 classes={classNames("me-1", {
984 "text-success": featuredCommunity,
988 {I18NextService.i18n.t("community")}
996 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
997 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
998 data-tippy-content={labelLocal}
999 aria-label={labelLocal}
1001 {this.state.featureLocalLoading ? (
1007 classes={classNames("me-1", {
1008 "text-success": featuredLocal,
1012 {I18NextService.i18n.t("local")}
1022 get modBanFromCommunityButton() {
1025 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1026 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
1028 {I18NextService.i18n.t("ban_from_community")}
1033 get modUnbanFromCommunityButton() {
1036 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1037 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
1039 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1044 get addModToCommunityButton() {
1047 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1048 onClick={linkEvent(this, this.handleAddModToCommunity)}
1050 {this.state.addModLoading ? (
1052 ) : this.creatorIsMod_ ? (
1053 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_mod"))
1055 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_mod"))
1061 get modBanButton() {
1064 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1065 onClick={linkEvent(this, this.handleModBanShow)}
1067 {capitalizeFirstLetter(I18NextService.i18n.t("ban_from_site"))}
1072 get modUnbanButton() {
1075 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1076 onClick={linkEvent(this, this.handleModBanSubmit)}
1078 {this.state.banLoading ? (
1081 capitalizeFirstLetter(I18NextService.i18n.t("unban_from_site"))
1087 get purgePersonButton() {
1090 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1091 onClick={linkEvent(this, this.handlePurgePersonShow)}
1093 {capitalizeFirstLetter(I18NextService.i18n.t("purge_user"))}
1098 get purgePostButton() {
1101 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1102 onClick={linkEvent(this, this.handlePurgePostShow)}
1104 {capitalizeFirstLetter(I18NextService.i18n.t("purge_post"))}
1109 get toggleAdminButton() {
1112 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1113 onClick={linkEvent(this, this.handleAddAdmin)}
1115 {this.state.addAdminLoading ? (
1117 ) : this.creatorIsAdmin_ ? (
1118 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_admin"))
1120 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_admin"))
1126 get transferCommunityButton() {
1129 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1130 onClick={linkEvent(this, this.handleShowConfirmTransferCommunity)}
1132 {capitalizeFirstLetter(I18NextService.i18n.t("transfer_community"))}
1137 get modRemoveButton() {
1138 const removed = this.postView.post.removed;
1141 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1144 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit,
1147 {/* TODO: Find an icon for this. */}
1148 {this.state.removeLoading ? (
1151 capitalizeFirstLetter(I18NextService.i18n.t("remove_post"))
1154 {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "}
1155 {I18NextService.i18n.t("post")}
1162 removeAndBanDialogs() {
1163 const post = this.postView;
1164 const purgeTypeText =
1165 this.state.purgeType === PurgeType.Post
1166 ? I18NextService.i18n.t("purge_post")
1167 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1170 {this.state.showRemoveDialog && (
1172 className="form-inline"
1173 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1176 className="visually-hidden"
1177 htmlFor="post-listing-remove-reason"
1179 {I18NextService.i18n.t("reason")}
1183 id="post-listing-remove-reason"
1184 className="form-control me-2"
1185 placeholder={I18NextService.i18n.t("reason")}
1186 value={this.state.removeReason}
1187 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1189 <button type="submit" className="btn btn-secondary">
1190 {this.state.removeLoading ? (
1193 I18NextService.i18n.t("remove_post")
1198 {this.state.showConfirmTransferCommunity && (
1200 <button className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0">
1201 {I18NextService.i18n.t("are_you_sure")}
1204 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1205 onClick={linkEvent(this, this.handleTransferCommunity)}
1207 {this.state.transferLoading ? (
1210 I18NextService.i18n.t("yes")
1214 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1217 this.handleCancelShowConfirmTransferCommunity,
1219 aria-label={I18NextService.i18n.t("no")}
1221 {I18NextService.i18n.t("no")}
1225 {this.state.showBanDialog && (
1226 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1227 <div className="mb-3 row col-12">
1229 className="col-form-label"
1230 htmlFor="post-listing-ban-reason"
1232 {I18NextService.i18n.t("reason")}
1236 id="post-listing-ban-reason"
1237 className="form-control me-2"
1238 placeholder={I18NextService.i18n.t("reason")}
1239 value={this.state.banReason}
1240 onInput={linkEvent(this, this.handleModBanReasonChange)}
1242 <label className="col-form-label" htmlFor="mod-ban-expires">
1243 {I18NextService.i18n.t("expires")}
1247 id="mod-ban-expires"
1248 className="form-control me-2"
1249 placeholder={I18NextService.i18n.t("number_of_days")}
1250 value={this.state.banExpireDays}
1251 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1253 <div className="input-group mb-3">
1254 <div className="form-check">
1256 className="form-check-input"
1257 id="mod-ban-remove-data"
1259 checked={this.state.removeData}
1260 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1263 className="form-check-label"
1264 htmlFor="mod-ban-remove-data"
1265 title={I18NextService.i18n.t("remove_content_more")}
1267 {I18NextService.i18n.t("remove_content")}
1272 {/* TODO hold off on expires until later */}
1273 {/* <div class="mb-3 row"> */}
1274 {/* <label class="col-form-label">Expires</label> */}
1275 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1277 <div className="mb-3 row">
1278 <button type="submit" className="btn btn-secondary">
1279 {this.state.banLoading ? (
1283 {I18NextService.i18n.t("ban")} {post.creator.name}
1290 {this.state.showReportDialog && (
1292 className="form-inline"
1293 onSubmit={linkEvent(this, this.handleReportSubmit)}
1295 <label className="visually-hidden" htmlFor="post-report-reason">
1296 {I18NextService.i18n.t("reason")}
1300 id="post-report-reason"
1301 className="form-control me-2"
1302 placeholder={I18NextService.i18n.t("reason")}
1304 value={this.state.reportReason}
1305 onInput={linkEvent(this, this.handleReportReasonChange)}
1307 <button type="submit" className="btn btn-secondary">
1308 {this.state.reportLoading ? (
1311 I18NextService.i18n.t("create_report")
1316 {this.state.showPurgeDialog && (
1318 className="form-inline"
1319 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1322 <label className="visually-hidden" htmlFor="purge-reason">
1323 {I18NextService.i18n.t("reason")}
1328 className="form-control me-2"
1329 placeholder={I18NextService.i18n.t("reason")}
1330 value={this.state.purgeReason}
1331 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1333 {this.state.purgeLoading ? (
1336 <button type="submit" className="btn btn-secondary">
1337 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1347 const post = this.postView.post;
1348 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1349 <div className="row">
1350 <div className={`${this.state.imageExpanded ? "col-12" : "col-9"}`}>
1351 {this.postTitleLine()}
1353 <div className="col-3 mobile-thumbnail-container">
1354 {/* Post thumbnail */}
1355 {!this.state.imageExpanded && this.thumbnail()}
1359 this.postTitleLine()
1363 showPreviewButton() {
1367 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1368 onClick={linkEvent(this, this.handleShowBody)}
1371 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1372 classes="icon-inline"
1381 {/* The mobile view*/}
1382 <div className="d-block d-sm-none">
1383 <article className="row post-container">
1384 <div className="col-12">
1385 {this.createdLine()}
1387 {/* If it has a thumbnail, do a right aligned thumbnail */}
1388 {this.mobileThumbnail()}
1390 {this.commentsLine(true)}
1391 {this.duplicatesLine()}
1392 {this.removeAndBanDialogs()}
1397 {/* The larger view*/}
1398 <div className="d-none d-sm-block">
1399 <article className="row post-container">
1400 {!this.props.viewOnly && (
1401 <div className="col flex-grow-0">
1403 voteContentType={VoteContentType.Post}
1404 id={this.postView.post.id}
1405 onVote={this.props.onPostVote}
1406 enableDownvotes={this.props.enableDownvotes}
1407 counts={this.postView.counts}
1408 my_vote={this.postView.my_vote}
1412 <div className="col flex-grow-1">
1413 <div className="row">
1414 <div className="col flex-grow-0 px-0">
1415 <div className="">{this.thumbnail()}</div>
1417 <div className="col flex-grow-1">
1418 {this.postTitleLine()}
1419 {this.createdLine()}
1420 {this.commentsLine()}
1421 {this.duplicatesLine()}
1422 {this.removeAndBanDialogs()}
1432 private get myPost(): boolean {
1434 this.postView.creator.id ===
1435 UserService.Instance.myUserInfo?.local_user_view.person.id
1439 handleEditClick(i: PostListing) {
1440 i.setState({ showEdit: true });
1443 handleEditCancel() {
1444 this.setState({ showEdit: false });
1447 // The actual editing is done in the receive for post
1448 handleEditPost(form: EditPost) {
1449 this.setState({ showEdit: false });
1450 this.props.onPostEdit(form);
1453 handleShare(i: PostListing) {
1454 const { name, body, id } = i.props.post_view.post;
1457 text: body?.slice(0, 50),
1458 url: `${getHttpBase()}/post/${id}`,
1462 handleShowReportDialog(i: PostListing) {
1463 i.setState({ showReportDialog: !i.state.showReportDialog });
1466 handleReportReasonChange(i: PostListing, event: any) {
1467 i.setState({ reportReason: event.target.value });
1470 handleReportSubmit(i: PostListing, event: any) {
1471 event.preventDefault();
1472 i.setState({ reportLoading: true });
1473 i.props.onPostReport({
1474 post_id: i.postView.post.id,
1475 reason: i.state.reportReason ?? "",
1476 auth: myAuthRequired(),
1480 handleBlockPersonClick(i: PostListing) {
1481 i.setState({ blockLoading: true });
1482 i.props.onBlockPerson({
1483 person_id: i.postView.creator.id,
1485 auth: myAuthRequired(),
1489 handleDeleteClick(i: PostListing) {
1490 i.setState({ deleteLoading: true });
1491 i.props.onDeletePost({
1492 post_id: i.postView.post.id,
1493 deleted: !i.postView.post.deleted,
1494 auth: myAuthRequired(),
1498 handleSavePostClick(i: PostListing) {
1499 i.setState({ saveLoading: true });
1500 i.props.onSavePost({
1501 post_id: i.postView.post.id,
1502 save: !i.postView.saved,
1503 auth: myAuthRequired(),
1507 get crossPostParams(): PostFormParams {
1508 const queryParams: PostFormParams = {};
1509 const { name, url } = this.postView.post;
1511 queryParams.name = name;
1514 queryParams.url = url;
1517 const crossPostBody = this.crossPostBody();
1518 if (crossPostBody) {
1519 queryParams.body = crossPostBody;
1525 crossPostBody(): string | undefined {
1526 const post = this.postView.post;
1527 const body = post.body;
1530 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1532 }\n\n${body.replace(/^/gm, "> ")}`
1536 get showBody(): boolean {
1537 return this.props.showBody || this.state.showBody;
1540 handleModRemoveShow(i: PostListing) {
1542 showRemoveDialog: !i.state.showRemoveDialog,
1543 showBanDialog: false,
1547 handleModRemoveReasonChange(i: PostListing, event: any) {
1548 i.setState({ removeReason: event.target.value });
1551 handleModRemoveDataChange(i: PostListing, event: any) {
1552 i.setState({ removeData: event.target.checked });
1555 handleModRemoveSubmit(i: PostListing, event: any) {
1556 event.preventDefault();
1557 i.setState({ removeLoading: true });
1558 i.props.onRemovePost({
1559 post_id: i.postView.post.id,
1560 removed: !i.postView.post.removed,
1561 auth: myAuthRequired(),
1562 reason: i.state.removeReason,
1566 handleModLock(i: PostListing) {
1567 i.setState({ lockLoading: true });
1568 i.props.onLockPost({
1569 post_id: i.postView.post.id,
1570 locked: !i.postView.post.locked,
1571 auth: myAuthRequired(),
1575 handleModFeaturePostLocal(i: PostListing) {
1576 i.setState({ featureLocalLoading: true });
1577 i.props.onFeaturePost({
1578 post_id: i.postView.post.id,
1579 featured: !i.postView.post.featured_local,
1580 feature_type: "Local",
1581 auth: myAuthRequired(),
1585 handleModFeaturePostCommunity(i: PostListing) {
1586 i.setState({ featureCommunityLoading: true });
1587 i.props.onFeaturePost({
1588 post_id: i.postView.post.id,
1589 featured: !i.postView.post.featured_community,
1590 feature_type: "Community",
1591 auth: myAuthRequired(),
1595 handleModBanFromCommunityShow(i: PostListing) {
1597 showBanDialog: true,
1598 banType: BanType.Community,
1599 showRemoveDialog: false,
1603 handleModBanShow(i: PostListing) {
1605 showBanDialog: true,
1606 banType: BanType.Site,
1607 showRemoveDialog: false,
1611 handlePurgePersonShow(i: PostListing) {
1613 showPurgeDialog: true,
1614 purgeType: PurgeType.Person,
1615 showRemoveDialog: false,
1619 handlePurgePostShow(i: PostListing) {
1621 showPurgeDialog: true,
1622 purgeType: PurgeType.Post,
1623 showRemoveDialog: false,
1627 handlePurgeReasonChange(i: PostListing, event: any) {
1628 i.setState({ purgeReason: event.target.value });
1631 handlePurgeSubmit(i: PostListing, event: any) {
1632 event.preventDefault();
1633 i.setState({ purgeLoading: true });
1634 if (i.state.purgeType === PurgeType.Person) {
1635 i.props.onPurgePerson({
1636 person_id: i.postView.creator.id,
1637 reason: i.state.purgeReason,
1638 auth: myAuthRequired(),
1640 } else if (i.state.purgeType === PurgeType.Post) {
1641 i.props.onPurgePost({
1642 post_id: i.postView.post.id,
1643 reason: i.state.purgeReason,
1644 auth: myAuthRequired(),
1649 handleModBanReasonChange(i: PostListing, event: any) {
1650 i.setState({ banReason: event.target.value });
1653 handleModBanExpireDaysChange(i: PostListing, event: any) {
1654 i.setState({ banExpireDays: event.target.value });
1657 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1658 i.setState({ banType: BanType.Community });
1659 i.handleModBanBothSubmit(i, event);
1662 handleModBanSubmit(i: PostListing, event: any) {
1663 i.setState({ banType: BanType.Site });
1664 i.handleModBanBothSubmit(i, event);
1667 handleModBanBothSubmit(i: PostListing, event: any) {
1668 event.preventDefault();
1669 i.setState({ banLoading: true });
1671 const ban = !i.props.post_view.creator_banned_from_community;
1672 // If its an unban, restore all their data
1673 if (ban === false) {
1674 i.setState({ removeData: false });
1676 const person_id = i.props.post_view.creator.id;
1677 const remove_data = i.state.removeData;
1678 const reason = i.state.banReason;
1679 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1681 if (i.state.banType === BanType.Community) {
1682 const community_id = i.postView.community.id;
1683 i.props.onBanPersonFromCommunity({
1690 auth: myAuthRequired(),
1693 i.props.onBanPerson({
1699 auth: myAuthRequired(),
1704 handleAddModToCommunity(i: PostListing) {
1705 i.setState({ addModLoading: true });
1706 i.props.onAddModToCommunity({
1707 community_id: i.postView.community.id,
1708 person_id: i.postView.creator.id,
1709 added: !i.creatorIsMod_,
1710 auth: myAuthRequired(),
1714 handleAddAdmin(i: PostListing) {
1715 i.setState({ addAdminLoading: true });
1716 i.props.onAddAdmin({
1717 person_id: i.postView.creator.id,
1718 added: !i.creatorIsAdmin_,
1719 auth: myAuthRequired(),
1723 handleShowConfirmTransferCommunity(i: PostListing) {
1724 i.setState({ showConfirmTransferCommunity: true });
1727 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1728 i.setState({ showConfirmTransferCommunity: false });
1731 handleTransferCommunity(i: PostListing) {
1732 i.setState({ transferLoading: true });
1733 i.props.onTransferCommunity({
1734 community_id: i.postView.community.id,
1735 person_id: i.postView.creator.id,
1736 auth: myAuthRequired(),
1740 handleShowConfirmTransferSite(i: PostListing) {
1741 i.setState({ showConfirmTransferSite: true });
1744 handleCancelShowConfirmTransferSite(i: PostListing) {
1745 i.setState({ showConfirmTransferSite: false });
1748 handleImageExpandClick(i: PostListing, event: any) {
1749 event.preventDefault();
1750 i.setState({ imageExpanded: !i.state.imageExpanded });
1753 const auth = myAuth();
1754 if (auth && !i.props.post_view.read) {
1755 i.props.onMarkPostAsRead({
1756 post_id: i.props.post_view.post.id,
1763 handleViewSource(i: PostListing) {
1764 i.setState({ viewSource: !i.state.viewSource });
1767 handleShowAdvanced(i: PostListing) {
1768 i.setState({ showAdvanced: !i.state.showAdvanced });
1772 handleShowMoreMobile(i: PostListing) {
1774 showMoreMobile: !i.state.showMoreMobile,
1775 showAdvanced: !i.state.showAdvanced,
1780 handleShowBody(i: PostListing) {
1781 i.setState({ showBody: !i.state.showBody });
1785 get pointsTippy(): string {
1786 const points = I18NextService.i18n.t("number_of_points", {
1787 count: Number(this.postView.counts.score),
1788 formattedCount: Number(this.postView.counts.score),
1791 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1792 count: Number(this.postView.counts.upvotes),
1793 formattedCount: Number(this.postView.counts.upvotes),
1796 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1797 count: Number(this.postView.counts.downvotes),
1798 formattedCount: Number(this.postView.counts.downvotes),
1801 return `${points} • ${upvotes} • ${downvotes}`;
1804 get canModOnSelf_(): boolean {
1806 this.postView.creator.id,
1807 this.props.moderators,
1814 get canMod_(): boolean {
1816 this.postView.creator.id,
1817 this.props.moderators,
1822 get canAdmin_(): boolean {
1823 return canAdmin(this.postView.creator.id, this.props.admins);
1826 get creatorIsMod_(): boolean {
1827 return isMod(this.postView.creator.id, this.props.moderators);
1830 get creatorIsAdmin_(): boolean {
1831 return isAdmin(this.postView.creator.id, this.props.admins);