1 import { getRoleLabelPill, 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 { 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 <div className="small">
402 <span className="me-1">
403 <PersonListing person={post_view.creator} />
405 {this.creatorIsMod_ &&
407 label: I18NextService.i18n.t("mod"),
408 tooltip: I18NextService.i18n.t("mod"),
409 classes: "text-bg-primary text-black",
411 {this.creatorIsAdmin_ &&
413 label: I18NextService.i18n.t("admin"),
414 tooltip: I18NextService.i18n.t("admin"),
415 classes: "text-bg-danger text-white",
417 {post_view.creator.bot_account &&
419 label: I18NextService.i18n.t("bot_account").toLowerCase(),
420 tooltip: I18NextService.i18n.t("bot_account"),
422 {this.props.showCommunity && (
425 {I18NextService.i18n.t("to")}{" "}
426 <CommunityLink community={post_view.community} />
429 {post_view.post.language_id !== 0 && (
430 <span className="mx-1 badge text-bg-light">
432 this.props.allLanguages.find(
433 lang => lang.id === post_view.post.language_id
440 published={post_view.post.published}
441 updated={post_view.post.updated}
448 const post = this.postView.post;
451 className={`d-inline ${
452 !post.featured_community && !post.featured_local
456 to={`/post/${post.id}`}
457 title={I18NextService.i18n.t("comments")}
461 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
468 const post = this.postView.post;
469 const url = post.url;
473 <div className="post-title overflow-hidden">
474 <h5 className="d-inline">
475 {url && this.props.showBody ? (
478 !post.featured_community && !post.featured_local
485 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
493 * If there is a URL, an embed title, and we were not told to show the
494 * body by the parent component, show the MetadataCard/body toggle.
496 {!this.props.showBody &&
499 this.showPreviewButton()}
502 <small className="ms-2 badge text-bg-secondary">
503 {I18NextService.i18n.t("removed")}
509 className="unselectable pointer ms-2 text-muted fst-italic"
510 data-tippy-content={I18NextService.i18n.t("deleted")}
512 <Icon icon="trash" classes="icon-inline text-danger" />
518 className="unselectable pointer ms-2 text-muted fst-italic"
519 data-tippy-content={I18NextService.i18n.t("locked")}
521 <Icon icon="lock" classes="icon-inline text-danger" />
525 {post.featured_community && (
527 className="unselectable pointer ms-2 text-muted fst-italic"
528 data-tippy-content={I18NextService.i18n.t(
529 "featured_in_community"
531 aria-label={I18NextService.i18n.t("featured_in_community")}
533 <Icon icon="pin" classes="icon-inline text-primary" />
537 {post.featured_local && (
539 className="unselectable pointer ms-2 text-muted fst-italic"
540 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
541 aria-label={I18NextService.i18n.t("featured_in_local")}
543 <Icon icon="pin" classes="icon-inline text-secondary" />
548 <small className="ms-2 badge text-bg-danger">
549 {I18NextService.i18n.t("nsfw")}
553 {url && this.urlLine()}
559 const post = this.postView.post;
560 const url = post.url;
563 <p className="small m-0">
564 {url && !(hostname(url) === getExternalHost()) && (
566 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
579 const dupes = this.props.crossPosts;
580 return dupes && dupes.length > 0 ? (
581 <ul className="list-inline mb-1 small text-muted">
583 <li className="list-inline-item me-2">
584 {I18NextService.i18n.t("cross_posted_to")}
587 <li key={pv.post.id} className="list-inline-item me-2">
588 <Link to={`/post/${pv.post.id}`}>
591 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
602 commentsLine(mobile = false) {
603 const post = this.postView.post;
606 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
607 {this.commentsButton}
610 className="btn btn-sm btn-animate text-muted py-0"
611 onClick={linkEvent(this, this.handleShare)}
614 <Icon icon="share" inline />
619 className="btn btn-sm btn-animate text-muted py-0"
620 title={I18NextService.i18n.t("link")}
623 <Icon icon="fedilink" inline />
626 {mobile && !this.props.viewOnly && (
628 voteContentType={VoteContentType.Post}
629 id={this.postView.post.id}
630 onVote={this.props.onPostVote}
631 enableDownvotes={this.props.enableDownvotes}
632 counts={this.postView.counts}
633 my_vote={this.postView.my_vote}
636 {UserService.Instance.myUserInfo &&
637 !this.props.viewOnly &&
644 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
645 // Possible enhancement: Make each button a component.
646 const post_view = this.postView;
647 const post = post_view.post;
652 {this.crossPostButton}
654 {this.props.showBody && post_view.post.body && this.viewSourceButton}
656 <div className="dropdown">
658 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
659 onClick={linkEvent(this, this.handleShowAdvanced)}
660 data-tippy-content={I18NextService.i18n.t("more")}
661 data-bs-toggle="dropdown"
662 aria-expanded="false"
663 aria-controls={`advancedButtonsDropdown${post.id}`}
664 aria-label={I18NextService.i18n.t("more")}
666 <Icon icon="more-vertical" inline />
670 className="dropdown-menu"
671 id={`advancedButtonsDropdown${post.id}`}
675 <li>{this.reportButton}</li>
676 <li>{this.blockButton}</li>
680 <li>{this.editButton}</li>
681 <li>{this.deleteButton}</li>
685 {/* Any mod can do these, not limited to hierarchy*/}
686 {(amMod(this.props.moderators) || amAdmin()) && (
689 <hr className="dropdown-divider" />
691 <li>{this.lockButton}</li>
692 {this.featureButtons}
696 {(this.canMod_ || this.canAdmin_) && (
697 <li>{this.modRemoveButton}</li>
705 get commentsButton() {
706 const post_view = this.postView;
707 const title = I18NextService.i18n.t("number_of_comments", {
708 count: Number(post_view.counts.comments),
709 formattedCount: Number(post_view.counts.comments),
714 className="btn btn-link btn-sm text-muted ps-0"
716 to={`/post/${post_view.post.id}?scrollToComments=true`}
717 data-tippy-content={title}
719 <Icon icon="message-square" classes="me-1" inline />
720 {post_view.counts.comments}
721 {this.unreadCount && (
724 <span className="fst-italic">
725 ({this.unreadCount} {I18NextService.i18n.t("new")})
733 get unreadCount(): number | undefined {
734 const pv = this.postView;
735 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
737 : pv.unread_comments;
741 const saved = this.postView.saved;
743 ? I18NextService.i18n.t("unsave")
744 : I18NextService.i18n.t("save");
747 className="btn btn-sm btn-animate text-muted py-0"
748 onClick={linkEvent(this, this.handleSavePostClick)}
749 data-tippy-content={label}
752 {this.state.saveLoading ? (
757 classes={classNames({ "text-warning": saved })}
765 get crossPostButton() {
768 className="btn btn-sm btn-animate text-muted py-0"
770 /* Empty string properties are required to satisfy type*/
771 pathname: "/create_post",
772 state: { ...this.crossPostParams },
777 title={I18NextService.i18n.t("cross_post")}
778 data-tippy-content={I18NextService.i18n.t("cross_post")}
779 aria-label={I18NextService.i18n.t("cross_post")}
781 <Icon icon="copy" inline />
789 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
790 onClick={linkEvent(this, this.handleShowReportDialog)}
791 aria-label={I18NextService.i18n.t("show_report_dialog")}
793 <Icon classes="me-1" icon="flag" inline />
794 {I18NextService.i18n.t("create_report")}
802 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
803 onClick={linkEvent(this, this.handleBlockPersonClick)}
804 aria-label={I18NextService.i18n.t("block_user")}
806 {this.state.blockLoading ? (
809 <Icon classes="me-1" icon="slash" inline />
811 {I18NextService.i18n.t("block_user")}
819 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
820 onClick={linkEvent(this, this.handleEditClick)}
821 aria-label={I18NextService.i18n.t("edit")}
823 <Icon classes="me-1" icon="edit" inline />
824 {I18NextService.i18n.t("edit")}
830 const deleted = this.postView.post.deleted;
831 const label = !deleted
832 ? I18NextService.i18n.t("delete")
833 : I18NextService.i18n.t("restore");
836 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
837 onClick={linkEvent(this, this.handleDeleteClick)}
839 {this.state.deleteLoading ? (
845 classes={classNames("me-1", { "text-danger": deleted })}
855 get viewSourceButton() {
858 className="btn btn-sm btn-animate text-muted py-0"
859 onClick={linkEvent(this, this.handleViewSource)}
860 data-tippy-content={I18NextService.i18n.t("view_source")}
861 aria-label={I18NextService.i18n.t("view_source")}
865 classes={classNames({ "text-success": this.state.viewSource })}
873 const locked = this.postView.post.locked;
875 ? I18NextService.i18n.t("unlock")
876 : I18NextService.i18n.t("lock");
879 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
880 onClick={linkEvent(this, this.handleModLock)}
883 {this.state.lockLoading ? (
889 classes={classNames("me-1", { "text-danger": locked })}
892 {capitalizeFirstLetter(label)}
899 get featureButtons() {
900 const featuredCommunity = this.postView.post.featured_community;
901 const labelCommunity = featuredCommunity
902 ? I18NextService.i18n.t("unfeature_from_community")
903 : I18NextService.i18n.t("feature_in_community");
905 const featuredLocal = this.postView.post.featured_local;
906 const labelLocal = featuredLocal
907 ? I18NextService.i18n.t("unfeature_from_local")
908 : I18NextService.i18n.t("feature_in_local");
913 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
914 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
915 data-tippy-content={labelCommunity}
916 aria-label={labelCommunity}
918 {this.state.featureCommunityLoading ? (
924 classes={classNames("me-1", {
925 "text-success": featuredCommunity,
929 {I18NextService.i18n.t("community")}
937 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
938 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
939 data-tippy-content={labelLocal}
940 aria-label={labelLocal}
942 {this.state.featureLocalLoading ? (
948 classes={classNames("me-1", {
949 "text-success": featuredLocal,
953 {I18NextService.i18n.t("local")}
963 get modBanFromCommunityButton() {
966 className="btn btn-link btn-animate text-muted py-0"
967 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
968 aria-label={I18NextService.i18n.t("ban_from_community")}
970 {I18NextService.i18n.t("ban_from_community")}
975 get modUnbanFromCommunityButton() {
978 className="btn btn-link btn-animate text-muted py-0"
979 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
980 aria-label={I18NextService.i18n.t("unban")}
982 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
987 get addModToCommunityButton() {
990 className="btn btn-link btn-animate text-muted py-0"
991 onClick={linkEvent(this, this.handleAddModToCommunity)}
994 ? I18NextService.i18n.t("remove_as_mod")
995 : I18NextService.i18n.t("appoint_as_mod")
998 {this.state.addModLoading ? (
1000 ) : this.creatorIsMod_ ? (
1001 I18NextService.i18n.t("remove_as_mod")
1003 I18NextService.i18n.t("appoint_as_mod")
1009 get modBanButton() {
1012 className="btn btn-link btn-animate text-muted py-0"
1013 onClick={linkEvent(this, this.handleModBanShow)}
1014 aria-label={I18NextService.i18n.t("ban_from_site")}
1016 {I18NextService.i18n.t("ban_from_site")}
1021 get modUnbanButton() {
1024 className="btn btn-link btn-animate text-muted py-0"
1025 onClick={linkEvent(this, this.handleModBanSubmit)}
1026 aria-label={I18NextService.i18n.t("unban_from_site")}
1028 {this.state.banLoading ? (
1031 I18NextService.i18n.t("unban_from_site")
1037 get purgePersonButton() {
1040 className="btn btn-link btn-animate text-muted py-0"
1041 onClick={linkEvent(this, this.handlePurgePersonShow)}
1042 aria-label={I18NextService.i18n.t("purge_user")}
1044 {I18NextService.i18n.t("purge_user")}
1049 get purgePostButton() {
1052 className="btn btn-link btn-animate text-muted py-0"
1053 onClick={linkEvent(this, this.handlePurgePostShow)}
1054 aria-label={I18NextService.i18n.t("purge_post")}
1056 {I18NextService.i18n.t("purge_post")}
1061 get toggleAdminButton() {
1064 className="btn btn-link btn-animate text-muted py-0"
1065 onClick={linkEvent(this, this.handleAddAdmin)}
1067 {this.state.addAdminLoading ? (
1069 ) : this.creatorIsAdmin_ ? (
1070 I18NextService.i18n.t("remove_as_admin")
1072 I18NextService.i18n.t("appoint_as_admin")
1078 get modRemoveButton() {
1079 const removed = this.postView.post.removed;
1082 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1085 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1088 {/* TODO: Find an icon for this. */}
1089 {this.state.removeLoading ? (
1092 I18NextService.i18n.t("remove")
1094 I18NextService.i18n.t("restore")
1101 * Mod/Admin actions to be taken against the author.
1105 const post_view = this.postView;
1107 this.state.showAdvanced && (
1108 <div className="mt-3">
1111 {!this.creatorIsMod_ &&
1112 (!post_view.creator_banned_from_community
1113 ? this.modBanFromCommunityButton
1114 : this.modUnbanFromCommunityButton)}
1115 {!post_view.creator_banned_from_community &&
1116 this.addModToCommunityButton}
1120 {/* Community creators and admins can transfer community to another mod */}
1121 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1123 this.creatorIsMod_ &&
1124 (!this.state.showConfirmTransferCommunity ? (
1126 className="btn btn-link btn-animate text-muted py-0"
1129 this.handleShowConfirmTransferCommunity
1131 aria-label={I18NextService.i18n.t("transfer_community")}
1133 {I18NextService.i18n.t("transfer_community")}
1138 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1139 aria-label={I18NextService.i18n.t("are_you_sure")}
1141 {I18NextService.i18n.t("are_you_sure")}
1144 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1145 aria-label={I18NextService.i18n.t("yes")}
1146 onClick={linkEvent(this, this.handleTransferCommunity)}
1148 {this.state.transferLoading ? (
1151 I18NextService.i18n.t("yes")
1155 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1158 this.handleCancelShowConfirmTransferCommunity
1160 aria-label={I18NextService.i18n.t("no")}
1162 {I18NextService.i18n.t("no")}
1166 {/* Admins can ban from all, and appoint other admins */}
1167 {this.canAdmin_ && (
1169 {!this.creatorIsAdmin_ && (
1171 {!isBanned(post_view.creator)
1173 : this.modUnbanButton}
1174 {this.purgePersonButton}
1175 {this.purgePostButton}
1178 {!isBanned(post_view.creator) &&
1179 post_view.creator.local &&
1180 this.toggleAdminButton}
1188 removeAndBanDialogs() {
1189 const post = this.postView;
1190 const purgeTypeText =
1191 this.state.purgeType == PurgeType.Post
1192 ? I18NextService.i18n.t("purge_post")
1193 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1196 {this.state.showRemoveDialog && (
1198 className="form-inline"
1199 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1202 className="visually-hidden"
1203 htmlFor="post-listing-remove-reason"
1205 {I18NextService.i18n.t("reason")}
1209 id="post-listing-remove-reason"
1210 className="form-control me-2"
1211 placeholder={I18NextService.i18n.t("reason")}
1212 value={this.state.removeReason}
1213 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1217 className="btn btn-secondary"
1218 aria-label={I18NextService.i18n.t("remove_post")}
1220 {this.state.removeLoading ? (
1223 I18NextService.i18n.t("remove_post")
1228 {this.state.showBanDialog && (
1229 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1230 <div className="mb-3 row col-12">
1232 className="col-form-label"
1233 htmlFor="post-listing-ban-reason"
1235 {I18NextService.i18n.t("reason")}
1239 id="post-listing-ban-reason"
1240 className="form-control me-2"
1241 placeholder={I18NextService.i18n.t("reason")}
1242 value={this.state.banReason}
1243 onInput={linkEvent(this, this.handleModBanReasonChange)}
1245 <label className="col-form-label" htmlFor="mod-ban-expires">
1246 {I18NextService.i18n.t("expires")}
1250 id="mod-ban-expires"
1251 className="form-control me-2"
1252 placeholder={I18NextService.i18n.t("number_of_days")}
1253 value={this.state.banExpireDays}
1254 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1256 <div className="input-group mb-3">
1257 <div className="form-check">
1259 className="form-check-input"
1260 id="mod-ban-remove-data"
1262 checked={this.state.removeData}
1263 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1266 className="form-check-label"
1267 htmlFor="mod-ban-remove-data"
1268 title={I18NextService.i18n.t("remove_content_more")}
1270 {I18NextService.i18n.t("remove_content")}
1275 {/* TODO hold off on expires until later */}
1276 {/* <div class="mb-3 row"> */}
1277 {/* <label class="col-form-label">Expires</label> */}
1278 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1280 <div className="mb-3 row">
1283 className="btn btn-secondary"
1284 aria-label={I18NextService.i18n.t("ban")}
1286 {this.state.banLoading ? (
1290 {I18NextService.i18n.t("ban")} {post.creator.name}
1297 {this.state.showReportDialog && (
1299 className="form-inline"
1300 onSubmit={linkEvent(this, this.handleReportSubmit)}
1302 <label className="visually-hidden" htmlFor="post-report-reason">
1303 {I18NextService.i18n.t("reason")}
1307 id="post-report-reason"
1308 className="form-control me-2"
1309 placeholder={I18NextService.i18n.t("reason")}
1311 value={this.state.reportReason}
1312 onInput={linkEvent(this, this.handleReportReasonChange)}
1316 className="btn btn-secondary"
1317 aria-label={I18NextService.i18n.t("create_report")}
1319 {this.state.reportLoading ? (
1322 I18NextService.i18n.t("create_report")
1327 {this.state.showPurgeDialog && (
1329 className="form-inline"
1330 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1333 <label className="visually-hidden" htmlFor="purge-reason">
1334 {I18NextService.i18n.t("reason")}
1339 className="form-control me-2"
1340 placeholder={I18NextService.i18n.t("reason")}
1341 value={this.state.purgeReason}
1342 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1344 {this.state.purgeLoading ? (
1349 className="btn btn-secondary"
1350 aria-label={purgeTypeText}
1352 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1362 const post = this.postView.post;
1363 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1364 <div className="row">
1365 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1366 {this.postTitleLine()}
1368 <div className="col-4">
1369 {/* Post thumbnail */}
1370 {!this.state.imageExpanded && this.thumbnail()}
1374 this.postTitleLine()
1378 showPreviewButton() {
1382 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1383 onClick={linkEvent(this, this.handleShowBody)}
1386 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1387 classes="icon-inline"
1396 {/* The mobile view*/}
1397 <div className="d-block d-sm-none">
1398 <article className="row post-container">
1399 <div className="col-12">
1400 {this.createdLine()}
1402 {/* If it has a thumbnail, do a right aligned thumbnail */}
1403 {this.mobileThumbnail()}
1405 {this.commentsLine(true)}
1406 {this.userActionsLine()}
1407 {this.duplicatesLine()}
1408 {this.removeAndBanDialogs()}
1413 {/* The larger view*/}
1414 <div className="d-none d-sm-block">
1415 <article className="row post-container">
1416 {!this.props.viewOnly && (
1417 <div className="col flex-grow-0">
1419 voteContentType={VoteContentType.Post}
1420 id={this.postView.post.id}
1421 onVote={this.props.onPostVote}
1422 enableDownvotes={this.props.enableDownvotes}
1423 counts={this.postView.counts}
1424 my_vote={this.postView.my_vote}
1428 <div className="col flex-grow-1">
1429 <div className="row">
1430 <div className="col-sm-3 col-lg-2 pe-0 post-media">
1431 <div className="">{this.thumbnail()}</div>
1433 <div className="col-12 col-sm-9 col-lg-10">
1434 {this.postTitleLine()}
1435 {this.createdLine()}
1436 {this.commentsLine()}
1437 {this.duplicatesLine()}
1438 {this.userActionsLine()}
1439 {this.removeAndBanDialogs()}
1449 private get myPost(): boolean {
1451 this.postView.creator.id ==
1452 UserService.Instance.myUserInfo?.local_user_view.person.id
1455 handleEditClick(i: PostListing) {
1456 i.setState({ showEdit: true });
1459 handleEditCancel() {
1460 this.setState({ showEdit: false });
1463 // The actual editing is done in the receive for post
1464 handleEditPost(form: EditPost) {
1465 this.setState({ showEdit: false });
1466 this.props.onPostEdit(form);
1469 handleShare(i: PostListing) {
1470 const { name, body, id } = i.props.post_view.post;
1473 text: body?.slice(0, 50),
1474 url: `${getHttpBase()}/post/${id}`,
1478 handleShowReportDialog(i: PostListing) {
1479 i.setState({ showReportDialog: !i.state.showReportDialog });
1482 handleReportReasonChange(i: PostListing, event: any) {
1483 i.setState({ reportReason: event.target.value });
1486 handleReportSubmit(i: PostListing, event: any) {
1487 event.preventDefault();
1488 i.setState({ reportLoading: true });
1489 i.props.onPostReport({
1490 post_id: i.postView.post.id,
1491 reason: i.state.reportReason ?? "",
1492 auth: myAuthRequired(),
1496 handleBlockPersonClick(i: PostListing) {
1497 i.setState({ blockLoading: true });
1498 i.props.onBlockPerson({
1499 person_id: i.postView.creator.id,
1501 auth: myAuthRequired(),
1505 handleDeleteClick(i: PostListing) {
1506 i.setState({ deleteLoading: true });
1507 i.props.onDeletePost({
1508 post_id: i.postView.post.id,
1509 deleted: !i.postView.post.deleted,
1510 auth: myAuthRequired(),
1514 handleSavePostClick(i: PostListing) {
1515 i.setState({ saveLoading: true });
1516 i.props.onSavePost({
1517 post_id: i.postView.post.id,
1518 save: !i.postView.saved,
1519 auth: myAuthRequired(),
1523 get crossPostParams(): PostFormParams {
1524 const queryParams: PostFormParams = {};
1525 const { name, url } = this.postView.post;
1527 queryParams.name = name;
1530 queryParams.url = url;
1533 const crossPostBody = this.crossPostBody();
1534 if (crossPostBody) {
1535 queryParams.body = crossPostBody;
1541 crossPostBody(): string | undefined {
1542 const post = this.postView.post;
1543 const body = post.body;
1546 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1548 }\n\n${body.replace(/^/gm, "> ")}`
1552 get showBody(): boolean {
1553 return this.props.showBody || this.state.showBody;
1556 handleModRemoveShow(i: PostListing) {
1558 showRemoveDialog: !i.state.showRemoveDialog,
1559 showBanDialog: false,
1563 handleModRemoveReasonChange(i: PostListing, event: any) {
1564 i.setState({ removeReason: event.target.value });
1567 handleModRemoveDataChange(i: PostListing, event: any) {
1568 i.setState({ removeData: event.target.checked });
1571 handleModRemoveSubmit(i: PostListing, event: any) {
1572 event.preventDefault();
1573 i.setState({ removeLoading: true });
1574 i.props.onRemovePost({
1575 post_id: i.postView.post.id,
1576 removed: !i.postView.post.removed,
1577 auth: myAuthRequired(),
1581 handleModLock(i: PostListing) {
1582 i.setState({ lockLoading: true });
1583 i.props.onLockPost({
1584 post_id: i.postView.post.id,
1585 locked: !i.postView.post.locked,
1586 auth: myAuthRequired(),
1590 handleModFeaturePostLocal(i: PostListing) {
1591 i.setState({ featureLocalLoading: true });
1592 i.props.onFeaturePost({
1593 post_id: i.postView.post.id,
1594 featured: !i.postView.post.featured_local,
1595 feature_type: "Local",
1596 auth: myAuthRequired(),
1600 handleModFeaturePostCommunity(i: PostListing) {
1601 i.setState({ featureCommunityLoading: true });
1602 i.props.onFeaturePost({
1603 post_id: i.postView.post.id,
1604 featured: !i.postView.post.featured_community,
1605 feature_type: "Community",
1606 auth: myAuthRequired(),
1610 handleModBanFromCommunityShow(i: PostListing) {
1612 showBanDialog: true,
1613 banType: BanType.Community,
1614 showRemoveDialog: false,
1618 handleModBanShow(i: PostListing) {
1620 showBanDialog: true,
1621 banType: BanType.Site,
1622 showRemoveDialog: false,
1626 handlePurgePersonShow(i: PostListing) {
1628 showPurgeDialog: true,
1629 purgeType: PurgeType.Person,
1630 showRemoveDialog: false,
1634 handlePurgePostShow(i: PostListing) {
1636 showPurgeDialog: true,
1637 purgeType: PurgeType.Post,
1638 showRemoveDialog: false,
1642 handlePurgeReasonChange(i: PostListing, event: any) {
1643 i.setState({ purgeReason: event.target.value });
1646 handlePurgeSubmit(i: PostListing, event: any) {
1647 event.preventDefault();
1648 i.setState({ purgeLoading: true });
1649 if (i.state.purgeType == PurgeType.Person) {
1650 i.props.onPurgePerson({
1651 person_id: i.postView.creator.id,
1652 reason: i.state.purgeReason,
1653 auth: myAuthRequired(),
1655 } else if (i.state.purgeType == PurgeType.Post) {
1656 i.props.onPurgePost({
1657 post_id: i.postView.post.id,
1658 reason: i.state.purgeReason,
1659 auth: myAuthRequired(),
1664 handleModBanReasonChange(i: PostListing, event: any) {
1665 i.setState({ banReason: event.target.value });
1668 handleModBanExpireDaysChange(i: PostListing, event: any) {
1669 i.setState({ banExpireDays: event.target.value });
1672 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1673 i.setState({ banType: BanType.Community });
1674 i.handleModBanBothSubmit(i, event);
1677 handleModBanSubmit(i: PostListing, event: any) {
1678 i.setState({ banType: BanType.Site });
1679 i.handleModBanBothSubmit(i, event);
1682 handleModBanBothSubmit(i: PostListing, event: any) {
1683 event.preventDefault();
1684 i.setState({ banLoading: true });
1686 const ban = !i.props.post_view.creator_banned_from_community;
1687 // If its an unban, restore all their data
1689 i.setState({ removeData: false });
1691 const person_id = i.props.post_view.creator.id;
1692 const remove_data = i.state.removeData;
1693 const reason = i.state.banReason;
1694 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1696 if (i.state.banType == BanType.Community) {
1697 const community_id = i.postView.community.id;
1698 i.props.onBanPersonFromCommunity({
1705 auth: myAuthRequired(),
1708 i.props.onBanPerson({
1714 auth: myAuthRequired(),
1719 handleAddModToCommunity(i: PostListing) {
1720 i.setState({ addModLoading: true });
1721 i.props.onAddModToCommunity({
1722 community_id: i.postView.community.id,
1723 person_id: i.postView.creator.id,
1724 added: !i.creatorIsMod_,
1725 auth: myAuthRequired(),
1729 handleAddAdmin(i: PostListing) {
1730 i.setState({ addAdminLoading: true });
1731 i.props.onAddAdmin({
1732 person_id: i.postView.creator.id,
1733 added: !i.creatorIsAdmin_,
1734 auth: myAuthRequired(),
1738 handleShowConfirmTransferCommunity(i: PostListing) {
1739 i.setState({ showConfirmTransferCommunity: true });
1742 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1743 i.setState({ showConfirmTransferCommunity: false });
1746 handleTransferCommunity(i: PostListing) {
1747 i.setState({ transferLoading: true });
1748 i.props.onTransferCommunity({
1749 community_id: i.postView.community.id,
1750 person_id: i.postView.creator.id,
1751 auth: myAuthRequired(),
1755 handleShowConfirmTransferSite(i: PostListing) {
1756 i.setState({ showConfirmTransferSite: true });
1759 handleCancelShowConfirmTransferSite(i: PostListing) {
1760 i.setState({ showConfirmTransferSite: false });
1763 handleImageExpandClick(i: PostListing, event: any) {
1764 event.preventDefault();
1765 i.setState({ imageExpanded: !i.state.imageExpanded });
1769 handleViewSource(i: PostListing) {
1770 i.setState({ viewSource: !i.state.viewSource });
1773 handleShowAdvanced(i: PostListing) {
1774 i.setState({ showAdvanced: !i.state.showAdvanced });
1778 handleShowMoreMobile(i: PostListing) {
1780 showMoreMobile: !i.state.showMoreMobile,
1781 showAdvanced: !i.state.showAdvanced,
1786 handleShowBody(i: PostListing) {
1787 i.setState({ showBody: !i.state.showBody });
1791 get pointsTippy(): string {
1792 const points = I18NextService.i18n.t("number_of_points", {
1793 count: Number(this.postView.counts.score),
1794 formattedCount: Number(this.postView.counts.score),
1797 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1798 count: Number(this.postView.counts.upvotes),
1799 formattedCount: Number(this.postView.counts.upvotes),
1802 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1803 count: Number(this.postView.counts.downvotes),
1804 formattedCount: Number(this.postView.counts.downvotes),
1807 return `${points} • ${upvotes} • ${downvotes}`;
1810 get canModOnSelf_(): boolean {
1812 this.postView.creator.id,
1813 this.props.moderators,
1820 get canMod_(): boolean {
1822 this.postView.creator.id,
1823 this.props.moderators,
1828 get canAdmin_(): boolean {
1829 return canAdmin(this.postView.creator.id, this.props.admins);
1832 get creatorIsMod_(): boolean {
1833 return isMod(this.postView.creator.id, this.props.moderators);
1836 get creatorIsAdmin_(): boolean {
1837 return isAdmin(this.postView.creator.id, this.props.admins);