1 import { myAuthRequired } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
51 } from "../../interfaces";
52 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
53 import { I18NextService, UserService } from "../../services";
54 import { setupTippy } from "../../tippy";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
59 import { CommunityLink } from "../community/community-link";
60 import { PersonListing } from "../person/person-listing";
61 import { MetadataCard } from "./metadata-card";
62 import { PostForm } from "./post-form";
64 interface PostListingState {
66 showRemoveDialog: boolean;
67 showPurgeDialog: boolean;
69 purgeType?: PurgeType;
70 purgeLoading: boolean;
71 removeReason?: string;
72 showBanDialog: boolean;
74 banExpireDays?: number;
77 showConfirmTransferSite: boolean;
78 showConfirmTransferCommunity: boolean;
79 imageExpanded: boolean;
81 showAdvanced: boolean;
82 showMoreMobile: boolean;
84 showReportDialog: boolean;
85 reportReason?: string;
86 reportLoading: boolean;
87 blockLoading: boolean;
89 deleteLoading: boolean;
90 removeLoading: boolean;
92 featureCommunityLoading: boolean;
93 featureLocalLoading: boolean;
95 addModLoading: boolean;
96 addAdminLoading: boolean;
97 transferLoading: boolean;
100 interface PostListingProps {
102 crossPosts?: PostView[];
103 moderators?: CommunityModeratorView[];
104 admins?: PersonView[];
105 allLanguages: Language[];
106 siteLanguages: number[];
107 showCommunity?: boolean;
110 enableDownvotes?: boolean;
111 enableNsfw?: boolean;
113 onPostEdit(form: EditPost): void;
114 onPostVote(form: CreatePostLike): void;
115 onPostReport(form: CreatePostReport): void;
116 onBlockPerson(form: BlockPerson): void;
117 onLockPost(form: LockPost): void;
118 onDeletePost(form: DeletePost): void;
119 onRemovePost(form: RemovePost): void;
120 onSavePost(form: SavePost): void;
121 onFeaturePost(form: FeaturePost): void;
122 onPurgePerson(form: PurgePerson): void;
123 onPurgePost(form: PurgePost): void;
124 onBanPersonFromCommunity(form: BanFromCommunity): void;
125 onBanPerson(form: BanPerson): void;
126 onAddModToCommunity(form: AddModToCommunity): void;
127 onAddAdmin(form: AddAdmin): void;
128 onTransferCommunity(form: TransferCommunity): void;
131 export class PostListing extends Component<PostListingProps, PostListingState> {
132 state: PostListingState = {
134 showRemoveDialog: false,
135 showPurgeDialog: false,
136 purgeType: PurgeType.Person,
137 showBanDialog: false,
138 banType: BanType.Community,
140 showConfirmTransferSite: false,
141 showConfirmTransferCommunity: false,
142 imageExpanded: false,
145 showMoreMobile: false,
147 showReportDialog: false,
149 reportLoading: false,
152 deleteLoading: false,
153 removeLoading: false,
155 featureCommunityLoading: false,
156 featureLocalLoading: false,
158 addModLoading: false,
159 addAdminLoading: false,
160 transferLoading: false,
163 constructor(props: any, context: any) {
164 super(props, context);
166 this.handleEditPost = this.handleEditPost.bind(this);
167 this.handleEditCancel = this.handleEditCancel.bind(this);
170 componentWillReceiveProps(nextProps: PostListingProps) {
171 if (this.props !== nextProps) {
174 reportLoading: false,
177 deleteLoading: false,
178 removeLoading: false,
180 featureCommunityLoading: false,
181 featureLocalLoading: false,
183 addModLoading: false,
184 addAdminLoading: false,
185 transferLoading: false,
190 get postView(): PostView {
191 return this.props.post_view;
195 const post = this.postView.post;
198 <div className="post-listing mt-2">
199 {!this.state.showEdit ? (
202 {this.state.imageExpanded && !this.props.hideImage && this.img}
203 {post.url && this.state.showBody && post.embed_title && (
204 <MetadataCard post={post} />
206 {this.showBody && this.body()}
210 post_view={this.postView}
211 crossPosts={this.props.crossPosts}
212 onEdit={this.handleEditPost}
213 onCancel={this.handleEditCancel}
214 enableNsfw={this.props.enableNsfw}
215 enableDownvotes={this.props.enableDownvotes}
216 allLanguages={this.props.allLanguages}
217 siteLanguages={this.props.siteLanguages}
225 const body = this.postView.post.body;
227 <article id="postContent" className="col-12 card my-2 p-2">
228 {this.state.viewSource ? (
231 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
243 <div className="offset-sm-3 my-2 d-none d-sm-block">
244 <a href={this.imageSrc} className="d-inline-block">
245 <PictrsImage src={this.imageSrc} />
248 <div className="my-2 d-block d-sm-none">
251 className="p-0 border-0 bg-transparent d-inline-block"
252 onClick={linkEvent(this, this.handleImageExpandClick)}
254 <PictrsImage src={this.imageSrc} />
261 const { post } = this.postView;
262 const { url } = post;
264 // if direct video link
265 if (url && isVideo(url)) {
267 <div className="embed-responsive mt-3">
268 <video muted controls className="embed-responsive-item col-12">
269 <source src={url} type="video/mp4" />
275 // if embedded video link
276 if (url && post.embed_video_url) {
278 <div className="ratio ratio-16x9">
281 className="post-metadata-iframe"
282 src={post.embed_video_url}
283 title={post.embed_title}
292 imgThumb(src: string) {
293 const post_view = this.postView;
299 nsfw={post_view.post.nsfw || post_view.community.nsfw}
304 get imageSrc(): string | undefined {
305 const post = this.postView.post;
306 const url = post.url;
307 const thumbnail = post.thumbnail_url;
309 if (url && isImage(url)) {
310 if (url.includes("pictrs")) {
312 } else if (thumbnail) {
317 } else if (thumbnail) {
325 const post = this.postView.post;
326 const url = post.url;
327 const thumbnail = post.thumbnail_url;
329 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
333 className="d-inline-block position-relative mb-2 p-0 border-0"
334 data-tippy-content={I18NextService.i18n.t("expand_here")}
335 onClick={linkEvent(this, this.handleImageExpandClick)}
336 aria-label={I18NextService.i18n.t("expand_here")}
338 {this.imgThumb(this.imageSrc)}
341 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
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)}
356 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
361 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
364 className="text-body"
368 data-tippy-content={I18NextService.i18n.t("expand_here")}
369 onClick={linkEvent(this, this.handleImageExpandClick)}
370 aria-label={I18NextService.i18n.t("expand_here")}
372 <div className="thumbnail rounded bg-light d-flex justify-content-center">
373 <Icon icon="play" classes="d-flex align-items-center" />
379 <a className="text-body" href={url} title={url} rel={relTags}>
380 <div className="thumbnail rounded bg-light d-flex justify-content-center">
381 <Icon icon="external-link" classes="d-flex align-items-center" />
389 className="text-body"
390 to={`/post/${post.id}`}
391 title={I18NextService.i18n.t("comments")}
393 <div className="thumbnail rounded bg-light d-flex justify-content-center">
394 <Icon icon="message-square" classes="d-flex align-items-center" />
402 const post_view = this.postView;
404 <span className="small">
405 <PersonListing person={post_view.creator} />
406 {this.creatorIsMod_ && (
407 <span className="mx-1 badge text-bg-light">
408 {I18NextService.i18n.t("mod")}
411 {this.creatorIsAdmin_ && (
412 <span className="mx-1 badge text-bg-light">
413 {I18NextService.i18n.t("admin")}
416 {post_view.creator.bot_account && (
417 <span className="mx-1 badge text-bg-light">
418 {I18NextService.i18n.t("bot_account").toLowerCase()}
421 {this.props.showCommunity && (
424 {I18NextService.i18n.t("to")}{" "}
425 <CommunityLink community={post_view.community} />
428 {post_view.post.language_id !== 0 && (
429 <span className="mx-1 badge text-bg-light">
431 this.props.allLanguages.find(
432 lang => lang.id === post_view.post.language_id
439 published={post_view.post.published}
440 updated={post_view.post.updated}
447 const post = this.postView.post;
450 className={`d-inline ${
451 !post.featured_community && !post.featured_local
455 to={`/post/${post.id}`}
456 title={I18NextService.i18n.t("comments")}
460 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
467 const post = this.postView.post;
468 const url = post.url;
472 <div className="post-title overflow-hidden">
473 <h5 className="d-inline">
474 {url && this.props.showBody ? (
477 !post.featured_community && !post.featured_local
484 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
492 <small className="ms-2 badge text-bg-secondary">
493 {I18NextService.i18n.t("removed")}
499 className="unselectable pointer ms-2 text-muted fst-italic"
500 data-tippy-content={I18NextService.i18n.t("deleted")}
502 <Icon icon="trash" classes="icon-inline text-danger" />
508 className="unselectable pointer ms-2 text-muted fst-italic"
509 data-tippy-content={I18NextService.i18n.t("locked")}
511 <Icon icon="lock" classes="icon-inline text-danger" />
515 {post.featured_community && (
517 className="unselectable pointer ms-2 text-muted fst-italic"
518 data-tippy-content={I18NextService.i18n.t(
519 "featured_in_community"
521 aria-label={I18NextService.i18n.t("featured_in_community")}
523 <Icon icon="pin" classes="icon-inline text-primary" />
527 {post.featured_local && (
529 className="unselectable pointer ms-2 text-muted fst-italic"
530 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
531 aria-label={I18NextService.i18n.t("featured_in_local")}
533 <Icon icon="pin" classes="icon-inline text-secondary" />
538 <small className="ms-2 badge text-bg-danger">
539 {I18NextService.i18n.t("nsfw")}
543 {url && this.urlLine()}
549 const post = this.postView.post;
550 const url = post.url;
553 <p className="small m-0">
554 {url && !(hostname(url) === getExternalHost()) && (
556 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
569 const dupes = this.props.crossPosts;
570 return dupes && dupes.length > 0 ? (
571 <ul className="list-inline mb-1 small text-muted">
573 <li className="list-inline-item me-2">
574 {I18NextService.i18n.t("cross_posted_to")}
577 <li key={pv.post.id} className="list-inline-item me-2">
578 <Link to={`/post/${pv.post.id}`}>
581 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
592 commentsLine(mobile = false) {
593 const post = this.postView.post;
596 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
597 {this.commentsButton}
600 className="btn btn-sm btn-animate text-muted py-0"
601 onClick={linkEvent(this, this.handleShare)}
604 <Icon icon="share" inline />
609 className="btn btn-sm btn-animate text-muted py-0"
610 title={I18NextService.i18n.t("link")}
613 <Icon icon="fedilink" inline />
616 {mobile && !this.props.viewOnly && (
618 voteContentType={VoteContentType.Post}
619 id={this.postView.post.id}
620 onVote={this.props.onPostVote}
621 enableDownvotes={this.props.enableDownvotes}
622 counts={this.postView.counts}
623 my_vote={this.postView.my_vote}
626 {UserService.Instance.myUserInfo &&
627 !this.props.viewOnly &&
633 showPreviewButton() {
634 const post_view = this.postView;
635 const body = post_view.post.body;
639 className="btn btn-sm btn-animate text-muted py-0"
640 data-tippy-content={body && mdNoImages.render(body)}
641 data-tippy-allowHtml={true}
642 onClick={linkEvent(this, this.handleShowBody)}
646 classes={classNames("icon-inline me-1", {
647 "text-success": this.state.showBody,
655 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
656 // Possible enhancement: Make each button a component.
657 const post_view = this.postView;
658 const post = post_view.post;
663 {this.crossPostButton}
666 * If there is a URL, or if the post has a body and we were told not to
667 * show the body, show the MetadataCard/body toggle.
669 {(post.url || (post.body && !this.props.showBody)) &&
670 this.showPreviewButton()}
672 {this.showBody && post_view.post.body && this.viewSourceButton}
674 <div className="dropdown">
676 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
677 onClick={linkEvent(this, this.handleShowAdvanced)}
678 data-tippy-content={I18NextService.i18n.t("more")}
679 data-bs-toggle="dropdown"
680 aria-expanded="false"
681 aria-controls={`advancedButtonsDropdown${post.id}`}
682 aria-label={I18NextService.i18n.t("more")}
684 <Icon icon="more-vertical" inline />
688 className="dropdown-menu"
689 id={`advancedButtonsDropdown${post.id}`}
693 <li>{this.reportButton}</li>
694 <li>{this.blockButton}</li>
698 <li>{this.editButton}</li>
699 <li>{this.deleteButton}</li>
703 {/* Any mod can do these, not limited to hierarchy*/}
704 {(amMod(this.props.moderators) || amAdmin()) && (
707 <hr className="dropdown-divider" />
709 <li>{this.lockButton}</li>
710 {this.featureButtons}
714 {(this.canMod_ || this.canAdmin_) && (
715 <li>{this.modRemoveButton}</li>
723 get commentsButton() {
724 const post_view = this.postView;
725 const title = I18NextService.i18n.t("number_of_comments", {
726 count: Number(post_view.counts.comments),
727 formattedCount: Number(post_view.counts.comments),
732 className="btn btn-link btn-sm text-muted ps-0"
734 to={`/post/${post_view.post.id}?scrollToComments=true`}
735 data-tippy-content={title}
737 <Icon icon="message-square" classes="me-1" inline />
738 {post_view.counts.comments}
739 {this.unreadCount && (
742 <span className="fst-italic">
743 ({this.unreadCount} {I18NextService.i18n.t("new")})
751 get unreadCount(): number | undefined {
752 const pv = this.postView;
753 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
755 : pv.unread_comments;
759 const saved = this.postView.saved;
761 ? I18NextService.i18n.t("unsave")
762 : I18NextService.i18n.t("save");
765 className="btn btn-sm btn-animate text-muted py-0"
766 onClick={linkEvent(this, this.handleSavePostClick)}
767 data-tippy-content={label}
770 {this.state.saveLoading ? (
775 classes={classNames({ "text-warning": saved })}
783 get crossPostButton() {
786 className="btn btn-sm btn-animate text-muted py-0"
788 /* Empty string properties are required to satisfy type*/
789 pathname: "/create_post",
790 state: { ...this.crossPostParams },
795 title={I18NextService.i18n.t("cross_post")}
796 data-tippy-content={I18NextService.i18n.t("cross_post")}
797 aria-label={I18NextService.i18n.t("cross_post")}
799 <Icon icon="copy" inline />
807 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
808 onClick={linkEvent(this, this.handleShowReportDialog)}
809 aria-label={I18NextService.i18n.t("show_report_dialog")}
811 <Icon classes="me-1" icon="flag" inline />
812 {I18NextService.i18n.t("create_report")}
820 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
821 onClick={linkEvent(this, this.handleBlockPersonClick)}
822 aria-label={I18NextService.i18n.t("block_user")}
824 {this.state.blockLoading ? (
827 <Icon classes="me-1" icon="slash" inline />
829 {I18NextService.i18n.t("block_user")}
837 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
838 onClick={linkEvent(this, this.handleEditClick)}
839 aria-label={I18NextService.i18n.t("edit")}
841 <Icon classes="me-1" icon="edit" inline />
842 {I18NextService.i18n.t("edit")}
848 const deleted = this.postView.post.deleted;
849 const label = !deleted
850 ? I18NextService.i18n.t("delete")
851 : I18NextService.i18n.t("restore");
854 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
855 onClick={linkEvent(this, this.handleDeleteClick)}
857 {this.state.deleteLoading ? (
863 classes={classNames("me-1", { "text-danger": deleted })}
873 get viewSourceButton() {
876 className="btn btn-sm btn-animate text-muted py-0"
877 onClick={linkEvent(this, this.handleViewSource)}
878 data-tippy-content={I18NextService.i18n.t("view_source")}
879 aria-label={I18NextService.i18n.t("view_source")}
883 classes={classNames({ "text-success": this.state.viewSource })}
891 const locked = this.postView.post.locked;
893 ? I18NextService.i18n.t("unlock")
894 : I18NextService.i18n.t("lock");
897 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
898 onClick={linkEvent(this, this.handleModLock)}
901 {this.state.lockLoading ? (
907 classes={classNames("me-1", { "text-danger": locked })}
910 {capitalizeFirstLetter(label)}
917 get featureButtons() {
918 const featuredCommunity = this.postView.post.featured_community;
919 const labelCommunity = featuredCommunity
920 ? I18NextService.i18n.t("unfeature_from_community")
921 : I18NextService.i18n.t("feature_in_community");
923 const featuredLocal = this.postView.post.featured_local;
924 const labelLocal = featuredLocal
925 ? I18NextService.i18n.t("unfeature_from_local")
926 : I18NextService.i18n.t("feature_in_local");
931 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
932 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
933 data-tippy-content={labelCommunity}
934 aria-label={labelCommunity}
936 {this.state.featureCommunityLoading ? (
942 classes={classNames("me-1", {
943 "text-success": featuredCommunity,
947 {I18NextService.i18n.t("community")}
955 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
956 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
957 data-tippy-content={labelLocal}
958 aria-label={labelLocal}
960 {this.state.featureLocalLoading ? (
966 classes={classNames("me-1", {
967 "text-success": featuredLocal,
971 {I18NextService.i18n.t("local")}
981 get modBanFromCommunityButton() {
984 className="btn btn-link btn-animate text-muted py-0"
985 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
986 aria-label={I18NextService.i18n.t("ban_from_community")}
988 {I18NextService.i18n.t("ban_from_community")}
993 get modUnbanFromCommunityButton() {
996 className="btn btn-link btn-animate text-muted py-0"
997 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
998 aria-label={I18NextService.i18n.t("unban")}
1000 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1005 get addModToCommunityButton() {
1008 className="btn btn-link btn-animate text-muted py-0"
1009 onClick={linkEvent(this, this.handleAddModToCommunity)}
1012 ? I18NextService.i18n.t("remove_as_mod")
1013 : I18NextService.i18n.t("appoint_as_mod")
1016 {this.state.addModLoading ? (
1018 ) : this.creatorIsMod_ ? (
1019 I18NextService.i18n.t("remove_as_mod")
1021 I18NextService.i18n.t("appoint_as_mod")
1027 get modBanButton() {
1030 className="btn btn-link btn-animate text-muted py-0"
1031 onClick={linkEvent(this, this.handleModBanShow)}
1032 aria-label={I18NextService.i18n.t("ban_from_site")}
1034 {I18NextService.i18n.t("ban_from_site")}
1039 get modUnbanButton() {
1042 className="btn btn-link btn-animate text-muted py-0"
1043 onClick={linkEvent(this, this.handleModBanSubmit)}
1044 aria-label={I18NextService.i18n.t("unban_from_site")}
1046 {this.state.banLoading ? (
1049 I18NextService.i18n.t("unban_from_site")
1055 get purgePersonButton() {
1058 className="btn btn-link btn-animate text-muted py-0"
1059 onClick={linkEvent(this, this.handlePurgePersonShow)}
1060 aria-label={I18NextService.i18n.t("purge_user")}
1062 {I18NextService.i18n.t("purge_user")}
1067 get purgePostButton() {
1070 className="btn btn-link btn-animate text-muted py-0"
1071 onClick={linkEvent(this, this.handlePurgePostShow)}
1072 aria-label={I18NextService.i18n.t("purge_post")}
1074 {I18NextService.i18n.t("purge_post")}
1079 get toggleAdminButton() {
1082 className="btn btn-link btn-animate text-muted py-0"
1083 onClick={linkEvent(this, this.handleAddAdmin)}
1085 {this.state.addAdminLoading ? (
1087 ) : this.creatorIsAdmin_ ? (
1088 I18NextService.i18n.t("remove_as_admin")
1090 I18NextService.i18n.t("appoint_as_admin")
1096 get modRemoveButton() {
1097 const removed = this.postView.post.removed;
1100 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1103 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1106 {/* TODO: Find an icon for this. */}
1107 {this.state.removeLoading ? (
1110 I18NextService.i18n.t("remove")
1112 I18NextService.i18n.t("restore")
1119 * Mod/Admin actions to be taken against the author.
1123 const post_view = this.postView;
1125 this.state.showAdvanced && (
1126 <div className="mt-3">
1129 {!this.creatorIsMod_ &&
1130 (!post_view.creator_banned_from_community
1131 ? this.modBanFromCommunityButton
1132 : this.modUnbanFromCommunityButton)}
1133 {!post_view.creator_banned_from_community &&
1134 this.addModToCommunityButton}
1138 {/* Community creators and admins can transfer community to another mod */}
1139 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1141 this.creatorIsMod_ &&
1142 (!this.state.showConfirmTransferCommunity ? (
1144 className="btn btn-link btn-animate text-muted py-0"
1147 this.handleShowConfirmTransferCommunity
1149 aria-label={I18NextService.i18n.t("transfer_community")}
1151 {I18NextService.i18n.t("transfer_community")}
1156 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1157 aria-label={I18NextService.i18n.t("are_you_sure")}
1159 {I18NextService.i18n.t("are_you_sure")}
1162 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1163 aria-label={I18NextService.i18n.t("yes")}
1164 onClick={linkEvent(this, this.handleTransferCommunity)}
1166 {this.state.transferLoading ? (
1169 I18NextService.i18n.t("yes")
1173 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1176 this.handleCancelShowConfirmTransferCommunity
1178 aria-label={I18NextService.i18n.t("no")}
1180 {I18NextService.i18n.t("no")}
1184 {/* Admins can ban from all, and appoint other admins */}
1185 {this.canAdmin_ && (
1187 {!this.creatorIsAdmin_ && (
1189 {!isBanned(post_view.creator)
1191 : this.modUnbanButton}
1192 {this.purgePersonButton}
1193 {this.purgePostButton}
1196 {!isBanned(post_view.creator) &&
1197 post_view.creator.local &&
1198 this.toggleAdminButton}
1206 removeAndBanDialogs() {
1207 const post = this.postView;
1208 const purgeTypeText =
1209 this.state.purgeType == PurgeType.Post
1210 ? I18NextService.i18n.t("purge_post")
1211 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1214 {this.state.showRemoveDialog && (
1216 className="form-inline"
1217 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1220 className="visually-hidden"
1221 htmlFor="post-listing-remove-reason"
1223 {I18NextService.i18n.t("reason")}
1227 id="post-listing-remove-reason"
1228 className="form-control me-2"
1229 placeholder={I18NextService.i18n.t("reason")}
1230 value={this.state.removeReason}
1231 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1235 className="btn btn-secondary"
1236 aria-label={I18NextService.i18n.t("remove_post")}
1238 {this.state.removeLoading ? (
1241 I18NextService.i18n.t("remove_post")
1246 {this.state.showBanDialog && (
1247 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1248 <div className="mb-3 row col-12">
1250 className="col-form-label"
1251 htmlFor="post-listing-ban-reason"
1253 {I18NextService.i18n.t("reason")}
1257 id="post-listing-ban-reason"
1258 className="form-control me-2"
1259 placeholder={I18NextService.i18n.t("reason")}
1260 value={this.state.banReason}
1261 onInput={linkEvent(this, this.handleModBanReasonChange)}
1263 <label className="col-form-label" htmlFor="mod-ban-expires">
1264 {I18NextService.i18n.t("expires")}
1268 id="mod-ban-expires"
1269 className="form-control me-2"
1270 placeholder={I18NextService.i18n.t("number_of_days")}
1271 value={this.state.banExpireDays}
1272 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1274 <div className="input-group mb-3">
1275 <div className="form-check">
1277 className="form-check-input"
1278 id="mod-ban-remove-data"
1280 checked={this.state.removeData}
1281 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1284 className="form-check-label"
1285 htmlFor="mod-ban-remove-data"
1286 title={I18NextService.i18n.t("remove_content_more")}
1288 {I18NextService.i18n.t("remove_content")}
1293 {/* TODO hold off on expires until later */}
1294 {/* <div class="mb-3 row"> */}
1295 {/* <label class="col-form-label">Expires</label> */}
1296 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1298 <div className="mb-3 row">
1301 className="btn btn-secondary"
1302 aria-label={I18NextService.i18n.t("ban")}
1304 {this.state.banLoading ? (
1308 {I18NextService.i18n.t("ban")} {post.creator.name}
1315 {this.state.showReportDialog && (
1317 className="form-inline"
1318 onSubmit={linkEvent(this, this.handleReportSubmit)}
1320 <label className="visually-hidden" htmlFor="post-report-reason">
1321 {I18NextService.i18n.t("reason")}
1325 id="post-report-reason"
1326 className="form-control me-2"
1327 placeholder={I18NextService.i18n.t("reason")}
1329 value={this.state.reportReason}
1330 onInput={linkEvent(this, this.handleReportReasonChange)}
1334 className="btn btn-secondary"
1335 aria-label={I18NextService.i18n.t("create_report")}
1337 {this.state.reportLoading ? (
1340 I18NextService.i18n.t("create_report")
1345 {this.state.showPurgeDialog && (
1347 className="form-inline"
1348 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1351 <label className="visually-hidden" htmlFor="purge-reason">
1352 {I18NextService.i18n.t("reason")}
1357 className="form-control me-2"
1358 placeholder={I18NextService.i18n.t("reason")}
1359 value={this.state.purgeReason}
1360 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1362 {this.state.purgeLoading ? (
1367 className="btn btn-secondary"
1368 aria-label={purgeTypeText}
1370 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1380 const post = this.postView.post;
1381 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1382 <div className="row">
1383 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1384 {this.postTitleLine()}
1386 <div className="col-4">
1387 {/* Post thumbnail */}
1388 {!this.state.imageExpanded && this.thumbnail()}
1392 this.postTitleLine()
1397 const { body, id } = this.postView.post;
1399 return !this.showBody && body ? (
1400 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1401 <div className="md-div mb-1 preview-lines">{body}</div>
1411 {/* The mobile view*/}
1412 <div className="d-block d-sm-none">
1413 <article className="row post-container">
1414 <div className="col-12">
1415 {this.createdLine()}
1417 {/* If it has a thumbnail, do a right aligned thumbnail */}
1418 {this.mobileThumbnail()}
1420 {this.commentsLine(true)}
1421 {this.userActionsLine()}
1422 {this.duplicatesLine()}
1423 {this.removeAndBanDialogs()}
1428 {/* The larger view*/}
1429 <div className="d-none d-sm-block">
1430 <article className="row post-container">
1431 {!this.props.viewOnly && (
1432 <div className="col flex-grow-0">
1434 voteContentType={VoteContentType.Post}
1435 id={this.postView.post.id}
1436 onVote={this.props.onPostVote}
1437 enableDownvotes={this.props.enableDownvotes}
1438 counts={this.postView.counts}
1439 my_vote={this.postView.my_vote}
1443 <div className="col flex-grow-1">
1444 <div className="row">
1445 <div className="col-sm-3 col-lg-2 pe-0 post-media">
1446 <div className="">{this.thumbnail()}</div>
1448 <div className="col-12 col-sm-9 col-lg-10">
1449 {this.postTitleLine()}
1450 {this.createdLine()}
1451 {this.commentsLine()}
1452 {this.duplicatesLine()}
1453 {this.userActionsLine()}
1454 {this.removeAndBanDialogs()}
1464 private get myPost(): boolean {
1466 this.postView.creator.id ==
1467 UserService.Instance.myUserInfo?.local_user_view.person.id
1470 handleEditClick(i: PostListing) {
1471 i.setState({ showEdit: true });
1474 handleEditCancel() {
1475 this.setState({ showEdit: false });
1478 // The actual editing is done in the receive for post
1479 handleEditPost(form: EditPost) {
1480 this.setState({ showEdit: false });
1481 this.props.onPostEdit(form);
1484 handleShare(i: PostListing) {
1485 const { name, body, id } = i.props.post_view.post;
1488 text: body?.slice(0, 50),
1489 url: `${getHttpBase()}/post/${id}`,
1493 handleShowReportDialog(i: PostListing) {
1494 i.setState({ showReportDialog: !i.state.showReportDialog });
1497 handleReportReasonChange(i: PostListing, event: any) {
1498 i.setState({ reportReason: event.target.value });
1501 handleReportSubmit(i: PostListing, event: any) {
1502 event.preventDefault();
1503 i.setState({ reportLoading: true });
1504 i.props.onPostReport({
1505 post_id: i.postView.post.id,
1506 reason: i.state.reportReason ?? "",
1507 auth: myAuthRequired(),
1511 handleBlockPersonClick(i: PostListing) {
1512 i.setState({ blockLoading: true });
1513 i.props.onBlockPerson({
1514 person_id: i.postView.creator.id,
1516 auth: myAuthRequired(),
1520 handleDeleteClick(i: PostListing) {
1521 i.setState({ deleteLoading: true });
1522 i.props.onDeletePost({
1523 post_id: i.postView.post.id,
1524 deleted: !i.postView.post.deleted,
1525 auth: myAuthRequired(),
1529 handleSavePostClick(i: PostListing) {
1530 i.setState({ saveLoading: true });
1531 i.props.onSavePost({
1532 post_id: i.postView.post.id,
1533 save: !i.postView.saved,
1534 auth: myAuthRequired(),
1538 get crossPostParams(): PostFormParams {
1539 const queryParams: PostFormParams = {};
1540 const { name, url } = this.postView.post;
1542 queryParams.name = name;
1545 queryParams.url = url;
1548 const crossPostBody = this.crossPostBody();
1549 if (crossPostBody) {
1550 queryParams.body = crossPostBody;
1556 crossPostBody(): string | undefined {
1557 const post = this.postView.post;
1558 const body = post.body;
1561 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1563 }\n\n${body.replace(/^/gm, "> ")}`
1567 get showBody(): boolean {
1568 return this.props.showBody || this.state.showBody;
1571 handleModRemoveShow(i: PostListing) {
1573 showRemoveDialog: !i.state.showRemoveDialog,
1574 showBanDialog: false,
1578 handleModRemoveReasonChange(i: PostListing, event: any) {
1579 i.setState({ removeReason: event.target.value });
1582 handleModRemoveDataChange(i: PostListing, event: any) {
1583 i.setState({ removeData: event.target.checked });
1586 handleModRemoveSubmit(i: PostListing, event: any) {
1587 event.preventDefault();
1588 i.setState({ removeLoading: true });
1589 i.props.onRemovePost({
1590 post_id: i.postView.post.id,
1591 removed: !i.postView.post.removed,
1592 auth: myAuthRequired(),
1596 handleModLock(i: PostListing) {
1597 i.setState({ lockLoading: true });
1598 i.props.onLockPost({
1599 post_id: i.postView.post.id,
1600 locked: !i.postView.post.locked,
1601 auth: myAuthRequired(),
1605 handleModFeaturePostLocal(i: PostListing) {
1606 i.setState({ featureLocalLoading: true });
1607 i.props.onFeaturePost({
1608 post_id: i.postView.post.id,
1609 featured: !i.postView.post.featured_local,
1610 feature_type: "Local",
1611 auth: myAuthRequired(),
1615 handleModFeaturePostCommunity(i: PostListing) {
1616 i.setState({ featureCommunityLoading: true });
1617 i.props.onFeaturePost({
1618 post_id: i.postView.post.id,
1619 featured: !i.postView.post.featured_community,
1620 feature_type: "Community",
1621 auth: myAuthRequired(),
1625 handleModBanFromCommunityShow(i: PostListing) {
1627 showBanDialog: true,
1628 banType: BanType.Community,
1629 showRemoveDialog: false,
1633 handleModBanShow(i: PostListing) {
1635 showBanDialog: true,
1636 banType: BanType.Site,
1637 showRemoveDialog: false,
1641 handlePurgePersonShow(i: PostListing) {
1643 showPurgeDialog: true,
1644 purgeType: PurgeType.Person,
1645 showRemoveDialog: false,
1649 handlePurgePostShow(i: PostListing) {
1651 showPurgeDialog: true,
1652 purgeType: PurgeType.Post,
1653 showRemoveDialog: false,
1657 handlePurgeReasonChange(i: PostListing, event: any) {
1658 i.setState({ purgeReason: event.target.value });
1661 handlePurgeSubmit(i: PostListing, event: any) {
1662 event.preventDefault();
1663 i.setState({ purgeLoading: true });
1664 if (i.state.purgeType == PurgeType.Person) {
1665 i.props.onPurgePerson({
1666 person_id: i.postView.creator.id,
1667 reason: i.state.purgeReason,
1668 auth: myAuthRequired(),
1670 } else if (i.state.purgeType == PurgeType.Post) {
1671 i.props.onPurgePost({
1672 post_id: i.postView.post.id,
1673 reason: i.state.purgeReason,
1674 auth: myAuthRequired(),
1679 handleModBanReasonChange(i: PostListing, event: any) {
1680 i.setState({ banReason: event.target.value });
1683 handleModBanExpireDaysChange(i: PostListing, event: any) {
1684 i.setState({ banExpireDays: event.target.value });
1687 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1688 i.setState({ banType: BanType.Community });
1689 i.handleModBanBothSubmit(i, event);
1692 handleModBanSubmit(i: PostListing, event: any) {
1693 i.setState({ banType: BanType.Site });
1694 i.handleModBanBothSubmit(i, event);
1697 handleModBanBothSubmit(i: PostListing, event: any) {
1698 event.preventDefault();
1699 i.setState({ banLoading: true });
1701 const ban = !i.props.post_view.creator_banned_from_community;
1702 // If its an unban, restore all their data
1704 i.setState({ removeData: false });
1706 const person_id = i.props.post_view.creator.id;
1707 const remove_data = i.state.removeData;
1708 const reason = i.state.banReason;
1709 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1711 if (i.state.banType == BanType.Community) {
1712 const community_id = i.postView.community.id;
1713 i.props.onBanPersonFromCommunity({
1720 auth: myAuthRequired(),
1723 i.props.onBanPerson({
1729 auth: myAuthRequired(),
1734 handleAddModToCommunity(i: PostListing) {
1735 i.setState({ addModLoading: true });
1736 i.props.onAddModToCommunity({
1737 community_id: i.postView.community.id,
1738 person_id: i.postView.creator.id,
1739 added: !i.creatorIsMod_,
1740 auth: myAuthRequired(),
1744 handleAddAdmin(i: PostListing) {
1745 i.setState({ addAdminLoading: true });
1746 i.props.onAddAdmin({
1747 person_id: i.postView.creator.id,
1748 added: !i.creatorIsAdmin_,
1749 auth: myAuthRequired(),
1753 handleShowConfirmTransferCommunity(i: PostListing) {
1754 i.setState({ showConfirmTransferCommunity: true });
1757 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1758 i.setState({ showConfirmTransferCommunity: false });
1761 handleTransferCommunity(i: PostListing) {
1762 i.setState({ transferLoading: true });
1763 i.props.onTransferCommunity({
1764 community_id: i.postView.community.id,
1765 person_id: i.postView.creator.id,
1766 auth: myAuthRequired(),
1770 handleShowConfirmTransferSite(i: PostListing) {
1771 i.setState({ showConfirmTransferSite: true });
1774 handleCancelShowConfirmTransferSite(i: PostListing) {
1775 i.setState({ showConfirmTransferSite: false });
1778 handleImageExpandClick(i: PostListing, event: any) {
1779 event.preventDefault();
1780 i.setState({ imageExpanded: !i.state.imageExpanded });
1784 handleViewSource(i: PostListing) {
1785 i.setState({ viewSource: !i.state.viewSource });
1788 handleShowAdvanced(i: PostListing) {
1789 i.setState({ showAdvanced: !i.state.showAdvanced });
1793 handleShowMoreMobile(i: PostListing) {
1795 showMoreMobile: !i.state.showMoreMobile,
1796 showAdvanced: !i.state.showAdvanced,
1801 handleShowBody(i: PostListing) {
1802 i.setState({ showBody: !i.state.showBody });
1806 get pointsTippy(): string {
1807 const points = I18NextService.i18n.t("number_of_points", {
1808 count: Number(this.postView.counts.score),
1809 formattedCount: Number(this.postView.counts.score),
1812 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1813 count: Number(this.postView.counts.upvotes),
1814 formattedCount: Number(this.postView.counts.upvotes),
1817 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1818 count: Number(this.postView.counts.downvotes),
1819 formattedCount: Number(this.postView.counts.downvotes),
1822 return `${points} • ${upvotes} • ${downvotes}`;
1825 get canModOnSelf_(): boolean {
1827 this.postView.creator.id,
1828 this.props.moderators,
1835 get canMod_(): boolean {
1837 this.postView.creator.id,
1838 this.props.moderators,
1843 get canAdmin_(): boolean {
1844 return canAdmin(this.postView.creator.id, this.props.admins);
1847 get creatorIsMod_(): boolean {
1848 return isMod(this.postView.creator.id, this.props.moderators);
1851 get creatorIsAdmin_(): boolean {
1852 return isAdmin(this.postView.creator.id, this.props.admins);