1 import { myAuthRequired, newVote, showScores } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { futureDaysToUnixTime, hostname, numToSI } from "@utils/helpers";
4 import { isImage, isVideo } from "@utils/media";
14 } from "@utils/roles";
15 import classNames from "classnames";
16 import { Component, linkEvent } from "inferno";
17 import { Link } from "inferno-router";
24 CommunityModeratorView,
39 } from "lemmy-js-client";
40 import { relTags } from "../../config";
41 import { getExternalHost, getHttpBase } from "../../env";
42 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
43 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
44 import { I18NextService, UserService } from "../../services";
45 import { setupTippy } from "../../tippy";
46 import { Icon, PurgeWarning, Spinner } from "../common/icon";
47 import { MomentTime } from "../common/moment-time";
48 import { PictrsImage } from "../common/pictrs-image";
49 import { CommunityLink } from "../community/community-link";
50 import { PersonListing } from "../person/person-listing";
51 import { MetadataCard } from "./metadata-card";
52 import { PostForm } from "./post-form";
54 interface PostListingState {
56 showRemoveDialog: boolean;
57 showPurgeDialog: boolean;
59 purgeType?: PurgeType;
60 purgeLoading: boolean;
61 removeReason?: string;
62 showBanDialog: boolean;
64 banExpireDays?: number;
67 showConfirmTransferSite: boolean;
68 showConfirmTransferCommunity: boolean;
69 imageExpanded: boolean;
71 showAdvanced: boolean;
72 showMoreMobile: boolean;
74 showReportDialog: boolean;
75 reportReason?: string;
76 upvoteLoading: boolean;
77 downvoteLoading: boolean;
78 reportLoading: boolean;
79 blockLoading: boolean;
81 deleteLoading: boolean;
82 removeLoading: boolean;
84 featureCommunityLoading: boolean;
85 featureLocalLoading: boolean;
87 addModLoading: boolean;
88 addAdminLoading: boolean;
89 transferLoading: boolean;
92 interface PostListingProps {
94 crossPosts?: PostView[];
95 moderators?: CommunityModeratorView[];
96 admins?: PersonView[];
97 allLanguages: Language[];
98 siteLanguages: number[];
99 showCommunity?: boolean;
102 enableDownvotes?: boolean;
103 enableNsfw?: boolean;
105 onPostEdit(form: EditPost): void;
106 onPostVote(form: CreatePostLike): void;
107 onPostReport(form: CreatePostReport): void;
108 onBlockPerson(form: BlockPerson): void;
109 onLockPost(form: LockPost): void;
110 onDeletePost(form: DeletePost): void;
111 onRemovePost(form: RemovePost): void;
112 onSavePost(form: SavePost): void;
113 onFeaturePost(form: FeaturePost): void;
114 onPurgePerson(form: PurgePerson): void;
115 onPurgePost(form: PurgePost): void;
116 onBanPersonFromCommunity(form: BanFromCommunity): void;
117 onBanPerson(form: BanPerson): void;
118 onAddModToCommunity(form: AddModToCommunity): void;
119 onAddAdmin(form: AddAdmin): void;
120 onTransferCommunity(form: TransferCommunity): void;
123 export class PostListing extends Component<PostListingProps, PostListingState> {
124 state: PostListingState = {
126 showRemoveDialog: false,
127 showPurgeDialog: false,
128 purgeType: PurgeType.Person,
129 showBanDialog: false,
130 banType: BanType.Community,
132 showConfirmTransferSite: false,
133 showConfirmTransferCommunity: false,
134 imageExpanded: false,
137 showMoreMobile: false,
139 showReportDialog: false,
140 upvoteLoading: false,
141 downvoteLoading: false,
143 reportLoading: false,
146 deleteLoading: false,
147 removeLoading: false,
149 featureCommunityLoading: false,
150 featureLocalLoading: false,
152 addModLoading: false,
153 addAdminLoading: false,
154 transferLoading: false,
157 constructor(props: any, context: any) {
158 super(props, context);
160 this.handleEditPost = this.handleEditPost.bind(this);
161 this.handleEditCancel = this.handleEditCancel.bind(this);
164 componentWillReceiveProps(nextProps: PostListingProps) {
165 if (this.props !== nextProps) {
167 upvoteLoading: false,
168 downvoteLoading: false,
170 reportLoading: false,
173 deleteLoading: false,
174 removeLoading: false,
176 featureCommunityLoading: false,
177 featureLocalLoading: false,
179 addModLoading: false,
180 addAdminLoading: false,
181 transferLoading: false,
182 imageExpanded: false,
187 get postView(): PostView {
188 return this.props.post_view;
192 const post = this.postView.post;
195 <div className="post-listing mt-2">
196 {!this.state.showEdit ? (
199 {this.state.imageExpanded && !this.props.hideImage && this.img}
200 {post.url && this.state.showBody && post.embed_title && (
201 <MetadataCard post={post} />
203 {this.showBody && this.body()}
207 post_view={this.postView}
208 crossPosts={this.props.crossPosts}
209 onEdit={this.handleEditPost}
210 onCancel={this.handleEditCancel}
211 enableNsfw={this.props.enableNsfw}
212 enableDownvotes={this.props.enableDownvotes}
213 allLanguages={this.props.allLanguages}
214 siteLanguages={this.props.siteLanguages}
222 const body = this.postView.post.body;
224 <article id="postContent" className="col-12 card my-2 p-2">
225 {this.state.viewSource ? (
228 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
237 return this.imageSrc ? (
239 <div className="offset-sm-3 my-2 d-none d-sm-block">
240 <a href={this.imageSrc} className="d-inline-block">
241 <PictrsImage src={this.imageSrc} />
244 <div className="my-2 d-block d-sm-none">
246 className="d-inline-block"
247 onClick={linkEvent(this, this.handleImageExpandClick)}
249 <PictrsImage src={this.imageSrc} />
258 imgThumb(src: string) {
259 const post_view = this.postView;
265 nsfw={post_view.post.nsfw || post_view.community.nsfw}
270 get imageSrc(): string | undefined {
271 const post = this.postView.post;
272 const url = post.url;
273 const thumbnail = post.thumbnail_url;
275 if (url && isImage(url)) {
276 if (url.includes("pictrs")) {
278 } else if (thumbnail) {
283 } else if (thumbnail) {
291 const post = this.postView.post;
292 const url = post.url;
293 const thumbnail = post.thumbnail_url;
295 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
299 className="text-body d-inline-block position-relative mb-2"
300 data-tippy-content={I18NextService.i18n.t("expand_here")}
301 onClick={linkEvent(this, this.handleImageExpandClick)}
302 aria-label={I18NextService.i18n.t("expand_here")}
304 {this.imgThumb(this.imageSrc)}
305 <Icon icon="image" classes="mini-overlay" />
308 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
311 className="text-body d-inline-block position-relative mb-2"
316 {this.imgThumb(this.imageSrc)}
317 <Icon icon="external-link" classes="mini-overlay" />
321 if (!this.props.hideImage && isVideo(url)) {
323 <div className="embed-responsive embed-responsive-16by9">
329 className="embed-responsive-item"
331 <source src={url} type="video/mp4" />
337 <a className="text-body" href={url} title={url} rel={relTags}>
338 <div className="thumbnail rounded bg-light d-flex justify-content-center">
339 <Icon icon="external-link" classes="d-flex align-items-center" />
347 className="text-body"
348 to={`/post/${post.id}`}
349 title={I18NextService.i18n.t("comments")}
351 <div className="thumbnail rounded bg-light d-flex justify-content-center">
352 <Icon icon="message-square" classes="d-flex align-items-center" />
360 const post_view = this.postView;
362 <ul className="list-inline mb-1 text-muted small mt-2">
363 <li className="list-inline-item">
364 <PersonListing person={post_view.creator} />
366 {this.creatorIsMod_ && (
367 <span className="mx-1 badge text-bg-light">
368 {I18NextService.i18n.t("mod")}
371 {this.creatorIsAdmin_ && (
372 <span className="mx-1 badge text-bg-light">
373 {I18NextService.i18n.t("admin")}
376 {post_view.creator.bot_account && (
377 <span className="mx-1 badge text-bg-light">
378 {I18NextService.i18n.t("bot_account").toLowerCase()}
381 {this.props.showCommunity && (
384 {I18NextService.i18n.t("to")}{" "}
385 <CommunityLink community={post_view.community} />
389 {post_view.post.language_id !== 0 && (
390 <span className="mx-1 badge text-bg-light">
392 this.props.allLanguages.find(
393 lang => lang.id === post_view.post.language_id
398 <li className="list-inline-item">•</li>
399 <li className="list-inline-item">
402 published={post_view.post.published}
403 updated={post_view.post.updated}
413 <div className={`vote-bar col-1 pe-0 small text-center`}>
415 className={`btn-animate btn btn-link p-0 ${
416 this.postView.my_vote == 1 ? "text-info" : "text-muted"
418 onClick={linkEvent(this, this.handleUpvote)}
419 data-tippy-content={I18NextService.i18n.t("upvote")}
420 aria-label={I18NextService.i18n.t("upvote")}
421 aria-pressed={this.postView.my_vote === 1}
423 {this.state.upvoteLoading ? (
426 <Icon icon="arrow-up1" classes="upvote" />
431 className={`unselectable pointer text-muted px-1 post-score`}
432 data-tippy-content={this.pointsTippy}
434 {numToSI(this.postView.counts.score)}
437 <div className="p-1"></div>
439 {this.props.enableDownvotes && (
441 className={`btn-animate btn btn-link p-0 ${
442 this.postView.my_vote == -1 ? "text-danger" : "text-muted"
444 onClick={linkEvent(this, this.handleDownvote)}
445 data-tippy-content={I18NextService.i18n.t("downvote")}
446 aria-label={I18NextService.i18n.t("downvote")}
447 aria-pressed={this.postView.my_vote === -1}
449 {this.state.downvoteLoading ? (
452 <Icon icon="arrow-down1" classes="downvote" />
461 const post = this.postView.post;
464 className={`d-inline ${
465 !post.featured_community && !post.featured_local
469 to={`/post/${post.id}`}
470 title={I18NextService.i18n.t("comments")}
474 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
481 const post = this.postView.post;
482 const url = post.url;
486 <div className="post-title overflow-hidden">
487 <h5 className="d-inline">
488 {url && this.props.showBody ? (
491 !post.featured_community && !post.featured_local
498 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
504 {(url && isImage(url)) ||
505 (post.thumbnail_url && (
507 className="btn btn-sm text-monospace text-muted d-inline-block"
508 data-tippy-content={I18NextService.i18n.t("expand_here")}
509 onClick={linkEvent(this, this.handleImageExpandClick)}
513 !this.state.imageExpanded ? "plus-square" : "minus-square"
515 classes="icon-inline"
520 <small className="ms-2 badge text-bg-secondary">
521 {I18NextService.i18n.t("removed")}
526 className="unselectable pointer ms-2 text-muted font-italic"
527 data-tippy-content={I18NextService.i18n.t("deleted")}
529 <Icon icon="trash" classes="icon-inline text-danger" />
534 className="unselectable pointer ms-2 text-muted font-italic"
535 data-tippy-content={I18NextService.i18n.t("locked")}
537 <Icon icon="lock" classes="icon-inline text-danger" />
540 {post.featured_community && (
542 className="unselectable pointer ms-2 text-muted font-italic"
543 data-tippy-content={I18NextService.i18n.t(
544 "featured_in_community"
546 aria-label={I18NextService.i18n.t("featured_in_community")}
548 <Icon icon="pin" classes="icon-inline text-primary" />
551 {post.featured_local && (
553 className="unselectable pointer ms-2 text-muted font-italic"
554 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
555 aria-label={I18NextService.i18n.t("featured_in_local")}
557 <Icon icon="pin" classes="icon-inline text-secondary" />
561 <small className="ms-2 badge text-bg-danger">
562 {I18NextService.i18n.t("nsfw")}
566 {url && this.urlLine()}
572 const post = this.postView.post;
573 const url = post.url;
576 <p className="d-flex text-muted align-items-center gap-1 small m-0">
577 {url && !(hostname(url) === getExternalHost()) && (
579 className="text-muted font-italic"
592 const dupes = this.props.crossPosts;
593 return dupes && dupes.length > 0 ? (
594 <ul className="list-inline mb-1 small text-muted">
596 <li className="list-inline-item me-2">
597 {I18NextService.i18n.t("cross_posted_to")}
600 <li key={pv.post.id} className="list-inline-item me-2">
601 <Link to={`/post/${pv.post.id}`}>
604 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
615 commentsLine(mobile = false) {
616 const post = this.postView.post;
619 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
620 {this.commentsButton}
623 className="btn btn-sm btn-animate text-muted py-0"
624 onClick={linkEvent(this, this.handleShare)}
627 <Icon icon="share" inline />
632 className="btn btn-sm btn-animate text-muted py-0"
633 title={I18NextService.i18n.t("link")}
636 <Icon icon="fedilink" inline />
639 {mobile && !this.props.viewOnly && this.mobileVotes}
640 {UserService.Instance.myUserInfo &&
641 !this.props.viewOnly &&
647 showPreviewButton() {
648 const post_view = this.postView;
649 const body = post_view.post.body;
653 className="btn btn-sm btn-animate text-muted py-0"
654 data-tippy-content={body && mdNoImages.render(body)}
655 data-tippy-allowHtml={true}
656 onClick={linkEvent(this, this.handleShowBody)}
660 classes={classNames("icon-inline me-1", {
661 "text-success": this.state.showBody,
669 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
670 // Possible enhancement: Make each button a component.
671 const post_view = this.postView;
672 const post = post_view.post;
677 {this.crossPostButton}
680 * If there is a URL, or if the post has a body and we were told not to
681 * show the body, show the MetadataCard/body toggle.
683 {(post.url || (post.body && !this.props.showBody)) &&
684 this.showPreviewButton()}
686 {this.showBody && post_view.post.body && this.viewSourceButton}
688 <div className="dropdown">
690 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
691 onClick={linkEvent(this, this.handleShowAdvanced)}
692 data-tippy-content={I18NextService.i18n.t("more")}
693 data-bs-toggle="dropdown"
694 aria-expanded="false"
695 aria-controls="advancedButtonsDropdown"
696 aria-label={I18NextService.i18n.t("more")}
698 <Icon icon="more-vertical" inline />
701 <ul className="dropdown-menu" id="advancedButtonsDropdown">
704 <li>{this.reportButton}</li>
705 <li>{this.blockButton}</li>
709 <li>{this.editButton}</li>
710 <li>{this.deleteButton}</li>
714 {/* Any mod can do these, not limited to hierarchy*/}
715 {(amMod(this.props.moderators) || amAdmin()) && (
718 <hr className="dropdown-divider" />
720 <li>{this.lockButton}</li>
721 {this.featureButtons}
725 {(this.canMod_ || this.canAdmin_) && (
726 <li>{this.modRemoveButton}</li>
734 get commentsButton() {
735 const post_view = this.postView;
736 const title = I18NextService.i18n.t("number_of_comments", {
737 count: Number(post_view.counts.comments),
738 formattedCount: Number(post_view.counts.comments),
743 className="btn btn-link btn-sm text-muted ps-0"
745 to={`/post/${post_view.post.id}?scrollToComments=true`}
746 data-tippy-content={title}
748 <span className="me-1">
749 <Icon icon="message-square" classes="me-1" inline />
750 {post_view.counts.comments}
752 {this.unreadCount && (
753 <span className="text-muted fst-italic">
754 ({this.unreadCount} {I18NextService.i18n.t("new")})
761 get unreadCount(): number | undefined {
762 const pv = this.postView;
763 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
765 : pv.unread_comments;
770 const tippy = showScores()
771 ? { "data-tippy-content": this.pointsTippy }
777 className={`btn-animate btn py-0 px-1 ${
778 this.postView.my_vote === 1 ? "text-info" : "text-muted"
781 onClick={linkEvent(this, this.handleUpvote)}
782 aria-label={I18NextService.i18n.t("upvote")}
783 aria-pressed={this.postView.my_vote === 1}
785 {this.state.upvoteLoading ? (
789 <Icon icon="arrow-up1" classes="icon-inline small" />
791 <span className="ms-2">
792 {numToSI(this.postView.counts.upvotes)}
798 {this.props.enableDownvotes && (
800 className={`ms-2 btn-animate btn py-0 px-1 ${
801 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
803 onClick={linkEvent(this, this.handleDownvote)}
805 aria-label={I18NextService.i18n.t("downvote")}
806 aria-pressed={this.postView.my_vote === -1}
808 {this.state.downvoteLoading ? (
812 <Icon icon="arrow-down1" classes="icon-inline small" />
815 className={classNames("ms-2", {
816 invisible: this.postView.counts.downvotes === 0,
819 {numToSI(this.postView.counts.downvotes)}
832 const saved = this.postView.saved;
834 ? I18NextService.i18n.t("unsave")
835 : I18NextService.i18n.t("save");
838 className="btn btn-sm btn-animate text-muted py-0"
839 onClick={linkEvent(this, this.handleSavePostClick)}
840 data-tippy-content={label}
843 {this.state.saveLoading ? (
848 classes={classNames({ "text-warning": saved })}
856 get crossPostButton() {
859 className="btn btn-sm btn-animate text-muted py-0"
861 /* Empty string properties are required to satisfy type*/
862 pathname: "/create_post",
863 state: { ...this.crossPostParams },
868 title={I18NextService.i18n.t("cross_post")}
869 data-tippy-content={I18NextService.i18n.t("cross_post")}
870 aria-label={I18NextService.i18n.t("cross_post")}
872 <Icon icon="copy" inline />
880 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
881 onClick={linkEvent(this, this.handleShowReportDialog)}
882 aria-label={I18NextService.i18n.t("show_report_dialog")}
884 <Icon classes="me-1" icon="flag" inline />
885 {I18NextService.i18n.t("create_report")}
893 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
894 onClick={linkEvent(this, this.handleBlockPersonClick)}
895 aria-label={I18NextService.i18n.t("block_user")}
897 {this.state.blockLoading ? (
900 <Icon classes="me-1" icon="slash" inline />
902 {I18NextService.i18n.t("block_user")}
910 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
911 onClick={linkEvent(this, this.handleEditClick)}
912 aria-label={I18NextService.i18n.t("edit")}
914 <Icon classes="me-1" icon="edit" inline />
915 {I18NextService.i18n.t("edit")}
921 const deleted = this.postView.post.deleted;
922 const label = !deleted
923 ? I18NextService.i18n.t("delete")
924 : I18NextService.i18n.t("restore");
927 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
928 onClick={linkEvent(this, this.handleDeleteClick)}
931 {this.state.deleteLoading ? (
937 classes={classNames("me-1", { "text-danger": deleted })}
947 get viewSourceButton() {
950 className="btn btn-sm btn-animate text-muted py-0"
951 onClick={linkEvent(this, this.handleViewSource)}
952 data-tippy-content={I18NextService.i18n.t("view_source")}
953 aria-label={I18NextService.i18n.t("view_source")}
957 classes={classNames({ "text-success": this.state.viewSource })}
965 const locked = this.postView.post.locked;
967 ? I18NextService.i18n.t("unlock")
968 : I18NextService.i18n.t("lock");
971 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
972 onClick={linkEvent(this, this.handleModLock)}
975 {this.state.lockLoading ? (
981 classes={classNames("me-1", { "text-danger": locked })}
991 get featureButtons() {
992 const featuredCommunity = this.postView.post.featured_community;
993 const labelCommunity = featuredCommunity
994 ? I18NextService.i18n.t("unfeature_from_community")
995 : I18NextService.i18n.t("feature_in_community");
997 const featuredLocal = this.postView.post.featured_local;
998 const labelLocal = featuredLocal
999 ? I18NextService.i18n.t("unfeature_from_local")
1000 : I18NextService.i18n.t("feature_in_local");
1005 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1006 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
1007 data-tippy-content={labelCommunity}
1008 aria-label={labelCommunity}
1010 {this.state.featureCommunityLoading ? (
1016 classes={classNames("me-1", {
1017 "text-success": featuredCommunity,
1021 {I18NextService.i18n.t("community")}
1029 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1030 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1031 data-tippy-content={labelLocal}
1032 aria-label={labelLocal}
1034 {this.state.featureLocalLoading ? (
1040 classes={classNames("me-1", {
1041 "text-success": featuredLocal,
1045 {I18NextService.i18n.t("local")}
1055 get modRemoveButton() {
1056 const removed = this.postView.post.removed;
1059 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1062 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1065 {/* TODO: Find an icon for this. */}
1066 {this.state.removeLoading ? (
1069 I18NextService.i18n.t("remove")
1071 I18NextService.i18n.t("restore")
1078 * Mod/Admin actions to be taken against the author.
1082 const post_view = this.postView;
1084 this.state.showAdvanced && (
1088 {!this.creatorIsMod_ &&
1089 (!post_view.creator_banned_from_community ? (
1091 className="btn btn-link btn-animate text-muted py-0"
1094 this.handleModBanFromCommunityShow
1096 aria-label={I18NextService.i18n.t("ban_from_community")}
1098 {I18NextService.i18n.t("ban_from_community")}
1102 className="btn btn-link btn-animate text-muted py-0"
1105 this.handleModBanFromCommunitySubmit
1107 aria-label={I18NextService.i18n.t("unban")}
1109 {this.state.banLoading ? (
1112 I18NextService.i18n.t("unban")
1116 {!post_view.creator_banned_from_community && (
1118 className="btn btn-link btn-animate text-muted py-0"
1119 onClick={linkEvent(this, this.handleAddModToCommunity)}
1122 ? I18NextService.i18n.t("remove_as_mod")
1123 : I18NextService.i18n.t("appoint_as_mod")
1126 {this.state.addModLoading ? (
1128 ) : this.creatorIsMod_ ? (
1129 I18NextService.i18n.t("remove_as_mod")
1131 I18NextService.i18n.t("appoint_as_mod")
1137 {/* Community creators and admins can transfer community to another mod */}
1138 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1140 this.creatorIsMod_ &&
1141 (!this.state.showConfirmTransferCommunity ? (
1143 className="btn btn-link btn-animate text-muted py-0"
1146 this.handleShowConfirmTransferCommunity
1148 aria-label={I18NextService.i18n.t("transfer_community")}
1150 {I18NextService.i18n.t("transfer_community")}
1155 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1156 aria-label={I18NextService.i18n.t("are_you_sure")}
1158 {I18NextService.i18n.t("are_you_sure")}
1161 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1162 aria-label={I18NextService.i18n.t("yes")}
1163 onClick={linkEvent(this, this.handleTransferCommunity)}
1165 {this.state.transferLoading ? (
1168 I18NextService.i18n.t("yes")
1172 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1175 this.handleCancelShowConfirmTransferCommunity
1177 aria-label={I18NextService.i18n.t("no")}
1179 {I18NextService.i18n.t("no")}
1183 {/* Admins can ban from all, and appoint other admins */}
1184 {this.canAdmin_ && (
1186 {!this.creatorIsAdmin_ && (
1188 {!isBanned(post_view.creator) ? (
1190 className="btn btn-link btn-animate text-muted py-0"
1191 onClick={linkEvent(this, this.handleModBanShow)}
1192 aria-label={I18NextService.i18n.t("ban_from_site")}
1194 {I18NextService.i18n.t("ban_from_site")}
1198 className="btn btn-link btn-animate text-muted py-0"
1199 onClick={linkEvent(this, this.handleModBanSubmit)}
1200 aria-label={I18NextService.i18n.t("unban_from_site")}
1202 {this.state.banLoading ? (
1205 I18NextService.i18n.t("unban_from_site")
1210 className="btn btn-link btn-animate text-muted py-0"
1211 onClick={linkEvent(this, this.handlePurgePersonShow)}
1212 aria-label={I18NextService.i18n.t("purge_user")}
1214 {I18NextService.i18n.t("purge_user")}
1217 className="btn btn-link btn-animate text-muted py-0"
1218 onClick={linkEvent(this, this.handlePurgePostShow)}
1219 aria-label={I18NextService.i18n.t("purge_post")}
1221 {I18NextService.i18n.t("purge_post")}
1225 {!isBanned(post_view.creator) && post_view.creator.local && (
1227 className="btn btn-link btn-animate text-muted py-0"
1228 onClick={linkEvent(this, this.handleAddAdmin)}
1230 this.creatorIsAdmin_
1231 ? I18NextService.i18n.t("remove_as_admin")
1232 : I18NextService.i18n.t("appoint_as_admin")
1235 {this.state.addAdminLoading ? (
1237 ) : this.creatorIsAdmin_ ? (
1238 I18NextService.i18n.t("remove_as_admin")
1240 I18NextService.i18n.t("appoint_as_admin")
1251 removeAndBanDialogs() {
1252 const post = this.postView;
1253 const purgeTypeText =
1254 this.state.purgeType == PurgeType.Post
1255 ? I18NextService.i18n.t("purge_post")
1256 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1259 {this.state.showRemoveDialog && (
1261 className="form-inline"
1262 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1265 className="visually-hidden"
1266 htmlFor="post-listing-remove-reason"
1268 {I18NextService.i18n.t("reason")}
1272 id="post-listing-remove-reason"
1273 className="form-control me-2"
1274 placeholder={I18NextService.i18n.t("reason")}
1275 value={this.state.removeReason}
1276 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1280 className="btn btn-secondary"
1281 aria-label={I18NextService.i18n.t("remove_post")}
1283 {this.state.removeLoading ? (
1286 I18NextService.i18n.t("remove_post")
1291 {this.state.showBanDialog && (
1292 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1293 <div className="mb-3 row col-12">
1295 className="col-form-label"
1296 htmlFor="post-listing-ban-reason"
1298 {I18NextService.i18n.t("reason")}
1302 id="post-listing-ban-reason"
1303 className="form-control me-2"
1304 placeholder={I18NextService.i18n.t("reason")}
1305 value={this.state.banReason}
1306 onInput={linkEvent(this, this.handleModBanReasonChange)}
1308 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1309 {I18NextService.i18n.t("expires")}
1313 id={`mod-ban-expires`}
1314 className="form-control me-2"
1315 placeholder={I18NextService.i18n.t("number_of_days")}
1316 value={this.state.banExpireDays}
1317 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1319 <div className="input-group mb-3">
1320 <div className="form-check">
1322 className="form-check-input"
1323 id="mod-ban-remove-data"
1325 checked={this.state.removeData}
1326 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1329 className="form-check-label"
1330 htmlFor="mod-ban-remove-data"
1331 title={I18NextService.i18n.t("remove_content_more")}
1333 {I18NextService.i18n.t("remove_content")}
1338 {/* TODO hold off on expires until later */}
1339 {/* <div class="mb-3 row"> */}
1340 {/* <label class="col-form-label">Expires</label> */}
1341 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1343 <div className="mb-3 row">
1346 className="btn btn-secondary"
1347 aria-label={I18NextService.i18n.t("ban")}
1349 {this.state.banLoading ? (
1353 {I18NextService.i18n.t("ban")} {post.creator.name}
1360 {this.state.showReportDialog && (
1362 className="form-inline"
1363 onSubmit={linkEvent(this, this.handleReportSubmit)}
1365 <label className="visually-hidden" htmlFor="post-report-reason">
1366 {I18NextService.i18n.t("reason")}
1370 id="post-report-reason"
1371 className="form-control me-2"
1372 placeholder={I18NextService.i18n.t("reason")}
1374 value={this.state.reportReason}
1375 onInput={linkEvent(this, this.handleReportReasonChange)}
1379 className="btn btn-secondary"
1380 aria-label={I18NextService.i18n.t("create_report")}
1382 {this.state.reportLoading ? (
1385 I18NextService.i18n.t("create_report")
1390 {this.state.showPurgeDialog && (
1392 className="form-inline"
1393 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1396 <label className="visually-hidden" htmlFor="purge-reason">
1397 {I18NextService.i18n.t("reason")}
1402 className="form-control me-2"
1403 placeholder={I18NextService.i18n.t("reason")}
1404 value={this.state.purgeReason}
1405 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1407 {this.state.purgeLoading ? (
1412 className="btn btn-secondary"
1413 aria-label={purgeTypeText}
1415 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1425 const post = this.postView.post;
1426 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1427 <div className="row">
1428 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1429 {this.postTitleLine()}
1431 <div className="col-4">
1432 {/* Post body prev or thumbnail */}
1433 {!this.state.imageExpanded && this.thumbnail()}
1437 this.postTitleLine()
1441 showMobilePreview() {
1442 const { body, id } = this.postView.post;
1444 return !this.showBody && body ? (
1445 <Link className="text-body" to={`/post/${id}`}>
1446 <div className="md-div mb-1 preview-lines">{body}</div>
1456 {/* The mobile view*/}
1457 <div className="d-block d-sm-none">
1458 <article className="row post-container">
1459 <div className="col-12">
1460 {this.createdLine()}
1462 {/* If it has a thumbnail, do a right aligned thumbnail */}
1463 {this.mobileThumbnail()}
1465 {/* Show a preview of the post body */}
1466 {this.showMobilePreview()}
1468 {this.commentsLine(true)}
1469 {this.userActionsLine()}
1470 {this.duplicatesLine()}
1471 {this.removeAndBanDialogs()}
1476 {/* The larger view*/}
1477 <div className="d-none d-sm-block">
1478 <article className="row post-container">
1479 {!this.props.viewOnly && this.voteBar()}
1480 <div className="col-sm-2 pe-0 post-media">
1481 <div className="">{this.thumbnail()}</div>
1483 <div className="col-12 col-sm-9">
1484 <div className="row">
1485 <div className="col-12">
1486 {this.postTitleLine()}
1487 {this.createdLine()}
1488 {this.commentsLine()}
1489 {this.duplicatesLine()}
1490 {this.userActionsLine()}
1491 {this.removeAndBanDialogs()}
1501 private get myPost(): boolean {
1503 this.postView.creator.id ==
1504 UserService.Instance.myUserInfo?.local_user_view.person.id
1507 handleEditClick(i: PostListing) {
1508 i.setState({ showEdit: true });
1511 handleEditCancel() {
1512 this.setState({ showEdit: false });
1515 // The actual editing is done in the receive for post
1516 handleEditPost(form: EditPost) {
1517 this.setState({ showEdit: false });
1518 this.props.onPostEdit(form);
1521 handleShare(i: PostListing) {
1522 const { name, body, id } = i.props.post_view.post;
1525 text: body?.slice(0, 50),
1526 url: `${getHttpBase()}/post/${id}`,
1530 handleShowReportDialog(i: PostListing) {
1531 i.setState({ showReportDialog: !i.state.showReportDialog });
1534 handleReportReasonChange(i: PostListing, event: any) {
1535 i.setState({ reportReason: event.target.value });
1538 handleReportSubmit(i: PostListing, event: any) {
1539 event.preventDefault();
1540 i.setState({ reportLoading: true });
1541 i.props.onPostReport({
1542 post_id: i.postView.post.id,
1543 reason: i.state.reportReason ?? "",
1544 auth: myAuthRequired(),
1548 handleBlockPersonClick(i: PostListing) {
1549 i.setState({ blockLoading: true });
1550 i.props.onBlockPerson({
1551 person_id: i.postView.creator.id,
1553 auth: myAuthRequired(),
1557 handleDeleteClick(i: PostListing) {
1558 i.setState({ deleteLoading: true });
1559 i.props.onDeletePost({
1560 post_id: i.postView.post.id,
1561 deleted: !i.postView.post.deleted,
1562 auth: myAuthRequired(),
1566 handleSavePostClick(i: PostListing) {
1567 i.setState({ saveLoading: true });
1568 i.props.onSavePost({
1569 post_id: i.postView.post.id,
1570 save: !i.postView.saved,
1571 auth: myAuthRequired(),
1575 get crossPostParams(): PostFormParams {
1576 const queryParams: PostFormParams = {};
1577 const { name, url } = this.postView.post;
1579 queryParams.name = name;
1582 queryParams.url = url;
1585 const crossPostBody = this.crossPostBody();
1586 if (crossPostBody) {
1587 queryParams.body = crossPostBody;
1593 crossPostBody(): string | undefined {
1594 const post = this.postView.post;
1595 const body = post.body;
1598 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1600 }\n\n${body.replace(/^/gm, "> ")}`
1604 get showBody(): boolean {
1605 return this.props.showBody || this.state.showBody;
1608 handleModRemoveShow(i: PostListing) {
1610 showRemoveDialog: !i.state.showRemoveDialog,
1611 showBanDialog: false,
1615 handleModRemoveReasonChange(i: PostListing, event: any) {
1616 i.setState({ removeReason: event.target.value });
1619 handleModRemoveDataChange(i: PostListing, event: any) {
1620 i.setState({ removeData: event.target.checked });
1623 handleModRemoveSubmit(i: PostListing, event: any) {
1624 event.preventDefault();
1625 i.setState({ removeLoading: true });
1626 i.props.onRemovePost({
1627 post_id: i.postView.post.id,
1628 removed: !i.postView.post.removed,
1629 auth: myAuthRequired(),
1633 handleModLock(i: PostListing) {
1634 i.setState({ lockLoading: true });
1635 i.props.onLockPost({
1636 post_id: i.postView.post.id,
1637 locked: !i.postView.post.locked,
1638 auth: myAuthRequired(),
1642 handleModFeaturePostLocal(i: PostListing) {
1643 i.setState({ featureLocalLoading: true });
1644 i.props.onFeaturePost({
1645 post_id: i.postView.post.id,
1646 featured: !i.postView.post.featured_local,
1647 feature_type: "Local",
1648 auth: myAuthRequired(),
1652 handleModFeaturePostCommunity(i: PostListing) {
1653 i.setState({ featureCommunityLoading: true });
1654 i.props.onFeaturePost({
1655 post_id: i.postView.post.id,
1656 featured: !i.postView.post.featured_community,
1657 feature_type: "Community",
1658 auth: myAuthRequired(),
1662 handleModBanFromCommunityShow(i: PostListing) {
1664 showBanDialog: true,
1665 banType: BanType.Community,
1666 showRemoveDialog: false,
1670 handleModBanShow(i: PostListing) {
1672 showBanDialog: true,
1673 banType: BanType.Site,
1674 showRemoveDialog: false,
1678 handlePurgePersonShow(i: PostListing) {
1680 showPurgeDialog: true,
1681 purgeType: PurgeType.Person,
1682 showRemoveDialog: false,
1686 handlePurgePostShow(i: PostListing) {
1688 showPurgeDialog: true,
1689 purgeType: PurgeType.Post,
1690 showRemoveDialog: false,
1694 handlePurgeReasonChange(i: PostListing, event: any) {
1695 i.setState({ purgeReason: event.target.value });
1698 handlePurgeSubmit(i: PostListing, event: any) {
1699 event.preventDefault();
1700 i.setState({ purgeLoading: true });
1701 if (i.state.purgeType == PurgeType.Person) {
1702 i.props.onPurgePerson({
1703 person_id: i.postView.creator.id,
1704 reason: i.state.purgeReason,
1705 auth: myAuthRequired(),
1707 } else if (i.state.purgeType == PurgeType.Post) {
1708 i.props.onPurgePost({
1709 post_id: i.postView.post.id,
1710 reason: i.state.purgeReason,
1711 auth: myAuthRequired(),
1716 handleModBanReasonChange(i: PostListing, event: any) {
1717 i.setState({ banReason: event.target.value });
1720 handleModBanExpireDaysChange(i: PostListing, event: any) {
1721 i.setState({ banExpireDays: event.target.value });
1724 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1725 i.setState({ banType: BanType.Community });
1726 i.handleModBanBothSubmit(i, event);
1729 handleModBanSubmit(i: PostListing, event: any) {
1730 i.setState({ banType: BanType.Site });
1731 i.handleModBanBothSubmit(i, event);
1734 handleModBanBothSubmit(i: PostListing, event: any) {
1735 event.preventDefault();
1736 i.setState({ banLoading: true });
1738 const ban = !i.props.post_view.creator_banned_from_community;
1739 // If its an unban, restore all their data
1741 i.setState({ removeData: false });
1743 const person_id = i.props.post_view.creator.id;
1744 const remove_data = i.state.removeData;
1745 const reason = i.state.banReason;
1746 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1748 if (i.state.banType == BanType.Community) {
1749 const community_id = i.postView.community.id;
1750 i.props.onBanPersonFromCommunity({
1757 auth: myAuthRequired(),
1760 i.props.onBanPerson({
1766 auth: myAuthRequired(),
1771 handleAddModToCommunity(i: PostListing) {
1772 i.setState({ addModLoading: true });
1773 i.props.onAddModToCommunity({
1774 community_id: i.postView.community.id,
1775 person_id: i.postView.creator.id,
1776 added: !i.creatorIsMod_,
1777 auth: myAuthRequired(),
1781 handleAddAdmin(i: PostListing) {
1782 i.setState({ addAdminLoading: true });
1783 i.props.onAddAdmin({
1784 person_id: i.postView.creator.id,
1785 added: !i.creatorIsAdmin_,
1786 auth: myAuthRequired(),
1790 handleShowConfirmTransferCommunity(i: PostListing) {
1791 i.setState({ showConfirmTransferCommunity: true });
1794 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1795 i.setState({ showConfirmTransferCommunity: false });
1798 handleTransferCommunity(i: PostListing) {
1799 i.setState({ transferLoading: true });
1800 i.props.onTransferCommunity({
1801 community_id: i.postView.community.id,
1802 person_id: i.postView.creator.id,
1803 auth: myAuthRequired(),
1807 handleShowConfirmTransferSite(i: PostListing) {
1808 i.setState({ showConfirmTransferSite: true });
1811 handleCancelShowConfirmTransferSite(i: PostListing) {
1812 i.setState({ showConfirmTransferSite: false });
1815 handleImageExpandClick(i: PostListing, event: any) {
1816 event.preventDefault();
1817 i.setState({ imageExpanded: !i.state.imageExpanded });
1821 handleViewSource(i: PostListing) {
1822 i.setState({ viewSource: !i.state.viewSource });
1825 handleShowAdvanced(i: PostListing) {
1826 i.setState({ showAdvanced: !i.state.showAdvanced });
1830 handleShowMoreMobile(i: PostListing) {
1832 showMoreMobile: !i.state.showMoreMobile,
1833 showAdvanced: !i.state.showAdvanced,
1838 handleShowBody(i: PostListing) {
1839 i.setState({ showBody: !i.state.showBody });
1843 handleUpvote(i: PostListing) {
1844 i.setState({ upvoteLoading: true });
1845 i.props.onPostVote({
1846 post_id: i.postView.post.id,
1847 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1848 auth: myAuthRequired(),
1852 handleDownvote(i: PostListing) {
1853 i.setState({ downvoteLoading: true });
1854 i.props.onPostVote({
1855 post_id: i.postView.post.id,
1856 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1857 auth: myAuthRequired(),
1861 get pointsTippy(): string {
1862 const points = I18NextService.i18n.t("number_of_points", {
1863 count: Number(this.postView.counts.score),
1864 formattedCount: Number(this.postView.counts.score),
1867 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1868 count: Number(this.postView.counts.upvotes),
1869 formattedCount: Number(this.postView.counts.upvotes),
1872 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1873 count: Number(this.postView.counts.downvotes),
1874 formattedCount: Number(this.postView.counts.downvotes),
1877 return `${points} • ${upvotes} • ${downvotes}`;
1880 get canModOnSelf_(): boolean {
1882 this.postView.creator.id,
1883 this.props.moderators,
1890 get canMod_(): boolean {
1892 this.postView.creator.id,
1893 this.props.moderators,
1898 get canAdmin_(): boolean {
1899 return canAdmin(this.postView.creator.id, this.props.admins);
1902 get creatorIsMod_(): boolean {
1903 return isMod(this.postView.creator.id, this.props.moderators);
1906 get creatorIsAdmin_(): boolean {
1907 return isAdmin(this.postView.creator.id, this.props.admins);