1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
10 CommunityModeratorView,
25 } from "lemmy-js-client";
26 import { getExternalHost, getHttpBase } from "../../env";
27 import { i18n } from "../../i18next";
28 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
29 import { UserService } from "../../services";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { CommunityLink } from "../community/community-link";
59 import { PersonListing } from "../person/person-listing";
60 import { MetadataCard } from "./metadata-card";
61 import { PostForm } from "./post-form";
63 interface PostListingState {
65 showRemoveDialog: boolean;
66 showPurgeDialog: boolean;
68 purgeType?: PurgeType;
69 purgeLoading: boolean;
70 removeReason?: string;
71 showBanDialog: boolean;
73 banExpireDays?: number;
76 showConfirmTransferSite: boolean;
77 showConfirmTransferCommunity: boolean;
78 imageExpanded: boolean;
80 showAdvanced: boolean;
81 showMoreMobile: boolean;
83 showReportDialog: boolean;
84 reportReason?: string;
85 upvoteLoading: boolean;
86 downvoteLoading: boolean;
87 reportLoading: boolean;
88 blockLoading: boolean;
90 deleteLoading: boolean;
91 removeLoading: boolean;
93 featureCommunityLoading: boolean;
94 featureLocalLoading: boolean;
96 addModLoading: boolean;
97 addAdminLoading: boolean;
98 transferLoading: boolean;
101 interface PostListingProps {
103 crossPosts?: PostView[];
104 moderators?: CommunityModeratorView[];
105 admins?: PersonView[];
106 allLanguages: Language[];
107 siteLanguages: number[];
108 showCommunity?: boolean;
111 enableDownvotes?: boolean;
112 enableNsfw?: boolean;
114 onPostEdit(form: EditPost): void;
115 onPostVote(form: CreatePostLike): void;
116 onPostReport(form: CreatePostReport): void;
117 onBlockPerson(form: BlockPerson): void;
118 onLockPost(form: LockPost): void;
119 onDeletePost(form: DeletePost): void;
120 onRemovePost(form: RemovePost): void;
121 onSavePost(form: SavePost): void;
122 onFeaturePost(form: FeaturePost): void;
123 onPurgePerson(form: PurgePerson): void;
124 onPurgePost(form: PurgePost): void;
125 onBanPersonFromCommunity(form: BanFromCommunity): void;
126 onBanPerson(form: BanPerson): void;
127 onAddModToCommunity(form: AddModToCommunity): void;
128 onAddAdmin(form: AddAdmin): void;
129 onTransferCommunity(form: TransferCommunity): void;
132 export class PostListing extends Component<PostListingProps, PostListingState> {
133 state: PostListingState = {
135 showRemoveDialog: false,
136 showPurgeDialog: false,
137 purgeType: PurgeType.Person,
138 showBanDialog: false,
139 banType: BanType.Community,
141 showConfirmTransferSite: false,
142 showConfirmTransferCommunity: false,
143 imageExpanded: false,
146 showMoreMobile: false,
148 showReportDialog: false,
149 upvoteLoading: false,
150 downvoteLoading: 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) {
176 upvoteLoading: false,
177 downvoteLoading: false,
179 reportLoading: false,
182 deleteLoading: false,
183 removeLoading: false,
185 featureCommunityLoading: false,
186 featureLocalLoading: false,
188 addModLoading: false,
189 addAdminLoading: false,
190 transferLoading: false,
191 imageExpanded: false,
196 get postView(): PostView {
197 return this.props.post_view;
201 const post = this.postView.post;
204 <div className="post-listing">
205 {!this.state.showEdit ? (
208 {this.state.imageExpanded && !this.props.hideImage && this.img}
209 {post.url && this.state.showBody && post.embed_title && (
210 <MetadataCard post={post} />
212 {this.showBody && this.body()}
216 post_view={this.postView}
217 crossPosts={this.props.crossPosts}
218 onEdit={this.handleEditPost}
219 onCancel={this.handleEditCancel}
220 enableNsfw={this.props.enableNsfw}
221 enableDownvotes={this.props.enableDownvotes}
222 allLanguages={this.props.allLanguages}
223 siteLanguages={this.props.siteLanguages}
231 const body = this.postView.post.body;
233 <div className="col-12 card my-2 p-2">
234 {this.state.viewSource ? (
237 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
246 return this.imageSrc ? (
248 <div className="offset-sm-3 my-2 d-none d-sm-block">
249 <a href={this.imageSrc} className="d-inline-block">
250 <PictrsImage src={this.imageSrc} />
253 <div className="my-2 d-block d-sm-none">
255 className="d-inline-block"
256 onClick={linkEvent(this, this.handleImageExpandClick)}
258 <PictrsImage src={this.imageSrc} />
267 imgThumb(src: string) {
268 const post_view = this.postView;
274 nsfw={post_view.post.nsfw || post_view.community.nsfw}
279 get imageSrc(): string | undefined {
280 const post = this.postView.post;
281 const url = post.url;
282 const thumbnail = post.thumbnail_url;
284 if (url && isImage(url)) {
285 if (url.includes("pictrs")) {
287 } else if (thumbnail) {
292 } else if (thumbnail) {
300 const post = this.postView.post;
301 const url = post.url;
302 const thumbnail = post.thumbnail_url;
304 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
308 className="text-body d-inline-block position-relative mb-2"
309 data-tippy-content={i18n.t("expand_here")}
310 onClick={linkEvent(this, this.handleImageExpandClick)}
311 aria-label={i18n.t("expand_here")}
313 {this.imgThumb(this.imageSrc)}
314 <Icon icon="image" classes="mini-overlay" />
317 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
320 className="text-body d-inline-block position-relative mb-2"
325 {this.imgThumb(this.imageSrc)}
326 <Icon icon="external-link" classes="mini-overlay" />
330 if (!this.props.hideImage && isVideo(url)) {
332 <div className="embed-responsive embed-responsive-16by9">
338 className="embed-responsive-item"
340 <source src={url} type="video/mp4" />
346 <a className="text-body" href={url} title={url} rel={relTags}>
347 <div className="thumbnail rounded bg-light d-flex justify-content-center">
348 <Icon icon="external-link" classes="d-flex align-items-center" />
356 className="text-body"
357 to={`/post/${post.id}`}
358 title={i18n.t("comments")}
360 <div className="thumbnail rounded bg-light d-flex justify-content-center">
361 <Icon icon="message-square" classes="d-flex align-items-center" />
369 const post_view = this.postView;
370 const url = post_view.post.url;
371 const body = post_view.post.body;
373 <ul className="list-inline mb-1 text-muted small">
374 <li className="list-inline-item">
375 <PersonListing person={post_view.creator} />
377 {this.creatorIsMod_ && (
378 <span className="mx-1 badge">{i18n.t("mod")}</span>
380 {this.creatorIsAdmin_ && (
381 <span className="mx-1 badge">{i18n.t("admin")}</span>
383 {post_view.creator.bot_account && (
384 <span className="mx-1 badge">
385 {i18n.t("bot_account").toLowerCase()}
388 {this.props.showCommunity && (
390 <span className="mx-1"> {i18n.t("to")} </span>
391 <CommunityLink community={post_view.community} />
395 {post_view.post.language_id !== 0 && (
396 <span className="mx-1 badge">
398 this.props.allLanguages.find(
399 lang => lang.id === post_view.post.language_id
404 <li className="list-inline-item">•</li>
405 {url && !(hostname(url) === getExternalHost()) && (
407 <li className="list-inline-item">
409 className="text-muted font-italic"
417 <li className="list-inline-item">•</li>
420 <li className="list-inline-item">
423 published={post_view.post.published}
424 updated={post_view.post.updated}
430 <li className="list-inline-item">•</li>
431 <li className="list-inline-item">
433 className="text-muted btn btn-sm btn-link p-0"
434 data-tippy-content={mdNoImages.render(body)}
435 data-tippy-allowHtml={true}
436 onClick={linkEvent(this, this.handleShowBody)}
438 <Icon icon="book-open" classes="icon-inline mr-1" />
449 <div className={`vote-bar col-1 pr-0 small text-center`}>
451 className={`btn-animate btn btn-link p-0 ${
452 this.postView.my_vote == 1 ? "text-info" : "text-muted"
454 onClick={linkEvent(this, this.handleUpvote)}
455 data-tippy-content={i18n.t("upvote")}
456 aria-label={i18n.t("upvote")}
457 aria-pressed={this.postView.my_vote === 1}
459 {this.state.upvoteLoading ? (
462 <Icon icon="arrow-up1" classes="upvote" />
467 className={`unselectable pointer font-weight-bold text-muted px-1`}
468 data-tippy-content={this.pointsTippy}
470 {numToSI(this.postView.counts.score)}
473 <div className="p-1"></div>
475 {this.props.enableDownvotes && (
477 className={`btn-animate btn btn-link p-0 ${
478 this.postView.my_vote == -1 ? "text-danger" : "text-muted"
480 onClick={linkEvent(this, this.handleDownvote)}
481 data-tippy-content={i18n.t("downvote")}
482 aria-label={i18n.t("downvote")}
483 aria-pressed={this.postView.my_vote === -1}
485 {this.state.downvoteLoading ? (
488 <Icon icon="arrow-down1" classes="downvote" />
497 const post = this.postView.post;
500 className={`d-inline-block ${
501 !post.featured_community && !post.featured_local
505 to={`/post/${post.id}`}
506 title={i18n.t("comments")}
509 className="d-inline-block"
510 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
517 const post = this.postView.post;
518 const url = post.url;
521 <div className="post-title overflow-hidden">
524 this.props.showBody ? (
526 className={`d-inline-block ${
527 !post.featured_community && !post.featured_local
536 className="d-inline-block"
537 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
546 {(url && isImage(url)) ||
547 (post.thumbnail_url && (
549 className="btn btn-link text-monospace text-muted small d-inline-block"
550 data-tippy-content={i18n.t("expand_here")}
551 onClick={linkEvent(this, this.handleImageExpandClick)}
555 !this.state.imageExpanded ? "plus-square" : "minus-square"
557 classes="icon-inline"
562 <small className="ml-2 text-muted font-italic">
568 className="unselectable pointer ml-2 text-muted font-italic"
569 data-tippy-content={i18n.t("deleted")}
571 <Icon icon="trash" classes="icon-inline text-danger" />
576 className="unselectable pointer ml-2 text-muted font-italic"
577 data-tippy-content={i18n.t("locked")}
579 <Icon icon="lock" classes="icon-inline text-danger" />
582 {post.featured_community && (
584 className="unselectable pointer ml-2 text-muted font-italic"
585 data-tippy-content={i18n.t("featured")}
587 <Icon icon="pin" classes="icon-inline text-primary" />
590 {post.featured_local && (
592 className="unselectable pointer ml-2 text-muted font-italic"
593 data-tippy-content={i18n.t("featured")}
595 <Icon icon="pin" classes="icon-inline text-secondary" />
599 <small className="ml-2 text-muted font-italic">
609 const dupes = this.props.crossPosts;
610 return dupes && dupes.length > 0 ? (
611 <ul className="list-inline mb-1 small text-muted">
613 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
615 <li key={pv.post.id} className="list-inline-item mr-2">
616 <Link to={`/post/${pv.post.id}`}>
619 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
630 commentsLine(mobile = false) {
631 const post = this.postView.post;
634 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
635 {this.commentsButton}
638 className="btn btn-link"
639 onClick={linkEvent(this, this.handleShare)}
642 <Icon icon="share" inline />
647 className="btn btn-link btn-animate text-muted py-0"
648 title={i18n.t("link")}
651 <Icon icon="fedilink" inline />
654 {mobile && !this.props.viewOnly && this.mobileVotes}
655 {UserService.Instance.myUserInfo &&
656 !this.props.viewOnly &&
657 this.postActions(mobile)}
662 postActions(mobile = false) {
663 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
664 // Possible enhancement: Make each button a component.
665 const post_view = this.postView;
669 {this.crossPostButton}
670 {mobile && this.showMoreButton}
671 {(!mobile || this.state.showAdvanced) && (
679 {this.myPost && (this.showBody || this.state.showAdvanced) && (
687 {this.state.showAdvanced && (
689 {this.showBody && post_view.post.body && this.viewSourceButton}
690 {/* Any mod can do these, not limited to hierarchy*/}
691 {(amMod(this.props.moderators) || amAdmin()) && (
697 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
700 {!mobile && this.showMoreButton}
705 get commentsButton() {
706 const post_view = this.postView;
709 className="btn btn-link text-muted py-0 pl-0 text-muted"
710 title={i18n.t("number_of_comments", {
711 count: Number(post_view.counts.comments),
712 formattedCount: Number(post_view.counts.comments),
714 to={`/post/${post_view.post.id}?scrollToComments=true`}
716 <Icon icon="message-square" classes="mr-1" inline />
717 <span className="mr-2">
718 {i18n.t("number_of_comments", {
719 count: Number(post_view.counts.comments),
720 formattedCount: numToSI(post_view.counts.comments),
723 {this.unreadCount && (
724 <span className="small text-warning">
725 ({this.unreadCount} {i18n.t("new")})
732 get unreadCount(): number | undefined {
733 const pv = this.postView;
734 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
736 : pv.unread_comments;
741 const tippy = showScores()
742 ? { "data-tippy-content": this.pointsTippy }
748 className={`btn-animate btn py-0 px-1 ${
749 this.postView.my_vote === 1 ? "text-info" : "text-muted"
752 onClick={linkEvent(this, this.handleUpvote)}
753 aria-label={i18n.t("upvote")}
754 aria-pressed={this.postView.my_vote === 1}
756 {this.state.upvoteLoading ? (
760 <Icon icon="arrow-up1" classes="icon-inline small" />
762 <span className="ml-2">
763 {numToSI(this.postView.counts.upvotes)}
769 {this.props.enableDownvotes && (
771 className={`ml-2 btn-animate btn py-0 px-1 ${
772 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
774 onClick={linkEvent(this, this.handleDownvote)}
776 aria-label={i18n.t("downvote")}
777 aria-pressed={this.postView.my_vote === -1}
779 {this.state.downvoteLoading ? (
783 <Icon icon="arrow-down1" classes="icon-inline small" />
786 className={classNames("ml-2", {
787 invisible: this.postView.counts.downvotes === 0,
790 {numToSI(this.postView.counts.downvotes)}
803 const saved = this.postView.saved;
804 const label = saved ? i18n.t("unsave") : i18n.t("save");
807 className="btn btn-link btn-animate text-muted py-0"
808 onClick={linkEvent(this, this.handleSavePostClick)}
809 data-tippy-content={label}
812 {this.state.saveLoading ? (
817 classes={classNames({ "text-warning": saved })}
825 get crossPostButton() {
828 className="btn btn-link btn-animate text-muted py-0"
830 /* Empty string properties are required to satisfy type*/
831 pathname: "/create_post",
832 state: { ...this.crossPostParams },
837 title={i18n.t("cross_post")}
839 <Icon icon="copy" inline />
847 className="btn btn-link btn-animate text-muted py-0"
848 onClick={linkEvent(this, this.handleShowReportDialog)}
849 data-tippy-content={i18n.t("show_report_dialog")}
850 aria-label={i18n.t("show_report_dialog")}
852 <Icon icon="flag" inline />
860 className="btn btn-link btn-animate text-muted py-0"
861 onClick={linkEvent(this, this.handleBlockPersonClick)}
862 data-tippy-content={i18n.t("block_user")}
863 aria-label={i18n.t("block_user")}
865 {this.state.blockLoading ? <Spinner /> : <Icon icon="slash" inline />}
873 className="btn btn-link btn-animate text-muted py-0"
874 onClick={linkEvent(this, this.handleEditClick)}
875 data-tippy-content={i18n.t("edit")}
876 aria-label={i18n.t("edit")}
878 <Icon icon="edit" inline />
884 const deleted = this.postView.post.deleted;
885 const label = !deleted ? i18n.t("delete") : i18n.t("restore");
888 className="btn btn-link btn-animate text-muted py-0"
889 onClick={linkEvent(this, this.handleDeleteClick)}
890 data-tippy-content={label}
893 {this.state.deleteLoading ? (
898 classes={classNames({ "text-danger": deleted })}
906 get showMoreButton() {
909 className="btn btn-link btn-animate text-muted py-0"
910 onClick={linkEvent(this, this.handleShowAdvanced)}
911 data-tippy-content={i18n.t("more")}
912 aria-label={i18n.t("more")}
914 <Icon icon="more-vertical" inline />
919 get viewSourceButton() {
922 className="btn btn-link btn-animate text-muted py-0"
923 onClick={linkEvent(this, this.handleViewSource)}
924 data-tippy-content={i18n.t("view_source")}
925 aria-label={i18n.t("view_source")}
929 classes={classNames({ "text-success": this.state.viewSource })}
937 const locked = this.postView.post.locked;
938 const label = locked ? i18n.t("unlock") : i18n.t("lock");
941 className="btn btn-link btn-animate text-muted py-0"
942 onClick={linkEvent(this, this.handleModLock)}
943 data-tippy-content={label}
946 {this.state.lockLoading ? (
951 classes={classNames({ "text-danger": locked })}
959 get featureButton() {
960 const featuredCommunity = this.postView.post.featured_community;
961 const labelCommunity = featuredCommunity
962 ? i18n.t("unfeature_from_community")
963 : i18n.t("feature_in_community");
965 const featuredLocal = this.postView.post.featured_local;
966 const labelLocal = featuredLocal
967 ? i18n.t("unfeature_from_local")
968 : i18n.t("feature_in_local");
972 className="btn btn-link btn-animate text-muted py-0 pl-0"
973 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
974 data-tippy-content={labelCommunity}
975 aria-label={labelCommunity}
977 {this.state.featureCommunityLoading ? (
983 classes={classNames({ "text-success": featuredCommunity })}
986 {i18n.t("community")}
992 className="btn btn-link btn-animate text-muted py-0"
993 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
994 data-tippy-content={labelLocal}
995 aria-label={labelLocal}
997 {this.state.featureLocalLoading ? (
1003 classes={classNames({ "text-success": featuredLocal })}
1015 get modRemoveButton() {
1016 const removed = this.postView.post.removed;
1019 className="btn btn-link btn-animate text-muted py-0"
1022 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1025 {/* TODO: Find an icon for this. */}
1026 {this.state.removeLoading ? (
1038 * Mod/Admin actions to be taken against the author.
1042 const post_view = this.postView;
1044 this.state.showAdvanced && (
1048 {!this.creatorIsMod_ &&
1049 (!post_view.creator_banned_from_community ? (
1051 className="btn btn-link btn-animate text-muted py-0"
1054 this.handleModBanFromCommunityShow
1056 aria-label={i18n.t("ban_from_community")}
1058 {i18n.t("ban_from_community")}
1062 className="btn btn-link btn-animate text-muted py-0"
1065 this.handleModBanFromCommunitySubmit
1067 aria-label={i18n.t("unban")}
1069 {this.state.banLoading ? <Spinner /> : i18n.t("unban")}
1072 {!post_view.creator_banned_from_community && (
1074 className="btn btn-link btn-animate text-muted py-0"
1075 onClick={linkEvent(this, this.handleAddModToCommunity)}
1078 ? i18n.t("remove_as_mod")
1079 : i18n.t("appoint_as_mod")
1082 {this.state.addModLoading ? (
1084 ) : this.creatorIsMod_ ? (
1085 i18n.t("remove_as_mod")
1087 i18n.t("appoint_as_mod")
1093 {/* Community creators and admins can transfer community to another mod */}
1094 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1096 this.creatorIsMod_ &&
1097 (!this.state.showConfirmTransferCommunity ? (
1099 className="btn btn-link btn-animate text-muted py-0"
1102 this.handleShowConfirmTransferCommunity
1104 aria-label={i18n.t("transfer_community")}
1106 {i18n.t("transfer_community")}
1111 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1112 aria-label={i18n.t("are_you_sure")}
1114 {i18n.t("are_you_sure")}
1117 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1118 aria-label={i18n.t("yes")}
1119 onClick={linkEvent(this, this.handleTransferCommunity)}
1121 {this.state.transferLoading ? <Spinner /> : i18n.t("yes")}
1124 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1127 this.handleCancelShowConfirmTransferCommunity
1129 aria-label={i18n.t("no")}
1135 {/* Admins can ban from all, and appoint other admins */}
1136 {this.canAdmin_ && (
1138 {!this.creatorIsAdmin_ && (
1140 {!isBanned(post_view.creator) ? (
1142 className="btn btn-link btn-animate text-muted py-0"
1143 onClick={linkEvent(this, this.handleModBanShow)}
1144 aria-label={i18n.t("ban_from_site")}
1146 {i18n.t("ban_from_site")}
1150 className="btn btn-link btn-animate text-muted py-0"
1151 onClick={linkEvent(this, this.handleModBanSubmit)}
1152 aria-label={i18n.t("unban_from_site")}
1154 {this.state.banLoading ? (
1157 i18n.t("unban_from_site")
1162 className="btn btn-link btn-animate text-muted py-0"
1163 onClick={linkEvent(this, this.handlePurgePersonShow)}
1164 aria-label={i18n.t("purge_user")}
1166 {i18n.t("purge_user")}
1169 className="btn btn-link btn-animate text-muted py-0"
1170 onClick={linkEvent(this, this.handlePurgePostShow)}
1171 aria-label={i18n.t("purge_post")}
1173 {i18n.t("purge_post")}
1177 {!isBanned(post_view.creator) && post_view.creator.local && (
1179 className="btn btn-link btn-animate text-muted py-0"
1180 onClick={linkEvent(this, this.handleAddAdmin)}
1182 this.creatorIsAdmin_
1183 ? i18n.t("remove_as_admin")
1184 : i18n.t("appoint_as_admin")
1187 {this.state.addAdminLoading ? (
1189 ) : this.creatorIsAdmin_ ? (
1190 i18n.t("remove_as_admin")
1192 i18n.t("appoint_as_admin")
1203 removeAndBanDialogs() {
1204 const post = this.postView;
1205 const purgeTypeText =
1206 this.state.purgeType == PurgeType.Post
1207 ? i18n.t("purge_post")
1208 : `${i18n.t("purge")} ${post.creator.name}`;
1211 {this.state.showRemoveDialog && (
1213 className="form-inline"
1214 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1216 <label className="sr-only" htmlFor="post-listing-remove-reason">
1221 id="post-listing-remove-reason"
1222 className="form-control mr-2"
1223 placeholder={i18n.t("reason")}
1224 value={this.state.removeReason}
1225 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1229 className="btn btn-secondary"
1230 aria-label={i18n.t("remove_post")}
1232 {this.state.removeLoading ? <Spinner /> : i18n.t("remove_post")}
1236 {this.state.showBanDialog && (
1237 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1238 <div className="form-group row col-12">
1240 className="col-form-label"
1241 htmlFor="post-listing-ban-reason"
1247 id="post-listing-ban-reason"
1248 className="form-control mr-2"
1249 placeholder={i18n.t("reason")}
1250 value={this.state.banReason}
1251 onInput={linkEvent(this, this.handleModBanReasonChange)}
1253 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1258 id={`mod-ban-expires`}
1259 className="form-control mr-2"
1260 placeholder={i18n.t("number_of_days")}
1261 value={this.state.banExpireDays}
1262 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1264 <div className="form-group">
1265 <div className="form-check">
1267 className="form-check-input"
1268 id="mod-ban-remove-data"
1270 checked={this.state.removeData}
1271 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1274 className="form-check-label"
1275 htmlFor="mod-ban-remove-data"
1276 title={i18n.t("remove_content_more")}
1278 {i18n.t("remove_content")}
1283 {/* TODO hold off on expires until later */}
1284 {/* <div class="form-group row"> */}
1285 {/* <label class="col-form-label">Expires</label> */}
1286 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1288 <div className="form-group row">
1291 className="btn btn-secondary"
1292 aria-label={i18n.t("ban")}
1294 {this.state.banLoading ? (
1298 {i18n.t("ban")} {post.creator.name}
1305 {this.state.showReportDialog && (
1307 className="form-inline"
1308 onSubmit={linkEvent(this, this.handleReportSubmit)}
1310 <label className="sr-only" htmlFor="post-report-reason">
1315 id="post-report-reason"
1316 className="form-control mr-2"
1317 placeholder={i18n.t("reason")}
1319 value={this.state.reportReason}
1320 onInput={linkEvent(this, this.handleReportReasonChange)}
1324 className="btn btn-secondary"
1325 aria-label={i18n.t("create_report")}
1327 {this.state.reportLoading ? <Spinner /> : i18n.t("create_report")}
1331 {this.state.showPurgeDialog && (
1333 className="form-inline"
1334 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1337 <label className="sr-only" htmlFor="purge-reason">
1343 className="form-control mr-2"
1344 placeholder={i18n.t("reason")}
1345 value={this.state.purgeReason}
1346 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1348 {this.state.purgeLoading ? (
1353 className="btn btn-secondary"
1354 aria-label={purgeTypeText}
1356 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1366 const post = this.postView.post;
1367 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1368 <div className="row">
1369 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1370 {this.postTitleLine()}
1372 <div className="col-4">
1373 {/* Post body prev or thumbnail */}
1374 {!this.state.imageExpanded && this.thumbnail()}
1378 this.postTitleLine()
1382 showMobilePreview() {
1383 const body = this.postView.post.body;
1384 return !this.showBody && body ? (
1385 <div className="md-div mb-1 preview-lines">{body}</div>
1394 {/* The mobile view*/}
1395 <div className="d-block d-sm-none">
1396 <div className="row">
1397 <div className="col-12">
1398 {this.createdLine()}
1400 {/* If it has a thumbnail, do a right aligned thumbnail */}
1401 {this.mobileThumbnail()}
1403 {/* Show a preview of the post body */}
1404 {this.showMobilePreview()}
1406 {this.commentsLine(true)}
1407 {this.userActionsLine()}
1408 {this.duplicatesLine()}
1409 {this.removeAndBanDialogs()}
1414 {/* The larger view*/}
1415 <div className="d-none d-sm-block">
1416 <div className="row">
1417 {!this.props.viewOnly && this.voteBar()}
1418 <div className="col-sm-2 pr-0">
1419 <div className="">{this.thumbnail()}</div>
1421 <div className="col-12 col-sm-9">
1422 <div className="row">
1423 <div className="col-12">
1424 {this.postTitleLine()}
1425 {this.createdLine()}
1426 {this.commentsLine()}
1427 {this.duplicatesLine()}
1428 {this.userActionsLine()}
1429 {this.removeAndBanDialogs()}
1439 private get myPost(): boolean {
1441 this.postView.creator.id ==
1442 UserService.Instance.myUserInfo?.local_user_view.person.id
1445 handleEditClick(i: PostListing) {
1446 i.setState({ showEdit: true });
1449 handleEditCancel() {
1450 this.setState({ showEdit: false });
1453 // The actual editing is done in the receive for post
1454 handleEditPost(form: EditPost) {
1455 this.setState({ showEdit: false });
1456 this.props.onPostEdit(form);
1459 handleShare(i: PostListing) {
1460 const { name, body, id } = i.props.post_view.post;
1463 text: body?.slice(0, 50),
1464 url: `${getHttpBase()}/post/${id}`,
1468 handleShowReportDialog(i: PostListing) {
1469 i.setState({ showReportDialog: !i.state.showReportDialog });
1472 handleReportReasonChange(i: PostListing, event: any) {
1473 i.setState({ reportReason: event.target.value });
1476 handleReportSubmit(i: PostListing, event: any) {
1477 event.preventDefault();
1478 i.setState({ reportLoading: true });
1479 i.props.onPostReport({
1480 post_id: i.postView.post.id,
1481 reason: i.state.reportReason ?? "",
1482 auth: myAuthRequired(),
1486 handleBlockPersonClick(i: PostListing) {
1487 i.setState({ blockLoading: true });
1488 i.props.onBlockPerson({
1489 person_id: i.postView.creator.id,
1491 auth: myAuthRequired(),
1495 handleDeleteClick(i: PostListing) {
1496 i.setState({ deleteLoading: true });
1497 i.props.onDeletePost({
1498 post_id: i.postView.post.id,
1499 deleted: !i.postView.post.deleted,
1500 auth: myAuthRequired(),
1504 handleSavePostClick(i: PostListing) {
1505 i.setState({ saveLoading: true });
1506 i.props.onSavePost({
1507 post_id: i.postView.post.id,
1508 save: !i.postView.saved,
1509 auth: myAuthRequired(),
1513 get crossPostParams(): PostFormParams {
1514 const queryParams: PostFormParams = {};
1515 const { name, url } = this.postView.post;
1517 queryParams.name = name;
1520 queryParams.url = url;
1523 const crossPostBody = this.crossPostBody();
1524 if (crossPostBody) {
1525 queryParams.body = crossPostBody;
1531 crossPostBody(): string | undefined {
1532 const post = this.postView.post;
1533 const body = post.body;
1536 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1543 get showBody(): boolean {
1544 return this.props.showBody || this.state.showBody;
1547 handleModRemoveShow(i: PostListing) {
1549 showRemoveDialog: !i.state.showRemoveDialog,
1550 showBanDialog: false,
1554 handleModRemoveReasonChange(i: PostListing, event: any) {
1555 i.setState({ removeReason: event.target.value });
1558 handleModRemoveDataChange(i: PostListing, event: any) {
1559 i.setState({ removeData: event.target.checked });
1562 handleModRemoveSubmit(i: PostListing, event: any) {
1563 event.preventDefault();
1564 i.setState({ removeLoading: true });
1565 i.props.onRemovePost({
1566 post_id: i.postView.post.id,
1567 removed: !i.postView.post.removed,
1568 auth: myAuthRequired(),
1572 handleModLock(i: PostListing) {
1573 i.setState({ lockLoading: true });
1574 i.props.onLockPost({
1575 post_id: i.postView.post.id,
1576 locked: !i.postView.post.locked,
1577 auth: myAuthRequired(),
1581 handleModFeaturePostLocal(i: PostListing) {
1582 i.setState({ featureLocalLoading: true });
1583 i.props.onFeaturePost({
1584 post_id: i.postView.post.id,
1585 featured: !i.postView.post.featured_local,
1586 feature_type: "Local",
1587 auth: myAuthRequired(),
1591 handleModFeaturePostCommunity(i: PostListing) {
1592 i.setState({ featureCommunityLoading: true });
1593 i.props.onFeaturePost({
1594 post_id: i.postView.post.id,
1595 featured: !i.postView.post.featured_community,
1596 feature_type: "Community",
1597 auth: myAuthRequired(),
1601 handleModBanFromCommunityShow(i: PostListing) {
1603 showBanDialog: true,
1604 banType: BanType.Community,
1605 showRemoveDialog: false,
1609 handleModBanShow(i: PostListing) {
1611 showBanDialog: true,
1612 banType: BanType.Site,
1613 showRemoveDialog: false,
1617 handlePurgePersonShow(i: PostListing) {
1619 showPurgeDialog: true,
1620 purgeType: PurgeType.Person,
1621 showRemoveDialog: false,
1625 handlePurgePostShow(i: PostListing) {
1627 showPurgeDialog: true,
1628 purgeType: PurgeType.Post,
1629 showRemoveDialog: false,
1633 handlePurgeReasonChange(i: PostListing, event: any) {
1634 i.setState({ purgeReason: event.target.value });
1637 handlePurgeSubmit(i: PostListing, event: any) {
1638 event.preventDefault();
1639 i.setState({ purgeLoading: true });
1640 if (i.state.purgeType == PurgeType.Person) {
1641 i.props.onPurgePerson({
1642 person_id: i.postView.creator.id,
1643 reason: i.state.purgeReason,
1644 auth: myAuthRequired(),
1646 } else if (i.state.purgeType == PurgeType.Post) {
1647 i.props.onPurgePost({
1648 post_id: i.postView.post.id,
1649 reason: i.state.purgeReason,
1650 auth: myAuthRequired(),
1655 handleModBanReasonChange(i: PostListing, event: any) {
1656 i.setState({ banReason: event.target.value });
1659 handleModBanExpireDaysChange(i: PostListing, event: any) {
1660 i.setState({ banExpireDays: event.target.value });
1663 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1664 i.setState({ banType: BanType.Community });
1665 i.handleModBanBothSubmit(i, event);
1668 handleModBanSubmit(i: PostListing, event: any) {
1669 i.setState({ banType: BanType.Site });
1670 i.handleModBanBothSubmit(i, event);
1673 handleModBanBothSubmit(i: PostListing, event: any) {
1674 event.preventDefault();
1675 i.setState({ banLoading: true });
1677 const ban = !i.props.post_view.creator_banned_from_community;
1678 // If its an unban, restore all their data
1680 i.setState({ removeData: false });
1682 const person_id = i.props.post_view.creator.id;
1683 const remove_data = i.state.removeData;
1684 const reason = i.state.banReason;
1685 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1687 if (i.state.banType == BanType.Community) {
1688 const community_id = i.postView.community.id;
1689 i.props.onBanPersonFromCommunity({
1696 auth: myAuthRequired(),
1699 i.props.onBanPerson({
1705 auth: myAuthRequired(),
1710 handleAddModToCommunity(i: PostListing) {
1711 i.setState({ addModLoading: true });
1712 i.props.onAddModToCommunity({
1713 community_id: i.postView.community.id,
1714 person_id: i.postView.creator.id,
1715 added: !i.creatorIsMod_,
1716 auth: myAuthRequired(),
1720 handleAddAdmin(i: PostListing) {
1721 i.setState({ addAdminLoading: true });
1722 i.props.onAddAdmin({
1723 person_id: i.postView.creator.id,
1724 added: !i.creatorIsAdmin_,
1725 auth: myAuthRequired(),
1729 handleShowConfirmTransferCommunity(i: PostListing) {
1730 i.setState({ showConfirmTransferCommunity: true });
1733 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1734 i.setState({ showConfirmTransferCommunity: false });
1737 handleTransferCommunity(i: PostListing) {
1738 i.setState({ transferLoading: true });
1739 i.props.onTransferCommunity({
1740 community_id: i.postView.community.id,
1741 person_id: i.postView.creator.id,
1742 auth: myAuthRequired(),
1746 handleShowConfirmTransferSite(i: PostListing) {
1747 i.setState({ showConfirmTransferSite: true });
1750 handleCancelShowConfirmTransferSite(i: PostListing) {
1751 i.setState({ showConfirmTransferSite: false });
1754 handleImageExpandClick(i: PostListing, event: any) {
1755 event.preventDefault();
1756 i.setState({ imageExpanded: !i.state.imageExpanded });
1760 handleViewSource(i: PostListing) {
1761 i.setState({ viewSource: !i.state.viewSource });
1764 handleShowAdvanced(i: PostListing) {
1765 i.setState({ showAdvanced: !i.state.showAdvanced });
1769 handleShowMoreMobile(i: PostListing) {
1771 showMoreMobile: !i.state.showMoreMobile,
1772 showAdvanced: !i.state.showAdvanced,
1777 handleShowBody(i: PostListing) {
1778 i.setState({ showBody: !i.state.showBody });
1782 handleUpvote(i: PostListing) {
1783 i.setState({ upvoteLoading: true });
1784 i.props.onPostVote({
1785 post_id: i.postView.post.id,
1786 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1787 auth: myAuthRequired(),
1791 handleDownvote(i: PostListing) {
1792 i.setState({ downvoteLoading: true });
1793 i.props.onPostVote({
1794 post_id: i.postView.post.id,
1795 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1796 auth: myAuthRequired(),
1800 get pointsTippy(): string {
1801 const points = i18n.t("number_of_points", {
1802 count: Number(this.postView.counts.score),
1803 formattedCount: Number(this.postView.counts.score),
1806 const upvotes = i18n.t("number_of_upvotes", {
1807 count: Number(this.postView.counts.upvotes),
1808 formattedCount: Number(this.postView.counts.upvotes),
1811 const downvotes = i18n.t("number_of_downvotes", {
1812 count: Number(this.postView.counts.downvotes),
1813 formattedCount: Number(this.postView.counts.downvotes),
1816 return `${points} • ${upvotes} • ${downvotes}`;
1819 get canModOnSelf_(): boolean {
1821 this.postView.creator.id,
1822 this.props.moderators,
1829 get canMod_(): boolean {
1831 this.postView.creator.id,
1832 this.props.moderators,
1837 get canAdmin_(): boolean {
1838 return canAdmin(this.postView.creator.id, this.props.admins);
1841 get creatorIsMod_(): boolean {
1842 return isMod(this.postView.creator.id, this.props.moderators);
1845 get creatorIsAdmin_(): boolean {
1846 return isAdmin(this.postView.creator.id, this.props.admins);