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 <article id="postContent" 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 post-score`}
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 aria-label={i18n.t("featured_in_community")}
586 data-tippy-content={i18n.t("featured_in_community")}
588 <Icon icon="pin" classes="icon-inline text-primary" />
591 {post.featured_local && (
593 className="unselectable pointer ml-2 text-muted font-italic"
594 aria-label={i18n.t("featured_in_local")}
595 data-tippy-content={i18n.t("featured_in_local")}
597 <Icon icon="pin" classes="icon-inline text-secondary" />
601 <small className="ml-2 text-muted font-italic">
611 const dupes = this.props.crossPosts;
612 return dupes && dupes.length > 0 ? (
613 <ul className="list-inline mb-1 small text-muted">
615 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
617 <li key={pv.post.id} className="list-inline-item mr-2">
618 <Link to={`/post/${pv.post.id}`}>
621 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
632 commentsLine(mobile = false) {
633 const post = this.postView.post;
636 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted font-weight-bold mb-1">
637 {this.commentsButton}
640 className="btn btn-link"
641 onClick={linkEvent(this, this.handleShare)}
644 <Icon icon="share" inline />
649 className="btn btn-link btn-animate text-muted py-0"
650 title={i18n.t("link")}
653 <Icon icon="fedilink" inline />
656 {mobile && !this.props.viewOnly && this.mobileVotes}
657 {UserService.Instance.myUserInfo &&
658 !this.props.viewOnly &&
664 get hasAdvancedButtons() {
667 (this.showBody && this.postView.post.body) ||
668 amMod(this.props.moderators) ||
676 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
677 // Possible enhancement: Make each button a component.
678 const post_view = this.postView;
682 {this.crossPostButton}
684 {this.showBody && post_view.post.body && this.viewSourceButton}
686 {this.hasAdvancedButtons && (
687 <div className="dropdown">
689 className="btn btn-link btn-animate text-muted py-0 dropdown-toggle"
690 onClick={linkEvent(this, this.handleShowAdvanced)}
691 data-tippy-content={i18n.t("more")}
692 data-bs-toggle="dropdown"
693 aria-expanded="false"
694 aria-label={i18n.t("more")}
696 <Icon icon="more-vertical" inline />
699 <ul className="dropdown-menu">
702 <li>{this.reportButton}</li>
703 <li>{this.blockButton}</li>
707 <li>{this.editButton}</li>
708 <li>{this.deleteButton}</li>
712 {/* Any mod can do these, not limited to hierarchy*/}
713 {(amMod(this.props.moderators) || amAdmin()) && (
716 <hr className="dropdown-divider" />
718 <li>{this.lockButton}</li>
719 {this.featureButtons}
723 {(this.canMod_ || this.canAdmin_) && (
724 <li>{this.modRemoveButton}</li>
733 get commentsButton() {
734 const post_view = this.postView;
737 className="btn btn-link text-muted py-0 pl-0 text-muted"
738 title={i18n.t("number_of_comments", {
739 count: Number(post_view.counts.comments),
740 formattedCount: Number(post_view.counts.comments),
742 to={`/post/${post_view.post.id}?scrollToComments=true`}
744 <Icon icon="message-square" classes="mr-1" inline />
745 <span className="mr-2">
746 {i18n.t("number_of_comments", {
747 count: Number(post_view.counts.comments),
748 formattedCount: numToSI(post_view.counts.comments),
751 {this.unreadCount && (
752 <span className="small text-warning">
753 ({this.unreadCount} {i18n.t("new")})
760 get unreadCount(): number | undefined {
761 const pv = this.postView;
762 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
764 : pv.unread_comments;
769 const tippy = showScores()
770 ? { "data-tippy-content": this.pointsTippy }
776 className={`btn-animate btn py-0 px-1 ${
777 this.postView.my_vote === 1 ? "text-info" : "text-muted"
780 onClick={linkEvent(this, this.handleUpvote)}
781 aria-label={i18n.t("upvote")}
782 aria-pressed={this.postView.my_vote === 1}
784 {this.state.upvoteLoading ? (
788 <Icon icon="arrow-up1" classes="icon-inline small" />
790 <span className="ml-2">
791 {numToSI(this.postView.counts.upvotes)}
797 {this.props.enableDownvotes && (
799 className={`ml-2 btn-animate btn py-0 px-1 ${
800 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
802 onClick={linkEvent(this, this.handleDownvote)}
804 aria-label={i18n.t("downvote")}
805 aria-pressed={this.postView.my_vote === -1}
807 {this.state.downvoteLoading ? (
811 <Icon icon="arrow-down1" classes="icon-inline small" />
814 className={classNames("ml-2", {
815 invisible: this.postView.counts.downvotes === 0,
818 {numToSI(this.postView.counts.downvotes)}
831 const saved = this.postView.saved;
832 const label = saved ? i18n.t("unsave") : i18n.t("save");
835 className="btn btn-link btn-animate text-muted py-0"
836 onClick={linkEvent(this, this.handleSavePostClick)}
837 data-tippy-content={label}
840 {this.state.saveLoading ? (
845 classes={classNames({ "text-warning": saved })}
853 get crossPostButton() {
856 className="btn btn-link btn-animate text-muted py-0"
858 /* Empty string properties are required to satisfy type*/
859 pathname: "/create_post",
860 state: { ...this.crossPostParams },
865 title={i18n.t("cross_post")}
866 data-tippy-content={i18n.t("cross_post")}
867 aria-label={i18n.t("cross_post")}
869 <Icon icon="copy" inline />
877 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
878 onClick={linkEvent(this, this.handleShowReportDialog)}
879 data-tippy-content={i18n.t("show_report_dialog")}
880 aria-label={i18n.t("show_report_dialog")}
882 <Icon icon="flag" inline />
890 className="btn btn-link btn-animate text-muted py-0 dropdown-item"
891 onClick={linkEvent(this, this.handleBlockPersonClick)}
892 data-tippy-content={i18n.t("block_user")}
893 aria-label={i18n.t("block_user")}
895 {this.state.blockLoading ? <Spinner /> : <Icon icon="slash" inline />}
903 className="btn btn-link text-muted dropdown-item"
904 onClick={linkEvent(this, this.handleEditClick)}
905 data-tippy-content={i18n.t("edit")}
906 aria-label={i18n.t("edit")}
908 <Icon classes="mr-1" icon="edit" inline />
915 const deleted = this.postView.post.deleted;
916 const label = !deleted ? i18n.t("delete") : i18n.t("restore");
919 className="btn btn-link text-muted dropdown-item"
920 onClick={linkEvent(this, this.handleDeleteClick)}
921 data-tippy-content={label}
924 {this.state.deleteLoading ? (
930 classes={classNames("mr-1", { "text-danger": deleted })}
940 get viewSourceButton() {
943 className="btn btn-link btn-animate text-muted py-0"
944 onClick={linkEvent(this, this.handleViewSource)}
945 data-tippy-content={i18n.t("view_source")}
946 aria-label={i18n.t("view_source")}
950 classes={classNames({ "text-success": this.state.viewSource })}
958 const locked = this.postView.post.locked;
959 const label = locked ? i18n.t("unlock") : i18n.t("lock");
962 className="btn btn-link text-muted dropdown-item"
963 onClick={linkEvent(this, this.handleModLock)}
964 data-tippy-content={label}
967 {this.state.lockLoading ? (
973 classes={classNames("mr-1", { "text-danger": locked })}
983 get featureButtons() {
984 const featuredCommunity = this.postView.post.featured_community;
985 const labelCommunity = featuredCommunity
986 ? i18n.t("unfeature_from_community")
987 : i18n.t("feature_in_community");
989 const featuredLocal = this.postView.post.featured_local;
990 const labelLocal = featuredLocal
991 ? i18n.t("unfeature_from_local")
992 : i18n.t("feature_in_local");
997 className="btn btn-link text-muted dropdown-item"
998 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
999 data-tippy-content={labelCommunity}
1000 aria-label={labelCommunity}
1002 {this.state.featureCommunityLoading ? (
1008 classes={classNames("mr-1", {
1009 "text-success": featuredCommunity,
1013 {i18n.t("community")}
1021 className="btn btn-link text-muted dropdown-item"
1022 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1023 data-tippy-content={labelLocal}
1024 aria-label={labelLocal}
1026 {this.state.featureLocalLoading ? (
1032 classes={classNames("mr-1", {
1033 "text-success": featuredLocal,
1047 get modRemoveButton() {
1048 const removed = this.postView.post.removed;
1051 className="btn btn-link text-muted dropdown-item"
1054 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1057 {/* TODO: Find an icon for this. */}
1058 {this.state.removeLoading ? (
1070 * Mod/Admin actions to be taken against the author.
1074 const post_view = this.postView;
1076 this.state.showAdvanced && (
1080 {!this.creatorIsMod_ &&
1081 (!post_view.creator_banned_from_community ? (
1083 className="btn btn-link btn-animate text-muted py-0"
1086 this.handleModBanFromCommunityShow
1088 aria-label={i18n.t("ban_from_community")}
1090 {i18n.t("ban_from_community")}
1094 className="btn btn-link btn-animate text-muted py-0"
1097 this.handleModBanFromCommunitySubmit
1099 aria-label={i18n.t("unban")}
1101 {this.state.banLoading ? <Spinner /> : i18n.t("unban")}
1104 {!post_view.creator_banned_from_community && (
1106 className="btn btn-link btn-animate text-muted py-0"
1107 onClick={linkEvent(this, this.handleAddModToCommunity)}
1110 ? i18n.t("remove_as_mod")
1111 : i18n.t("appoint_as_mod")
1114 {this.state.addModLoading ? (
1116 ) : this.creatorIsMod_ ? (
1117 i18n.t("remove_as_mod")
1119 i18n.t("appoint_as_mod")
1125 {/* Community creators and admins can transfer community to another mod */}
1126 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1128 this.creatorIsMod_ &&
1129 (!this.state.showConfirmTransferCommunity ? (
1131 className="btn btn-link btn-animate text-muted py-0"
1134 this.handleShowConfirmTransferCommunity
1136 aria-label={i18n.t("transfer_community")}
1138 {i18n.t("transfer_community")}
1143 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1144 aria-label={i18n.t("are_you_sure")}
1146 {i18n.t("are_you_sure")}
1149 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1150 aria-label={i18n.t("yes")}
1151 onClick={linkEvent(this, this.handleTransferCommunity)}
1153 {this.state.transferLoading ? <Spinner /> : i18n.t("yes")}
1156 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1159 this.handleCancelShowConfirmTransferCommunity
1161 aria-label={i18n.t("no")}
1167 {/* Admins can ban from all, and appoint other admins */}
1168 {this.canAdmin_ && (
1170 {!this.creatorIsAdmin_ && (
1172 {!isBanned(post_view.creator) ? (
1174 className="btn btn-link btn-animate text-muted py-0"
1175 onClick={linkEvent(this, this.handleModBanShow)}
1176 aria-label={i18n.t("ban_from_site")}
1178 {i18n.t("ban_from_site")}
1182 className="btn btn-link btn-animate text-muted py-0"
1183 onClick={linkEvent(this, this.handleModBanSubmit)}
1184 aria-label={i18n.t("unban_from_site")}
1186 {this.state.banLoading ? (
1189 i18n.t("unban_from_site")
1194 className="btn btn-link btn-animate text-muted py-0"
1195 onClick={linkEvent(this, this.handlePurgePersonShow)}
1196 aria-label={i18n.t("purge_user")}
1198 {i18n.t("purge_user")}
1201 className="btn btn-link btn-animate text-muted py-0"
1202 onClick={linkEvent(this, this.handlePurgePostShow)}
1203 aria-label={i18n.t("purge_post")}
1205 {i18n.t("purge_post")}
1209 {!isBanned(post_view.creator) && post_view.creator.local && (
1211 className="btn btn-link btn-animate text-muted py-0"
1212 onClick={linkEvent(this, this.handleAddAdmin)}
1214 this.creatorIsAdmin_
1215 ? i18n.t("remove_as_admin")
1216 : i18n.t("appoint_as_admin")
1219 {this.state.addAdminLoading ? (
1221 ) : this.creatorIsAdmin_ ? (
1222 i18n.t("remove_as_admin")
1224 i18n.t("appoint_as_admin")
1235 removeAndBanDialogs() {
1236 const post = this.postView;
1237 const purgeTypeText =
1238 this.state.purgeType == PurgeType.Post
1239 ? i18n.t("purge_post")
1240 : `${i18n.t("purge")} ${post.creator.name}`;
1243 {this.state.showRemoveDialog && (
1245 className="form-inline"
1246 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1248 <label className="sr-only" htmlFor="post-listing-remove-reason">
1253 id="post-listing-remove-reason"
1254 className="form-control mr-2"
1255 placeholder={i18n.t("reason")}
1256 value={this.state.removeReason}
1257 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1261 className="btn btn-secondary"
1262 aria-label={i18n.t("remove_post")}
1264 {this.state.removeLoading ? <Spinner /> : i18n.t("remove_post")}
1268 {this.state.showBanDialog && (
1269 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1270 <div className="form-group row col-12">
1272 className="col-form-label"
1273 htmlFor="post-listing-ban-reason"
1279 id="post-listing-ban-reason"
1280 className="form-control mr-2"
1281 placeholder={i18n.t("reason")}
1282 value={this.state.banReason}
1283 onInput={linkEvent(this, this.handleModBanReasonChange)}
1285 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1290 id={`mod-ban-expires`}
1291 className="form-control mr-2"
1292 placeholder={i18n.t("number_of_days")}
1293 value={this.state.banExpireDays}
1294 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1296 <div className="form-group">
1297 <div className="form-check">
1299 className="form-check-input"
1300 id="mod-ban-remove-data"
1302 checked={this.state.removeData}
1303 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1306 className="form-check-label"
1307 htmlFor="mod-ban-remove-data"
1308 title={i18n.t("remove_content_more")}
1310 {i18n.t("remove_content")}
1315 {/* TODO hold off on expires until later */}
1316 {/* <div class="form-group row"> */}
1317 {/* <label class="col-form-label">Expires</label> */}
1318 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1320 <div className="form-group row">
1323 className="btn btn-secondary"
1324 aria-label={i18n.t("ban")}
1326 {this.state.banLoading ? (
1330 {i18n.t("ban")} {post.creator.name}
1337 {this.state.showReportDialog && (
1339 className="form-inline"
1340 onSubmit={linkEvent(this, this.handleReportSubmit)}
1342 <label className="sr-only" htmlFor="post-report-reason">
1347 id="post-report-reason"
1348 className="form-control mr-2"
1349 placeholder={i18n.t("reason")}
1351 value={this.state.reportReason}
1352 onInput={linkEvent(this, this.handleReportReasonChange)}
1356 className="btn btn-secondary"
1357 aria-label={i18n.t("create_report")}
1359 {this.state.reportLoading ? <Spinner /> : i18n.t("create_report")}
1363 {this.state.showPurgeDialog && (
1365 className="form-inline"
1366 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1369 <label className="sr-only" htmlFor="purge-reason">
1375 className="form-control mr-2"
1376 placeholder={i18n.t("reason")}
1377 value={this.state.purgeReason}
1378 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1380 {this.state.purgeLoading ? (
1385 className="btn btn-secondary"
1386 aria-label={purgeTypeText}
1388 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1398 const post = this.postView.post;
1399 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1400 <div className="row">
1401 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1402 {this.postTitleLine()}
1404 <div className="col-4">
1405 {/* Post body prev or thumbnail */}
1406 {!this.state.imageExpanded && this.thumbnail()}
1410 this.postTitleLine()
1414 showMobilePreview() {
1415 const { body, id } = this.postView.post;
1417 return !this.showBody && body ? (
1418 <Link className="text-body" to={`/post/${id}`}>
1419 <div className="md-div mb-1 preview-lines">{body}</div>
1429 {/* The mobile view*/}
1430 <div className="d-block d-sm-none">
1431 <article className="row post-container">
1432 <div className="col-12">
1433 {this.createdLine()}
1435 {/* If it has a thumbnail, do a right aligned thumbnail */}
1436 {this.mobileThumbnail()}
1438 {/* Show a preview of the post body */}
1439 {this.showMobilePreview()}
1441 {this.commentsLine(true)}
1442 {this.userActionsLine()}
1443 {this.duplicatesLine()}
1444 {this.removeAndBanDialogs()}
1449 {/* The larger view*/}
1450 <div className="d-none d-sm-block">
1451 <article className="row post-container">
1452 {!this.props.viewOnly && this.voteBar()}
1453 <div className="col-sm-2 pr-0 post-media">
1454 <div className="">{this.thumbnail()}</div>
1456 <div className="col-12 col-sm-9">
1457 <div className="row">
1458 <div className="col-12">
1459 {this.postTitleLine()}
1460 {this.createdLine()}
1461 {this.commentsLine()}
1462 {this.duplicatesLine()}
1463 {this.userActionsLine()}
1464 {this.removeAndBanDialogs()}
1474 private get myPost(): boolean {
1476 this.postView.creator.id ==
1477 UserService.Instance.myUserInfo?.local_user_view.person.id
1480 handleEditClick(i: PostListing) {
1481 i.setState({ showEdit: true });
1484 handleEditCancel() {
1485 this.setState({ showEdit: false });
1488 // The actual editing is done in the receive for post
1489 handleEditPost(form: EditPost) {
1490 this.setState({ showEdit: false });
1491 this.props.onPostEdit(form);
1494 handleShare(i: PostListing) {
1495 const { name, body, id } = i.props.post_view.post;
1498 text: body?.slice(0, 50),
1499 url: `${getHttpBase()}/post/${id}`,
1503 handleShowReportDialog(i: PostListing) {
1504 i.setState({ showReportDialog: !i.state.showReportDialog });
1507 handleReportReasonChange(i: PostListing, event: any) {
1508 i.setState({ reportReason: event.target.value });
1511 handleReportSubmit(i: PostListing, event: any) {
1512 event.preventDefault();
1513 i.setState({ reportLoading: true });
1514 i.props.onPostReport({
1515 post_id: i.postView.post.id,
1516 reason: i.state.reportReason ?? "",
1517 auth: myAuthRequired(),
1521 handleBlockPersonClick(i: PostListing) {
1522 i.setState({ blockLoading: true });
1523 i.props.onBlockPerson({
1524 person_id: i.postView.creator.id,
1526 auth: myAuthRequired(),
1530 handleDeleteClick(i: PostListing) {
1531 i.setState({ deleteLoading: true });
1532 i.props.onDeletePost({
1533 post_id: i.postView.post.id,
1534 deleted: !i.postView.post.deleted,
1535 auth: myAuthRequired(),
1539 handleSavePostClick(i: PostListing) {
1540 i.setState({ saveLoading: true });
1541 i.props.onSavePost({
1542 post_id: i.postView.post.id,
1543 save: !i.postView.saved,
1544 auth: myAuthRequired(),
1548 get crossPostParams(): PostFormParams {
1549 const queryParams: PostFormParams = {};
1550 const { name, url } = this.postView.post;
1552 queryParams.name = name;
1555 queryParams.url = url;
1558 const crossPostBody = this.crossPostBody();
1559 if (crossPostBody) {
1560 queryParams.body = crossPostBody;
1566 crossPostBody(): string | undefined {
1567 const post = this.postView.post;
1568 const body = post.body;
1571 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1578 get showBody(): boolean {
1579 return this.props.showBody || this.state.showBody;
1582 handleModRemoveShow(i: PostListing) {
1584 showRemoveDialog: !i.state.showRemoveDialog,
1585 showBanDialog: false,
1589 handleModRemoveReasonChange(i: PostListing, event: any) {
1590 i.setState({ removeReason: event.target.value });
1593 handleModRemoveDataChange(i: PostListing, event: any) {
1594 i.setState({ removeData: event.target.checked });
1597 handleModRemoveSubmit(i: PostListing, event: any) {
1598 event.preventDefault();
1599 i.setState({ removeLoading: true });
1600 i.props.onRemovePost({
1601 post_id: i.postView.post.id,
1602 removed: !i.postView.post.removed,
1603 auth: myAuthRequired(),
1607 handleModLock(i: PostListing) {
1608 i.setState({ lockLoading: true });
1609 i.props.onLockPost({
1610 post_id: i.postView.post.id,
1611 locked: !i.postView.post.locked,
1612 auth: myAuthRequired(),
1616 handleModFeaturePostLocal(i: PostListing) {
1617 i.setState({ featureLocalLoading: true });
1618 i.props.onFeaturePost({
1619 post_id: i.postView.post.id,
1620 featured: !i.postView.post.featured_local,
1621 feature_type: "Local",
1622 auth: myAuthRequired(),
1626 handleModFeaturePostCommunity(i: PostListing) {
1627 i.setState({ featureCommunityLoading: true });
1628 i.props.onFeaturePost({
1629 post_id: i.postView.post.id,
1630 featured: !i.postView.post.featured_community,
1631 feature_type: "Community",
1632 auth: myAuthRequired(),
1636 handleModBanFromCommunityShow(i: PostListing) {
1638 showBanDialog: true,
1639 banType: BanType.Community,
1640 showRemoveDialog: false,
1644 handleModBanShow(i: PostListing) {
1646 showBanDialog: true,
1647 banType: BanType.Site,
1648 showRemoveDialog: false,
1652 handlePurgePersonShow(i: PostListing) {
1654 showPurgeDialog: true,
1655 purgeType: PurgeType.Person,
1656 showRemoveDialog: false,
1660 handlePurgePostShow(i: PostListing) {
1662 showPurgeDialog: true,
1663 purgeType: PurgeType.Post,
1664 showRemoveDialog: false,
1668 handlePurgeReasonChange(i: PostListing, event: any) {
1669 i.setState({ purgeReason: event.target.value });
1672 handlePurgeSubmit(i: PostListing, event: any) {
1673 event.preventDefault();
1674 i.setState({ purgeLoading: true });
1675 if (i.state.purgeType == PurgeType.Person) {
1676 i.props.onPurgePerson({
1677 person_id: i.postView.creator.id,
1678 reason: i.state.purgeReason,
1679 auth: myAuthRequired(),
1681 } else if (i.state.purgeType == PurgeType.Post) {
1682 i.props.onPurgePost({
1683 post_id: i.postView.post.id,
1684 reason: i.state.purgeReason,
1685 auth: myAuthRequired(),
1690 handleModBanReasonChange(i: PostListing, event: any) {
1691 i.setState({ banReason: event.target.value });
1694 handleModBanExpireDaysChange(i: PostListing, event: any) {
1695 i.setState({ banExpireDays: event.target.value });
1698 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1699 i.setState({ banType: BanType.Community });
1700 i.handleModBanBothSubmit(i, event);
1703 handleModBanSubmit(i: PostListing, event: any) {
1704 i.setState({ banType: BanType.Site });
1705 i.handleModBanBothSubmit(i, event);
1708 handleModBanBothSubmit(i: PostListing, event: any) {
1709 event.preventDefault();
1710 i.setState({ banLoading: true });
1712 const ban = !i.props.post_view.creator_banned_from_community;
1713 // If its an unban, restore all their data
1715 i.setState({ removeData: false });
1717 const person_id = i.props.post_view.creator.id;
1718 const remove_data = i.state.removeData;
1719 const reason = i.state.banReason;
1720 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1722 if (i.state.banType == BanType.Community) {
1723 const community_id = i.postView.community.id;
1724 i.props.onBanPersonFromCommunity({
1731 auth: myAuthRequired(),
1734 i.props.onBanPerson({
1740 auth: myAuthRequired(),
1745 handleAddModToCommunity(i: PostListing) {
1746 i.setState({ addModLoading: true });
1747 i.props.onAddModToCommunity({
1748 community_id: i.postView.community.id,
1749 person_id: i.postView.creator.id,
1750 added: !i.creatorIsMod_,
1751 auth: myAuthRequired(),
1755 handleAddAdmin(i: PostListing) {
1756 i.setState({ addAdminLoading: true });
1757 i.props.onAddAdmin({
1758 person_id: i.postView.creator.id,
1759 added: !i.creatorIsAdmin_,
1760 auth: myAuthRequired(),
1764 handleShowConfirmTransferCommunity(i: PostListing) {
1765 i.setState({ showConfirmTransferCommunity: true });
1768 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1769 i.setState({ showConfirmTransferCommunity: false });
1772 handleTransferCommunity(i: PostListing) {
1773 i.setState({ transferLoading: true });
1774 i.props.onTransferCommunity({
1775 community_id: i.postView.community.id,
1776 person_id: i.postView.creator.id,
1777 auth: myAuthRequired(),
1781 handleShowConfirmTransferSite(i: PostListing) {
1782 i.setState({ showConfirmTransferSite: true });
1785 handleCancelShowConfirmTransferSite(i: PostListing) {
1786 i.setState({ showConfirmTransferSite: false });
1789 handleImageExpandClick(i: PostListing, event: any) {
1790 event.preventDefault();
1791 i.setState({ imageExpanded: !i.state.imageExpanded });
1795 handleViewSource(i: PostListing) {
1796 i.setState({ viewSource: !i.state.viewSource });
1799 handleShowAdvanced(i: PostListing) {
1800 i.setState({ showAdvanced: !i.state.showAdvanced });
1804 handleShowMoreMobile(i: PostListing) {
1806 showMoreMobile: !i.state.showMoreMobile,
1807 showAdvanced: !i.state.showAdvanced,
1812 handleShowBody(i: PostListing) {
1813 i.setState({ showBody: !i.state.showBody });
1817 handleUpvote(i: PostListing) {
1818 i.setState({ upvoteLoading: true });
1819 i.props.onPostVote({
1820 post_id: i.postView.post.id,
1821 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1822 auth: myAuthRequired(),
1826 handleDownvote(i: PostListing) {
1827 i.setState({ downvoteLoading: true });
1828 i.props.onPostVote({
1829 post_id: i.postView.post.id,
1830 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1831 auth: myAuthRequired(),
1835 get pointsTippy(): string {
1836 const points = i18n.t("number_of_points", {
1837 count: Number(this.postView.counts.score),
1838 formattedCount: Number(this.postView.counts.score),
1841 const upvotes = i18n.t("number_of_upvotes", {
1842 count: Number(this.postView.counts.upvotes),
1843 formattedCount: Number(this.postView.counts.upvotes),
1846 const downvotes = i18n.t("number_of_downvotes", {
1847 count: Number(this.postView.counts.downvotes),
1848 formattedCount: Number(this.postView.counts.downvotes),
1851 return `${points} • ${upvotes} • ${downvotes}`;
1854 get canModOnSelf_(): boolean {
1856 this.postView.creator.id,
1857 this.props.moderators,
1864 get canMod_(): boolean {
1866 this.postView.creator.id,
1867 this.props.moderators,
1872 get canAdmin_(): boolean {
1873 return canAdmin(this.postView.creator.id, this.props.admins);
1876 get creatorIsMod_(): boolean {
1877 return isMod(this.postView.creator.id, this.props.moderators);
1880 get creatorIsAdmin_(): boolean {
1881 return isAdmin(this.postView.creator.id, this.props.admins);