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;
109 * Controls whether to show both the body *and* the metadata preview card
113 enableDownvotes?: boolean;
114 enableNsfw?: boolean;
116 onPostEdit(form: EditPost): void;
117 onPostVote(form: CreatePostLike): void;
118 onPostReport(form: CreatePostReport): void;
119 onBlockPerson(form: BlockPerson): void;
120 onLockPost(form: LockPost): void;
121 onDeletePost(form: DeletePost): void;
122 onRemovePost(form: RemovePost): void;
123 onSavePost(form: SavePost): void;
124 onFeaturePost(form: FeaturePost): void;
125 onPurgePerson(form: PurgePerson): void;
126 onPurgePost(form: PurgePost): void;
127 onBanPersonFromCommunity(form: BanFromCommunity): void;
128 onBanPerson(form: BanPerson): void;
129 onAddModToCommunity(form: AddModToCommunity): void;
130 onAddAdmin(form: AddAdmin): void;
131 onTransferCommunity(form: TransferCommunity): void;
134 export class PostListing extends Component<PostListingProps, PostListingState> {
135 state: PostListingState = {
137 showRemoveDialog: false,
138 showPurgeDialog: false,
139 purgeType: PurgeType.Person,
140 showBanDialog: false,
141 banType: BanType.Community,
143 showConfirmTransferSite: false,
144 showConfirmTransferCommunity: false,
145 imageExpanded: false,
148 showMoreMobile: false,
150 showReportDialog: false,
152 reportLoading: false,
155 deleteLoading: false,
156 removeLoading: false,
158 featureCommunityLoading: false,
159 featureLocalLoading: false,
161 addModLoading: false,
162 addAdminLoading: false,
163 transferLoading: false,
166 constructor(props: any, context: any) {
167 super(props, context);
169 this.handleEditPost = this.handleEditPost.bind(this);
170 this.handleEditCancel = this.handleEditCancel.bind(this);
173 componentWillReceiveProps(nextProps: PostListingProps) {
174 if (this.props !== nextProps) {
177 reportLoading: false,
180 deleteLoading: false,
181 removeLoading: false,
183 featureCommunityLoading: false,
184 featureLocalLoading: false,
186 addModLoading: false,
187 addAdminLoading: false,
188 transferLoading: false,
193 get postView(): PostView {
194 return this.props.post_view;
198 const post = this.postView.post;
201 <div className="post-listing mt-2">
202 {!this.state.showEdit ? (
205 {this.state.imageExpanded && !this.props.hideImage && this.img}
206 {this.showBody && post.url && post.embed_title && (
207 <MetadataCard post={post} />
209 {this.showBody && this.body()}
213 post_view={this.postView}
214 crossPosts={this.props.crossPosts}
215 onEdit={this.handleEditPost}
216 onCancel={this.handleEditCancel}
217 enableNsfw={this.props.enableNsfw}
218 enableDownvotes={this.props.enableDownvotes}
219 allLanguages={this.props.allLanguages}
220 siteLanguages={this.props.siteLanguages}
228 const body = this.postView.post.body;
230 <article id="postContent" className="col-12 card my-2 p-2">
231 {this.state.viewSource ? (
234 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
246 <div className="offset-sm-3 my-2 d-none d-sm-block">
247 <a href={this.imageSrc} className="d-inline-block">
248 <PictrsImage src={this.imageSrc} />
251 <div className="my-2 d-block d-sm-none">
254 className="p-0 border-0 bg-transparent d-inline-block"
255 onClick={linkEvent(this, this.handleImageExpandClick)}
257 <PictrsImage src={this.imageSrc} />
264 const { post } = this.postView;
265 const { url } = post;
267 // if direct video link
268 if (url && isVideo(url)) {
270 <div className="embed-responsive mt-3">
271 <video muted controls className="embed-responsive-item col-12">
272 <source src={url} type="video/mp4" />
278 // if embedded video link
279 if (url && post.embed_video_url) {
281 <div className="ratio ratio-16x9">
284 className="post-metadata-iframe"
285 src={post.embed_video_url}
286 title={post.embed_title}
295 imgThumb(src: string) {
296 const post_view = this.postView;
302 nsfw={post_view.post.nsfw || post_view.community.nsfw}
307 get imageSrc(): string | undefined {
308 const post = this.postView.post;
309 const url = post.url;
310 const thumbnail = post.thumbnail_url;
312 if (url && isImage(url)) {
313 if (url.includes("pictrs")) {
315 } else if (thumbnail) {
320 } else if (thumbnail) {
328 const post = this.postView.post;
329 const url = post.url;
330 const thumbnail = post.thumbnail_url;
332 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
336 className="text-body d-inline-block position-relative mb-2"
337 data-tippy-content={I18NextService.i18n.t("expand_here")}
338 onClick={linkEvent(this, this.handleImageExpandClick)}
339 aria-label={I18NextService.i18n.t("expand_here")}
341 {this.imgThumb(this.imageSrc)}
342 <Icon icon="image" classes="mini-overlay" />
345 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
348 className="text-body d-inline-block position-relative mb-2"
353 {this.imgThumb(this.imageSrc)}
354 <Icon icon="external-link" classes="mini-overlay" />
358 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
361 className="text-body"
365 data-tippy-content={I18NextService.i18n.t("expand_here")}
366 onClick={linkEvent(this, this.handleImageExpandClick)}
367 aria-label={I18NextService.i18n.t("expand_here")}
369 <div className="thumbnail rounded bg-light d-flex justify-content-center">
370 <Icon icon="play" classes="d-flex align-items-center" />
376 <a className="text-body" href={url} title={url} rel={relTags}>
377 <div className="thumbnail rounded bg-light d-flex justify-content-center">
378 <Icon icon="external-link" classes="d-flex align-items-center" />
386 className="text-body"
387 to={`/post/${post.id}`}
388 title={I18NextService.i18n.t("comments")}
390 <div className="thumbnail rounded bg-light d-flex justify-content-center">
391 <Icon icon="message-square" classes="d-flex align-items-center" />
399 const post_view = this.postView;
401 <span className="small">
402 <PersonListing person={post_view.creator} muted={true} />
403 {this.creatorIsMod_ && (
404 <span className="mx-1 badge text-bg-light">
405 {I18NextService.i18n.t("mod")}
408 {this.creatorIsAdmin_ && (
409 <span className="mx-1 badge text-bg-light">
410 {I18NextService.i18n.t("admin")}
413 {post_view.creator.bot_account && (
414 <span className="mx-1 badge text-bg-light">
415 {I18NextService.i18n.t("bot_account").toLowerCase()}
418 {this.props.showCommunity && (
421 {I18NextService.i18n.t("to")}{" "}
422 <CommunityLink community={post_view.community} />
425 {post_view.post.language_id !== 0 && (
426 <span className="mx-1 badge text-bg-light">
428 this.props.allLanguages.find(
429 lang => lang.id === post_view.post.language_id
436 published={post_view.post.published}
437 updated={post_view.post.updated}
444 const post = this.postView.post;
447 className={`d-inline ${
448 !post.featured_community && !post.featured_local
452 to={`/post/${post.id}`}
453 title={I18NextService.i18n.t("comments")}
457 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
464 const post = this.postView.post;
465 const url = post.url;
469 <div className="post-title overflow-hidden">
470 <h5 className="d-inline">
471 {url && this.props.showBody ? (
474 !post.featured_community && !post.featured_local
481 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
489 * If there is a URL, an embed title, and we were not told to show the
490 * body by the parent component, show the MetadataCard/body toggle.
492 {!this.props.showBody && post.url && post.embed_title && (
494 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
495 data-tippy-content={post.body && mdNoImages.render(post.body)}
496 data-tippy-allowHtml={true}
497 onClick={linkEvent(this, this.handleShowBody)}
500 icon={!this.state.showBody ? "plus-square" : "minus-square"}
501 classes="icon-inline"
507 <small className="ms-2 badge text-bg-secondary">
508 {I18NextService.i18n.t("removed")}
514 className="unselectable pointer ms-2 text-muted fst-italic"
515 data-tippy-content={I18NextService.i18n.t("deleted")}
517 <Icon icon="trash" classes="icon-inline text-danger" />
523 className="unselectable pointer ms-2 text-muted fst-italic"
524 data-tippy-content={I18NextService.i18n.t("locked")}
526 <Icon icon="lock" classes="icon-inline text-danger" />
530 {post.featured_community && (
532 className="unselectable pointer ms-2 text-muted fst-italic"
533 data-tippy-content={I18NextService.i18n.t(
534 "featured_in_community"
536 aria-label={I18NextService.i18n.t("featured_in_community")}
538 <Icon icon="pin" classes="icon-inline text-primary" />
542 {post.featured_local && (
544 className="unselectable pointer ms-2 text-muted fst-italic"
545 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
546 aria-label={I18NextService.i18n.t("featured_in_local")}
548 <Icon icon="pin" classes="icon-inline text-secondary" />
553 <small className="ms-2 badge text-bg-danger">
554 {I18NextService.i18n.t("nsfw")}
558 {url && this.urlLine()}
564 const post = this.postView.post;
565 const url = post.url;
568 <p className="small m-0">
569 {url && !(hostname(url) === getExternalHost()) && (
571 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
584 const dupes = this.props.crossPosts;
585 return dupes && dupes.length > 0 ? (
586 <ul className="list-inline mb-1 small text-muted">
588 <li className="list-inline-item me-2">
589 {I18NextService.i18n.t("cross_posted_to")}
592 <li key={pv.post.id} className="list-inline-item me-2">
593 <Link to={`/post/${pv.post.id}`}>
596 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
607 commentsLine(mobile = false) {
608 const post = this.postView.post;
611 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
612 {this.commentsButton}
615 className="btn btn-sm btn-animate text-muted py-0"
616 onClick={linkEvent(this, this.handleShare)}
619 <Icon icon="share" inline />
624 className="btn btn-sm btn-animate text-muted py-0"
625 title={I18NextService.i18n.t("link")}
628 <Icon icon="fedilink" inline />
631 {mobile && !this.props.viewOnly && (
633 voteContentType={VoteContentType.Post}
634 id={this.postView.post.id}
635 onVote={this.props.onPostVote}
636 enableDownvotes={this.props.enableDownvotes}
637 counts={this.postView.counts}
638 my_vote={this.postView.my_vote}
641 {UserService.Instance.myUserInfo &&
642 !this.props.viewOnly &&
649 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
650 // Possible enhancement: Make each button a component.
651 const post_view = this.postView;
652 const post = post_view.post;
657 {this.crossPostButton}
659 {this.props.showBody && post_view.post.body && this.viewSourceButton}
661 <div className="dropdown">
663 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
664 onClick={linkEvent(this, this.handleShowAdvanced)}
665 data-tippy-content={I18NextService.i18n.t("more")}
666 data-bs-toggle="dropdown"
667 aria-expanded="false"
668 aria-controls={`advancedButtonsDropdown${post.id}`}
669 aria-label={I18NextService.i18n.t("more")}
671 <Icon icon="more-vertical" inline />
675 className="dropdown-menu"
676 id={`advancedButtonsDropdown${post.id}`}
680 <li>{this.reportButton}</li>
681 <li>{this.blockButton}</li>
685 <li>{this.editButton}</li>
686 <li>{this.deleteButton}</li>
690 {/* Any mod can do these, not limited to hierarchy*/}
691 {(amMod(this.props.moderators) || amAdmin()) && (
694 <hr className="dropdown-divider" />
696 <li>{this.lockButton}</li>
697 {this.featureButtons}
701 {(this.canMod_ || this.canAdmin_) && (
702 <li>{this.modRemoveButton}</li>
710 get commentsButton() {
711 const post_view = this.postView;
712 const title = I18NextService.i18n.t("number_of_comments", {
713 count: Number(post_view.counts.comments),
714 formattedCount: Number(post_view.counts.comments),
719 className="btn btn-link btn-sm text-muted ps-0"
721 to={`/post/${post_view.post.id}?scrollToComments=true`}
722 data-tippy-content={title}
724 <Icon icon="message-square" classes="me-1" inline />
725 {post_view.counts.comments}
726 {this.unreadCount && (
729 <span className="fst-italic">
730 ({this.unreadCount} {I18NextService.i18n.t("new")})
738 get unreadCount(): number | undefined {
739 const pv = this.postView;
740 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
742 : pv.unread_comments;
746 const saved = this.postView.saved;
748 ? I18NextService.i18n.t("unsave")
749 : I18NextService.i18n.t("save");
752 className="btn btn-sm btn-animate text-muted py-0"
753 onClick={linkEvent(this, this.handleSavePostClick)}
754 data-tippy-content={label}
757 {this.state.saveLoading ? (
762 classes={classNames({ "text-warning": saved })}
770 get crossPostButton() {
773 className="btn btn-sm btn-animate text-muted py-0"
775 /* Empty string properties are required to satisfy type*/
776 pathname: "/create_post",
777 state: { ...this.crossPostParams },
782 title={I18NextService.i18n.t("cross_post")}
783 data-tippy-content={I18NextService.i18n.t("cross_post")}
784 aria-label={I18NextService.i18n.t("cross_post")}
786 <Icon icon="copy" inline />
794 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
795 onClick={linkEvent(this, this.handleShowReportDialog)}
796 aria-label={I18NextService.i18n.t("show_report_dialog")}
798 <Icon classes="me-1" icon="flag" inline />
799 {I18NextService.i18n.t("create_report")}
807 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
808 onClick={linkEvent(this, this.handleBlockPersonClick)}
809 aria-label={I18NextService.i18n.t("block_user")}
811 {this.state.blockLoading ? (
814 <Icon classes="me-1" icon="slash" inline />
816 {I18NextService.i18n.t("block_user")}
824 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
825 onClick={linkEvent(this, this.handleEditClick)}
826 aria-label={I18NextService.i18n.t("edit")}
828 <Icon classes="me-1" icon="edit" inline />
829 {I18NextService.i18n.t("edit")}
835 const deleted = this.postView.post.deleted;
836 const label = !deleted
837 ? I18NextService.i18n.t("delete")
838 : I18NextService.i18n.t("restore");
841 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
842 onClick={linkEvent(this, this.handleDeleteClick)}
844 {this.state.deleteLoading ? (
850 classes={classNames("me-1", { "text-danger": deleted })}
860 get viewSourceButton() {
863 className="btn btn-sm btn-animate text-muted py-0"
864 onClick={linkEvent(this, this.handleViewSource)}
865 data-tippy-content={I18NextService.i18n.t("view_source")}
866 aria-label={I18NextService.i18n.t("view_source")}
870 classes={classNames({ "text-success": this.state.viewSource })}
878 const locked = this.postView.post.locked;
880 ? I18NextService.i18n.t("unlock")
881 : I18NextService.i18n.t("lock");
884 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
885 onClick={linkEvent(this, this.handleModLock)}
888 {this.state.lockLoading ? (
894 classes={classNames("me-1", { "text-danger": locked })}
897 {capitalizeFirstLetter(label)}
904 get featureButtons() {
905 const featuredCommunity = this.postView.post.featured_community;
906 const labelCommunity = featuredCommunity
907 ? I18NextService.i18n.t("unfeature_from_community")
908 : I18NextService.i18n.t("feature_in_community");
910 const featuredLocal = this.postView.post.featured_local;
911 const labelLocal = featuredLocal
912 ? I18NextService.i18n.t("unfeature_from_local")
913 : I18NextService.i18n.t("feature_in_local");
918 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
919 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
920 data-tippy-content={labelCommunity}
921 aria-label={labelCommunity}
923 {this.state.featureCommunityLoading ? (
929 classes={classNames("me-1", {
930 "text-success": featuredCommunity,
934 {I18NextService.i18n.t("community")}
942 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
943 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
944 data-tippy-content={labelLocal}
945 aria-label={labelLocal}
947 {this.state.featureLocalLoading ? (
953 classes={classNames("me-1", {
954 "text-success": featuredLocal,
958 {I18NextService.i18n.t("local")}
968 get modBanFromCommunityButton() {
971 className="btn btn-link btn-animate text-muted py-0"
972 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
973 aria-label={I18NextService.i18n.t("ban_from_community")}
975 {I18NextService.i18n.t("ban_from_community")}
980 get modUnbanFromCommunityButton() {
983 className="btn btn-link btn-animate text-muted py-0"
984 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
985 aria-label={I18NextService.i18n.t("unban")}
987 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
992 get addModToCommunityButton() {
995 className="btn btn-link btn-animate text-muted py-0"
996 onClick={linkEvent(this, this.handleAddModToCommunity)}
999 ? I18NextService.i18n.t("remove_as_mod")
1000 : I18NextService.i18n.t("appoint_as_mod")
1003 {this.state.addModLoading ? (
1005 ) : this.creatorIsMod_ ? (
1006 I18NextService.i18n.t("remove_as_mod")
1008 I18NextService.i18n.t("appoint_as_mod")
1014 get modBanButton() {
1017 className="btn btn-link btn-animate text-muted py-0"
1018 onClick={linkEvent(this, this.handleModBanShow)}
1019 aria-label={I18NextService.i18n.t("ban_from_site")}
1021 {I18NextService.i18n.t("ban_from_site")}
1026 get modUnbanButton() {
1029 className="btn btn-link btn-animate text-muted py-0"
1030 onClick={linkEvent(this, this.handleModBanSubmit)}
1031 aria-label={I18NextService.i18n.t("unban_from_site")}
1033 {this.state.banLoading ? (
1036 I18NextService.i18n.t("unban_from_site")
1042 get purgePersonButton() {
1045 className="btn btn-link btn-animate text-muted py-0"
1046 onClick={linkEvent(this, this.handlePurgePersonShow)}
1047 aria-label={I18NextService.i18n.t("purge_user")}
1049 {I18NextService.i18n.t("purge_user")}
1054 get purgePostButton() {
1057 className="btn btn-link btn-animate text-muted py-0"
1058 onClick={linkEvent(this, this.handlePurgePostShow)}
1059 aria-label={I18NextService.i18n.t("purge_post")}
1061 {I18NextService.i18n.t("purge_post")}
1066 get toggleAdminButton() {
1069 className="btn btn-link btn-animate text-muted py-0"
1070 onClick={linkEvent(this, this.handleAddAdmin)}
1072 {this.state.addAdminLoading ? (
1074 ) : this.creatorIsAdmin_ ? (
1075 I18NextService.i18n.t("remove_as_admin")
1077 I18NextService.i18n.t("appoint_as_admin")
1083 get modRemoveButton() {
1084 const removed = this.postView.post.removed;
1087 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1090 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1093 {/* TODO: Find an icon for this. */}
1094 {this.state.removeLoading ? (
1097 I18NextService.i18n.t("remove")
1099 I18NextService.i18n.t("restore")
1106 * Mod/Admin actions to be taken against the author.
1110 const post_view = this.postView;
1112 this.state.showAdvanced && (
1113 <div className="mt-3">
1116 {!this.creatorIsMod_ &&
1117 (!post_view.creator_banned_from_community
1118 ? this.modBanFromCommunityButton
1119 : this.modUnbanFromCommunityButton)}
1120 {!post_view.creator_banned_from_community &&
1121 this.addModToCommunityButton}
1125 {/* Community creators and admins can transfer community to another mod */}
1126 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1128 this.creatorIsMod_ &&
1129 (!this.state.showConfirmTransferCommunity ? (
1131 className="btn btn-link btn-animate text-muted py-0"
1134 this.handleShowConfirmTransferCommunity
1136 aria-label={I18NextService.i18n.t("transfer_community")}
1138 {I18NextService.i18n.t("transfer_community")}
1143 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1144 aria-label={I18NextService.i18n.t("are_you_sure")}
1146 {I18NextService.i18n.t("are_you_sure")}
1149 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1150 aria-label={I18NextService.i18n.t("yes")}
1151 onClick={linkEvent(this, this.handleTransferCommunity)}
1153 {this.state.transferLoading ? (
1156 I18NextService.i18n.t("yes")
1160 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1163 this.handleCancelShowConfirmTransferCommunity
1165 aria-label={I18NextService.i18n.t("no")}
1167 {I18NextService.i18n.t("no")}
1171 {/* Admins can ban from all, and appoint other admins */}
1172 {this.canAdmin_ && (
1174 {!this.creatorIsAdmin_ && (
1176 {!isBanned(post_view.creator)
1178 : this.modUnbanButton}
1179 {this.purgePersonButton}
1180 {this.purgePostButton}
1183 {!isBanned(post_view.creator) &&
1184 post_view.creator.local &&
1185 this.toggleAdminButton}
1193 removeAndBanDialogs() {
1194 const post = this.postView;
1195 const purgeTypeText =
1196 this.state.purgeType == PurgeType.Post
1197 ? I18NextService.i18n.t("purge_post")
1198 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1201 {this.state.showRemoveDialog && (
1203 className="form-inline"
1204 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1207 className="visually-hidden"
1208 htmlFor="post-listing-remove-reason"
1210 {I18NextService.i18n.t("reason")}
1214 id="post-listing-remove-reason"
1215 className="form-control me-2"
1216 placeholder={I18NextService.i18n.t("reason")}
1217 value={this.state.removeReason}
1218 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1222 className="btn btn-secondary"
1223 aria-label={I18NextService.i18n.t("remove_post")}
1225 {this.state.removeLoading ? (
1228 I18NextService.i18n.t("remove_post")
1233 {this.state.showBanDialog && (
1234 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1235 <div className="mb-3 row col-12">
1237 className="col-form-label"
1238 htmlFor="post-listing-ban-reason"
1240 {I18NextService.i18n.t("reason")}
1244 id="post-listing-ban-reason"
1245 className="form-control me-2"
1246 placeholder={I18NextService.i18n.t("reason")}
1247 value={this.state.banReason}
1248 onInput={linkEvent(this, this.handleModBanReasonChange)}
1250 <label className="col-form-label" htmlFor="mod-ban-expires">
1251 {I18NextService.i18n.t("expires")}
1255 id="mod-ban-expires"
1256 className="form-control me-2"
1257 placeholder={I18NextService.i18n.t("number_of_days")}
1258 value={this.state.banExpireDays}
1259 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1261 <div className="input-group mb-3">
1262 <div className="form-check">
1264 className="form-check-input"
1265 id="mod-ban-remove-data"
1267 checked={this.state.removeData}
1268 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1271 className="form-check-label"
1272 htmlFor="mod-ban-remove-data"
1273 title={I18NextService.i18n.t("remove_content_more")}
1275 {I18NextService.i18n.t("remove_content")}
1280 {/* TODO hold off on expires until later */}
1281 {/* <div class="mb-3 row"> */}
1282 {/* <label class="col-form-label">Expires</label> */}
1283 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1285 <div className="mb-3 row">
1288 className="btn btn-secondary"
1289 aria-label={I18NextService.i18n.t("ban")}
1291 {this.state.banLoading ? (
1295 {I18NextService.i18n.t("ban")} {post.creator.name}
1302 {this.state.showReportDialog && (
1304 className="form-inline"
1305 onSubmit={linkEvent(this, this.handleReportSubmit)}
1307 <label className="visually-hidden" htmlFor="post-report-reason">
1308 {I18NextService.i18n.t("reason")}
1312 id="post-report-reason"
1313 className="form-control me-2"
1314 placeholder={I18NextService.i18n.t("reason")}
1316 value={this.state.reportReason}
1317 onInput={linkEvent(this, this.handleReportReasonChange)}
1321 className="btn btn-secondary"
1322 aria-label={I18NextService.i18n.t("create_report")}
1324 {this.state.reportLoading ? (
1327 I18NextService.i18n.t("create_report")
1332 {this.state.showPurgeDialog && (
1334 className="form-inline"
1335 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1338 <label className="visually-hidden" htmlFor="purge-reason">
1339 {I18NextService.i18n.t("reason")}
1344 className="form-control me-2"
1345 placeholder={I18NextService.i18n.t("reason")}
1346 value={this.state.purgeReason}
1347 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1349 {this.state.purgeLoading ? (
1354 className="btn btn-secondary"
1355 aria-label={purgeTypeText}
1357 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1367 const post = this.postView.post;
1368 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1369 <div className="row">
1370 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1371 {this.postTitleLine()}
1373 <div className="col-4">
1374 {/* Post thumbnail */}
1375 {!this.state.imageExpanded && this.thumbnail()}
1379 this.postTitleLine()
1386 {/* The mobile view*/}
1387 <div className="d-block d-sm-none">
1388 <article className="row post-container">
1389 <div className="col-12">
1390 {this.createdLine()}
1392 {/* If it has a thumbnail, do a right aligned thumbnail */}
1393 {this.mobileThumbnail()}
1395 {this.commentsLine(true)}
1396 {this.userActionsLine()}
1397 {this.duplicatesLine()}
1398 {this.removeAndBanDialogs()}
1403 {/* The larger view*/}
1404 <div className="d-none d-sm-block">
1405 <article className="row post-container">
1406 {!this.props.viewOnly && (
1408 voteContentType={VoteContentType.Post}
1409 id={this.postView.post.id}
1410 onVote={this.props.onPostVote}
1411 enableDownvotes={this.props.enableDownvotes}
1412 counts={this.postView.counts}
1413 my_vote={this.postView.my_vote}
1416 <div className="col-sm-2 pe-0 post-media">
1417 <div className="">{this.thumbnail()}</div>
1419 <div className="col-12 col-sm-9">
1420 <div className="row">
1421 <div className="col-12">
1422 {this.postTitleLine()}
1423 {this.createdLine()}
1424 {this.commentsLine()}
1425 {this.duplicatesLine()}
1426 {this.userActionsLine()}
1427 {this.removeAndBanDialogs()}
1437 private get myPost(): boolean {
1439 this.postView.creator.id ==
1440 UserService.Instance.myUserInfo?.local_user_view.person.id
1443 handleEditClick(i: PostListing) {
1444 i.setState({ showEdit: true });
1447 handleEditCancel() {
1448 this.setState({ showEdit: false });
1451 // The actual editing is done in the receive for post
1452 handleEditPost(form: EditPost) {
1453 this.setState({ showEdit: false });
1454 this.props.onPostEdit(form);
1457 handleShare(i: PostListing) {
1458 const { name, body, id } = i.props.post_view.post;
1461 text: body?.slice(0, 50),
1462 url: `${getHttpBase()}/post/${id}`,
1466 handleShowReportDialog(i: PostListing) {
1467 i.setState({ showReportDialog: !i.state.showReportDialog });
1470 handleReportReasonChange(i: PostListing, event: any) {
1471 i.setState({ reportReason: event.target.value });
1474 handleReportSubmit(i: PostListing, event: any) {
1475 event.preventDefault();
1476 i.setState({ reportLoading: true });
1477 i.props.onPostReport({
1478 post_id: i.postView.post.id,
1479 reason: i.state.reportReason ?? "",
1480 auth: myAuthRequired(),
1484 handleBlockPersonClick(i: PostListing) {
1485 i.setState({ blockLoading: true });
1486 i.props.onBlockPerson({
1487 person_id: i.postView.creator.id,
1489 auth: myAuthRequired(),
1493 handleDeleteClick(i: PostListing) {
1494 i.setState({ deleteLoading: true });
1495 i.props.onDeletePost({
1496 post_id: i.postView.post.id,
1497 deleted: !i.postView.post.deleted,
1498 auth: myAuthRequired(),
1502 handleSavePostClick(i: PostListing) {
1503 i.setState({ saveLoading: true });
1504 i.props.onSavePost({
1505 post_id: i.postView.post.id,
1506 save: !i.postView.saved,
1507 auth: myAuthRequired(),
1511 get crossPostParams(): PostFormParams {
1512 const queryParams: PostFormParams = {};
1513 const { name, url } = this.postView.post;
1515 queryParams.name = name;
1518 queryParams.url = url;
1521 const crossPostBody = this.crossPostBody();
1522 if (crossPostBody) {
1523 queryParams.body = crossPostBody;
1529 crossPostBody(): string | undefined {
1530 const post = this.postView.post;
1531 const body = post.body;
1534 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1536 }\n\n${body.replace(/^/gm, "> ")}`
1540 get showBody(): boolean {
1541 return this.props.showBody || this.state.showBody;
1544 handleModRemoveShow(i: PostListing) {
1546 showRemoveDialog: !i.state.showRemoveDialog,
1547 showBanDialog: false,
1551 handleModRemoveReasonChange(i: PostListing, event: any) {
1552 i.setState({ removeReason: event.target.value });
1555 handleModRemoveDataChange(i: PostListing, event: any) {
1556 i.setState({ removeData: event.target.checked });
1559 handleModRemoveSubmit(i: PostListing, event: any) {
1560 event.preventDefault();
1561 i.setState({ removeLoading: true });
1562 i.props.onRemovePost({
1563 post_id: i.postView.post.id,
1564 removed: !i.postView.post.removed,
1565 auth: myAuthRequired(),
1569 handleModLock(i: PostListing) {
1570 i.setState({ lockLoading: true });
1571 i.props.onLockPost({
1572 post_id: i.postView.post.id,
1573 locked: !i.postView.post.locked,
1574 auth: myAuthRequired(),
1578 handleModFeaturePostLocal(i: PostListing) {
1579 i.setState({ featureLocalLoading: true });
1580 i.props.onFeaturePost({
1581 post_id: i.postView.post.id,
1582 featured: !i.postView.post.featured_local,
1583 feature_type: "Local",
1584 auth: myAuthRequired(),
1588 handleModFeaturePostCommunity(i: PostListing) {
1589 i.setState({ featureCommunityLoading: true });
1590 i.props.onFeaturePost({
1591 post_id: i.postView.post.id,
1592 featured: !i.postView.post.featured_community,
1593 feature_type: "Community",
1594 auth: myAuthRequired(),
1598 handleModBanFromCommunityShow(i: PostListing) {
1600 showBanDialog: true,
1601 banType: BanType.Community,
1602 showRemoveDialog: false,
1606 handleModBanShow(i: PostListing) {
1608 showBanDialog: true,
1609 banType: BanType.Site,
1610 showRemoveDialog: false,
1614 handlePurgePersonShow(i: PostListing) {
1616 showPurgeDialog: true,
1617 purgeType: PurgeType.Person,
1618 showRemoveDialog: false,
1622 handlePurgePostShow(i: PostListing) {
1624 showPurgeDialog: true,
1625 purgeType: PurgeType.Post,
1626 showRemoveDialog: false,
1630 handlePurgeReasonChange(i: PostListing, event: any) {
1631 i.setState({ purgeReason: event.target.value });
1634 handlePurgeSubmit(i: PostListing, event: any) {
1635 event.preventDefault();
1636 i.setState({ purgeLoading: true });
1637 if (i.state.purgeType == PurgeType.Person) {
1638 i.props.onPurgePerson({
1639 person_id: i.postView.creator.id,
1640 reason: i.state.purgeReason,
1641 auth: myAuthRequired(),
1643 } else if (i.state.purgeType == PurgeType.Post) {
1644 i.props.onPurgePost({
1645 post_id: i.postView.post.id,
1646 reason: i.state.purgeReason,
1647 auth: myAuthRequired(),
1652 handleModBanReasonChange(i: PostListing, event: any) {
1653 i.setState({ banReason: event.target.value });
1656 handleModBanExpireDaysChange(i: PostListing, event: any) {
1657 i.setState({ banExpireDays: event.target.value });
1660 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1661 i.setState({ banType: BanType.Community });
1662 i.handleModBanBothSubmit(i, event);
1665 handleModBanSubmit(i: PostListing, event: any) {
1666 i.setState({ banType: BanType.Site });
1667 i.handleModBanBothSubmit(i, event);
1670 handleModBanBothSubmit(i: PostListing, event: any) {
1671 event.preventDefault();
1672 i.setState({ banLoading: true });
1674 const ban = !i.props.post_view.creator_banned_from_community;
1675 // If its an unban, restore all their data
1677 i.setState({ removeData: false });
1679 const person_id = i.props.post_view.creator.id;
1680 const remove_data = i.state.removeData;
1681 const reason = i.state.banReason;
1682 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1684 if (i.state.banType == BanType.Community) {
1685 const community_id = i.postView.community.id;
1686 i.props.onBanPersonFromCommunity({
1693 auth: myAuthRequired(),
1696 i.props.onBanPerson({
1702 auth: myAuthRequired(),
1707 handleAddModToCommunity(i: PostListing) {
1708 i.setState({ addModLoading: true });
1709 i.props.onAddModToCommunity({
1710 community_id: i.postView.community.id,
1711 person_id: i.postView.creator.id,
1712 added: !i.creatorIsMod_,
1713 auth: myAuthRequired(),
1717 handleAddAdmin(i: PostListing) {
1718 i.setState({ addAdminLoading: true });
1719 i.props.onAddAdmin({
1720 person_id: i.postView.creator.id,
1721 added: !i.creatorIsAdmin_,
1722 auth: myAuthRequired(),
1726 handleShowConfirmTransferCommunity(i: PostListing) {
1727 i.setState({ showConfirmTransferCommunity: true });
1730 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1731 i.setState({ showConfirmTransferCommunity: false });
1734 handleTransferCommunity(i: PostListing) {
1735 i.setState({ transferLoading: true });
1736 i.props.onTransferCommunity({
1737 community_id: i.postView.community.id,
1738 person_id: i.postView.creator.id,
1739 auth: myAuthRequired(),
1743 handleShowConfirmTransferSite(i: PostListing) {
1744 i.setState({ showConfirmTransferSite: true });
1747 handleCancelShowConfirmTransferSite(i: PostListing) {
1748 i.setState({ showConfirmTransferSite: false });
1751 handleImageExpandClick(i: PostListing, event: any) {
1752 event.preventDefault();
1753 i.setState({ imageExpanded: !i.state.imageExpanded });
1757 handleViewSource(i: PostListing) {
1758 i.setState({ viewSource: !i.state.viewSource });
1761 handleShowAdvanced(i: PostListing) {
1762 i.setState({ showAdvanced: !i.state.showAdvanced });
1766 handleShowMoreMobile(i: PostListing) {
1768 showMoreMobile: !i.state.showMoreMobile,
1769 showAdvanced: !i.state.showAdvanced,
1774 handleShowBody(i: PostListing) {
1775 i.setState({ showBody: !i.state.showBody });
1779 get pointsTippy(): string {
1780 const points = I18NextService.i18n.t("number_of_points", {
1781 count: Number(this.postView.counts.score),
1782 formattedCount: Number(this.postView.counts.score),
1785 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1786 count: Number(this.postView.counts.upvotes),
1787 formattedCount: Number(this.postView.counts.upvotes),
1790 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1791 count: Number(this.postView.counts.downvotes),
1792 formattedCount: Number(this.postView.counts.downvotes),
1795 return `${points} • ${upvotes} • ${downvotes}`;
1798 get canModOnSelf_(): boolean {
1800 this.postView.creator.id,
1801 this.props.moderators,
1808 get canMod_(): boolean {
1810 this.postView.creator.id,
1811 this.props.moderators,
1816 get canAdmin_(): boolean {
1817 return canAdmin(this.postView.creator.id, this.props.admins);
1820 get creatorIsMod_(): boolean {
1821 return isMod(this.postView.creator.id, this.props.moderators);
1824 get creatorIsAdmin_(): boolean {
1825 return isAdmin(this.postView.creator.id, this.props.admins);