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="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0"
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)}
344 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
348 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
351 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0"
356 {this.imgThumb(this.imageSrc)}
359 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
364 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
367 className="text-body"
371 data-tippy-content={I18NextService.i18n.t("expand_here")}
372 onClick={linkEvent(this, this.handleImageExpandClick)}
373 aria-label={I18NextService.i18n.t("expand_here")}
375 <div className="thumbnail rounded bg-light d-flex justify-content-center">
376 <Icon icon="play" classes="d-flex align-items-center" />
382 <a className="text-body" href={url} title={url} rel={relTags}>
383 <div className="thumbnail rounded bg-light d-flex justify-content-center">
384 <Icon icon="external-link" classes="d-flex align-items-center" />
392 className="text-body"
393 to={`/post/${post.id}`}
394 title={I18NextService.i18n.t("comments")}
396 <div className="thumbnail rounded bg-light d-flex justify-content-center">
397 <Icon icon="message-square" classes="d-flex align-items-center" />
405 const post_view = this.postView;
407 <div className="small">
408 <span className="me-1">
409 <PersonListing person={post_view.creator} />
411 {this.creatorIsMod_ &&
413 label: I18NextService.i18n.t("mod"),
414 tooltip: I18NextService.i18n.t("mod"),
415 classes: "text-bg-primary",
417 {this.creatorIsAdmin_ &&
419 label: I18NextService.i18n.t("admin"),
420 tooltip: I18NextService.i18n.t("admin"),
421 classes: "text-bg-danger",
423 {post_view.creator.bot_account &&
425 label: I18NextService.i18n.t("bot_account").toLowerCase(),
426 tooltip: I18NextService.i18n.t("bot_account"),
428 {this.props.showCommunity && (
431 {I18NextService.i18n.t("to")}{" "}
432 <CommunityLink community={post_view.community} />
435 {post_view.post.language_id !== 0 && (
436 <span className="mx-1 badge text-bg-light">
438 this.props.allLanguages.find(
439 lang => lang.id === post_view.post.language_id
446 published={post_view.post.published}
447 updated={post_view.post.updated}
454 const post = this.postView.post;
457 className={`d-inline ${
458 !post.featured_community && !post.featured_local
462 to={`/post/${post.id}`}
463 title={I18NextService.i18n.t("comments")}
467 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
474 const post = this.postView.post;
475 const url = post.url;
479 <div className="post-title overflow-hidden">
480 <h5 className="d-inline">
481 {url && this.props.showBody ? (
484 !post.featured_community && !post.featured_local
491 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
499 * If there is a URL, an embed title, and we were not told to show the
500 * body by the parent component, show the MetadataCard/body toggle.
502 {!this.props.showBody &&
505 this.showPreviewButton()}
508 <small className="ms-2 badge text-bg-secondary">
509 {I18NextService.i18n.t("removed")}
515 className="unselectable pointer ms-2 text-muted fst-italic"
516 data-tippy-content={I18NextService.i18n.t("deleted")}
518 <Icon icon="trash" classes="icon-inline text-danger" />
524 className="unselectable pointer ms-2 text-muted fst-italic"
525 data-tippy-content={I18NextService.i18n.t("locked")}
527 <Icon icon="lock" classes="icon-inline text-danger" />
531 {post.featured_community && (
533 className="unselectable pointer ms-2 text-muted fst-italic"
534 data-tippy-content={I18NextService.i18n.t(
535 "featured_in_community"
537 aria-label={I18NextService.i18n.t("featured_in_community")}
539 <Icon icon="pin" classes="icon-inline text-primary" />
543 {post.featured_local && (
545 className="unselectable pointer ms-2 text-muted fst-italic"
546 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
547 aria-label={I18NextService.i18n.t("featured_in_local")}
549 <Icon icon="pin" classes="icon-inline text-secondary" />
554 <small className="ms-2 badge text-bg-danger">
555 {I18NextService.i18n.t("nsfw")}
559 {url && this.urlLine()}
565 const post = this.postView.post;
566 const url = post.url;
569 <p className="small m-0">
570 {url && !(hostname(url) === getExternalHost()) && (
572 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
585 const dupes = this.props.crossPosts;
586 return dupes && dupes.length > 0 ? (
587 <ul className="list-inline mb-1 small text-muted">
589 <li className="list-inline-item me-2">
590 {I18NextService.i18n.t("cross_posted_to")}
593 <li key={pv.post.id} className="list-inline-item me-2">
594 <Link to={`/post/${pv.post.id}`}>
597 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
608 commentsLine(mobile = false) {
609 const post = this.postView.post;
612 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
613 {this.commentsButton}
616 className="btn btn-sm btn-animate text-muted py-0"
617 onClick={linkEvent(this, this.handleShare)}
620 <Icon icon="share" inline />
625 className="btn btn-sm btn-animate text-muted py-0"
626 title={I18NextService.i18n.t("link")}
629 <Icon icon="fedilink" inline />
632 {mobile && !this.props.viewOnly && (
634 voteContentType={VoteContentType.Post}
635 id={this.postView.post.id}
636 onVote={this.props.onPostVote}
637 enableDownvotes={this.props.enableDownvotes}
638 counts={this.postView.counts}
639 my_vote={this.postView.my_vote}
642 {UserService.Instance.myUserInfo &&
643 !this.props.viewOnly &&
650 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
651 // Possible enhancement: Make each button a component.
652 const post_view = this.postView;
653 const post = post_view.post;
658 {this.crossPostButton}
660 {this.props.showBody && post_view.post.body && this.viewSourceButton}
662 <div className="dropdown">
664 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
665 onClick={linkEvent(this, this.handleShowAdvanced)}
666 data-tippy-content={I18NextService.i18n.t("more")}
667 data-bs-toggle="dropdown"
668 aria-expanded="false"
669 aria-controls={`advancedButtonsDropdown${post.id}`}
670 aria-label={I18NextService.i18n.t("more")}
672 <Icon icon="more-vertical" inline />
676 className="dropdown-menu"
677 id={`advancedButtonsDropdown${post.id}`}
681 <li>{this.reportButton}</li>
682 <li>{this.blockButton}</li>
686 <li>{this.editButton}</li>
687 <li>{this.deleteButton}</li>
691 {/* Any mod can do these, not limited to hierarchy*/}
692 {(amMod(this.props.moderators) || amAdmin()) && (
695 <hr className="dropdown-divider" />
697 <li>{this.lockButton}</li>
698 {this.featureButtons}
702 {(this.canMod_ || this.canAdmin_) && (
703 <li>{this.modRemoveButton}</li>
709 <hr className="dropdown-divider" />
711 {!this.creatorIsMod_ &&
712 (!post_view.creator_banned_from_community ? (
713 <li>{this.modBanFromCommunityButton}</li>
715 <li>{this.modUnbanFromCommunityButton}</li>
717 {!post_view.creator_banned_from_community && (
718 <li>{this.addModToCommunityButton}</li>
723 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
725 this.creatorIsMod_ && <li>{this.transferCommunityButton}</li>}
727 {/* Admins can ban from all, and appoint other admins */}
731 <hr className="dropdown-divider" />
733 {!this.creatorIsAdmin_ && (
735 {!isBanned(post_view.creator) ? (
736 <li>{this.modBanButton}</li>
738 <li>{this.modUnbanButton}</li>
740 <li>{this.purgePersonButton}</li>
741 <li>{this.purgePostButton}</li>
744 {!isBanned(post_view.creator) && post_view.creator.local && (
745 <li>{this.toggleAdminButton}</li>
755 get commentsButton() {
756 const post_view = this.postView;
757 const title = I18NextService.i18n.t("number_of_comments", {
758 count: Number(post_view.counts.comments),
759 formattedCount: Number(post_view.counts.comments),
764 className="btn btn-link btn-sm text-muted ps-0"
766 to={`/post/${post_view.post.id}?scrollToComments=true`}
767 data-tippy-content={title}
769 <Icon icon="message-square" classes="me-1" inline />
770 {post_view.counts.comments}
771 {this.unreadCount && (
774 <span className="fst-italic">
775 ({this.unreadCount} {I18NextService.i18n.t("new")})
783 get unreadCount(): number | undefined {
784 const pv = this.postView;
785 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
787 : pv.unread_comments;
791 const saved = this.postView.saved;
793 ? I18NextService.i18n.t("unsave")
794 : I18NextService.i18n.t("save");
797 className="btn btn-sm btn-animate text-muted py-0"
798 onClick={linkEvent(this, this.handleSavePostClick)}
799 data-tippy-content={label}
802 {this.state.saveLoading ? (
807 classes={classNames({ "text-warning": saved })}
815 get crossPostButton() {
818 className="btn btn-sm btn-animate text-muted py-0"
820 /* Empty string properties are required to satisfy type*/
821 pathname: "/create_post",
822 state: { ...this.crossPostParams },
827 title={I18NextService.i18n.t("cross_post")}
828 data-tippy-content={I18NextService.i18n.t("cross_post")}
829 aria-label={I18NextService.i18n.t("cross_post")}
831 <Icon icon="copy" inline />
839 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
840 onClick={linkEvent(this, this.handleShowReportDialog)}
841 aria-label={I18NextService.i18n.t("show_report_dialog")}
843 <Icon classes="me-1" icon="flag" inline />
844 {I18NextService.i18n.t("create_report")}
852 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
853 onClick={linkEvent(this, this.handleBlockPersonClick)}
854 aria-label={I18NextService.i18n.t("block_user")}
856 {this.state.blockLoading ? (
859 <Icon classes="me-1" icon="slash" inline />
861 {I18NextService.i18n.t("block_user")}
869 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
870 onClick={linkEvent(this, this.handleEditClick)}
871 aria-label={I18NextService.i18n.t("edit")}
873 <Icon classes="me-1" icon="edit" inline />
874 {I18NextService.i18n.t("edit")}
880 const deleted = this.postView.post.deleted;
881 const label = !deleted
882 ? I18NextService.i18n.t("delete")
883 : I18NextService.i18n.t("restore");
886 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
887 onClick={linkEvent(this, this.handleDeleteClick)}
889 {this.state.deleteLoading ? (
895 classes={classNames("me-1", { "text-danger": deleted })}
905 get viewSourceButton() {
908 className="btn btn-sm btn-animate text-muted py-0"
909 onClick={linkEvent(this, this.handleViewSource)}
910 data-tippy-content={I18NextService.i18n.t("view_source")}
911 aria-label={I18NextService.i18n.t("view_source")}
915 classes={classNames({ "text-success": this.state.viewSource })}
923 const locked = this.postView.post.locked;
925 ? I18NextService.i18n.t("unlock")
926 : I18NextService.i18n.t("lock");
929 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
930 onClick={linkEvent(this, this.handleModLock)}
933 {this.state.lockLoading ? (
939 classes={classNames("me-1", { "text-danger": locked })}
942 {capitalizeFirstLetter(label)}
949 get featureButtons() {
950 const featuredCommunity = this.postView.post.featured_community;
951 const labelCommunity = featuredCommunity
952 ? I18NextService.i18n.t("unfeature_from_community")
953 : I18NextService.i18n.t("feature_in_community");
955 const featuredLocal = this.postView.post.featured_local;
956 const labelLocal = featuredLocal
957 ? I18NextService.i18n.t("unfeature_from_local")
958 : I18NextService.i18n.t("feature_in_local");
963 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
964 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
965 data-tippy-content={labelCommunity}
966 aria-label={labelCommunity}
968 {this.state.featureCommunityLoading ? (
974 classes={classNames("me-1", {
975 "text-success": featuredCommunity,
979 {I18NextService.i18n.t("community")}
987 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
988 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
989 data-tippy-content={labelLocal}
990 aria-label={labelLocal}
992 {this.state.featureLocalLoading ? (
998 classes={classNames("me-1", {
999 "text-success": featuredLocal,
1003 {I18NextService.i18n.t("local")}
1013 get modBanFromCommunityButton() {
1016 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1017 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
1019 {I18NextService.i18n.t("ban_from_community")}
1024 get modUnbanFromCommunityButton() {
1027 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1028 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
1030 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1035 get addModToCommunityButton() {
1038 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1039 onClick={linkEvent(this, this.handleAddModToCommunity)}
1041 {this.state.addModLoading ? (
1043 ) : this.creatorIsMod_ ? (
1044 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_mod"))
1046 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_mod"))
1052 get modBanButton() {
1055 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1056 onClick={linkEvent(this, this.handleModBanShow)}
1058 {capitalizeFirstLetter(I18NextService.i18n.t("ban_from_site"))}
1063 get modUnbanButton() {
1066 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1067 onClick={linkEvent(this, this.handleModBanSubmit)}
1069 {this.state.banLoading ? (
1072 capitalizeFirstLetter(I18NextService.i18n.t("unban_from_site"))
1078 get purgePersonButton() {
1081 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1082 onClick={linkEvent(this, this.handlePurgePersonShow)}
1084 {capitalizeFirstLetter(I18NextService.i18n.t("purge_user"))}
1089 get purgePostButton() {
1092 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1093 onClick={linkEvent(this, this.handlePurgePostShow)}
1095 {capitalizeFirstLetter(I18NextService.i18n.t("purge_post"))}
1100 get toggleAdminButton() {
1103 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1104 onClick={linkEvent(this, this.handleAddAdmin)}
1106 {this.state.addAdminLoading ? (
1108 ) : this.creatorIsAdmin_ ? (
1109 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_admin"))
1111 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_admin"))
1117 get transferCommunityButton() {
1120 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1121 onClick={linkEvent(this, this.handleShowConfirmTransferCommunity)}
1123 {capitalizeFirstLetter(I18NextService.i18n.t("transfer_community"))}
1128 get modRemoveButton() {
1129 const removed = this.postView.post.removed;
1132 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1135 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1138 {/* TODO: Find an icon for this. */}
1139 {this.state.removeLoading ? (
1142 capitalizeFirstLetter(I18NextService.i18n.t("remove_post"))
1145 {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "}
1146 {I18NextService.i18n.t("post")}
1153 removeAndBanDialogs() {
1154 const post = this.postView;
1155 const purgeTypeText =
1156 this.state.purgeType == PurgeType.Post
1157 ? I18NextService.i18n.t("purge_post")
1158 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1161 {this.state.showRemoveDialog && (
1163 className="form-inline"
1164 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1167 className="visually-hidden"
1168 htmlFor="post-listing-remove-reason"
1170 {I18NextService.i18n.t("reason")}
1174 id="post-listing-remove-reason"
1175 className="form-control me-2"
1176 placeholder={I18NextService.i18n.t("reason")}
1177 value={this.state.removeReason}
1178 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1180 <button type="submit" className="btn btn-secondary">
1181 {this.state.removeLoading ? (
1184 I18NextService.i18n.t("remove_post")
1189 {this.state.showConfirmTransferCommunity && (
1191 <button className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0">
1192 {I18NextService.i18n.t("are_you_sure")}
1195 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1196 onClick={linkEvent(this, this.handleTransferCommunity)}
1198 {this.state.transferLoading ? (
1201 I18NextService.i18n.t("yes")
1205 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1208 this.handleCancelShowConfirmTransferCommunity
1210 aria-label={I18NextService.i18n.t("no")}
1212 {I18NextService.i18n.t("no")}
1216 {this.state.showBanDialog && (
1217 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1218 <div className="mb-3 row col-12">
1220 className="col-form-label"
1221 htmlFor="post-listing-ban-reason"
1223 {I18NextService.i18n.t("reason")}
1227 id="post-listing-ban-reason"
1228 className="form-control me-2"
1229 placeholder={I18NextService.i18n.t("reason")}
1230 value={this.state.banReason}
1231 onInput={linkEvent(this, this.handleModBanReasonChange)}
1233 <label className="col-form-label" htmlFor="mod-ban-expires">
1234 {I18NextService.i18n.t("expires")}
1238 id="mod-ban-expires"
1239 className="form-control me-2"
1240 placeholder={I18NextService.i18n.t("number_of_days")}
1241 value={this.state.banExpireDays}
1242 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1244 <div className="input-group mb-3">
1245 <div className="form-check">
1247 className="form-check-input"
1248 id="mod-ban-remove-data"
1250 checked={this.state.removeData}
1251 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1254 className="form-check-label"
1255 htmlFor="mod-ban-remove-data"
1256 title={I18NextService.i18n.t("remove_content_more")}
1258 {I18NextService.i18n.t("remove_content")}
1263 {/* TODO hold off on expires until later */}
1264 {/* <div class="mb-3 row"> */}
1265 {/* <label class="col-form-label">Expires</label> */}
1266 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1268 <div className="mb-3 row">
1269 <button type="submit" className="btn btn-secondary">
1270 {this.state.banLoading ? (
1274 {I18NextService.i18n.t("ban")} {post.creator.name}
1281 {this.state.showReportDialog && (
1283 className="form-inline"
1284 onSubmit={linkEvent(this, this.handleReportSubmit)}
1286 <label className="visually-hidden" htmlFor="post-report-reason">
1287 {I18NextService.i18n.t("reason")}
1291 id="post-report-reason"
1292 className="form-control me-2"
1293 placeholder={I18NextService.i18n.t("reason")}
1295 value={this.state.reportReason}
1296 onInput={linkEvent(this, this.handleReportReasonChange)}
1298 <button type="submit" className="btn btn-secondary">
1299 {this.state.reportLoading ? (
1302 I18NextService.i18n.t("create_report")
1307 {this.state.showPurgeDialog && (
1309 className="form-inline"
1310 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1313 <label className="visually-hidden" htmlFor="purge-reason">
1314 {I18NextService.i18n.t("reason")}
1319 className="form-control me-2"
1320 placeholder={I18NextService.i18n.t("reason")}
1321 value={this.state.purgeReason}
1322 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1324 {this.state.purgeLoading ? (
1327 <button type="submit" className="btn btn-secondary">
1328 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1338 const post = this.postView.post;
1339 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1340 <div className="row">
1341 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1342 {this.postTitleLine()}
1344 <div className="col-4">
1345 {/* Post thumbnail */}
1346 {!this.state.imageExpanded && this.thumbnail()}
1350 this.postTitleLine()
1354 showPreviewButton() {
1358 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1359 onClick={linkEvent(this, this.handleShowBody)}
1362 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1363 classes="icon-inline"
1372 {/* The mobile view*/}
1373 <div className="d-block d-sm-none">
1374 <article className="row post-container">
1375 <div className="col-12">
1376 {this.createdLine()}
1378 {/* If it has a thumbnail, do a right aligned thumbnail */}
1379 {this.mobileThumbnail()}
1381 {this.commentsLine(true)}
1382 {this.duplicatesLine()}
1383 {this.removeAndBanDialogs()}
1388 {/* The larger view*/}
1389 <div className="d-none d-sm-block">
1390 <article className="row post-container">
1391 {!this.props.viewOnly && (
1392 <div className="col flex-grow-0">
1394 voteContentType={VoteContentType.Post}
1395 id={this.postView.post.id}
1396 onVote={this.props.onPostVote}
1397 enableDownvotes={this.props.enableDownvotes}
1398 counts={this.postView.counts}
1399 my_vote={this.postView.my_vote}
1403 <div className="col flex-grow-1">
1404 <div className="row">
1405 <div className="col flex-grow-0 px-0">
1406 <div className="">{this.thumbnail()}</div>
1408 <div className="col flex-grow-1">
1409 {this.postTitleLine()}
1410 {this.createdLine()}
1411 {this.commentsLine()}
1412 {this.duplicatesLine()}
1413 {this.removeAndBanDialogs()}
1423 private get myPost(): boolean {
1425 this.postView.creator.id ==
1426 UserService.Instance.myUserInfo?.local_user_view.person.id
1429 handleEditClick(i: PostListing) {
1430 i.setState({ showEdit: true });
1433 handleEditCancel() {
1434 this.setState({ showEdit: false });
1437 // The actual editing is done in the receive for post
1438 handleEditPost(form: EditPost) {
1439 this.setState({ showEdit: false });
1440 this.props.onPostEdit(form);
1443 handleShare(i: PostListing) {
1444 const { name, body, id } = i.props.post_view.post;
1447 text: body?.slice(0, 50),
1448 url: `${getHttpBase()}/post/${id}`,
1452 handleShowReportDialog(i: PostListing) {
1453 i.setState({ showReportDialog: !i.state.showReportDialog });
1456 handleReportReasonChange(i: PostListing, event: any) {
1457 i.setState({ reportReason: event.target.value });
1460 handleReportSubmit(i: PostListing, event: any) {
1461 event.preventDefault();
1462 i.setState({ reportLoading: true });
1463 i.props.onPostReport({
1464 post_id: i.postView.post.id,
1465 reason: i.state.reportReason ?? "",
1466 auth: myAuthRequired(),
1470 handleBlockPersonClick(i: PostListing) {
1471 i.setState({ blockLoading: true });
1472 i.props.onBlockPerson({
1473 person_id: i.postView.creator.id,
1475 auth: myAuthRequired(),
1479 handleDeleteClick(i: PostListing) {
1480 i.setState({ deleteLoading: true });
1481 i.props.onDeletePost({
1482 post_id: i.postView.post.id,
1483 deleted: !i.postView.post.deleted,
1484 auth: myAuthRequired(),
1488 handleSavePostClick(i: PostListing) {
1489 i.setState({ saveLoading: true });
1490 i.props.onSavePost({
1491 post_id: i.postView.post.id,
1492 save: !i.postView.saved,
1493 auth: myAuthRequired(),
1497 get crossPostParams(): PostFormParams {
1498 const queryParams: PostFormParams = {};
1499 const { name, url } = this.postView.post;
1501 queryParams.name = name;
1504 queryParams.url = url;
1507 const crossPostBody = this.crossPostBody();
1508 if (crossPostBody) {
1509 queryParams.body = crossPostBody;
1515 crossPostBody(): string | undefined {
1516 const post = this.postView.post;
1517 const body = post.body;
1520 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1522 }\n\n${body.replace(/^/gm, "> ")}`
1526 get showBody(): boolean {
1527 return this.props.showBody || this.state.showBody;
1530 handleModRemoveShow(i: PostListing) {
1532 showRemoveDialog: !i.state.showRemoveDialog,
1533 showBanDialog: false,
1537 handleModRemoveReasonChange(i: PostListing, event: any) {
1538 i.setState({ removeReason: event.target.value });
1541 handleModRemoveDataChange(i: PostListing, event: any) {
1542 i.setState({ removeData: event.target.checked });
1545 handleModRemoveSubmit(i: PostListing, event: any) {
1546 event.preventDefault();
1547 i.setState({ removeLoading: true });
1548 i.props.onRemovePost({
1549 post_id: i.postView.post.id,
1550 removed: !i.postView.post.removed,
1551 auth: myAuthRequired(),
1555 handleModLock(i: PostListing) {
1556 i.setState({ lockLoading: true });
1557 i.props.onLockPost({
1558 post_id: i.postView.post.id,
1559 locked: !i.postView.post.locked,
1560 auth: myAuthRequired(),
1564 handleModFeaturePostLocal(i: PostListing) {
1565 i.setState({ featureLocalLoading: true });
1566 i.props.onFeaturePost({
1567 post_id: i.postView.post.id,
1568 featured: !i.postView.post.featured_local,
1569 feature_type: "Local",
1570 auth: myAuthRequired(),
1574 handleModFeaturePostCommunity(i: PostListing) {
1575 i.setState({ featureCommunityLoading: true });
1576 i.props.onFeaturePost({
1577 post_id: i.postView.post.id,
1578 featured: !i.postView.post.featured_community,
1579 feature_type: "Community",
1580 auth: myAuthRequired(),
1584 handleModBanFromCommunityShow(i: PostListing) {
1586 showBanDialog: true,
1587 banType: BanType.Community,
1588 showRemoveDialog: false,
1592 handleModBanShow(i: PostListing) {
1594 showBanDialog: true,
1595 banType: BanType.Site,
1596 showRemoveDialog: false,
1600 handlePurgePersonShow(i: PostListing) {
1602 showPurgeDialog: true,
1603 purgeType: PurgeType.Person,
1604 showRemoveDialog: false,
1608 handlePurgePostShow(i: PostListing) {
1610 showPurgeDialog: true,
1611 purgeType: PurgeType.Post,
1612 showRemoveDialog: false,
1616 handlePurgeReasonChange(i: PostListing, event: any) {
1617 i.setState({ purgeReason: event.target.value });
1620 handlePurgeSubmit(i: PostListing, event: any) {
1621 event.preventDefault();
1622 i.setState({ purgeLoading: true });
1623 if (i.state.purgeType == PurgeType.Person) {
1624 i.props.onPurgePerson({
1625 person_id: i.postView.creator.id,
1626 reason: i.state.purgeReason,
1627 auth: myAuthRequired(),
1629 } else if (i.state.purgeType == PurgeType.Post) {
1630 i.props.onPurgePost({
1631 post_id: i.postView.post.id,
1632 reason: i.state.purgeReason,
1633 auth: myAuthRequired(),
1638 handleModBanReasonChange(i: PostListing, event: any) {
1639 i.setState({ banReason: event.target.value });
1642 handleModBanExpireDaysChange(i: PostListing, event: any) {
1643 i.setState({ banExpireDays: event.target.value });
1646 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1647 i.setState({ banType: BanType.Community });
1648 i.handleModBanBothSubmit(i, event);
1651 handleModBanSubmit(i: PostListing, event: any) {
1652 i.setState({ banType: BanType.Site });
1653 i.handleModBanBothSubmit(i, event);
1656 handleModBanBothSubmit(i: PostListing, event: any) {
1657 event.preventDefault();
1658 i.setState({ banLoading: true });
1660 const ban = !i.props.post_view.creator_banned_from_community;
1661 // If its an unban, restore all their data
1663 i.setState({ removeData: false });
1665 const person_id = i.props.post_view.creator.id;
1666 const remove_data = i.state.removeData;
1667 const reason = i.state.banReason;
1668 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1670 if (i.state.banType == BanType.Community) {
1671 const community_id = i.postView.community.id;
1672 i.props.onBanPersonFromCommunity({
1679 auth: myAuthRequired(),
1682 i.props.onBanPerson({
1688 auth: myAuthRequired(),
1693 handleAddModToCommunity(i: PostListing) {
1694 i.setState({ addModLoading: true });
1695 i.props.onAddModToCommunity({
1696 community_id: i.postView.community.id,
1697 person_id: i.postView.creator.id,
1698 added: !i.creatorIsMod_,
1699 auth: myAuthRequired(),
1703 handleAddAdmin(i: PostListing) {
1704 i.setState({ addAdminLoading: true });
1705 i.props.onAddAdmin({
1706 person_id: i.postView.creator.id,
1707 added: !i.creatorIsAdmin_,
1708 auth: myAuthRequired(),
1712 handleShowConfirmTransferCommunity(i: PostListing) {
1713 i.setState({ showConfirmTransferCommunity: true });
1716 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1717 i.setState({ showConfirmTransferCommunity: false });
1720 handleTransferCommunity(i: PostListing) {
1721 i.setState({ transferLoading: true });
1722 i.props.onTransferCommunity({
1723 community_id: i.postView.community.id,
1724 person_id: i.postView.creator.id,
1725 auth: myAuthRequired(),
1729 handleShowConfirmTransferSite(i: PostListing) {
1730 i.setState({ showConfirmTransferSite: true });
1733 handleCancelShowConfirmTransferSite(i: PostListing) {
1734 i.setState({ showConfirmTransferSite: false });
1737 handleImageExpandClick(i: PostListing, event: any) {
1738 event.preventDefault();
1739 i.setState({ imageExpanded: !i.state.imageExpanded });
1743 handleViewSource(i: PostListing) {
1744 i.setState({ viewSource: !i.state.viewSource });
1747 handleShowAdvanced(i: PostListing) {
1748 i.setState({ showAdvanced: !i.state.showAdvanced });
1752 handleShowMoreMobile(i: PostListing) {
1754 showMoreMobile: !i.state.showMoreMobile,
1755 showAdvanced: !i.state.showAdvanced,
1760 handleShowBody(i: PostListing) {
1761 i.setState({ showBody: !i.state.showBody });
1765 get pointsTippy(): string {
1766 const points = I18NextService.i18n.t("number_of_points", {
1767 count: Number(this.postView.counts.score),
1768 formattedCount: Number(this.postView.counts.score),
1771 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1772 count: Number(this.postView.counts.upvotes),
1773 formattedCount: Number(this.postView.counts.upvotes),
1776 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1777 count: Number(this.postView.counts.downvotes),
1778 formattedCount: Number(this.postView.counts.downvotes),
1781 return `${points} • ${upvotes} • ${downvotes}`;
1784 get canModOnSelf_(): boolean {
1786 this.postView.creator.id,
1787 this.props.moderators,
1794 get canMod_(): boolean {
1796 this.postView.creator.id,
1797 this.props.moderators,
1802 get canAdmin_(): boolean {
1803 return canAdmin(this.postView.creator.id, this.props.admins);
1806 get creatorIsMod_(): boolean {
1807 return isMod(this.postView.creator.id, this.props.moderators);
1810 get creatorIsAdmin_(): boolean {
1811 return isAdmin(this.postView.creator.id, this.props.admins);