1 import { myAuthRequired } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
51 } from "../../interfaces";
52 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
53 import { I18NextService, UserService } from "../../services";
54 import { setupTippy } from "../../tippy";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
59 import { CommunityLink } from "../community/community-link";
60 import { PersonListing } from "../person/person-listing";
61 import { MetadataCard } from "./metadata-card";
62 import { PostForm } from "./post-form";
64 interface PostListingState {
66 showRemoveDialog: boolean;
67 showPurgeDialog: boolean;
69 purgeType?: PurgeType;
70 purgeLoading: boolean;
71 removeReason?: string;
72 showBanDialog: boolean;
74 banExpireDays?: number;
77 showConfirmTransferSite: boolean;
78 showConfirmTransferCommunity: boolean;
79 imageExpanded: boolean;
81 showAdvanced: boolean;
82 showMoreMobile: boolean;
84 showReportDialog: boolean;
85 reportReason?: string;
86 reportLoading: boolean;
87 blockLoading: boolean;
89 deleteLoading: boolean;
90 removeLoading: boolean;
92 featureCommunityLoading: boolean;
93 featureLocalLoading: boolean;
95 addModLoading: boolean;
96 addAdminLoading: boolean;
97 transferLoading: boolean;
100 interface PostListingProps {
102 crossPosts?: PostView[];
103 moderators?: CommunityModeratorView[];
104 admins?: PersonView[];
105 allLanguages: Language[];
106 siteLanguages: number[];
107 showCommunity?: boolean;
110 enableDownvotes?: boolean;
111 enableNsfw?: boolean;
113 onPostEdit(form: EditPost): void;
114 onPostVote(form: CreatePostLike): void;
115 onPostReport(form: CreatePostReport): void;
116 onBlockPerson(form: BlockPerson): void;
117 onLockPost(form: LockPost): void;
118 onDeletePost(form: DeletePost): void;
119 onRemovePost(form: RemovePost): void;
120 onSavePost(form: SavePost): void;
121 onFeaturePost(form: FeaturePost): void;
122 onPurgePerson(form: PurgePerson): void;
123 onPurgePost(form: PurgePost): void;
124 onBanPersonFromCommunity(form: BanFromCommunity): void;
125 onBanPerson(form: BanPerson): void;
126 onAddModToCommunity(form: AddModToCommunity): void;
127 onAddAdmin(form: AddAdmin): void;
128 onTransferCommunity(form: TransferCommunity): void;
131 export class PostListing extends Component<PostListingProps, PostListingState> {
132 state: PostListingState = {
134 showRemoveDialog: false,
135 showPurgeDialog: false,
136 purgeType: PurgeType.Person,
137 showBanDialog: false,
138 banType: BanType.Community,
140 showConfirmTransferSite: false,
141 showConfirmTransferCommunity: false,
142 imageExpanded: false,
145 showMoreMobile: false,
147 showReportDialog: false,
149 reportLoading: false,
152 deleteLoading: false,
153 removeLoading: false,
155 featureCommunityLoading: false,
156 featureLocalLoading: false,
158 addModLoading: false,
159 addAdminLoading: false,
160 transferLoading: false,
163 constructor(props: any, context: any) {
164 super(props, context);
166 this.handleEditPost = this.handleEditPost.bind(this);
167 this.handleEditCancel = this.handleEditCancel.bind(this);
170 componentWillReceiveProps(nextProps: PostListingProps) {
171 if (this.props !== nextProps) {
174 reportLoading: false,
177 deleteLoading: false,
178 removeLoading: false,
180 featureCommunityLoading: false,
181 featureLocalLoading: false,
183 addModLoading: false,
184 addAdminLoading: false,
185 transferLoading: false,
190 get postView(): PostView {
191 return this.props.post_view;
195 const post = this.postView.post;
198 <div className="post-listing mt-2">
199 {!this.state.showEdit ? (
202 {this.state.imageExpanded && !this.props.hideImage && this.img}
203 {post.url && this.state.showBody && post.embed_title && (
204 <MetadataCard post={post} />
206 {this.showBody && this.body()}
210 post_view={this.postView}
211 crossPosts={this.props.crossPosts}
212 onEdit={this.handleEditPost}
213 onCancel={this.handleEditCancel}
214 enableNsfw={this.props.enableNsfw}
215 enableDownvotes={this.props.enableDownvotes}
216 allLanguages={this.props.allLanguages}
217 siteLanguages={this.props.siteLanguages}
225 const body = this.postView.post.body;
227 <article id="postContent" className="col-12 card my-2 p-2">
228 {this.state.viewSource ? (
231 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
243 <div className="offset-sm-3 my-2 d-none d-sm-block">
244 <a href={this.imageSrc} className="d-inline-block">
245 <PictrsImage src={this.imageSrc} />
248 <div className="my-2 d-block d-sm-none">
251 className="p-0 border-0 bg-transparent d-inline-block"
252 onClick={linkEvent(this, this.handleImageExpandClick)}
254 <PictrsImage src={this.imageSrc} />
261 const { post } = this.postView;
262 const { url } = post;
264 // if direct video link
265 if (url && isVideo(url)) {
267 <div className="embed-responsive mt-3">
268 <video muted controls className="embed-responsive-item col-12">
269 <source src={url} type="video/mp4" />
275 // if embedded video link
276 if (url && post.embed_video_url) {
278 <div className="ratio ratio-16x9">
281 className="post-metadata-iframe"
282 src={post.embed_video_url}
283 title={post.embed_title}
292 imgThumb(src: string) {
293 const post_view = this.postView;
299 nsfw={post_view.post.nsfw || post_view.community.nsfw}
304 get imageSrc(): string | undefined {
305 const post = this.postView.post;
306 const url = post.url;
307 const thumbnail = post.thumbnail_url;
309 if (url && isImage(url)) {
310 if (url.includes("pictrs")) {
312 } else if (thumbnail) {
317 } else if (thumbnail) {
325 const post = this.postView.post;
326 const url = post.url;
327 const thumbnail = post.thumbnail_url;
329 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
333 className="text-body d-inline-block position-relative mb-2"
334 data-tippy-content={I18NextService.i18n.t("expand_here")}
335 onClick={linkEvent(this, this.handleImageExpandClick)}
336 aria-label={I18NextService.i18n.t("expand_here")}
338 {this.imgThumb(this.imageSrc)}
339 <Icon icon="image" classes="mini-overlay" />
342 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
345 className="text-body d-inline-block position-relative mb-2"
350 {this.imgThumb(this.imageSrc)}
351 <Icon icon="external-link" classes="mini-overlay" />
355 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
358 className="text-body"
362 data-tippy-content={I18NextService.i18n.t("expand_here")}
363 onClick={linkEvent(this, this.handleImageExpandClick)}
364 aria-label={I18NextService.i18n.t("expand_here")}
366 <div className="thumbnail rounded bg-light d-flex justify-content-center">
367 <Icon icon="play" classes="d-flex align-items-center" />
373 <a className="text-body" href={url} title={url} rel={relTags}>
374 <div className="thumbnail rounded bg-light d-flex justify-content-center">
375 <Icon icon="external-link" classes="d-flex align-items-center" />
383 className="text-body"
384 to={`/post/${post.id}`}
385 title={I18NextService.i18n.t("comments")}
387 <div className="thumbnail rounded bg-light d-flex justify-content-center">
388 <Icon icon="message-square" classes="d-flex align-items-center" />
396 const post_view = this.postView;
398 <span className="small">
399 <PersonListing person={post_view.creator} muted={true} />
400 {this.creatorIsMod_ && (
401 <span className="mx-1 badge text-bg-light">
402 {I18NextService.i18n.t("mod")}
405 {this.creatorIsAdmin_ && (
406 <span className="mx-1 badge text-bg-light">
407 {I18NextService.i18n.t("admin")}
410 {post_view.creator.bot_account && (
411 <span className="mx-1 badge text-bg-light">
412 {I18NextService.i18n.t("bot_account").toLowerCase()}
415 {this.props.showCommunity && (
418 {I18NextService.i18n.t("to")}{" "}
419 <CommunityLink community={post_view.community} />
422 {post_view.post.language_id !== 0 && (
423 <span className="mx-1 badge text-bg-light">
425 this.props.allLanguages.find(
426 lang => lang.id === post_view.post.language_id
433 published={post_view.post.published}
434 updated={post_view.post.updated}
441 const post = this.postView.post;
444 className={`d-inline ${
445 !post.featured_community && !post.featured_local
449 to={`/post/${post.id}`}
450 title={I18NextService.i18n.t("comments")}
454 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
461 const post = this.postView.post;
462 const url = post.url;
466 <div className="post-title overflow-hidden">
467 <h5 className="d-inline">
468 {url && this.props.showBody ? (
471 !post.featured_community && !post.featured_local
478 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
486 * If there is a URL, or if the post has a body and we were told not to
487 * show the body, show the MetadataCard/body toggle.
489 {(post.url || (post.body && !this.props.showBody)) && (
491 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
492 data-tippy-content={post.body && mdNoImages.render(post.body)}
493 data-tippy-allowHtml={true}
494 onClick={linkEvent(this, this.handleShowBody)}
497 icon={!this.state.showBody ? "plus-square" : "minus-square"}
498 classes="icon-inline"
504 <small className="ms-2 badge text-bg-secondary">
505 {I18NextService.i18n.t("removed")}
511 className="unselectable pointer ms-2 text-muted fst-italic"
512 data-tippy-content={I18NextService.i18n.t("deleted")}
514 <Icon icon="trash" classes="icon-inline text-danger" />
520 className="unselectable pointer ms-2 text-muted fst-italic"
521 data-tippy-content={I18NextService.i18n.t("locked")}
523 <Icon icon="lock" classes="icon-inline text-danger" />
527 {post.featured_community && (
529 className="unselectable pointer ms-2 text-muted fst-italic"
530 data-tippy-content={I18NextService.i18n.t(
531 "featured_in_community"
533 aria-label={I18NextService.i18n.t("featured_in_community")}
535 <Icon icon="pin" classes="icon-inline text-primary" />
539 {post.featured_local && (
541 className="unselectable pointer ms-2 text-muted fst-italic"
542 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
543 aria-label={I18NextService.i18n.t("featured_in_local")}
545 <Icon icon="pin" classes="icon-inline text-secondary" />
550 <small className="ms-2 badge text-bg-danger">
551 {I18NextService.i18n.t("nsfw")}
555 {url && this.urlLine()}
561 const post = this.postView.post;
562 const url = post.url;
565 <p className="small m-0">
566 {url && !(hostname(url) === getExternalHost()) && (
568 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
581 const dupes = this.props.crossPosts;
582 return dupes && dupes.length > 0 ? (
583 <ul className="list-inline mb-1 small text-muted">
585 <li className="list-inline-item me-2">
586 {I18NextService.i18n.t("cross_posted_to")}
589 <li key={pv.post.id} className="list-inline-item me-2">
590 <Link to={`/post/${pv.post.id}`}>
593 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
604 commentsLine(mobile = false) {
605 const post = this.postView.post;
608 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
609 {this.commentsButton}
612 className="btn btn-sm btn-animate text-muted py-0"
613 onClick={linkEvent(this, this.handleShare)}
616 <Icon icon="share" inline />
621 className="btn btn-sm btn-animate text-muted py-0"
622 title={I18NextService.i18n.t("link")}
625 <Icon icon="fedilink" inline />
628 {mobile && !this.props.viewOnly && (
630 voteContentType={VoteContentType.Post}
631 id={this.postView.post.id}
632 onVote={this.props.onPostVote}
633 enableDownvotes={this.props.enableDownvotes}
634 counts={this.postView.counts}
635 my_vote={this.postView.my_vote}
638 {UserService.Instance.myUserInfo &&
639 !this.props.viewOnly &&
646 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
647 // Possible enhancement: Make each button a component.
648 const post_view = this.postView;
649 const post = post_view.post;
654 {this.crossPostButton}
656 {this.props.showBody && post_view.post.body && this.viewSourceButton}
658 <div className="dropdown">
660 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
661 onClick={linkEvent(this, this.handleShowAdvanced)}
662 data-tippy-content={I18NextService.i18n.t("more")}
663 data-bs-toggle="dropdown"
664 aria-expanded="false"
665 aria-controls={`advancedButtonsDropdown${post.id}`}
666 aria-label={I18NextService.i18n.t("more")}
668 <Icon icon="more-vertical" inline />
672 className="dropdown-menu"
673 id={`advancedButtonsDropdown${post.id}`}
677 <li>{this.reportButton}</li>
678 <li>{this.blockButton}</li>
682 <li>{this.editButton}</li>
683 <li>{this.deleteButton}</li>
687 {/* Any mod can do these, not limited to hierarchy*/}
688 {(amMod(this.props.moderators) || amAdmin()) && (
691 <hr className="dropdown-divider" />
693 <li>{this.lockButton}</li>
694 {this.featureButtons}
698 {(this.canMod_ || this.canAdmin_) && (
699 <li>{this.modRemoveButton}</li>
707 get commentsButton() {
708 const post_view = this.postView;
709 const title = I18NextService.i18n.t("number_of_comments", {
710 count: Number(post_view.counts.comments),
711 formattedCount: Number(post_view.counts.comments),
716 className="btn btn-link btn-sm text-muted ps-0"
718 to={`/post/${post_view.post.id}?scrollToComments=true`}
719 data-tippy-content={title}
721 <Icon icon="message-square" classes="me-1" inline />
722 {post_view.counts.comments}
723 {this.unreadCount && (
726 <span className="fst-italic">
727 ({this.unreadCount} {I18NextService.i18n.t("new")})
735 get unreadCount(): number | undefined {
736 const pv = this.postView;
737 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
739 : pv.unread_comments;
743 const saved = this.postView.saved;
745 ? I18NextService.i18n.t("unsave")
746 : I18NextService.i18n.t("save");
749 className="btn btn-sm btn-animate text-muted py-0"
750 onClick={linkEvent(this, this.handleSavePostClick)}
751 data-tippy-content={label}
754 {this.state.saveLoading ? (
759 classes={classNames({ "text-warning": saved })}
767 get crossPostButton() {
770 className="btn btn-sm btn-animate text-muted py-0"
772 /* Empty string properties are required to satisfy type*/
773 pathname: "/create_post",
774 state: { ...this.crossPostParams },
779 title={I18NextService.i18n.t("cross_post")}
780 data-tippy-content={I18NextService.i18n.t("cross_post")}
781 aria-label={I18NextService.i18n.t("cross_post")}
783 <Icon icon="copy" inline />
791 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
792 onClick={linkEvent(this, this.handleShowReportDialog)}
793 aria-label={I18NextService.i18n.t("show_report_dialog")}
795 <Icon classes="me-1" icon="flag" inline />
796 {I18NextService.i18n.t("create_report")}
804 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
805 onClick={linkEvent(this, this.handleBlockPersonClick)}
806 aria-label={I18NextService.i18n.t("block_user")}
808 {this.state.blockLoading ? (
811 <Icon classes="me-1" icon="slash" inline />
813 {I18NextService.i18n.t("block_user")}
821 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
822 onClick={linkEvent(this, this.handleEditClick)}
823 aria-label={I18NextService.i18n.t("edit")}
825 <Icon classes="me-1" icon="edit" inline />
826 {I18NextService.i18n.t("edit")}
832 const deleted = this.postView.post.deleted;
833 const label = !deleted
834 ? I18NextService.i18n.t("delete")
835 : I18NextService.i18n.t("restore");
838 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
839 onClick={linkEvent(this, this.handleDeleteClick)}
841 {this.state.deleteLoading ? (
847 classes={classNames("me-1", { "text-danger": deleted })}
857 get viewSourceButton() {
860 className="btn btn-sm btn-animate text-muted py-0"
861 onClick={linkEvent(this, this.handleViewSource)}
862 data-tippy-content={I18NextService.i18n.t("view_source")}
863 aria-label={I18NextService.i18n.t("view_source")}
867 classes={classNames({ "text-success": this.state.viewSource })}
875 const locked = this.postView.post.locked;
877 ? I18NextService.i18n.t("unlock")
878 : I18NextService.i18n.t("lock");
881 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
882 onClick={linkEvent(this, this.handleModLock)}
885 {this.state.lockLoading ? (
891 classes={classNames("me-1", { "text-danger": locked })}
894 {capitalizeFirstLetter(label)}
901 get featureButtons() {
902 const featuredCommunity = this.postView.post.featured_community;
903 const labelCommunity = featuredCommunity
904 ? I18NextService.i18n.t("unfeature_from_community")
905 : I18NextService.i18n.t("feature_in_community");
907 const featuredLocal = this.postView.post.featured_local;
908 const labelLocal = featuredLocal
909 ? I18NextService.i18n.t("unfeature_from_local")
910 : I18NextService.i18n.t("feature_in_local");
915 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
916 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
917 data-tippy-content={labelCommunity}
918 aria-label={labelCommunity}
920 {this.state.featureCommunityLoading ? (
926 classes={classNames("me-1", {
927 "text-success": featuredCommunity,
931 {I18NextService.i18n.t("community")}
939 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
940 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
941 data-tippy-content={labelLocal}
942 aria-label={labelLocal}
944 {this.state.featureLocalLoading ? (
950 classes={classNames("me-1", {
951 "text-success": featuredLocal,
955 {I18NextService.i18n.t("local")}
965 get modBanFromCommunityButton() {
968 className="btn btn-link btn-animate text-muted py-0"
969 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
970 aria-label={I18NextService.i18n.t("ban_from_community")}
972 {I18NextService.i18n.t("ban_from_community")}
977 get modUnbanFromCommunityButton() {
980 className="btn btn-link btn-animate text-muted py-0"
981 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
982 aria-label={I18NextService.i18n.t("unban")}
984 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
989 get addModToCommunityButton() {
992 className="btn btn-link btn-animate text-muted py-0"
993 onClick={linkEvent(this, this.handleAddModToCommunity)}
996 ? I18NextService.i18n.t("remove_as_mod")
997 : I18NextService.i18n.t("appoint_as_mod")
1000 {this.state.addModLoading ? (
1002 ) : this.creatorIsMod_ ? (
1003 I18NextService.i18n.t("remove_as_mod")
1005 I18NextService.i18n.t("appoint_as_mod")
1011 get modBanButton() {
1014 className="btn btn-link btn-animate text-muted py-0"
1015 onClick={linkEvent(this, this.handleModBanShow)}
1016 aria-label={I18NextService.i18n.t("ban_from_site")}
1018 {I18NextService.i18n.t("ban_from_site")}
1023 get modUnbanButton() {
1026 className="btn btn-link btn-animate text-muted py-0"
1027 onClick={linkEvent(this, this.handleModBanSubmit)}
1028 aria-label={I18NextService.i18n.t("unban_from_site")}
1030 {this.state.banLoading ? (
1033 I18NextService.i18n.t("unban_from_site")
1039 get purgePersonButton() {
1042 className="btn btn-link btn-animate text-muted py-0"
1043 onClick={linkEvent(this, this.handlePurgePersonShow)}
1044 aria-label={I18NextService.i18n.t("purge_user")}
1046 {I18NextService.i18n.t("purge_user")}
1051 get purgePostButton() {
1054 className="btn btn-link btn-animate text-muted py-0"
1055 onClick={linkEvent(this, this.handlePurgePostShow)}
1056 aria-label={I18NextService.i18n.t("purge_post")}
1058 {I18NextService.i18n.t("purge_post")}
1063 get toggleAdminButton() {
1066 className="btn btn-link btn-animate text-muted py-0"
1067 onClick={linkEvent(this, this.handleAddAdmin)}
1069 {this.state.addAdminLoading ? (
1071 ) : this.creatorIsAdmin_ ? (
1072 I18NextService.i18n.t("remove_as_admin")
1074 I18NextService.i18n.t("appoint_as_admin")
1080 get modRemoveButton() {
1081 const removed = this.postView.post.removed;
1084 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1087 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1090 {/* TODO: Find an icon for this. */}
1091 {this.state.removeLoading ? (
1094 I18NextService.i18n.t("remove")
1096 I18NextService.i18n.t("restore")
1103 * Mod/Admin actions to be taken against the author.
1107 const post_view = this.postView;
1109 this.state.showAdvanced && (
1110 <div className="mt-3">
1113 {!this.creatorIsMod_ &&
1114 (!post_view.creator_banned_from_community
1115 ? this.modBanFromCommunityButton
1116 : this.modUnbanFromCommunityButton)}
1117 {!post_view.creator_banned_from_community &&
1118 this.addModToCommunityButton}
1122 {/* Community creators and admins can transfer community to another mod */}
1123 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1125 this.creatorIsMod_ &&
1126 (!this.state.showConfirmTransferCommunity ? (
1128 className="btn btn-link btn-animate text-muted py-0"
1131 this.handleShowConfirmTransferCommunity
1133 aria-label={I18NextService.i18n.t("transfer_community")}
1135 {I18NextService.i18n.t("transfer_community")}
1140 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1141 aria-label={I18NextService.i18n.t("are_you_sure")}
1143 {I18NextService.i18n.t("are_you_sure")}
1146 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1147 aria-label={I18NextService.i18n.t("yes")}
1148 onClick={linkEvent(this, this.handleTransferCommunity)}
1150 {this.state.transferLoading ? (
1153 I18NextService.i18n.t("yes")
1157 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1160 this.handleCancelShowConfirmTransferCommunity
1162 aria-label={I18NextService.i18n.t("no")}
1164 {I18NextService.i18n.t("no")}
1168 {/* Admins can ban from all, and appoint other admins */}
1169 {this.canAdmin_ && (
1171 {!this.creatorIsAdmin_ && (
1173 {!isBanned(post_view.creator)
1175 : this.modUnbanButton}
1176 {this.purgePersonButton}
1177 {this.purgePostButton}
1180 {!isBanned(post_view.creator) &&
1181 post_view.creator.local &&
1182 this.toggleAdminButton}
1190 removeAndBanDialogs() {
1191 const post = this.postView;
1192 const purgeTypeText =
1193 this.state.purgeType == PurgeType.Post
1194 ? I18NextService.i18n.t("purge_post")
1195 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1198 {this.state.showRemoveDialog && (
1200 className="form-inline"
1201 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1204 className="visually-hidden"
1205 htmlFor="post-listing-remove-reason"
1207 {I18NextService.i18n.t("reason")}
1211 id="post-listing-remove-reason"
1212 className="form-control me-2"
1213 placeholder={I18NextService.i18n.t("reason")}
1214 value={this.state.removeReason}
1215 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1219 className="btn btn-secondary"
1220 aria-label={I18NextService.i18n.t("remove_post")}
1222 {this.state.removeLoading ? (
1225 I18NextService.i18n.t("remove_post")
1230 {this.state.showBanDialog && (
1231 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1232 <div className="mb-3 row col-12">
1234 className="col-form-label"
1235 htmlFor="post-listing-ban-reason"
1237 {I18NextService.i18n.t("reason")}
1241 id="post-listing-ban-reason"
1242 className="form-control me-2"
1243 placeholder={I18NextService.i18n.t("reason")}
1244 value={this.state.banReason}
1245 onInput={linkEvent(this, this.handleModBanReasonChange)}
1247 <label className="col-form-label" htmlFor="mod-ban-expires">
1248 {I18NextService.i18n.t("expires")}
1252 id="mod-ban-expires"
1253 className="form-control me-2"
1254 placeholder={I18NextService.i18n.t("number_of_days")}
1255 value={this.state.banExpireDays}
1256 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1258 <div className="input-group mb-3">
1259 <div className="form-check">
1261 className="form-check-input"
1262 id="mod-ban-remove-data"
1264 checked={this.state.removeData}
1265 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1268 className="form-check-label"
1269 htmlFor="mod-ban-remove-data"
1270 title={I18NextService.i18n.t("remove_content_more")}
1272 {I18NextService.i18n.t("remove_content")}
1277 {/* TODO hold off on expires until later */}
1278 {/* <div class="mb-3 row"> */}
1279 {/* <label class="col-form-label">Expires</label> */}
1280 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1282 <div className="mb-3 row">
1285 className="btn btn-secondary"
1286 aria-label={I18NextService.i18n.t("ban")}
1288 {this.state.banLoading ? (
1292 {I18NextService.i18n.t("ban")} {post.creator.name}
1299 {this.state.showReportDialog && (
1301 className="form-inline"
1302 onSubmit={linkEvent(this, this.handleReportSubmit)}
1304 <label className="visually-hidden" htmlFor="post-report-reason">
1305 {I18NextService.i18n.t("reason")}
1309 id="post-report-reason"
1310 className="form-control me-2"
1311 placeholder={I18NextService.i18n.t("reason")}
1313 value={this.state.reportReason}
1314 onInput={linkEvent(this, this.handleReportReasonChange)}
1318 className="btn btn-secondary"
1319 aria-label={I18NextService.i18n.t("create_report")}
1321 {this.state.reportLoading ? (
1324 I18NextService.i18n.t("create_report")
1329 {this.state.showPurgeDialog && (
1331 className="form-inline"
1332 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1335 <label className="visually-hidden" htmlFor="purge-reason">
1336 {I18NextService.i18n.t("reason")}
1341 className="form-control me-2"
1342 placeholder={I18NextService.i18n.t("reason")}
1343 value={this.state.purgeReason}
1344 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1346 {this.state.purgeLoading ? (
1351 className="btn btn-secondary"
1352 aria-label={purgeTypeText}
1354 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1364 const post = this.postView.post;
1365 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1366 <div className="row">
1367 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1368 {this.postTitleLine()}
1370 <div className="col-4">
1371 {/* Post thumbnail */}
1372 {!this.state.imageExpanded && this.thumbnail()}
1376 this.postTitleLine()
1383 {/* The mobile view*/}
1384 <div className="d-block d-sm-none">
1385 <article className="row post-container">
1386 <div className="col-12">
1387 {this.createdLine()}
1389 {/* If it has a thumbnail, do a right aligned thumbnail */}
1390 {this.mobileThumbnail()}
1392 {this.commentsLine(true)}
1393 {this.userActionsLine()}
1394 {this.duplicatesLine()}
1395 {this.removeAndBanDialogs()}
1400 {/* The larger view*/}
1401 <div className="d-none d-sm-block">
1402 <article className="row post-container">
1403 {!this.props.viewOnly && (
1405 voteContentType={VoteContentType.Post}
1406 id={this.postView.post.id}
1407 onVote={this.props.onPostVote}
1408 enableDownvotes={this.props.enableDownvotes}
1409 counts={this.postView.counts}
1410 my_vote={this.postView.my_vote}
1413 <div className="col-sm-2 pe-0 post-media">
1414 <div className="">{this.thumbnail()}</div>
1416 <div className="col-12 col-sm-9">
1417 <div className="row">
1418 <div className="col-12">
1419 {this.postTitleLine()}
1420 {this.createdLine()}
1421 {this.commentsLine()}
1422 {this.duplicatesLine()}
1423 {this.userActionsLine()}
1424 {this.removeAndBanDialogs()}
1434 private get myPost(): boolean {
1436 this.postView.creator.id ==
1437 UserService.Instance.myUserInfo?.local_user_view.person.id
1440 handleEditClick(i: PostListing) {
1441 i.setState({ showEdit: true });
1444 handleEditCancel() {
1445 this.setState({ showEdit: false });
1448 // The actual editing is done in the receive for post
1449 handleEditPost(form: EditPost) {
1450 this.setState({ showEdit: false });
1451 this.props.onPostEdit(form);
1454 handleShare(i: PostListing) {
1455 const { name, body, id } = i.props.post_view.post;
1458 text: body?.slice(0, 50),
1459 url: `${getHttpBase()}/post/${id}`,
1463 handleShowReportDialog(i: PostListing) {
1464 i.setState({ showReportDialog: !i.state.showReportDialog });
1467 handleReportReasonChange(i: PostListing, event: any) {
1468 i.setState({ reportReason: event.target.value });
1471 handleReportSubmit(i: PostListing, event: any) {
1472 event.preventDefault();
1473 i.setState({ reportLoading: true });
1474 i.props.onPostReport({
1475 post_id: i.postView.post.id,
1476 reason: i.state.reportReason ?? "",
1477 auth: myAuthRequired(),
1481 handleBlockPersonClick(i: PostListing) {
1482 i.setState({ blockLoading: true });
1483 i.props.onBlockPerson({
1484 person_id: i.postView.creator.id,
1486 auth: myAuthRequired(),
1490 handleDeleteClick(i: PostListing) {
1491 i.setState({ deleteLoading: true });
1492 i.props.onDeletePost({
1493 post_id: i.postView.post.id,
1494 deleted: !i.postView.post.deleted,
1495 auth: myAuthRequired(),
1499 handleSavePostClick(i: PostListing) {
1500 i.setState({ saveLoading: true });
1501 i.props.onSavePost({
1502 post_id: i.postView.post.id,
1503 save: !i.postView.saved,
1504 auth: myAuthRequired(),
1508 get crossPostParams(): PostFormParams {
1509 const queryParams: PostFormParams = {};
1510 const { name, url } = this.postView.post;
1512 queryParams.name = name;
1515 queryParams.url = url;
1518 const crossPostBody = this.crossPostBody();
1519 if (crossPostBody) {
1520 queryParams.body = crossPostBody;
1526 crossPostBody(): string | undefined {
1527 const post = this.postView.post;
1528 const body = post.body;
1531 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1533 }\n\n${body.replace(/^/gm, "> ")}`
1537 get showBody(): boolean {
1538 return this.props.showBody || this.state.showBody;
1541 handleModRemoveShow(i: PostListing) {
1543 showRemoveDialog: !i.state.showRemoveDialog,
1544 showBanDialog: false,
1548 handleModRemoveReasonChange(i: PostListing, event: any) {
1549 i.setState({ removeReason: event.target.value });
1552 handleModRemoveDataChange(i: PostListing, event: any) {
1553 i.setState({ removeData: event.target.checked });
1556 handleModRemoveSubmit(i: PostListing, event: any) {
1557 event.preventDefault();
1558 i.setState({ removeLoading: true });
1559 i.props.onRemovePost({
1560 post_id: i.postView.post.id,
1561 removed: !i.postView.post.removed,
1562 auth: myAuthRequired(),
1566 handleModLock(i: PostListing) {
1567 i.setState({ lockLoading: true });
1568 i.props.onLockPost({
1569 post_id: i.postView.post.id,
1570 locked: !i.postView.post.locked,
1571 auth: myAuthRequired(),
1575 handleModFeaturePostLocal(i: PostListing) {
1576 i.setState({ featureLocalLoading: true });
1577 i.props.onFeaturePost({
1578 post_id: i.postView.post.id,
1579 featured: !i.postView.post.featured_local,
1580 feature_type: "Local",
1581 auth: myAuthRequired(),
1585 handleModFeaturePostCommunity(i: PostListing) {
1586 i.setState({ featureCommunityLoading: true });
1587 i.props.onFeaturePost({
1588 post_id: i.postView.post.id,
1589 featured: !i.postView.post.featured_community,
1590 feature_type: "Community",
1591 auth: myAuthRequired(),
1595 handleModBanFromCommunityShow(i: PostListing) {
1597 showBanDialog: true,
1598 banType: BanType.Community,
1599 showRemoveDialog: false,
1603 handleModBanShow(i: PostListing) {
1605 showBanDialog: true,
1606 banType: BanType.Site,
1607 showRemoveDialog: false,
1611 handlePurgePersonShow(i: PostListing) {
1613 showPurgeDialog: true,
1614 purgeType: PurgeType.Person,
1615 showRemoveDialog: false,
1619 handlePurgePostShow(i: PostListing) {
1621 showPurgeDialog: true,
1622 purgeType: PurgeType.Post,
1623 showRemoveDialog: false,
1627 handlePurgeReasonChange(i: PostListing, event: any) {
1628 i.setState({ purgeReason: event.target.value });
1631 handlePurgeSubmit(i: PostListing, event: any) {
1632 event.preventDefault();
1633 i.setState({ purgeLoading: true });
1634 if (i.state.purgeType == PurgeType.Person) {
1635 i.props.onPurgePerson({
1636 person_id: i.postView.creator.id,
1637 reason: i.state.purgeReason,
1638 auth: myAuthRequired(),
1640 } else if (i.state.purgeType == PurgeType.Post) {
1641 i.props.onPurgePost({
1642 post_id: i.postView.post.id,
1643 reason: i.state.purgeReason,
1644 auth: myAuthRequired(),
1649 handleModBanReasonChange(i: PostListing, event: any) {
1650 i.setState({ banReason: event.target.value });
1653 handleModBanExpireDaysChange(i: PostListing, event: any) {
1654 i.setState({ banExpireDays: event.target.value });
1657 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1658 i.setState({ banType: BanType.Community });
1659 i.handleModBanBothSubmit(i, event);
1662 handleModBanSubmit(i: PostListing, event: any) {
1663 i.setState({ banType: BanType.Site });
1664 i.handleModBanBothSubmit(i, event);
1667 handleModBanBothSubmit(i: PostListing, event: any) {
1668 event.preventDefault();
1669 i.setState({ banLoading: true });
1671 const ban = !i.props.post_view.creator_banned_from_community;
1672 // If its an unban, restore all their data
1674 i.setState({ removeData: false });
1676 const person_id = i.props.post_view.creator.id;
1677 const remove_data = i.state.removeData;
1678 const reason = i.state.banReason;
1679 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1681 if (i.state.banType == BanType.Community) {
1682 const community_id = i.postView.community.id;
1683 i.props.onBanPersonFromCommunity({
1690 auth: myAuthRequired(),
1693 i.props.onBanPerson({
1699 auth: myAuthRequired(),
1704 handleAddModToCommunity(i: PostListing) {
1705 i.setState({ addModLoading: true });
1706 i.props.onAddModToCommunity({
1707 community_id: i.postView.community.id,
1708 person_id: i.postView.creator.id,
1709 added: !i.creatorIsMod_,
1710 auth: myAuthRequired(),
1714 handleAddAdmin(i: PostListing) {
1715 i.setState({ addAdminLoading: true });
1716 i.props.onAddAdmin({
1717 person_id: i.postView.creator.id,
1718 added: !i.creatorIsAdmin_,
1719 auth: myAuthRequired(),
1723 handleShowConfirmTransferCommunity(i: PostListing) {
1724 i.setState({ showConfirmTransferCommunity: true });
1727 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1728 i.setState({ showConfirmTransferCommunity: false });
1731 handleTransferCommunity(i: PostListing) {
1732 i.setState({ transferLoading: true });
1733 i.props.onTransferCommunity({
1734 community_id: i.postView.community.id,
1735 person_id: i.postView.creator.id,
1736 auth: myAuthRequired(),
1740 handleShowConfirmTransferSite(i: PostListing) {
1741 i.setState({ showConfirmTransferSite: true });
1744 handleCancelShowConfirmTransferSite(i: PostListing) {
1745 i.setState({ showConfirmTransferSite: false });
1748 handleImageExpandClick(i: PostListing, event: any) {
1749 event.preventDefault();
1750 i.setState({ imageExpanded: !i.state.imageExpanded });
1754 handleViewSource(i: PostListing) {
1755 i.setState({ viewSource: !i.state.viewSource });
1758 handleShowAdvanced(i: PostListing) {
1759 i.setState({ showAdvanced: !i.state.showAdvanced });
1763 handleShowMoreMobile(i: PostListing) {
1765 showMoreMobile: !i.state.showMoreMobile,
1766 showAdvanced: !i.state.showAdvanced,
1771 handleShowBody(i: PostListing) {
1772 i.setState({ showBody: !i.state.showBody });
1776 get pointsTippy(): string {
1777 const points = I18NextService.i18n.t("number_of_points", {
1778 count: Number(this.postView.counts.score),
1779 formattedCount: Number(this.postView.counts.score),
1782 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1783 count: Number(this.postView.counts.upvotes),
1784 formattedCount: Number(this.postView.counts.upvotes),
1787 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1788 count: Number(this.postView.counts.downvotes),
1789 formattedCount: Number(this.postView.counts.downvotes),
1792 return `${points} • ${upvotes} • ${downvotes}`;
1795 get canModOnSelf_(): boolean {
1797 this.postView.creator.id,
1798 this.props.moderators,
1805 get canMod_(): boolean {
1807 this.postView.creator.id,
1808 this.props.moderators,
1813 get canAdmin_(): boolean {
1814 return canAdmin(this.postView.creator.id, this.props.admins);
1817 get creatorIsMod_(): boolean {
1818 return isMod(this.postView.creator.id, this.props.moderators);
1821 get creatorIsAdmin_(): boolean {
1822 return isAdmin(this.postView.creator.id, this.props.admins);