1 import { myAuthRequired } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
51 } from "../../interfaces";
52 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
53 import { I18NextService, UserService } from "../../services";
54 import { setupTippy } from "../../tippy";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
59 import { CommunityLink } from "../community/community-link";
60 import { PersonListing } from "../person/person-listing";
61 import { MetadataCard } from "./metadata-card";
62 import { PostForm } from "./post-form";
64 interface PostListingState {
66 showRemoveDialog: boolean;
67 showPurgeDialog: boolean;
69 purgeType?: PurgeType;
70 purgeLoading: boolean;
71 removeReason?: string;
72 showBanDialog: boolean;
74 banExpireDays?: number;
77 showConfirmTransferSite: boolean;
78 showConfirmTransferCommunity: boolean;
79 imageExpanded: boolean;
81 showAdvanced: boolean;
82 showMoreMobile: boolean;
84 showReportDialog: boolean;
85 reportReason?: string;
86 reportLoading: boolean;
87 blockLoading: boolean;
89 deleteLoading: boolean;
90 removeLoading: boolean;
92 featureCommunityLoading: boolean;
93 featureLocalLoading: boolean;
95 addModLoading: boolean;
96 addAdminLoading: boolean;
97 transferLoading: boolean;
100 interface PostListingProps {
102 crossPosts?: PostView[];
103 moderators?: CommunityModeratorView[];
104 admins?: PersonView[];
105 allLanguages: Language[];
106 siteLanguages: number[];
107 showCommunity?: boolean;
110 enableDownvotes?: boolean;
111 enableNsfw?: boolean;
113 onPostEdit(form: EditPost): void;
114 onPostVote(form: CreatePostLike): void;
115 onPostReport(form: CreatePostReport): void;
116 onBlockPerson(form: BlockPerson): void;
117 onLockPost(form: LockPost): void;
118 onDeletePost(form: DeletePost): void;
119 onRemovePost(form: RemovePost): void;
120 onSavePost(form: SavePost): void;
121 onFeaturePost(form: FeaturePost): void;
122 onPurgePerson(form: PurgePerson): void;
123 onPurgePost(form: PurgePost): void;
124 onBanPersonFromCommunity(form: BanFromCommunity): void;
125 onBanPerson(form: BanPerson): void;
126 onAddModToCommunity(form: AddModToCommunity): void;
127 onAddAdmin(form: AddAdmin): void;
128 onTransferCommunity(form: TransferCommunity): void;
131 export class PostListing extends Component<PostListingProps, PostListingState> {
132 state: PostListingState = {
134 showRemoveDialog: false,
135 showPurgeDialog: false,
136 purgeType: PurgeType.Person,
137 showBanDialog: false,
138 banType: BanType.Community,
140 showConfirmTransferSite: false,
141 showConfirmTransferCommunity: false,
142 imageExpanded: false,
145 showMoreMobile: false,
147 showReportDialog: false,
149 reportLoading: false,
152 deleteLoading: false,
153 removeLoading: false,
155 featureCommunityLoading: false,
156 featureLocalLoading: false,
158 addModLoading: false,
159 addAdminLoading: false,
160 transferLoading: false,
163 constructor(props: any, context: any) {
164 super(props, context);
166 this.handleEditPost = this.handleEditPost.bind(this);
167 this.handleEditCancel = this.handleEditCancel.bind(this);
170 get postView(): PostView {
171 return this.props.post_view;
175 const post = this.postView.post;
178 <div className="post-listing mt-2">
179 {!this.state.showEdit ? (
182 {this.state.imageExpanded && !this.props.hideImage && this.img}
183 {post.url && this.state.showBody && post.embed_title && (
184 <MetadataCard post={post} />
186 {this.showBody && this.body()}
190 post_view={this.postView}
191 crossPosts={this.props.crossPosts}
192 onEdit={this.handleEditPost}
193 onCancel={this.handleEditCancel}
194 enableNsfw={this.props.enableNsfw}
195 enableDownvotes={this.props.enableDownvotes}
196 allLanguages={this.props.allLanguages}
197 siteLanguages={this.props.siteLanguages}
205 const body = this.postView.post.body;
207 <article id="postContent" className="col-12 card my-2 p-2">
208 {this.state.viewSource ? (
211 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
223 <div className="offset-sm-3 my-2 d-none d-sm-block">
224 <a href={this.imageSrc} className="d-inline-block">
225 <PictrsImage src={this.imageSrc} />
228 <div className="my-2 d-block d-sm-none">
231 className="p-0 border-0 bg-transparent d-inline-block"
232 onClick={linkEvent(this, this.handleImageExpandClick)}
234 <PictrsImage src={this.imageSrc} />
241 const { post } = this.postView;
242 const { url } = post;
244 // if direct video link
245 if (url && isVideo(url)) {
247 <div className="embed-responsive mt-3">
248 <video muted controls className="embed-responsive-item col-12">
249 <source src={url} type="video/mp4" />
255 // if embedded video link
256 if (url && post.embed_video_url) {
258 <div className="ratio ratio-16x9">
261 className="post-metadata-iframe"
262 src={post.embed_video_url}
263 title={post.embed_title}
272 imgThumb(src: string) {
273 const post_view = this.postView;
279 nsfw={post_view.post.nsfw || post_view.community.nsfw}
284 get imageSrc(): string | undefined {
285 const post = this.postView.post;
286 const url = post.url;
287 const thumbnail = post.thumbnail_url;
289 if (url && isImage(url)) {
290 if (url.includes("pictrs")) {
292 } else if (thumbnail) {
297 } else if (thumbnail) {
305 const post = this.postView.post;
306 const url = post.url;
307 const thumbnail = post.thumbnail_url;
309 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
313 className="text-body d-inline-block position-relative mb-2"
314 data-tippy-content={I18NextService.i18n.t("expand_here")}
315 onClick={linkEvent(this, this.handleImageExpandClick)}
316 aria-label={I18NextService.i18n.t("expand_here")}
318 {this.imgThumb(this.imageSrc)}
319 <Icon icon="image" classes="mini-overlay" />
322 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
325 className="text-body d-inline-block position-relative mb-2"
330 {this.imgThumb(this.imageSrc)}
331 <Icon icon="external-link" classes="mini-overlay" />
335 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
338 className="text-body"
342 data-tippy-content={I18NextService.i18n.t("expand_here")}
343 onClick={linkEvent(this, this.handleImageExpandClick)}
344 aria-label={I18NextService.i18n.t("expand_here")}
346 <div className="thumbnail rounded bg-light d-flex justify-content-center">
347 <Icon icon="play" classes="d-flex align-items-center" />
353 <a className="text-body" href={url} title={url} rel={relTags}>
354 <div className="thumbnail rounded bg-light d-flex justify-content-center">
355 <Icon icon="external-link" classes="d-flex align-items-center" />
363 className="text-body"
364 to={`/post/${post.id}`}
365 title={I18NextService.i18n.t("comments")}
367 <div className="thumbnail rounded bg-light d-flex justify-content-center">
368 <Icon icon="message-square" classes="d-flex align-items-center" />
376 const post_view = this.postView;
378 <span className="small">
379 <PersonListing person={post_view.creator} muted={true} />
380 {this.creatorIsMod_ && (
381 <span className="mx-1 badge text-bg-light">
382 {I18NextService.i18n.t("mod")}
385 {this.creatorIsAdmin_ && (
386 <span className="mx-1 badge text-bg-light">
387 {I18NextService.i18n.t("admin")}
390 {post_view.creator.bot_account && (
391 <span className="mx-1 badge text-bg-light">
392 {I18NextService.i18n.t("bot_account").toLowerCase()}
395 {this.props.showCommunity && (
398 {I18NextService.i18n.t("to")}{" "}
399 <CommunityLink community={post_view.community} />
402 {post_view.post.language_id !== 0 && (
403 <span className="mx-1 badge text-bg-light">
405 this.props.allLanguages.find(
406 lang => lang.id === post_view.post.language_id
413 published={post_view.post.published}
414 updated={post_view.post.updated}
421 const post = this.postView.post;
424 className={`d-inline ${
425 !post.featured_community && !post.featured_local
429 to={`/post/${post.id}`}
430 title={I18NextService.i18n.t("comments")}
434 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
441 const post = this.postView.post;
442 const url = post.url;
446 <div className="post-title overflow-hidden">
447 <h5 className="d-inline">
448 {url && this.props.showBody ? (
451 !post.featured_community && !post.featured_local
458 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
464 {(url && isImage(url)) ||
465 (post.thumbnail_url && (
467 className="btn btn-sm text-monospace text-muted d-inline-block"
468 data-tippy-content={I18NextService.i18n.t("expand_here")}
469 onClick={linkEvent(this, this.handleImageExpandClick)}
473 !this.state.imageExpanded ? "plus-square" : "minus-square"
475 classes="icon-inline"
481 * If there is a URL, or if the post has a body and we were told not to
482 * show the body, show the MetadataCard/body toggle.
484 {(post.url || (post.body && !this.props.showBody)) && (
486 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
487 data-tippy-content={post.body && mdNoImages.render(post.body)}
488 data-tippy-allowHtml={true}
489 onClick={linkEvent(this, this.handleShowBody)}
492 icon={!this.state.showBody ? "plus-square" : "minus-square"}
493 classes="icon-inline"
499 <small className="ms-2 badge text-bg-secondary">
500 {I18NextService.i18n.t("removed")}
505 className="unselectable pointer ms-2 text-muted fst-italic"
506 data-tippy-content={I18NextService.i18n.t("deleted")}
508 <Icon icon="trash" classes="icon-inline text-danger" />
513 className="unselectable pointer ms-2 text-muted fst-italic"
514 data-tippy-content={I18NextService.i18n.t("locked")}
516 <Icon icon="lock" classes="icon-inline text-danger" />
519 {post.featured_community && (
521 className="unselectable pointer ms-2 text-muted fst-italic"
522 data-tippy-content={I18NextService.i18n.t(
523 "featured_in_community"
525 aria-label={I18NextService.i18n.t("featured_in_community")}
527 <Icon icon="pin" classes="icon-inline text-primary" />
530 {post.featured_local && (
532 className="unselectable pointer ms-2 text-muted fst-italic"
533 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
534 aria-label={I18NextService.i18n.t("featured_in_local")}
536 <Icon icon="pin" classes="icon-inline text-secondary" />
540 <small className="ms-2 badge text-bg-danger">
541 {I18NextService.i18n.t("nsfw")}
545 {url && this.urlLine()}
551 const post = this.postView.post;
552 const url = post.url;
555 <p className="small m-0">
556 {url && !(hostname(url) === getExternalHost()) && (
558 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
571 const dupes = this.props.crossPosts;
572 return dupes && dupes.length > 0 ? (
573 <ul className="list-inline mb-1 small text-muted">
575 <li className="list-inline-item me-2">
576 {I18NextService.i18n.t("cross_posted_to")}
579 <li key={pv.post.id} className="list-inline-item me-2">
580 <Link to={`/post/${pv.post.id}`}>
583 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
594 commentsLine(mobile = false) {
595 const post = this.postView.post;
598 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
599 {this.commentsButton}
602 className="btn btn-sm btn-animate text-muted py-0"
603 onClick={linkEvent(this, this.handleShare)}
606 <Icon icon="share" inline />
611 className="btn btn-sm btn-animate text-muted py-0"
612 title={I18NextService.i18n.t("link")}
615 <Icon icon="fedilink" inline />
618 {mobile && !this.props.viewOnly && (
620 voteContentType={VoteContentType.Post}
621 id={this.postView.post.id}
622 onVote={this.props.onPostVote}
623 enableDownvotes={this.props.enableDownvotes}
624 counts={this.postView.counts}
625 my_vote={this.postView.my_vote}
628 {UserService.Instance.myUserInfo &&
629 !this.props.viewOnly &&
636 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
637 // Possible enhancement: Make each button a component.
638 const post_view = this.postView;
639 const post = post_view.post;
644 {this.crossPostButton}
646 {this.props.showBody && post_view.post.body && this.viewSourceButton}
648 <div className="dropdown">
650 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
651 onClick={linkEvent(this, this.handleShowAdvanced)}
652 data-tippy-content={I18NextService.i18n.t("more")}
653 data-bs-toggle="dropdown"
654 aria-expanded="false"
655 aria-controls={`advancedButtonsDropdown${post.id}`}
656 aria-label={I18NextService.i18n.t("more")}
658 <Icon icon="more-vertical" inline />
662 className="dropdown-menu"
663 id={`advancedButtonsDropdown${post.id}`}
667 <li>{this.reportButton}</li>
668 <li>{this.blockButton}</li>
672 <li>{this.editButton}</li>
673 <li>{this.deleteButton}</li>
677 {/* Any mod can do these, not limited to hierarchy*/}
678 {(amMod(this.props.moderators) || amAdmin()) && (
681 <hr className="dropdown-divider" />
683 <li>{this.lockButton}</li>
684 {this.featureButtons}
688 {(this.canMod_ || this.canAdmin_) && (
689 <li>{this.modRemoveButton}</li>
697 get commentsButton() {
698 const post_view = this.postView;
699 const title = I18NextService.i18n.t("number_of_comments", {
700 count: Number(post_view.counts.comments),
701 formattedCount: Number(post_view.counts.comments),
706 className="btn btn-link btn-sm text-muted ps-0"
708 to={`/post/${post_view.post.id}?scrollToComments=true`}
709 data-tippy-content={title}
711 <Icon icon="message-square" classes="me-1" inline />
712 {post_view.counts.comments}
713 {this.unreadCount && (
716 <span className="fst-italic">
717 ({this.unreadCount} {I18NextService.i18n.t("new")})
725 get unreadCount(): number | undefined {
726 const pv = this.postView;
727 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
729 : pv.unread_comments;
733 const saved = this.postView.saved;
735 ? I18NextService.i18n.t("unsave")
736 : I18NextService.i18n.t("save");
739 className="btn btn-sm btn-animate text-muted py-0"
740 onClick={linkEvent(this, this.handleSavePostClick)}
741 data-tippy-content={label}
744 {this.state.saveLoading ? (
749 classes={classNames({ "text-warning": saved })}
757 get crossPostButton() {
760 className="btn btn-sm btn-animate text-muted py-0"
762 /* Empty string properties are required to satisfy type*/
763 pathname: "/create_post",
764 state: { ...this.crossPostParams },
769 title={I18NextService.i18n.t("cross_post")}
770 data-tippy-content={I18NextService.i18n.t("cross_post")}
771 aria-label={I18NextService.i18n.t("cross_post")}
773 <Icon icon="copy" inline />
781 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
782 onClick={linkEvent(this, this.handleShowReportDialog)}
783 aria-label={I18NextService.i18n.t("show_report_dialog")}
785 <Icon classes="me-1" icon="flag" inline />
786 {I18NextService.i18n.t("create_report")}
794 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
795 onClick={linkEvent(this, this.handleBlockPersonClick)}
796 aria-label={I18NextService.i18n.t("block_user")}
798 {this.state.blockLoading ? (
801 <Icon classes="me-1" icon="slash" inline />
803 {I18NextService.i18n.t("block_user")}
811 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
812 onClick={linkEvent(this, this.handleEditClick)}
813 aria-label={I18NextService.i18n.t("edit")}
815 <Icon classes="me-1" icon="edit" inline />
816 {I18NextService.i18n.t("edit")}
822 const deleted = this.postView.post.deleted;
823 const label = !deleted
824 ? I18NextService.i18n.t("delete")
825 : I18NextService.i18n.t("restore");
828 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
829 onClick={linkEvent(this, this.handleDeleteClick)}
831 {this.state.deleteLoading ? (
837 classes={classNames("me-1", { "text-danger": deleted })}
847 get viewSourceButton() {
850 className="btn btn-sm btn-animate text-muted py-0"
851 onClick={linkEvent(this, this.handleViewSource)}
852 data-tippy-content={I18NextService.i18n.t("view_source")}
853 aria-label={I18NextService.i18n.t("view_source")}
857 classes={classNames({ "text-success": this.state.viewSource })}
865 const locked = this.postView.post.locked;
867 ? I18NextService.i18n.t("unlock")
868 : I18NextService.i18n.t("lock");
871 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
872 onClick={linkEvent(this, this.handleModLock)}
875 {this.state.lockLoading ? (
881 classes={classNames("me-1", { "text-danger": locked })}
884 {capitalizeFirstLetter(label)}
891 get featureButtons() {
892 const featuredCommunity = this.postView.post.featured_community;
893 const labelCommunity = featuredCommunity
894 ? I18NextService.i18n.t("unfeature_from_community")
895 : I18NextService.i18n.t("feature_in_community");
897 const featuredLocal = this.postView.post.featured_local;
898 const labelLocal = featuredLocal
899 ? I18NextService.i18n.t("unfeature_from_local")
900 : I18NextService.i18n.t("feature_in_local");
905 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
906 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
907 data-tippy-content={labelCommunity}
908 aria-label={labelCommunity}
910 {this.state.featureCommunityLoading ? (
916 classes={classNames("me-1", {
917 "text-success": featuredCommunity,
921 {I18NextService.i18n.t("community")}
929 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
930 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
931 data-tippy-content={labelLocal}
932 aria-label={labelLocal}
934 {this.state.featureLocalLoading ? (
940 classes={classNames("me-1", {
941 "text-success": featuredLocal,
945 {I18NextService.i18n.t("local")}
955 get modBanFromCommunityButton() {
958 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
959 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
960 aria-label={I18NextService.i18n.t("ban_from_community")}
962 {I18NextService.i18n.t("ban_from_community")}
967 get modUnbanFromCommunityButton() {
970 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
971 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
972 aria-label={I18NextService.i18n.t("unban")}
974 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
979 get addModToCommunityButton() {
982 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
983 onClick={linkEvent(this, this.handleAddModToCommunity)}
986 ? I18NextService.i18n.t("remove_as_mod")
987 : I18NextService.i18n.t("appoint_as_mod")
990 {this.state.addModLoading ? (
992 ) : this.creatorIsMod_ ? (
993 I18NextService.i18n.t("remove_as_mod")
995 I18NextService.i18n.t("appoint_as_mod")
1001 get modBanButton() {
1004 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1005 onClick={linkEvent(this, this.handleModBanShow)}
1006 aria-label={I18NextService.i18n.t("ban_from_site")}
1008 {I18NextService.i18n.t("ban_from_site")}
1013 get modUnbanButton() {
1016 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1017 onClick={linkEvent(this, this.handleModBanSubmit)}
1018 aria-label={I18NextService.i18n.t("unban_from_site")}
1020 {this.state.banLoading ? (
1023 I18NextService.i18n.t("unban_from_site")
1029 get purgePersonButton() {
1032 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1033 onClick={linkEvent(this, this.handlePurgePersonShow)}
1034 aria-label={I18NextService.i18n.t("purge_user")}
1036 {I18NextService.i18n.t("purge_user")}
1041 get purgePostButton() {
1044 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1045 onClick={linkEvent(this, this.handlePurgePostShow)}
1046 aria-label={I18NextService.i18n.t("purge_post")}
1048 {I18NextService.i18n.t("purge_post")}
1053 get toggleAdminButton() {
1056 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1057 onClick={linkEvent(this, this.handleAddAdmin)}
1059 {this.state.addAdminLoading ? (
1061 ) : this.creatorIsAdmin_ ? (
1062 I18NextService.i18n.t("remove_as_admin")
1064 I18NextService.i18n.t("appoint_as_admin")
1070 get modRemoveButton() {
1071 const removed = this.postView.post.removed;
1074 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1077 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1080 {/* TODO: Find an icon for this. */}
1081 {this.state.removeLoading ? (
1084 I18NextService.i18n.t("remove")
1086 I18NextService.i18n.t("restore")
1093 * Mod/Admin actions to be taken against the author.
1097 const post_view = this.postView;
1099 this.state.showAdvanced && (
1100 <div className="mt-3 user-actions-line">
1103 {!this.creatorIsMod_ &&
1104 (!post_view.creator_banned_from_community ? (
1105 <li>{this.modBanFromCommunityButton}</li>
1107 <li>{this.modUnbanFromCommunityButton}</li>
1109 {!post_view.creator_banned_from_community && (
1110 <li>{this.addModToCommunityButton}</li>
1115 {/* Community creators and admins can transfer community to another mod */}
1116 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1118 this.creatorIsMod_ &&
1119 (!this.state.showConfirmTransferCommunity ? (
1122 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1125 this.handleShowConfirmTransferCommunity
1127 aria-label={I18NextService.i18n.t("transfer_community")}
1129 {I18NextService.i18n.t("transfer_community")}
1136 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1137 aria-label={I18NextService.i18n.t("are_you_sure")}
1139 {I18NextService.i18n.t("are_you_sure")}
1144 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1145 aria-label={I18NextService.i18n.t("yes")}
1146 onClick={linkEvent(this, this.handleTransferCommunity)}
1148 {this.state.transferLoading ? (
1151 I18NextService.i18n.t("yes")
1157 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
1160 this.handleCancelShowConfirmTransferCommunity
1162 aria-label={I18NextService.i18n.t("no")}
1164 {I18NextService.i18n.t("no")}
1169 {/* Admins can ban from all, and appoint other admins */}
1170 {this.canAdmin_ && (
1172 {!this.creatorIsAdmin_ && (
1174 {!isBanned(post_view.creator) ? (
1175 <li>{this.modBanButton}</li>
1177 <li>{this.modUnbanButton}</li>
1179 <li>{this.purgePersonButton}</li>
1180 <li>{this.purgePostButton}</li>
1183 {!isBanned(post_view.creator) && post_view.creator.local && (
1184 <li>{this.toggleAdminButton}</li>
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);