1 import { myAuthRequired, newVote } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
46 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
47 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
48 import { I18NextService, UserService } from "../../services";
49 import { setupTippy } from "../../tippy";
50 import { Icon, PurgeWarning, Spinner } from "../common/icon";
51 import { MomentTime } from "../common/moment-time";
52 import { PictrsImage } from "../common/pictrs-image";
53 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
54 import { CommunityLink } from "../community/community-link";
55 import { PersonListing } from "../person/person-listing";
56 import { MetadataCard } from "./metadata-card";
57 import { PostForm } from "./post-form";
59 interface PostListingState {
61 showRemoveDialog: boolean;
62 showPurgeDialog: boolean;
64 purgeType?: PurgeType;
65 purgeLoading: boolean;
66 removeReason?: string;
67 showBanDialog: boolean;
69 banExpireDays?: number;
72 showConfirmTransferSite: boolean;
73 showConfirmTransferCommunity: boolean;
74 imageExpanded: boolean;
76 showAdvanced: boolean;
77 showMoreMobile: boolean;
79 showReportDialog: boolean;
80 reportReason?: string;
81 upvoteLoading: boolean;
82 downvoteLoading: boolean;
83 reportLoading: boolean;
84 blockLoading: boolean;
86 deleteLoading: boolean;
87 removeLoading: boolean;
89 featureCommunityLoading: boolean;
90 featureLocalLoading: boolean;
92 addModLoading: boolean;
93 addAdminLoading: boolean;
94 transferLoading: boolean;
97 interface PostListingProps {
99 crossPosts?: PostView[];
100 moderators?: CommunityModeratorView[];
101 admins?: PersonView[];
102 allLanguages: Language[];
103 siteLanguages: number[];
104 showCommunity?: boolean;
107 enableDownvotes?: boolean;
108 enableNsfw?: boolean;
110 onPostEdit(form: EditPost): void;
111 onPostVote(form: CreatePostLike): void;
112 onPostReport(form: CreatePostReport): void;
113 onBlockPerson(form: BlockPerson): void;
114 onLockPost(form: LockPost): void;
115 onDeletePost(form: DeletePost): void;
116 onRemovePost(form: RemovePost): void;
117 onSavePost(form: SavePost): void;
118 onFeaturePost(form: FeaturePost): void;
119 onPurgePerson(form: PurgePerson): void;
120 onPurgePost(form: PurgePost): void;
121 onBanPersonFromCommunity(form: BanFromCommunity): void;
122 onBanPerson(form: BanPerson): void;
123 onAddModToCommunity(form: AddModToCommunity): void;
124 onAddAdmin(form: AddAdmin): void;
125 onTransferCommunity(form: TransferCommunity): void;
128 export class PostListing extends Component<PostListingProps, PostListingState> {
129 state: PostListingState = {
131 showRemoveDialog: false,
132 showPurgeDialog: false,
133 purgeType: PurgeType.Person,
134 showBanDialog: false,
135 banType: BanType.Community,
137 showConfirmTransferSite: false,
138 showConfirmTransferCommunity: false,
139 imageExpanded: false,
142 showMoreMobile: false,
144 showReportDialog: false,
145 upvoteLoading: false,
146 downvoteLoading: false,
148 reportLoading: false,
151 deleteLoading: false,
152 removeLoading: false,
154 featureCommunityLoading: false,
155 featureLocalLoading: false,
157 addModLoading: false,
158 addAdminLoading: false,
159 transferLoading: false,
162 constructor(props: any, context: any) {
163 super(props, context);
165 this.handleEditPost = this.handleEditPost.bind(this);
166 this.handleEditCancel = this.handleEditCancel.bind(this);
169 componentWillReceiveProps(nextProps: PostListingProps) {
170 if (this.props !== nextProps) {
172 upvoteLoading: false,
173 downvoteLoading: false,
175 reportLoading: false,
178 deleteLoading: false,
179 removeLoading: false,
181 featureCommunityLoading: false,
182 featureLocalLoading: false,
184 addModLoading: false,
185 addAdminLoading: false,
186 transferLoading: false,
187 imageExpanded: false,
192 get postView(): PostView {
193 return this.props.post_view;
197 const post = this.postView.post;
200 <div className="post-listing mt-2">
201 {!this.state.showEdit ? (
204 {this.state.imageExpanded && !this.props.hideImage && this.img}
205 {post.url && this.state.showBody && post.embed_title && (
206 <MetadataCard post={post} />
208 {this.showBody && this.body()}
212 post_view={this.postView}
213 crossPosts={this.props.crossPosts}
214 onEdit={this.handleEditPost}
215 onCancel={this.handleEditCancel}
216 enableNsfw={this.props.enableNsfw}
217 enableDownvotes={this.props.enableDownvotes}
218 allLanguages={this.props.allLanguages}
219 siteLanguages={this.props.siteLanguages}
227 const body = this.postView.post.body;
229 <article id="postContent" className="col-12 card my-2 p-2">
230 {this.state.viewSource ? (
233 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
245 <div className="offset-sm-3 my-2 d-none d-sm-block">
246 <a href={this.imageSrc} className="d-inline-block">
247 <PictrsImage src={this.imageSrc} />
250 <div className="my-2 d-block d-sm-none">
252 className="d-inline-block"
253 onClick={linkEvent(this, this.handleImageExpandClick)}
255 <PictrsImage src={this.imageSrc} />
262 const { post } = this.postView;
263 const { url } = post;
265 if (url && isVideo(url)) {
267 <div className="embed-responsive mt-3">
268 <video muted controls className="embed-responsive-item col-12">
269 <source src={url} type="video/mp4" />
278 imgThumb(src: string) {
279 const post_view = this.postView;
285 nsfw={post_view.post.nsfw || post_view.community.nsfw}
290 get imageSrc(): string | undefined {
291 const post = this.postView.post;
292 const url = post.url;
293 const thumbnail = post.thumbnail_url;
295 if (url && isImage(url)) {
296 if (url.includes("pictrs")) {
298 } else if (thumbnail) {
303 } else if (thumbnail) {
311 const post = this.postView.post;
312 const url = post.url;
313 const thumbnail = post.thumbnail_url;
315 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
319 className="text-body d-inline-block position-relative mb-2"
320 data-tippy-content={I18NextService.i18n.t("expand_here")}
321 onClick={linkEvent(this, this.handleImageExpandClick)}
322 aria-label={I18NextService.i18n.t("expand_here")}
324 {this.imgThumb(this.imageSrc)}
325 <Icon icon="image" classes="mini-overlay" />
328 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
331 className="text-body d-inline-block position-relative mb-2"
336 {this.imgThumb(this.imageSrc)}
337 <Icon icon="external-link" classes="mini-overlay" />
341 if (!this.props.hideImage && isVideo(url)) {
344 className="text-body"
348 data-tippy-content={I18NextService.i18n.t("expand_here")}
349 onClick={linkEvent(this, this.handleImageExpandClick)}
350 aria-label={I18NextService.i18n.t("expand_here")}
352 <div className="thumbnail rounded bg-light d-flex justify-content-center">
353 <Icon icon="play" classes="d-flex align-items-center" />
359 <a className="text-body" href={url} title={url} rel={relTags}>
360 <div className="thumbnail rounded bg-light d-flex justify-content-center">
361 <Icon icon="external-link" classes="d-flex align-items-center" />
369 className="text-body"
370 to={`/post/${post.id}`}
371 title={I18NextService.i18n.t("comments")}
373 <div className="thumbnail rounded bg-light d-flex justify-content-center">
374 <Icon icon="message-square" classes="d-flex align-items-center" />
382 const post_view = this.postView;
384 <ul className="list-inline mb-1 text-muted small mt-2">
385 <li className="list-inline-item">
386 <PersonListing person={post_view.creator} />
388 {this.creatorIsMod_ && (
389 <span className="mx-1 badge text-bg-light">
390 {I18NextService.i18n.t("mod")}
393 {this.creatorIsAdmin_ && (
394 <span className="mx-1 badge text-bg-light">
395 {I18NextService.i18n.t("admin")}
398 {post_view.creator.bot_account && (
399 <span className="mx-1 badge text-bg-light">
400 {I18NextService.i18n.t("bot_account").toLowerCase()}
403 {this.props.showCommunity && (
406 {I18NextService.i18n.t("to")}{" "}
407 <CommunityLink community={post_view.community} />
411 {post_view.post.language_id !== 0 && (
412 <span className="mx-1 badge text-bg-light">
414 this.props.allLanguages.find(
415 lang => lang.id === post_view.post.language_id
420 <li className="list-inline-item">•</li>
421 <li className="list-inline-item">
424 published={post_view.post.published}
425 updated={post_view.post.updated}
434 const post = this.postView.post;
437 className={`d-inline ${
438 !post.featured_community && !post.featured_local
442 to={`/post/${post.id}`}
443 title={I18NextService.i18n.t("comments")}
447 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
454 const post = this.postView.post;
455 const url = post.url;
459 <div className="post-title overflow-hidden">
460 <h5 className="d-inline">
461 {url && this.props.showBody ? (
464 !post.featured_community && !post.featured_local
471 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
477 {(url && isImage(url)) ||
478 (post.thumbnail_url && (
480 className="btn btn-sm text-monospace text-muted d-inline-block"
481 data-tippy-content={I18NextService.i18n.t("expand_here")}
482 onClick={linkEvent(this, this.handleImageExpandClick)}
486 !this.state.imageExpanded ? "plus-square" : "minus-square"
488 classes="icon-inline"
493 <small className="ms-2 badge text-bg-secondary">
494 {I18NextService.i18n.t("removed")}
499 className="unselectable pointer ms-2 text-muted font-italic"
500 data-tippy-content={I18NextService.i18n.t("deleted")}
502 <Icon icon="trash" classes="icon-inline text-danger" />
507 className="unselectable pointer ms-2 text-muted font-italic"
508 data-tippy-content={I18NextService.i18n.t("locked")}
510 <Icon icon="lock" classes="icon-inline text-danger" />
513 {post.featured_community && (
515 className="unselectable pointer ms-2 text-muted font-italic"
516 data-tippy-content={I18NextService.i18n.t(
517 "featured_in_community"
519 aria-label={I18NextService.i18n.t("featured_in_community")}
521 <Icon icon="pin" classes="icon-inline text-primary" />
524 {post.featured_local && (
526 className="unselectable pointer ms-2 text-muted font-italic"
527 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
528 aria-label={I18NextService.i18n.t("featured_in_local")}
530 <Icon icon="pin" classes="icon-inline text-secondary" />
534 <small className="ms-2 badge text-bg-danger">
535 {I18NextService.i18n.t("nsfw")}
539 {url && this.urlLine()}
545 const post = this.postView.post;
546 const url = post.url;
549 <p className="d-flex text-muted align-items-center gap-1 small m-0">
550 {url && !(hostname(url) === getExternalHost()) && (
552 className="text-muted font-italic"
565 const dupes = this.props.crossPosts;
566 return dupes && dupes.length > 0 ? (
567 <ul className="list-inline mb-1 small text-muted">
569 <li className="list-inline-item me-2">
570 {I18NextService.i18n.t("cross_posted_to")}
573 <li key={pv.post.id} className="list-inline-item me-2">
574 <Link to={`/post/${pv.post.id}`}>
577 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
588 commentsLine(mobile = false) {
589 const post = this.postView.post;
592 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
593 {this.commentsButton}
596 className="btn btn-sm btn-animate text-muted py-0"
597 onClick={linkEvent(this, this.handleShare)}
600 <Icon icon="share" inline />
605 className="btn btn-sm btn-animate text-muted py-0"
606 title={I18NextService.i18n.t("link")}
609 <Icon icon="fedilink" inline />
612 {mobile && !this.props.viewOnly && (
615 enableDownvotes={this.props.enableDownvotes}
616 handleUpvote={this.handleUpvote}
617 handleDownvote={this.handleDownvote}
618 counts={this.postView.counts}
619 my_vote={this.postView.my_vote}
622 {UserService.Instance.myUserInfo &&
623 !this.props.viewOnly &&
629 showPreviewButton() {
630 const post_view = this.postView;
631 const body = post_view.post.body;
635 className="btn btn-sm btn-animate text-muted py-0"
636 data-tippy-content={body && mdNoImages.render(body)}
637 data-tippy-allowHtml={true}
638 onClick={linkEvent(this, this.handleShowBody)}
642 classes={classNames("icon-inline me-1", {
643 "text-success": this.state.showBody,
651 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
652 // Possible enhancement: Make each button a component.
653 const post_view = this.postView;
654 const post = post_view.post;
661 * If there is a URL, or if the post has a body and we were told not to
662 * show the body, show the MetadataCard/body toggle.
664 {(post.url || (post.body && !this.props.showBody)) &&
665 this.showPreviewButton()}
667 {this.showBody && post_view.post.body && this.viewSourceButton}
669 <div className="dropdown">
671 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
672 onClick={linkEvent(this, this.handleShowAdvanced)}
673 data-tippy-content={I18NextService.i18n.t("more")}
674 data-bs-toggle="dropdown"
675 aria-expanded="false"
676 aria-controls="advancedButtonsDropdown"
677 aria-label={I18NextService.i18n.t("more")}
679 <Icon icon="more-vertical" inline />
682 <ul className="dropdown-menu" id="advancedButtonsDropdown">
683 <li>{this.crossPostButton}</li>
685 <hr className="dropdown-divider" />
690 <li>{this.reportButton}</li>
691 <li>{this.blockButton}</li>
695 <li>{this.editButton}</li>
696 <li>{this.deleteButton}</li>
700 {/* Any mod can do these, not limited to hierarchy*/}
701 {(amMod(this.props.moderators) || amAdmin()) && (
704 <hr className="dropdown-divider" />
706 <li>{this.lockButton}</li>
707 {this.featureButtons}
711 {(this.canMod_ || this.canAdmin_) && (
712 <li>{this.modRemoveButton}</li>
720 get commentsButton() {
721 const post_view = this.postView;
722 const title = I18NextService.i18n.t("number_of_comments", {
723 count: Number(post_view.counts.comments),
724 formattedCount: Number(post_view.counts.comments),
729 className="btn btn-link btn-sm text-muted ps-0"
731 to={`/post/${post_view.post.id}?scrollToComments=true`}
732 data-tippy-content={title}
734 <span className="me-1">
735 <Icon icon="message-square" classes="me-1" inline />
736 {post_view.counts.comments}
738 {this.unreadCount && (
739 <span className="text-muted fst-italic">
740 ({this.unreadCount} {I18NextService.i18n.t("new")})
747 get unreadCount(): number | undefined {
748 const pv = this.postView;
749 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
751 : pv.unread_comments;
755 const saved = this.postView.saved;
757 ? I18NextService.i18n.t("unsave")
758 : I18NextService.i18n.t("save");
761 className="btn btn-sm btn-animate text-muted py-0"
762 onClick={linkEvent(this, this.handleSavePostClick)}
763 data-tippy-content={label}
766 {this.state.saveLoading ? (
771 classes={classNames({ "text-warning": saved })}
779 get crossPostButton() {
782 className="btn btn-sm d-flex align-items-center rounded-0 dropdown-item"
784 /* Empty string properties are required to satisfy type*/
785 pathname: "/create_post",
786 state: { ...this.crossPostParams },
791 title={I18NextService.i18n.t("cross_post")}
792 data-tippy-content={I18NextService.i18n.t("cross_post")}
793 aria-label={I18NextService.i18n.t("cross_post")}
795 <Icon classes="me-1" icon="copy" inline />
796 {I18NextService.i18n.t("cross_post")}
804 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
805 onClick={linkEvent(this, this.handleShowReportDialog)}
806 aria-label={I18NextService.i18n.t("show_report_dialog")}
808 <Icon classes="me-1" icon="flag" inline />
809 {I18NextService.i18n.t("create_report")}
817 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
818 onClick={linkEvent(this, this.handleBlockPersonClick)}
819 aria-label={I18NextService.i18n.t("block_user")}
821 {this.state.blockLoading ? (
824 <Icon classes="me-1" icon="slash" inline />
826 {I18NextService.i18n.t("block_user")}
834 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
835 onClick={linkEvent(this, this.handleEditClick)}
836 aria-label={I18NextService.i18n.t("edit")}
838 <Icon classes="me-1" icon="edit" inline />
839 {I18NextService.i18n.t("edit")}
845 const deleted = this.postView.post.deleted;
846 const label = !deleted
847 ? I18NextService.i18n.t("delete")
848 : I18NextService.i18n.t("restore");
851 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
852 onClick={linkEvent(this, this.handleDeleteClick)}
854 {this.state.deleteLoading ? (
860 classes={classNames("me-1", { "text-danger": deleted })}
870 get viewSourceButton() {
873 className="btn btn-sm btn-animate text-muted py-0"
874 onClick={linkEvent(this, this.handleViewSource)}
875 data-tippy-content={I18NextService.i18n.t("view_source")}
876 aria-label={I18NextService.i18n.t("view_source")}
880 classes={classNames({ "text-success": this.state.viewSource })}
888 const locked = this.postView.post.locked;
890 ? I18NextService.i18n.t("unlock")
891 : I18NextService.i18n.t("lock");
894 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
895 onClick={linkEvent(this, this.handleModLock)}
898 {this.state.lockLoading ? (
904 classes={classNames("me-1", { "text-danger": locked })}
907 {capitalizeFirstLetter(label)}
914 get featureButtons() {
915 const featuredCommunity = this.postView.post.featured_community;
916 const labelCommunity = featuredCommunity
917 ? I18NextService.i18n.t("unfeature_from_community")
918 : I18NextService.i18n.t("feature_in_community");
920 const featuredLocal = this.postView.post.featured_local;
921 const labelLocal = featuredLocal
922 ? I18NextService.i18n.t("unfeature_from_local")
923 : I18NextService.i18n.t("feature_in_local");
928 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
929 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
930 data-tippy-content={labelCommunity}
931 aria-label={labelCommunity}
933 {this.state.featureCommunityLoading ? (
939 classes={classNames("me-1", {
940 "text-success": featuredCommunity,
944 {I18NextService.i18n.t("community")}
952 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
953 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
954 data-tippy-content={labelLocal}
955 aria-label={labelLocal}
957 {this.state.featureLocalLoading ? (
963 classes={classNames("me-1", {
964 "text-success": featuredLocal,
968 {I18NextService.i18n.t("local")}
978 get modRemoveButton() {
979 const removed = this.postView.post.removed;
982 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
985 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
988 {/* TODO: Find an icon for this. */}
989 {this.state.removeLoading ? (
992 I18NextService.i18n.t("remove")
994 I18NextService.i18n.t("restore")
1001 * Mod/Admin actions to be taken against the author.
1005 const post_view = this.postView;
1007 this.state.showAdvanced && (
1011 {!this.creatorIsMod_ &&
1012 (!post_view.creator_banned_from_community ? (
1014 className="btn btn-link btn-animate text-muted py-0"
1017 this.handleModBanFromCommunityShow
1019 aria-label={I18NextService.i18n.t("ban_from_community")}
1021 {I18NextService.i18n.t("ban_from_community")}
1025 className="btn btn-link btn-animate text-muted py-0"
1028 this.handleModBanFromCommunitySubmit
1030 aria-label={I18NextService.i18n.t("unban")}
1032 {this.state.banLoading ? (
1035 I18NextService.i18n.t("unban")
1039 {!post_view.creator_banned_from_community && (
1041 className="btn btn-link btn-animate text-muted py-0"
1042 onClick={linkEvent(this, this.handleAddModToCommunity)}
1045 ? I18NextService.i18n.t("remove_as_mod")
1046 : I18NextService.i18n.t("appoint_as_mod")
1049 {this.state.addModLoading ? (
1051 ) : this.creatorIsMod_ ? (
1052 I18NextService.i18n.t("remove_as_mod")
1054 I18NextService.i18n.t("appoint_as_mod")
1060 {/* Community creators and admins can transfer community to another mod */}
1061 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1063 this.creatorIsMod_ &&
1064 (!this.state.showConfirmTransferCommunity ? (
1066 className="btn btn-link btn-animate text-muted py-0"
1069 this.handleShowConfirmTransferCommunity
1071 aria-label={I18NextService.i18n.t("transfer_community")}
1073 {I18NextService.i18n.t("transfer_community")}
1078 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1079 aria-label={I18NextService.i18n.t("are_you_sure")}
1081 {I18NextService.i18n.t("are_you_sure")}
1084 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1085 aria-label={I18NextService.i18n.t("yes")}
1086 onClick={linkEvent(this, this.handleTransferCommunity)}
1088 {this.state.transferLoading ? (
1091 I18NextService.i18n.t("yes")
1095 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1098 this.handleCancelShowConfirmTransferCommunity
1100 aria-label={I18NextService.i18n.t("no")}
1102 {I18NextService.i18n.t("no")}
1106 {/* Admins can ban from all, and appoint other admins */}
1107 {this.canAdmin_ && (
1109 {!this.creatorIsAdmin_ && (
1111 {!isBanned(post_view.creator) ? (
1113 className="btn btn-link btn-animate text-muted py-0"
1114 onClick={linkEvent(this, this.handleModBanShow)}
1115 aria-label={I18NextService.i18n.t("ban_from_site")}
1117 {I18NextService.i18n.t("ban_from_site")}
1121 className="btn btn-link btn-animate text-muted py-0"
1122 onClick={linkEvent(this, this.handleModBanSubmit)}
1123 aria-label={I18NextService.i18n.t("unban_from_site")}
1125 {this.state.banLoading ? (
1128 I18NextService.i18n.t("unban_from_site")
1133 className="btn btn-link btn-animate text-muted py-0"
1134 onClick={linkEvent(this, this.handlePurgePersonShow)}
1135 aria-label={I18NextService.i18n.t("purge_user")}
1137 {I18NextService.i18n.t("purge_user")}
1140 className="btn btn-link btn-animate text-muted py-0"
1141 onClick={linkEvent(this, this.handlePurgePostShow)}
1142 aria-label={I18NextService.i18n.t("purge_post")}
1144 {I18NextService.i18n.t("purge_post")}
1148 {!isBanned(post_view.creator) && post_view.creator.local && (
1150 className="btn btn-link btn-animate text-muted py-0"
1151 onClick={linkEvent(this, this.handleAddAdmin)}
1153 this.creatorIsAdmin_
1154 ? I18NextService.i18n.t("remove_as_admin")
1155 : I18NextService.i18n.t("appoint_as_admin")
1158 {this.state.addAdminLoading ? (
1160 ) : this.creatorIsAdmin_ ? (
1161 I18NextService.i18n.t("remove_as_admin")
1163 I18NextService.i18n.t("appoint_as_admin")
1174 removeAndBanDialogs() {
1175 const post = this.postView;
1176 const purgeTypeText =
1177 this.state.purgeType == PurgeType.Post
1178 ? I18NextService.i18n.t("purge_post")
1179 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1182 {this.state.showRemoveDialog && (
1184 className="form-inline"
1185 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1188 className="visually-hidden"
1189 htmlFor="post-listing-remove-reason"
1191 {I18NextService.i18n.t("reason")}
1195 id="post-listing-remove-reason"
1196 className="form-control me-2"
1197 placeholder={I18NextService.i18n.t("reason")}
1198 value={this.state.removeReason}
1199 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1203 className="btn btn-secondary"
1204 aria-label={I18NextService.i18n.t("remove_post")}
1206 {this.state.removeLoading ? (
1209 I18NextService.i18n.t("remove_post")
1214 {this.state.showBanDialog && (
1215 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1216 <div className="mb-3 row col-12">
1218 className="col-form-label"
1219 htmlFor="post-listing-ban-reason"
1221 {I18NextService.i18n.t("reason")}
1225 id="post-listing-ban-reason"
1226 className="form-control me-2"
1227 placeholder={I18NextService.i18n.t("reason")}
1228 value={this.state.banReason}
1229 onInput={linkEvent(this, this.handleModBanReasonChange)}
1231 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1232 {I18NextService.i18n.t("expires")}
1236 id={`mod-ban-expires`}
1237 className="form-control me-2"
1238 placeholder={I18NextService.i18n.t("number_of_days")}
1239 value={this.state.banExpireDays}
1240 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1242 <div className="input-group mb-3">
1243 <div className="form-check">
1245 className="form-check-input"
1246 id="mod-ban-remove-data"
1248 checked={this.state.removeData}
1249 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1252 className="form-check-label"
1253 htmlFor="mod-ban-remove-data"
1254 title={I18NextService.i18n.t("remove_content_more")}
1256 {I18NextService.i18n.t("remove_content")}
1261 {/* TODO hold off on expires until later */}
1262 {/* <div class="mb-3 row"> */}
1263 {/* <label class="col-form-label">Expires</label> */}
1264 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1266 <div className="mb-3 row">
1269 className="btn btn-secondary"
1270 aria-label={I18NextService.i18n.t("ban")}
1272 {this.state.banLoading ? (
1276 {I18NextService.i18n.t("ban")} {post.creator.name}
1283 {this.state.showReportDialog && (
1285 className="form-inline"
1286 onSubmit={linkEvent(this, this.handleReportSubmit)}
1288 <label className="visually-hidden" htmlFor="post-report-reason">
1289 {I18NextService.i18n.t("reason")}
1293 id="post-report-reason"
1294 className="form-control me-2"
1295 placeholder={I18NextService.i18n.t("reason")}
1297 value={this.state.reportReason}
1298 onInput={linkEvent(this, this.handleReportReasonChange)}
1302 className="btn btn-secondary"
1303 aria-label={I18NextService.i18n.t("create_report")}
1305 {this.state.reportLoading ? (
1308 I18NextService.i18n.t("create_report")
1313 {this.state.showPurgeDialog && (
1315 className="form-inline"
1316 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1319 <label className="visually-hidden" htmlFor="purge-reason">
1320 {I18NextService.i18n.t("reason")}
1325 className="form-control me-2"
1326 placeholder={I18NextService.i18n.t("reason")}
1327 value={this.state.purgeReason}
1328 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1330 {this.state.purgeLoading ? (
1335 className="btn btn-secondary"
1336 aria-label={purgeTypeText}
1338 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1348 const post = this.postView.post;
1349 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1350 <div className="row">
1351 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1352 {this.postTitleLine()}
1354 <div className="col-4">
1355 {/* Post thumbnail */}
1356 {!this.state.imageExpanded && this.thumbnail()}
1360 this.postTitleLine()
1365 const { body, id } = this.postView.post;
1367 return !this.showBody && body ? (
1368 <Link className="text-body" to={`/post/${id}`}>
1369 <div className="md-div mb-1 preview-lines">{body}</div>
1379 {/* The mobile view*/}
1380 <div className="d-block d-sm-none">
1381 <article className="row post-container">
1382 <div className="col-12">
1383 {this.createdLine()}
1385 {/* If it has a thumbnail, do a right aligned thumbnail */}
1386 {this.mobileThumbnail()}
1388 <div className="mt-2">
1389 {this.bodyPreview()}
1390 {this.commentsLine(true)}
1392 {this.userActionsLine()}
1393 {this.duplicatesLine()}
1394 {this.removeAndBanDialogs()}
1399 {/* The larger view*/}
1400 <div className="d-none d-sm-block">
1401 <article className="row post-container">
1402 {!this.props.viewOnly && (
1405 enableDownvotes={this.props.enableDownvotes}
1406 handleUpvote={this.handleUpvote}
1407 handleDownvote={this.handleDownvote}
1408 counts={this.postView.counts}
1409 my_vote={this.postView.my_vote}
1412 <div className="col-sm-2 pe-0 post-media">
1413 <div className="">{this.thumbnail()}</div>
1415 <div className="col-12 col-sm-9">
1416 <div className="row">
1417 <div className="col-12">
1418 {this.postTitleLine()}
1419 {this.createdLine()}
1420 {this.bodyPreview()}
1421 {this.commentsLine()}
1422 {this.duplicatesLine()}
1423 {this.userActionsLine()}
1424 {this.removeAndBanDialogs()}
1434 private get myPost(): boolean {
1436 this.postView.creator.id ==
1437 UserService.Instance.myUserInfo?.local_user_view.person.id
1440 handleEditClick(i: PostListing) {
1441 i.setState({ showEdit: true });
1444 handleEditCancel() {
1445 this.setState({ showEdit: false });
1448 // The actual editing is done in the receive for post
1449 handleEditPost(form: EditPost) {
1450 this.setState({ showEdit: false });
1451 this.props.onPostEdit(form);
1454 handleShare(i: PostListing) {
1455 const { name, body, id } = i.props.post_view.post;
1458 text: body?.slice(0, 50),
1459 url: `${getHttpBase()}/post/${id}`,
1463 handleShowReportDialog(i: PostListing) {
1464 i.setState({ showReportDialog: !i.state.showReportDialog });
1467 handleReportReasonChange(i: PostListing, event: any) {
1468 i.setState({ reportReason: event.target.value });
1471 handleReportSubmit(i: PostListing, event: any) {
1472 event.preventDefault();
1473 i.setState({ reportLoading: true });
1474 i.props.onPostReport({
1475 post_id: i.postView.post.id,
1476 reason: i.state.reportReason ?? "",
1477 auth: myAuthRequired(),
1481 handleBlockPersonClick(i: PostListing) {
1482 i.setState({ blockLoading: true });
1483 i.props.onBlockPerson({
1484 person_id: i.postView.creator.id,
1486 auth: myAuthRequired(),
1490 handleDeleteClick(i: PostListing) {
1491 i.setState({ deleteLoading: true });
1492 i.props.onDeletePost({
1493 post_id: i.postView.post.id,
1494 deleted: !i.postView.post.deleted,
1495 auth: myAuthRequired(),
1499 handleSavePostClick(i: PostListing) {
1500 i.setState({ saveLoading: true });
1501 i.props.onSavePost({
1502 post_id: i.postView.post.id,
1503 save: !i.postView.saved,
1504 auth: myAuthRequired(),
1508 get crossPostParams(): PostFormParams {
1509 const queryParams: PostFormParams = {};
1510 const { name, url } = this.postView.post;
1512 queryParams.name = name;
1515 queryParams.url = url;
1518 const crossPostBody = this.crossPostBody();
1519 if (crossPostBody) {
1520 queryParams.body = crossPostBody;
1526 crossPostBody(): string | undefined {
1527 const post = this.postView.post;
1528 const body = post.body;
1531 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1533 }\n\n${body.replace(/^/gm, "> ")}`
1537 get showBody(): boolean {
1538 return this.props.showBody || this.state.showBody;
1541 handleModRemoveShow(i: PostListing) {
1543 showRemoveDialog: !i.state.showRemoveDialog,
1544 showBanDialog: false,
1548 handleModRemoveReasonChange(i: PostListing, event: any) {
1549 i.setState({ removeReason: event.target.value });
1552 handleModRemoveDataChange(i: PostListing, event: any) {
1553 i.setState({ removeData: event.target.checked });
1556 handleModRemoveSubmit(i: PostListing, event: any) {
1557 event.preventDefault();
1558 i.setState({ removeLoading: true });
1559 i.props.onRemovePost({
1560 post_id: i.postView.post.id,
1561 removed: !i.postView.post.removed,
1562 auth: myAuthRequired(),
1566 handleModLock(i: PostListing) {
1567 i.setState({ lockLoading: true });
1568 i.props.onLockPost({
1569 post_id: i.postView.post.id,
1570 locked: !i.postView.post.locked,
1571 auth: myAuthRequired(),
1575 handleModFeaturePostLocal(i: PostListing) {
1576 i.setState({ featureLocalLoading: true });
1577 i.props.onFeaturePost({
1578 post_id: i.postView.post.id,
1579 featured: !i.postView.post.featured_local,
1580 feature_type: "Local",
1581 auth: myAuthRequired(),
1585 handleModFeaturePostCommunity(i: PostListing) {
1586 i.setState({ featureCommunityLoading: true });
1587 i.props.onFeaturePost({
1588 post_id: i.postView.post.id,
1589 featured: !i.postView.post.featured_community,
1590 feature_type: "Community",
1591 auth: myAuthRequired(),
1595 handleModBanFromCommunityShow(i: PostListing) {
1597 showBanDialog: true,
1598 banType: BanType.Community,
1599 showRemoveDialog: false,
1603 handleModBanShow(i: PostListing) {
1605 showBanDialog: true,
1606 banType: BanType.Site,
1607 showRemoveDialog: false,
1611 handlePurgePersonShow(i: PostListing) {
1613 showPurgeDialog: true,
1614 purgeType: PurgeType.Person,
1615 showRemoveDialog: false,
1619 handlePurgePostShow(i: PostListing) {
1621 showPurgeDialog: true,
1622 purgeType: PurgeType.Post,
1623 showRemoveDialog: false,
1627 handlePurgeReasonChange(i: PostListing, event: any) {
1628 i.setState({ purgeReason: event.target.value });
1631 handlePurgeSubmit(i: PostListing, event: any) {
1632 event.preventDefault();
1633 i.setState({ purgeLoading: true });
1634 if (i.state.purgeType == PurgeType.Person) {
1635 i.props.onPurgePerson({
1636 person_id: i.postView.creator.id,
1637 reason: i.state.purgeReason,
1638 auth: myAuthRequired(),
1640 } else if (i.state.purgeType == PurgeType.Post) {
1641 i.props.onPurgePost({
1642 post_id: i.postView.post.id,
1643 reason: i.state.purgeReason,
1644 auth: myAuthRequired(),
1649 handleModBanReasonChange(i: PostListing, event: any) {
1650 i.setState({ banReason: event.target.value });
1653 handleModBanExpireDaysChange(i: PostListing, event: any) {
1654 i.setState({ banExpireDays: event.target.value });
1657 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1658 i.setState({ banType: BanType.Community });
1659 i.handleModBanBothSubmit(i, event);
1662 handleModBanSubmit(i: PostListing, event: any) {
1663 i.setState({ banType: BanType.Site });
1664 i.handleModBanBothSubmit(i, event);
1667 handleModBanBothSubmit(i: PostListing, event: any) {
1668 event.preventDefault();
1669 i.setState({ banLoading: true });
1671 const ban = !i.props.post_view.creator_banned_from_community;
1672 // If its an unban, restore all their data
1674 i.setState({ removeData: false });
1676 const person_id = i.props.post_view.creator.id;
1677 const remove_data = i.state.removeData;
1678 const reason = i.state.banReason;
1679 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1681 if (i.state.banType == BanType.Community) {
1682 const community_id = i.postView.community.id;
1683 i.props.onBanPersonFromCommunity({
1690 auth: myAuthRequired(),
1693 i.props.onBanPerson({
1699 auth: myAuthRequired(),
1704 handleAddModToCommunity(i: PostListing) {
1705 i.setState({ addModLoading: true });
1706 i.props.onAddModToCommunity({
1707 community_id: i.postView.community.id,
1708 person_id: i.postView.creator.id,
1709 added: !i.creatorIsMod_,
1710 auth: myAuthRequired(),
1714 handleAddAdmin(i: PostListing) {
1715 i.setState({ addAdminLoading: true });
1716 i.props.onAddAdmin({
1717 person_id: i.postView.creator.id,
1718 added: !i.creatorIsAdmin_,
1719 auth: myAuthRequired(),
1723 handleShowConfirmTransferCommunity(i: PostListing) {
1724 i.setState({ showConfirmTransferCommunity: true });
1727 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1728 i.setState({ showConfirmTransferCommunity: false });
1731 handleTransferCommunity(i: PostListing) {
1732 i.setState({ transferLoading: true });
1733 i.props.onTransferCommunity({
1734 community_id: i.postView.community.id,
1735 person_id: i.postView.creator.id,
1736 auth: myAuthRequired(),
1740 handleShowConfirmTransferSite(i: PostListing) {
1741 i.setState({ showConfirmTransferSite: true });
1744 handleCancelShowConfirmTransferSite(i: PostListing) {
1745 i.setState({ showConfirmTransferSite: false });
1748 handleImageExpandClick(i: PostListing, event: any) {
1749 event.preventDefault();
1750 i.setState({ imageExpanded: !i.state.imageExpanded });
1754 handleViewSource(i: PostListing) {
1755 i.setState({ viewSource: !i.state.viewSource });
1758 handleShowAdvanced(i: PostListing) {
1759 i.setState({ showAdvanced: !i.state.showAdvanced });
1763 handleShowMoreMobile(i: PostListing) {
1765 showMoreMobile: !i.state.showMoreMobile,
1766 showAdvanced: !i.state.showAdvanced,
1771 handleShowBody(i: PostListing) {
1772 i.setState({ showBody: !i.state.showBody });
1776 handleUpvote(i: PostListing) {
1777 i.setState({ upvoteLoading: true });
1778 i.props.onPostVote({
1779 post_id: i.postView.post.id,
1780 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1781 auth: myAuthRequired(),
1785 handleDownvote(i: PostListing) {
1786 i.setState({ downvoteLoading: true });
1787 i.props.onPostVote({
1788 post_id: i.postView.post.id,
1789 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1790 auth: myAuthRequired(),
1794 get pointsTippy(): string {
1795 const points = I18NextService.i18n.t("number_of_points", {
1796 count: Number(this.postView.counts.score),
1797 formattedCount: Number(this.postView.counts.score),
1800 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1801 count: Number(this.postView.counts.upvotes),
1802 formattedCount: Number(this.postView.counts.upvotes),
1805 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1806 count: Number(this.postView.counts.downvotes),
1807 formattedCount: Number(this.postView.counts.downvotes),
1810 return `${points} • ${upvotes} • ${downvotes}`;
1813 get canModOnSelf_(): boolean {
1815 this.postView.creator.id,
1816 this.props.moderators,
1823 get canMod_(): boolean {
1825 this.postView.creator.id,
1826 this.props.moderators,
1831 get canAdmin_(): boolean {
1832 return canAdmin(this.postView.creator.id, this.props.admins);
1835 get creatorIsMod_(): boolean {
1836 return isMod(this.postView.creator.id, this.props.moderators);
1839 get creatorIsAdmin_(): boolean {
1840 return isAdmin(this.postView.creator.id, this.props.admins);