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,
186 imageExpanded: false,
191 get postView(): PostView {
192 return this.props.post_view;
196 const post = this.postView.post;
199 <div className="post-listing mt-2">
200 {!this.state.showEdit ? (
203 {this.state.imageExpanded && !this.props.hideImage && this.img}
204 {post.url && this.state.showBody && post.embed_title && (
205 <MetadataCard post={post} />
207 {this.showBody && this.body()}
211 post_view={this.postView}
212 crossPosts={this.props.crossPosts}
213 onEdit={this.handleEditPost}
214 onCancel={this.handleEditCancel}
215 enableNsfw={this.props.enableNsfw}
216 enableDownvotes={this.props.enableDownvotes}
217 allLanguages={this.props.allLanguages}
218 siteLanguages={this.props.siteLanguages}
226 const body = this.postView.post.body;
228 <article id="postContent" className="col-12 card my-2 p-2">
229 {this.state.viewSource ? (
232 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
244 <div className="offset-sm-3 my-2 d-none d-sm-block">
245 <a href={this.imageSrc} className="d-inline-block">
246 <PictrsImage src={this.imageSrc} />
249 <div className="my-2 d-block d-sm-none">
252 className="p-0 border-0 bg-transparent d-inline-block"
253 onClick={linkEvent(this, this.handleImageExpandClick)}
255 <PictrsImage src={this.imageSrc} />
262 const { post } = this.postView;
263 const { url } = post;
265 // if direct video link
266 if (url && isVideo(url)) {
268 <div className="embed-responsive mt-3">
269 <video muted controls className="embed-responsive-item col-12">
270 <source src={url} type="video/mp4" />
276 // if embedded video link
277 if (url && post.embed_video_url) {
279 <div className="ratio ratio-16x9">
282 className="post-metadata-iframe"
283 src={post.embed_video_url}
284 title={post.embed_title}
293 imgThumb(src: string) {
294 const post_view = this.postView;
300 nsfw={post_view.post.nsfw || post_view.community.nsfw}
305 get imageSrc(): string | undefined {
306 const post = this.postView.post;
307 const url = post.url;
308 const thumbnail = post.thumbnail_url;
310 if (url && isImage(url)) {
311 if (url.includes("pictrs")) {
313 } else if (thumbnail) {
318 } else if (thumbnail) {
326 const post = this.postView.post;
327 const url = post.url;
328 const thumbnail = post.thumbnail_url;
330 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
334 className="text-body d-inline-block position-relative mb-2"
335 data-tippy-content={I18NextService.i18n.t("expand_here")}
336 onClick={linkEvent(this, this.handleImageExpandClick)}
337 aria-label={I18NextService.i18n.t("expand_here")}
339 {this.imgThumb(this.imageSrc)}
340 <Icon icon="image" classes="mini-overlay" />
343 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
346 className="text-body d-inline-block position-relative mb-2"
351 {this.imgThumb(this.imageSrc)}
352 <Icon icon="external-link" classes="mini-overlay" />
356 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
359 className="text-body"
363 data-tippy-content={I18NextService.i18n.t("expand_here")}
364 onClick={linkEvent(this, this.handleImageExpandClick)}
365 aria-label={I18NextService.i18n.t("expand_here")}
367 <div className="thumbnail rounded bg-light d-flex justify-content-center">
368 <Icon icon="play" classes="d-flex align-items-center" />
374 <a className="text-body" href={url} title={url} rel={relTags}>
375 <div className="thumbnail rounded bg-light d-flex justify-content-center">
376 <Icon icon="external-link" classes="d-flex align-items-center" />
384 className="text-body"
385 to={`/post/${post.id}`}
386 title={I18NextService.i18n.t("comments")}
388 <div className="thumbnail rounded bg-light d-flex justify-content-center">
389 <Icon icon="message-square" classes="d-flex align-items-center" />
397 const post_view = this.postView;
399 <span className="small">
400 <PersonListing person={post_view.creator} muted={true} />
401 {this.creatorIsMod_ && (
402 <span className="mx-1 badge text-bg-light">
403 {I18NextService.i18n.t("mod")}
406 {this.creatorIsAdmin_ && (
407 <span className="mx-1 badge text-bg-light">
408 {I18NextService.i18n.t("admin")}
411 {post_view.creator.bot_account && (
412 <span className="mx-1 badge text-bg-light">
413 {I18NextService.i18n.t("bot_account").toLowerCase()}
416 {this.props.showCommunity && (
419 {I18NextService.i18n.t("to")}{" "}
420 <CommunityLink community={post_view.community} />
423 {post_view.post.language_id !== 0 && (
424 <span className="mx-1 badge text-bg-light">
426 this.props.allLanguages.find(
427 lang => lang.id === post_view.post.language_id
434 published={post_view.post.published}
435 updated={post_view.post.updated}
442 const post = this.postView.post;
445 className={`d-inline ${
446 !post.featured_community && !post.featured_local
450 to={`/post/${post.id}`}
451 title={I18NextService.i18n.t("comments")}
455 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
462 const post = this.postView.post;
463 const url = post.url;
467 <div className="post-title overflow-hidden">
468 <h5 className="d-inline">
469 {url && this.props.showBody ? (
472 !post.featured_community && !post.featured_local
479 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
487 <small className="ms-2 badge text-bg-secondary">
488 {I18NextService.i18n.t("removed")}
494 className="unselectable pointer ms-2 text-muted fst-italic"
495 data-tippy-content={I18NextService.i18n.t("deleted")}
497 <Icon icon="trash" classes="icon-inline text-danger" />
503 className="unselectable pointer ms-2 text-muted fst-italic"
504 data-tippy-content={I18NextService.i18n.t("locked")}
506 <Icon icon="lock" classes="icon-inline text-danger" />
510 {post.featured_community && (
512 className="unselectable pointer ms-2 text-muted fst-italic"
513 data-tippy-content={I18NextService.i18n.t(
514 "featured_in_community"
516 aria-label={I18NextService.i18n.t("featured_in_community")}
518 <Icon icon="pin" classes="icon-inline text-primary" />
522 {post.featured_local && (
524 className="unselectable pointer ms-2 text-muted fst-italic"
525 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
526 aria-label={I18NextService.i18n.t("featured_in_local")}
528 <Icon icon="pin" classes="icon-inline text-secondary" />
533 <small className="ms-2 badge text-bg-danger">
534 {I18NextService.i18n.t("nsfw")}
538 {url && this.urlLine()}
544 const post = this.postView.post;
545 const url = post.url;
548 <p className="small m-0">
549 {url && !(hostname(url) === getExternalHost()) && (
551 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
564 const dupes = this.props.crossPosts;
565 return dupes && dupes.length > 0 ? (
566 <ul className="list-inline mb-1 small text-muted">
568 <li className="list-inline-item me-2">
569 {I18NextService.i18n.t("cross_posted_to")}
572 <li key={pv.post.id} className="list-inline-item me-2">
573 <Link to={`/post/${pv.post.id}`}>
576 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
587 commentsLine(mobile = false) {
588 const post = this.postView.post;
591 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
592 {this.commentsButton}
595 className="btn btn-sm btn-animate text-muted py-0"
596 onClick={linkEvent(this, this.handleShare)}
599 <Icon icon="share" inline />
604 className="btn btn-sm btn-animate text-muted py-0"
605 title={I18NextService.i18n.t("link")}
608 <Icon icon="fedilink" inline />
611 {mobile && !this.props.viewOnly && (
613 voteContentType={VoteContentType.Post}
614 id={this.postView.post.id}
615 onVote={this.props.onPostVote}
616 enableDownvotes={this.props.enableDownvotes}
617 counts={this.postView.counts}
618 my_vote={this.postView.my_vote}
621 {UserService.Instance.myUserInfo &&
622 !this.props.viewOnly &&
628 showPreviewButton() {
629 const post_view = this.postView;
630 const body = post_view.post.body;
634 className="btn btn-sm btn-animate text-muted py-0"
635 data-tippy-content={body && mdNoImages.render(body)}
636 data-tippy-allowHtml={true}
637 onClick={linkEvent(this, this.handleShowBody)}
641 classes={classNames("icon-inline me-1", {
642 "text-success": this.state.showBody,
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}
661 * If there is a URL, or if the post has a body and we were told not to
662 * show the body, show the MetadataCard/body toggle.
664 {(post.url || (post.body && !this.props.showBody)) &&
665 this.showPreviewButton()}
667 {this.showBody && post_view.post.body && this.viewSourceButton}
669 <div className="dropdown">
671 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
672 onClick={linkEvent(this, this.handleShowAdvanced)}
673 data-tippy-content={I18NextService.i18n.t("more")}
674 data-bs-toggle="dropdown"
675 aria-expanded="false"
676 aria-controls={`advancedButtonsDropdown${post.id}`}
677 aria-label={I18NextService.i18n.t("more")}
679 <Icon icon="more-vertical" inline />
683 className="dropdown-menu"
684 id={`advancedButtonsDropdown${post.id}`}
688 <li>{this.reportButton}</li>
689 <li>{this.blockButton}</li>
693 <li>{this.editButton}</li>
694 <li>{this.deleteButton}</li>
698 {/* Any mod can do these, not limited to hierarchy*/}
699 {(amMod(this.props.moderators) || amAdmin()) && (
702 <hr className="dropdown-divider" />
704 <li>{this.lockButton}</li>
705 {this.featureButtons}
709 {(this.canMod_ || this.canAdmin_) && (
710 <li>{this.modRemoveButton}</li>
718 get commentsButton() {
719 const post_view = this.postView;
720 const title = I18NextService.i18n.t("number_of_comments", {
721 count: Number(post_view.counts.comments),
722 formattedCount: Number(post_view.counts.comments),
727 className="btn btn-link btn-sm text-muted ps-0"
729 to={`/post/${post_view.post.id}?scrollToComments=true`}
730 data-tippy-content={title}
732 <Icon icon="message-square" classes="me-1" inline />
733 {post_view.counts.comments}
734 {this.unreadCount && (
737 <span className="fst-italic">
738 ({this.unreadCount} {I18NextService.i18n.t("new")})
746 get unreadCount(): number | undefined {
747 const pv = this.postView;
748 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
750 : pv.unread_comments;
754 const saved = this.postView.saved;
756 ? I18NextService.i18n.t("unsave")
757 : I18NextService.i18n.t("save");
760 className="btn btn-sm btn-animate text-muted py-0"
761 onClick={linkEvent(this, this.handleSavePostClick)}
762 data-tippy-content={label}
765 {this.state.saveLoading ? (
770 classes={classNames({ "text-warning": saved })}
778 get crossPostButton() {
781 className="btn btn-sm btn-animate text-muted py-0"
783 /* Empty string properties are required to satisfy type*/
784 pathname: "/create_post",
785 state: { ...this.crossPostParams },
790 title={I18NextService.i18n.t("cross_post")}
791 data-tippy-content={I18NextService.i18n.t("cross_post")}
792 aria-label={I18NextService.i18n.t("cross_post")}
794 <Icon icon="copy" inline />
802 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
803 onClick={linkEvent(this, this.handleShowReportDialog)}
804 aria-label={I18NextService.i18n.t("show_report_dialog")}
806 <Icon classes="me-1" icon="flag" inline />
807 {I18NextService.i18n.t("create_report")}
815 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
816 onClick={linkEvent(this, this.handleBlockPersonClick)}
817 aria-label={I18NextService.i18n.t("block_user")}
819 {this.state.blockLoading ? (
822 <Icon classes="me-1" icon="slash" inline />
824 {I18NextService.i18n.t("block_user")}
832 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
833 onClick={linkEvent(this, this.handleEditClick)}
834 aria-label={I18NextService.i18n.t("edit")}
836 <Icon classes="me-1" icon="edit" inline />
837 {I18NextService.i18n.t("edit")}
843 const deleted = this.postView.post.deleted;
844 const label = !deleted
845 ? I18NextService.i18n.t("delete")
846 : I18NextService.i18n.t("restore");
849 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
850 onClick={linkEvent(this, this.handleDeleteClick)}
852 {this.state.deleteLoading ? (
858 classes={classNames("me-1", { "text-danger": deleted })}
868 get viewSourceButton() {
871 className="btn btn-sm btn-animate text-muted py-0"
872 onClick={linkEvent(this, this.handleViewSource)}
873 data-tippy-content={I18NextService.i18n.t("view_source")}
874 aria-label={I18NextService.i18n.t("view_source")}
878 classes={classNames({ "text-success": this.state.viewSource })}
886 const locked = this.postView.post.locked;
888 ? I18NextService.i18n.t("unlock")
889 : I18NextService.i18n.t("lock");
892 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
893 onClick={linkEvent(this, this.handleModLock)}
896 {this.state.lockLoading ? (
902 classes={classNames("me-1", { "text-danger": locked })}
905 {capitalizeFirstLetter(label)}
912 get featureButtons() {
913 const featuredCommunity = this.postView.post.featured_community;
914 const labelCommunity = featuredCommunity
915 ? I18NextService.i18n.t("unfeature_from_community")
916 : I18NextService.i18n.t("feature_in_community");
918 const featuredLocal = this.postView.post.featured_local;
919 const labelLocal = featuredLocal
920 ? I18NextService.i18n.t("unfeature_from_local")
921 : I18NextService.i18n.t("feature_in_local");
926 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
927 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
928 data-tippy-content={labelCommunity}
929 aria-label={labelCommunity}
931 {this.state.featureCommunityLoading ? (
937 classes={classNames("me-1", {
938 "text-success": featuredCommunity,
942 {I18NextService.i18n.t("community")}
950 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
951 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
952 data-tippy-content={labelLocal}
953 aria-label={labelLocal}
955 {this.state.featureLocalLoading ? (
961 classes={classNames("me-1", {
962 "text-success": featuredLocal,
966 {I18NextService.i18n.t("local")}
976 get modBanFromCommunityButton() {
979 className="btn btn-link btn-animate text-muted py-0"
980 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
981 aria-label={I18NextService.i18n.t("ban_from_community")}
983 {I18NextService.i18n.t("ban_from_community")}
988 get modUnbanFromCommunityButton() {
991 className="btn btn-link btn-animate text-muted py-0"
992 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
993 aria-label={I18NextService.i18n.t("unban")}
995 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1000 get addModToCommunityButton() {
1003 className="btn btn-link btn-animate text-muted py-0"
1004 onClick={linkEvent(this, this.handleAddModToCommunity)}
1007 ? I18NextService.i18n.t("remove_as_mod")
1008 : I18NextService.i18n.t("appoint_as_mod")
1011 {this.state.addModLoading ? (
1013 ) : this.creatorIsMod_ ? (
1014 I18NextService.i18n.t("remove_as_mod")
1016 I18NextService.i18n.t("appoint_as_mod")
1022 get modBanButton() {
1025 className="btn btn-link btn-animate text-muted py-0"
1026 onClick={linkEvent(this, this.handleModBanShow)}
1027 aria-label={I18NextService.i18n.t("ban_from_site")}
1029 {I18NextService.i18n.t("ban_from_site")}
1034 get modUnbanButton() {
1037 className="btn btn-link btn-animate text-muted py-0"
1038 onClick={linkEvent(this, this.handleModBanSubmit)}
1039 aria-label={I18NextService.i18n.t("unban_from_site")}
1041 {this.state.banLoading ? (
1044 I18NextService.i18n.t("unban_from_site")
1050 get purgePersonButton() {
1053 className="btn btn-link btn-animate text-muted py-0"
1054 onClick={linkEvent(this, this.handlePurgePersonShow)}
1055 aria-label={I18NextService.i18n.t("purge_user")}
1057 {I18NextService.i18n.t("purge_user")}
1062 get purgePostButton() {
1065 className="btn btn-link btn-animate text-muted py-0"
1066 onClick={linkEvent(this, this.handlePurgePostShow)}
1067 aria-label={I18NextService.i18n.t("purge_post")}
1069 {I18NextService.i18n.t("purge_post")}
1074 get toggleAdminButton() {
1077 className="btn btn-link btn-animate text-muted py-0"
1078 onClick={linkEvent(this, this.handleAddAdmin)}
1080 {this.state.addAdminLoading ? (
1082 ) : this.creatorIsAdmin_ ? (
1083 I18NextService.i18n.t("remove_as_admin")
1085 I18NextService.i18n.t("appoint_as_admin")
1091 get modRemoveButton() {
1092 const removed = this.postView.post.removed;
1095 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1098 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1101 {/* TODO: Find an icon for this. */}
1102 {this.state.removeLoading ? (
1105 I18NextService.i18n.t("remove")
1107 I18NextService.i18n.t("restore")
1114 * Mod/Admin actions to be taken against the author.
1118 const post_view = this.postView;
1120 this.state.showAdvanced && (
1121 <div className="mt-3">
1124 {!this.creatorIsMod_ &&
1125 (!post_view.creator_banned_from_community
1126 ? this.modBanFromCommunityButton
1127 : this.modUnbanFromCommunityButton)}
1128 {!post_view.creator_banned_from_community &&
1129 this.addModToCommunityButton}
1133 {/* Community creators and admins can transfer community to another mod */}
1134 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1136 this.creatorIsMod_ &&
1137 (!this.state.showConfirmTransferCommunity ? (
1139 className="btn btn-link btn-animate text-muted py-0"
1142 this.handleShowConfirmTransferCommunity
1144 aria-label={I18NextService.i18n.t("transfer_community")}
1146 {I18NextService.i18n.t("transfer_community")}
1151 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1152 aria-label={I18NextService.i18n.t("are_you_sure")}
1154 {I18NextService.i18n.t("are_you_sure")}
1157 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1158 aria-label={I18NextService.i18n.t("yes")}
1159 onClick={linkEvent(this, this.handleTransferCommunity)}
1161 {this.state.transferLoading ? (
1164 I18NextService.i18n.t("yes")
1168 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1171 this.handleCancelShowConfirmTransferCommunity
1173 aria-label={I18NextService.i18n.t("no")}
1175 {I18NextService.i18n.t("no")}
1179 {/* Admins can ban from all, and appoint other admins */}
1180 {this.canAdmin_ && (
1182 {!this.creatorIsAdmin_ && (
1184 {!isBanned(post_view.creator)
1186 : this.modUnbanButton}
1187 {this.purgePersonButton}
1188 {this.purgePostButton}
1191 {!isBanned(post_view.creator) &&
1192 post_view.creator.local &&
1193 this.toggleAdminButton}
1201 removeAndBanDialogs() {
1202 const post = this.postView;
1203 const purgeTypeText =
1204 this.state.purgeType == PurgeType.Post
1205 ? I18NextService.i18n.t("purge_post")
1206 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1209 {this.state.showRemoveDialog && (
1211 className="form-inline"
1212 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1215 className="visually-hidden"
1216 htmlFor="post-listing-remove-reason"
1218 {I18NextService.i18n.t("reason")}
1222 id="post-listing-remove-reason"
1223 className="form-control me-2"
1224 placeholder={I18NextService.i18n.t("reason")}
1225 value={this.state.removeReason}
1226 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1230 className="btn btn-secondary"
1231 aria-label={I18NextService.i18n.t("remove_post")}
1233 {this.state.removeLoading ? (
1236 I18NextService.i18n.t("remove_post")
1241 {this.state.showBanDialog && (
1242 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1243 <div className="mb-3 row col-12">
1245 className="col-form-label"
1246 htmlFor="post-listing-ban-reason"
1248 {I18NextService.i18n.t("reason")}
1252 id="post-listing-ban-reason"
1253 className="form-control me-2"
1254 placeholder={I18NextService.i18n.t("reason")}
1255 value={this.state.banReason}
1256 onInput={linkEvent(this, this.handleModBanReasonChange)}
1258 <label className="col-form-label" htmlFor="mod-ban-expires">
1259 {I18NextService.i18n.t("expires")}
1263 id="mod-ban-expires"
1264 className="form-control me-2"
1265 placeholder={I18NextService.i18n.t("number_of_days")}
1266 value={this.state.banExpireDays}
1267 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1269 <div className="input-group mb-3">
1270 <div className="form-check">
1272 className="form-check-input"
1273 id="mod-ban-remove-data"
1275 checked={this.state.removeData}
1276 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1279 className="form-check-label"
1280 htmlFor="mod-ban-remove-data"
1281 title={I18NextService.i18n.t("remove_content_more")}
1283 {I18NextService.i18n.t("remove_content")}
1288 {/* TODO hold off on expires until later */}
1289 {/* <div class="mb-3 row"> */}
1290 {/* <label class="col-form-label">Expires</label> */}
1291 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1293 <div className="mb-3 row">
1296 className="btn btn-secondary"
1297 aria-label={I18NextService.i18n.t("ban")}
1299 {this.state.banLoading ? (
1303 {I18NextService.i18n.t("ban")} {post.creator.name}
1310 {this.state.showReportDialog && (
1312 className="form-inline"
1313 onSubmit={linkEvent(this, this.handleReportSubmit)}
1315 <label className="visually-hidden" htmlFor="post-report-reason">
1316 {I18NextService.i18n.t("reason")}
1320 id="post-report-reason"
1321 className="form-control me-2"
1322 placeholder={I18NextService.i18n.t("reason")}
1324 value={this.state.reportReason}
1325 onInput={linkEvent(this, this.handleReportReasonChange)}
1329 className="btn btn-secondary"
1330 aria-label={I18NextService.i18n.t("create_report")}
1332 {this.state.reportLoading ? (
1335 I18NextService.i18n.t("create_report")
1340 {this.state.showPurgeDialog && (
1342 className="form-inline"
1343 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1346 <label className="visually-hidden" htmlFor="purge-reason">
1347 {I18NextService.i18n.t("reason")}
1352 className="form-control me-2"
1353 placeholder={I18NextService.i18n.t("reason")}
1354 value={this.state.purgeReason}
1355 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1357 {this.state.purgeLoading ? (
1362 className="btn btn-secondary"
1363 aria-label={purgeTypeText}
1365 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1375 const post = this.postView.post;
1376 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1377 <div className="row">
1378 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1379 {this.postTitleLine()}
1381 <div className="col-4">
1382 {/* Post thumbnail */}
1383 {!this.state.imageExpanded && this.thumbnail()}
1387 this.postTitleLine()
1392 const { body, id } = this.postView.post;
1394 return !this.showBody && body ? (
1395 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1396 <div className="md-div mb-1 preview-lines">{body}</div>
1406 {/* The mobile view*/}
1407 <div className="d-block d-sm-none">
1408 <article className="row post-container">
1409 <div className="col-12">
1410 {this.createdLine()}
1412 {/* If it has a thumbnail, do a right aligned thumbnail */}
1413 {this.mobileThumbnail()}
1415 {/* Show a preview of the post body */}
1416 {this.showBodyPreview()}
1418 {this.commentsLine(true)}
1419 {this.userActionsLine()}
1420 {this.duplicatesLine()}
1421 {this.removeAndBanDialogs()}
1426 {/* The larger view*/}
1427 <div className="d-none d-sm-block">
1428 <article className="row post-container">
1429 {!this.props.viewOnly && (
1431 voteContentType={VoteContentType.Post}
1432 id={this.postView.post.id}
1433 onVote={this.props.onPostVote}
1434 enableDownvotes={this.props.enableDownvotes}
1435 counts={this.postView.counts}
1436 my_vote={this.postView.my_vote}
1439 <div className="col-sm-2 pe-0 post-media">
1440 <div className="">{this.thumbnail()}</div>
1442 <div className="col-12 col-sm-9">
1443 <div className="row">
1444 <div className="col-12">
1445 {this.postTitleLine()}
1446 {this.createdLine()}
1447 {this.showBodyPreview()}
1448 {this.commentsLine()}
1449 {this.duplicatesLine()}
1450 {this.userActionsLine()}
1451 {this.removeAndBanDialogs()}
1461 private get myPost(): boolean {
1463 this.postView.creator.id ==
1464 UserService.Instance.myUserInfo?.local_user_view.person.id
1467 handleEditClick(i: PostListing) {
1468 i.setState({ showEdit: true });
1471 handleEditCancel() {
1472 this.setState({ showEdit: false });
1475 // The actual editing is done in the receive for post
1476 handleEditPost(form: EditPost) {
1477 this.setState({ showEdit: false });
1478 this.props.onPostEdit(form);
1481 handleShare(i: PostListing) {
1482 const { name, body, id } = i.props.post_view.post;
1485 text: body?.slice(0, 50),
1486 url: `${getHttpBase()}/post/${id}`,
1490 handleShowReportDialog(i: PostListing) {
1491 i.setState({ showReportDialog: !i.state.showReportDialog });
1494 handleReportReasonChange(i: PostListing, event: any) {
1495 i.setState({ reportReason: event.target.value });
1498 handleReportSubmit(i: PostListing, event: any) {
1499 event.preventDefault();
1500 i.setState({ reportLoading: true });
1501 i.props.onPostReport({
1502 post_id: i.postView.post.id,
1503 reason: i.state.reportReason ?? "",
1504 auth: myAuthRequired(),
1508 handleBlockPersonClick(i: PostListing) {
1509 i.setState({ blockLoading: true });
1510 i.props.onBlockPerson({
1511 person_id: i.postView.creator.id,
1513 auth: myAuthRequired(),
1517 handleDeleteClick(i: PostListing) {
1518 i.setState({ deleteLoading: true });
1519 i.props.onDeletePost({
1520 post_id: i.postView.post.id,
1521 deleted: !i.postView.post.deleted,
1522 auth: myAuthRequired(),
1526 handleSavePostClick(i: PostListing) {
1527 i.setState({ saveLoading: true });
1528 i.props.onSavePost({
1529 post_id: i.postView.post.id,
1530 save: !i.postView.saved,
1531 auth: myAuthRequired(),
1535 get crossPostParams(): PostFormParams {
1536 const queryParams: PostFormParams = {};
1537 const { name, url } = this.postView.post;
1539 queryParams.name = name;
1542 queryParams.url = url;
1545 const crossPostBody = this.crossPostBody();
1546 if (crossPostBody) {
1547 queryParams.body = crossPostBody;
1553 crossPostBody(): string | undefined {
1554 const post = this.postView.post;
1555 const body = post.body;
1558 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1560 }\n\n${body.replace(/^/gm, "> ")}`
1564 get showBody(): boolean {
1565 return this.props.showBody || this.state.showBody;
1568 handleModRemoveShow(i: PostListing) {
1570 showRemoveDialog: !i.state.showRemoveDialog,
1571 showBanDialog: false,
1575 handleModRemoveReasonChange(i: PostListing, event: any) {
1576 i.setState({ removeReason: event.target.value });
1579 handleModRemoveDataChange(i: PostListing, event: any) {
1580 i.setState({ removeData: event.target.checked });
1583 handleModRemoveSubmit(i: PostListing, event: any) {
1584 event.preventDefault();
1585 i.setState({ removeLoading: true });
1586 i.props.onRemovePost({
1587 post_id: i.postView.post.id,
1588 removed: !i.postView.post.removed,
1589 auth: myAuthRequired(),
1593 handleModLock(i: PostListing) {
1594 i.setState({ lockLoading: true });
1595 i.props.onLockPost({
1596 post_id: i.postView.post.id,
1597 locked: !i.postView.post.locked,
1598 auth: myAuthRequired(),
1602 handleModFeaturePostLocal(i: PostListing) {
1603 i.setState({ featureLocalLoading: true });
1604 i.props.onFeaturePost({
1605 post_id: i.postView.post.id,
1606 featured: !i.postView.post.featured_local,
1607 feature_type: "Local",
1608 auth: myAuthRequired(),
1612 handleModFeaturePostCommunity(i: PostListing) {
1613 i.setState({ featureCommunityLoading: true });
1614 i.props.onFeaturePost({
1615 post_id: i.postView.post.id,
1616 featured: !i.postView.post.featured_community,
1617 feature_type: "Community",
1618 auth: myAuthRequired(),
1622 handleModBanFromCommunityShow(i: PostListing) {
1624 showBanDialog: true,
1625 banType: BanType.Community,
1626 showRemoveDialog: false,
1630 handleModBanShow(i: PostListing) {
1632 showBanDialog: true,
1633 banType: BanType.Site,
1634 showRemoveDialog: false,
1638 handlePurgePersonShow(i: PostListing) {
1640 showPurgeDialog: true,
1641 purgeType: PurgeType.Person,
1642 showRemoveDialog: false,
1646 handlePurgePostShow(i: PostListing) {
1648 showPurgeDialog: true,
1649 purgeType: PurgeType.Post,
1650 showRemoveDialog: false,
1654 handlePurgeReasonChange(i: PostListing, event: any) {
1655 i.setState({ purgeReason: event.target.value });
1658 handlePurgeSubmit(i: PostListing, event: any) {
1659 event.preventDefault();
1660 i.setState({ purgeLoading: true });
1661 if (i.state.purgeType == PurgeType.Person) {
1662 i.props.onPurgePerson({
1663 person_id: i.postView.creator.id,
1664 reason: i.state.purgeReason,
1665 auth: myAuthRequired(),
1667 } else if (i.state.purgeType == PurgeType.Post) {
1668 i.props.onPurgePost({
1669 post_id: i.postView.post.id,
1670 reason: i.state.purgeReason,
1671 auth: myAuthRequired(),
1676 handleModBanReasonChange(i: PostListing, event: any) {
1677 i.setState({ banReason: event.target.value });
1680 handleModBanExpireDaysChange(i: PostListing, event: any) {
1681 i.setState({ banExpireDays: event.target.value });
1684 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1685 i.setState({ banType: BanType.Community });
1686 i.handleModBanBothSubmit(i, event);
1689 handleModBanSubmit(i: PostListing, event: any) {
1690 i.setState({ banType: BanType.Site });
1691 i.handleModBanBothSubmit(i, event);
1694 handleModBanBothSubmit(i: PostListing, event: any) {
1695 event.preventDefault();
1696 i.setState({ banLoading: true });
1698 const ban = !i.props.post_view.creator_banned_from_community;
1699 // If its an unban, restore all their data
1701 i.setState({ removeData: false });
1703 const person_id = i.props.post_view.creator.id;
1704 const remove_data = i.state.removeData;
1705 const reason = i.state.banReason;
1706 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1708 if (i.state.banType == BanType.Community) {
1709 const community_id = i.postView.community.id;
1710 i.props.onBanPersonFromCommunity({
1717 auth: myAuthRequired(),
1720 i.props.onBanPerson({
1726 auth: myAuthRequired(),
1731 handleAddModToCommunity(i: PostListing) {
1732 i.setState({ addModLoading: true });
1733 i.props.onAddModToCommunity({
1734 community_id: i.postView.community.id,
1735 person_id: i.postView.creator.id,
1736 added: !i.creatorIsMod_,
1737 auth: myAuthRequired(),
1741 handleAddAdmin(i: PostListing) {
1742 i.setState({ addAdminLoading: true });
1743 i.props.onAddAdmin({
1744 person_id: i.postView.creator.id,
1745 added: !i.creatorIsAdmin_,
1746 auth: myAuthRequired(),
1750 handleShowConfirmTransferCommunity(i: PostListing) {
1751 i.setState({ showConfirmTransferCommunity: true });
1754 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1755 i.setState({ showConfirmTransferCommunity: false });
1758 handleTransferCommunity(i: PostListing) {
1759 i.setState({ transferLoading: true });
1760 i.props.onTransferCommunity({
1761 community_id: i.postView.community.id,
1762 person_id: i.postView.creator.id,
1763 auth: myAuthRequired(),
1767 handleShowConfirmTransferSite(i: PostListing) {
1768 i.setState({ showConfirmTransferSite: true });
1771 handleCancelShowConfirmTransferSite(i: PostListing) {
1772 i.setState({ showConfirmTransferSite: false });
1775 handleImageExpandClick(i: PostListing, event: any) {
1776 event.preventDefault();
1777 i.setState({ imageExpanded: !i.state.imageExpanded });
1781 handleViewSource(i: PostListing) {
1782 i.setState({ viewSource: !i.state.viewSource });
1785 handleShowAdvanced(i: PostListing) {
1786 i.setState({ showAdvanced: !i.state.showAdvanced });
1790 handleShowMoreMobile(i: PostListing) {
1792 showMoreMobile: !i.state.showMoreMobile,
1793 showAdvanced: !i.state.showAdvanced,
1798 handleShowBody(i: PostListing) {
1799 i.setState({ showBody: !i.state.showBody });
1803 get pointsTippy(): string {
1804 const points = I18NextService.i18n.t("number_of_points", {
1805 count: Number(this.postView.counts.score),
1806 formattedCount: Number(this.postView.counts.score),
1809 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1810 count: Number(this.postView.counts.upvotes),
1811 formattedCount: Number(this.postView.counts.upvotes),
1814 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1815 count: Number(this.postView.counts.downvotes),
1816 formattedCount: Number(this.postView.counts.downvotes),
1819 return `${points} • ${upvotes} • ${downvotes}`;
1822 get canModOnSelf_(): boolean {
1824 this.postView.creator.id,
1825 this.props.moderators,
1832 get canMod_(): boolean {
1834 this.postView.creator.id,
1835 this.props.moderators,
1840 get canAdmin_(): boolean {
1841 return canAdmin(this.postView.creator.id, this.props.admins);
1844 get creatorIsMod_(): boolean {
1845 return isMod(this.postView.creator.id, this.props.moderators);
1848 get creatorIsAdmin_(): boolean {
1849 return isAdmin(this.postView.creator.id, this.props.admins);