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-animate text-muted py-0"
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 icon="copy" inline />
803 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
804 onClick={linkEvent(this, this.handleShowReportDialog)}
805 aria-label={I18NextService.i18n.t("show_report_dialog")}
807 <Icon classes="me-1" icon="flag" inline />
808 {I18NextService.i18n.t("create_report")}
816 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
817 onClick={linkEvent(this, this.handleBlockPersonClick)}
818 aria-label={I18NextService.i18n.t("block_user")}
820 {this.state.blockLoading ? (
823 <Icon classes="me-1" icon="slash" inline />
825 {I18NextService.i18n.t("block_user")}
833 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
834 onClick={linkEvent(this, this.handleEditClick)}
835 aria-label={I18NextService.i18n.t("edit")}
837 <Icon classes="me-1" icon="edit" inline />
838 {I18NextService.i18n.t("edit")}
844 const deleted = this.postView.post.deleted;
845 const label = !deleted
846 ? I18NextService.i18n.t("delete")
847 : I18NextService.i18n.t("restore");
850 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
851 onClick={linkEvent(this, this.handleDeleteClick)}
853 {this.state.deleteLoading ? (
859 classes={classNames("me-1", { "text-danger": deleted })}
869 get viewSourceButton() {
872 className="btn btn-sm btn-animate text-muted py-0"
873 onClick={linkEvent(this, this.handleViewSource)}
874 data-tippy-content={I18NextService.i18n.t("view_source")}
875 aria-label={I18NextService.i18n.t("view_source")}
879 classes={classNames({ "text-success": this.state.viewSource })}
887 const locked = this.postView.post.locked;
889 ? I18NextService.i18n.t("unlock")
890 : I18NextService.i18n.t("lock");
893 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
894 onClick={linkEvent(this, this.handleModLock)}
897 {this.state.lockLoading ? (
903 classes={classNames("me-1", { "text-danger": locked })}
906 {capitalizeFirstLetter(label)}
913 get featureButtons() {
914 const featuredCommunity = this.postView.post.featured_community;
915 const labelCommunity = featuredCommunity
916 ? I18NextService.i18n.t("unfeature_from_community")
917 : I18NextService.i18n.t("feature_in_community");
919 const featuredLocal = this.postView.post.featured_local;
920 const labelLocal = featuredLocal
921 ? I18NextService.i18n.t("unfeature_from_local")
922 : I18NextService.i18n.t("feature_in_local");
927 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
928 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
929 data-tippy-content={labelCommunity}
930 aria-label={labelCommunity}
932 {this.state.featureCommunityLoading ? (
938 classes={classNames("me-1", {
939 "text-success": featuredCommunity,
943 {I18NextService.i18n.t("community")}
951 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
952 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
953 data-tippy-content={labelLocal}
954 aria-label={labelLocal}
956 {this.state.featureLocalLoading ? (
962 classes={classNames("me-1", {
963 "text-success": featuredLocal,
967 {I18NextService.i18n.t("local")}
977 get modRemoveButton() {
978 const removed = this.postView.post.removed;
981 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
984 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
987 {/* TODO: Find an icon for this. */}
988 {this.state.removeLoading ? (
991 I18NextService.i18n.t("remove")
993 I18NextService.i18n.t("restore")
1000 * Mod/Admin actions to be taken against the author.
1004 const post_view = this.postView;
1006 this.state.showAdvanced && (
1010 {!this.creatorIsMod_ &&
1011 (!post_view.creator_banned_from_community ? (
1013 className="btn btn-link btn-animate text-muted py-0"
1016 this.handleModBanFromCommunityShow
1018 aria-label={I18NextService.i18n.t("ban_from_community")}
1020 {I18NextService.i18n.t("ban_from_community")}
1024 className="btn btn-link btn-animate text-muted py-0"
1027 this.handleModBanFromCommunitySubmit
1029 aria-label={I18NextService.i18n.t("unban")}
1031 {this.state.banLoading ? (
1034 I18NextService.i18n.t("unban")
1038 {!post_view.creator_banned_from_community && (
1040 className="btn btn-link btn-animate text-muted py-0"
1041 onClick={linkEvent(this, this.handleAddModToCommunity)}
1044 ? I18NextService.i18n.t("remove_as_mod")
1045 : I18NextService.i18n.t("appoint_as_mod")
1048 {this.state.addModLoading ? (
1050 ) : this.creatorIsMod_ ? (
1051 I18NextService.i18n.t("remove_as_mod")
1053 I18NextService.i18n.t("appoint_as_mod")
1059 {/* Community creators and admins can transfer community to another mod */}
1060 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1062 this.creatorIsMod_ &&
1063 (!this.state.showConfirmTransferCommunity ? (
1065 className="btn btn-link btn-animate text-muted py-0"
1068 this.handleShowConfirmTransferCommunity
1070 aria-label={I18NextService.i18n.t("transfer_community")}
1072 {I18NextService.i18n.t("transfer_community")}
1077 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1078 aria-label={I18NextService.i18n.t("are_you_sure")}
1080 {I18NextService.i18n.t("are_you_sure")}
1083 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1084 aria-label={I18NextService.i18n.t("yes")}
1085 onClick={linkEvent(this, this.handleTransferCommunity)}
1087 {this.state.transferLoading ? (
1090 I18NextService.i18n.t("yes")
1094 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1097 this.handleCancelShowConfirmTransferCommunity
1099 aria-label={I18NextService.i18n.t("no")}
1101 {I18NextService.i18n.t("no")}
1105 {/* Admins can ban from all, and appoint other admins */}
1106 {this.canAdmin_ && (
1108 {!this.creatorIsAdmin_ && (
1110 {!isBanned(post_view.creator) ? (
1112 className="btn btn-link btn-animate text-muted py-0"
1113 onClick={linkEvent(this, this.handleModBanShow)}
1114 aria-label={I18NextService.i18n.t("ban_from_site")}
1116 {I18NextService.i18n.t("ban_from_site")}
1120 className="btn btn-link btn-animate text-muted py-0"
1121 onClick={linkEvent(this, this.handleModBanSubmit)}
1122 aria-label={I18NextService.i18n.t("unban_from_site")}
1124 {this.state.banLoading ? (
1127 I18NextService.i18n.t("unban_from_site")
1132 className="btn btn-link btn-animate text-muted py-0"
1133 onClick={linkEvent(this, this.handlePurgePersonShow)}
1134 aria-label={I18NextService.i18n.t("purge_user")}
1136 {I18NextService.i18n.t("purge_user")}
1139 className="btn btn-link btn-animate text-muted py-0"
1140 onClick={linkEvent(this, this.handlePurgePostShow)}
1141 aria-label={I18NextService.i18n.t("purge_post")}
1143 {I18NextService.i18n.t("purge_post")}
1147 {!isBanned(post_view.creator) && post_view.creator.local && (
1149 className="btn btn-link btn-animate text-muted py-0"
1150 onClick={linkEvent(this, this.handleAddAdmin)}
1152 this.creatorIsAdmin_
1153 ? I18NextService.i18n.t("remove_as_admin")
1154 : I18NextService.i18n.t("appoint_as_admin")
1157 {this.state.addAdminLoading ? (
1159 ) : this.creatorIsAdmin_ ? (
1160 I18NextService.i18n.t("remove_as_admin")
1162 I18NextService.i18n.t("appoint_as_admin")
1173 removeAndBanDialogs() {
1174 const post = this.postView;
1175 const purgeTypeText =
1176 this.state.purgeType == PurgeType.Post
1177 ? I18NextService.i18n.t("purge_post")
1178 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1181 {this.state.showRemoveDialog && (
1183 className="form-inline"
1184 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1187 className="visually-hidden"
1188 htmlFor="post-listing-remove-reason"
1190 {I18NextService.i18n.t("reason")}
1194 id="post-listing-remove-reason"
1195 className="form-control me-2"
1196 placeholder={I18NextService.i18n.t("reason")}
1197 value={this.state.removeReason}
1198 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1202 className="btn btn-secondary"
1203 aria-label={I18NextService.i18n.t("remove_post")}
1205 {this.state.removeLoading ? (
1208 I18NextService.i18n.t("remove_post")
1213 {this.state.showBanDialog && (
1214 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1215 <div className="mb-3 row col-12">
1217 className="col-form-label"
1218 htmlFor="post-listing-ban-reason"
1220 {I18NextService.i18n.t("reason")}
1224 id="post-listing-ban-reason"
1225 className="form-control me-2"
1226 placeholder={I18NextService.i18n.t("reason")}
1227 value={this.state.banReason}
1228 onInput={linkEvent(this, this.handleModBanReasonChange)}
1230 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1231 {I18NextService.i18n.t("expires")}
1235 id={`mod-ban-expires`}
1236 className="form-control me-2"
1237 placeholder={I18NextService.i18n.t("number_of_days")}
1238 value={this.state.banExpireDays}
1239 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1241 <div className="input-group mb-3">
1242 <div className="form-check">
1244 className="form-check-input"
1245 id="mod-ban-remove-data"
1247 checked={this.state.removeData}
1248 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1251 className="form-check-label"
1252 htmlFor="mod-ban-remove-data"
1253 title={I18NextService.i18n.t("remove_content_more")}
1255 {I18NextService.i18n.t("remove_content")}
1260 {/* TODO hold off on expires until later */}
1261 {/* <div class="mb-3 row"> */}
1262 {/* <label class="col-form-label">Expires</label> */}
1263 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1265 <div className="mb-3 row">
1268 className="btn btn-secondary"
1269 aria-label={I18NextService.i18n.t("ban")}
1271 {this.state.banLoading ? (
1275 {I18NextService.i18n.t("ban")} {post.creator.name}
1282 {this.state.showReportDialog && (
1284 className="form-inline"
1285 onSubmit={linkEvent(this, this.handleReportSubmit)}
1287 <label className="visually-hidden" htmlFor="post-report-reason">
1288 {I18NextService.i18n.t("reason")}
1292 id="post-report-reason"
1293 className="form-control me-2"
1294 placeholder={I18NextService.i18n.t("reason")}
1296 value={this.state.reportReason}
1297 onInput={linkEvent(this, this.handleReportReasonChange)}
1301 className="btn btn-secondary"
1302 aria-label={I18NextService.i18n.t("create_report")}
1304 {this.state.reportLoading ? (
1307 I18NextService.i18n.t("create_report")
1312 {this.state.showPurgeDialog && (
1314 className="form-inline"
1315 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1318 <label className="visually-hidden" htmlFor="purge-reason">
1319 {I18NextService.i18n.t("reason")}
1324 className="form-control me-2"
1325 placeholder={I18NextService.i18n.t("reason")}
1326 value={this.state.purgeReason}
1327 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1329 {this.state.purgeLoading ? (
1334 className="btn btn-secondary"
1335 aria-label={purgeTypeText}
1337 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1347 const post = this.postView.post;
1348 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1349 <div className="row">
1350 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1351 {this.postTitleLine()}
1353 <div className="col-4">
1354 {/* Post thumbnail */}
1355 {!this.state.imageExpanded && this.thumbnail()}
1359 this.postTitleLine()
1363 showMobilePreview() {
1364 const { body, id } = this.postView.post;
1366 return !this.showBody && body ? (
1367 <Link className="text-body" to={`/post/${id}`}>
1368 <div className="md-div mb-1 preview-lines">{body}</div>
1378 {/* The mobile view*/}
1379 <div className="d-block d-sm-none">
1380 <article className="row post-container">
1381 <div className="col-12">
1382 {this.createdLine()}
1384 {/* If it has a thumbnail, do a right aligned thumbnail */}
1385 {this.mobileThumbnail()}
1387 {/* Show a preview of the post body */}
1388 {this.showMobilePreview()}
1390 {this.commentsLine(true)}
1391 {this.userActionsLine()}
1392 {this.duplicatesLine()}
1393 {this.removeAndBanDialogs()}
1398 {/* The larger view*/}
1399 <div className="d-none d-sm-block">
1400 <article className="row post-container">
1401 {!this.props.viewOnly && (
1404 enableDownvotes={this.props.enableDownvotes}
1405 handleUpvote={this.handleUpvote}
1406 handleDownvote={this.handleDownvote}
1407 counts={this.postView.counts}
1408 my_vote={this.postView.my_vote}
1411 <div className="col-sm-2 pe-0 post-media">
1412 <div className="">{this.thumbnail()}</div>
1414 <div className="col-12 col-sm-9">
1415 <div className="row">
1416 <div className="col-12">
1417 {this.postTitleLine()}
1418 {this.createdLine()}
1419 {this.commentsLine()}
1420 {this.duplicatesLine()}
1421 {this.userActionsLine()}
1422 {this.removeAndBanDialogs()}
1432 private get myPost(): boolean {
1434 this.postView.creator.id ==
1435 UserService.Instance.myUserInfo?.local_user_view.person.id
1438 handleEditClick(i: PostListing) {
1439 i.setState({ showEdit: true });
1442 handleEditCancel() {
1443 this.setState({ showEdit: false });
1446 // The actual editing is done in the receive for post
1447 handleEditPost(form: EditPost) {
1448 this.setState({ showEdit: false });
1449 this.props.onPostEdit(form);
1452 handleShare(i: PostListing) {
1453 const { name, body, id } = i.props.post_view.post;
1456 text: body?.slice(0, 50),
1457 url: `${getHttpBase()}/post/${id}`,
1461 handleShowReportDialog(i: PostListing) {
1462 i.setState({ showReportDialog: !i.state.showReportDialog });
1465 handleReportReasonChange(i: PostListing, event: any) {
1466 i.setState({ reportReason: event.target.value });
1469 handleReportSubmit(i: PostListing, event: any) {
1470 event.preventDefault();
1471 i.setState({ reportLoading: true });
1472 i.props.onPostReport({
1473 post_id: i.postView.post.id,
1474 reason: i.state.reportReason ?? "",
1475 auth: myAuthRequired(),
1479 handleBlockPersonClick(i: PostListing) {
1480 i.setState({ blockLoading: true });
1481 i.props.onBlockPerson({
1482 person_id: i.postView.creator.id,
1484 auth: myAuthRequired(),
1488 handleDeleteClick(i: PostListing) {
1489 i.setState({ deleteLoading: true });
1490 i.props.onDeletePost({
1491 post_id: i.postView.post.id,
1492 deleted: !i.postView.post.deleted,
1493 auth: myAuthRequired(),
1497 handleSavePostClick(i: PostListing) {
1498 i.setState({ saveLoading: true });
1499 i.props.onSavePost({
1500 post_id: i.postView.post.id,
1501 save: !i.postView.saved,
1502 auth: myAuthRequired(),
1506 get crossPostParams(): PostFormParams {
1507 const queryParams: PostFormParams = {};
1508 const { name, url } = this.postView.post;
1510 queryParams.name = name;
1513 queryParams.url = url;
1516 const crossPostBody = this.crossPostBody();
1517 if (crossPostBody) {
1518 queryParams.body = crossPostBody;
1524 crossPostBody(): string | undefined {
1525 const post = this.postView.post;
1526 const body = post.body;
1529 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1531 }\n\n${body.replace(/^/gm, "> ")}`
1535 get showBody(): boolean {
1536 return this.props.showBody || this.state.showBody;
1539 handleModRemoveShow(i: PostListing) {
1541 showRemoveDialog: !i.state.showRemoveDialog,
1542 showBanDialog: false,
1546 handleModRemoveReasonChange(i: PostListing, event: any) {
1547 i.setState({ removeReason: event.target.value });
1550 handleModRemoveDataChange(i: PostListing, event: any) {
1551 i.setState({ removeData: event.target.checked });
1554 handleModRemoveSubmit(i: PostListing, event: any) {
1555 event.preventDefault();
1556 i.setState({ removeLoading: true });
1557 i.props.onRemovePost({
1558 post_id: i.postView.post.id,
1559 removed: !i.postView.post.removed,
1560 auth: myAuthRequired(),
1564 handleModLock(i: PostListing) {
1565 i.setState({ lockLoading: true });
1566 i.props.onLockPost({
1567 post_id: i.postView.post.id,
1568 locked: !i.postView.post.locked,
1569 auth: myAuthRequired(),
1573 handleModFeaturePostLocal(i: PostListing) {
1574 i.setState({ featureLocalLoading: true });
1575 i.props.onFeaturePost({
1576 post_id: i.postView.post.id,
1577 featured: !i.postView.post.featured_local,
1578 feature_type: "Local",
1579 auth: myAuthRequired(),
1583 handleModFeaturePostCommunity(i: PostListing) {
1584 i.setState({ featureCommunityLoading: true });
1585 i.props.onFeaturePost({
1586 post_id: i.postView.post.id,
1587 featured: !i.postView.post.featured_community,
1588 feature_type: "Community",
1589 auth: myAuthRequired(),
1593 handleModBanFromCommunityShow(i: PostListing) {
1595 showBanDialog: true,
1596 banType: BanType.Community,
1597 showRemoveDialog: false,
1601 handleModBanShow(i: PostListing) {
1603 showBanDialog: true,
1604 banType: BanType.Site,
1605 showRemoveDialog: false,
1609 handlePurgePersonShow(i: PostListing) {
1611 showPurgeDialog: true,
1612 purgeType: PurgeType.Person,
1613 showRemoveDialog: false,
1617 handlePurgePostShow(i: PostListing) {
1619 showPurgeDialog: true,
1620 purgeType: PurgeType.Post,
1621 showRemoveDialog: false,
1625 handlePurgeReasonChange(i: PostListing, event: any) {
1626 i.setState({ purgeReason: event.target.value });
1629 handlePurgeSubmit(i: PostListing, event: any) {
1630 event.preventDefault();
1631 i.setState({ purgeLoading: true });
1632 if (i.state.purgeType == PurgeType.Person) {
1633 i.props.onPurgePerson({
1634 person_id: i.postView.creator.id,
1635 reason: i.state.purgeReason,
1636 auth: myAuthRequired(),
1638 } else if (i.state.purgeType == PurgeType.Post) {
1639 i.props.onPurgePost({
1640 post_id: i.postView.post.id,
1641 reason: i.state.purgeReason,
1642 auth: myAuthRequired(),
1647 handleModBanReasonChange(i: PostListing, event: any) {
1648 i.setState({ banReason: event.target.value });
1651 handleModBanExpireDaysChange(i: PostListing, event: any) {
1652 i.setState({ banExpireDays: event.target.value });
1655 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1656 i.setState({ banType: BanType.Community });
1657 i.handleModBanBothSubmit(i, event);
1660 handleModBanSubmit(i: PostListing, event: any) {
1661 i.setState({ banType: BanType.Site });
1662 i.handleModBanBothSubmit(i, event);
1665 handleModBanBothSubmit(i: PostListing, event: any) {
1666 event.preventDefault();
1667 i.setState({ banLoading: true });
1669 const ban = !i.props.post_view.creator_banned_from_community;
1670 // If its an unban, restore all their data
1672 i.setState({ removeData: false });
1674 const person_id = i.props.post_view.creator.id;
1675 const remove_data = i.state.removeData;
1676 const reason = i.state.banReason;
1677 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1679 if (i.state.banType == BanType.Community) {
1680 const community_id = i.postView.community.id;
1681 i.props.onBanPersonFromCommunity({
1688 auth: myAuthRequired(),
1691 i.props.onBanPerson({
1697 auth: myAuthRequired(),
1702 handleAddModToCommunity(i: PostListing) {
1703 i.setState({ addModLoading: true });
1704 i.props.onAddModToCommunity({
1705 community_id: i.postView.community.id,
1706 person_id: i.postView.creator.id,
1707 added: !i.creatorIsMod_,
1708 auth: myAuthRequired(),
1712 handleAddAdmin(i: PostListing) {
1713 i.setState({ addAdminLoading: true });
1714 i.props.onAddAdmin({
1715 person_id: i.postView.creator.id,
1716 added: !i.creatorIsAdmin_,
1717 auth: myAuthRequired(),
1721 handleShowConfirmTransferCommunity(i: PostListing) {
1722 i.setState({ showConfirmTransferCommunity: true });
1725 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1726 i.setState({ showConfirmTransferCommunity: false });
1729 handleTransferCommunity(i: PostListing) {
1730 i.setState({ transferLoading: true });
1731 i.props.onTransferCommunity({
1732 community_id: i.postView.community.id,
1733 person_id: i.postView.creator.id,
1734 auth: myAuthRequired(),
1738 handleShowConfirmTransferSite(i: PostListing) {
1739 i.setState({ showConfirmTransferSite: true });
1742 handleCancelShowConfirmTransferSite(i: PostListing) {
1743 i.setState({ showConfirmTransferSite: false });
1746 handleImageExpandClick(i: PostListing, event: any) {
1747 event.preventDefault();
1748 i.setState({ imageExpanded: !i.state.imageExpanded });
1752 handleViewSource(i: PostListing) {
1753 i.setState({ viewSource: !i.state.viewSource });
1756 handleShowAdvanced(i: PostListing) {
1757 i.setState({ showAdvanced: !i.state.showAdvanced });
1761 handleShowMoreMobile(i: PostListing) {
1763 showMoreMobile: !i.state.showMoreMobile,
1764 showAdvanced: !i.state.showAdvanced,
1769 handleShowBody(i: PostListing) {
1770 i.setState({ showBody: !i.state.showBody });
1774 handleUpvote(i: PostListing) {
1775 i.setState({ upvoteLoading: true });
1776 i.props.onPostVote({
1777 post_id: i.postView.post.id,
1778 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1779 auth: myAuthRequired(),
1783 handleDownvote(i: PostListing) {
1784 i.setState({ downvoteLoading: true });
1785 i.props.onPostVote({
1786 post_id: i.postView.post.id,
1787 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1788 auth: myAuthRequired(),
1792 get pointsTippy(): string {
1793 const points = I18NextService.i18n.t("number_of_points", {
1794 count: Number(this.postView.counts.score),
1795 formattedCount: Number(this.postView.counts.score),
1798 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1799 count: Number(this.postView.counts.upvotes),
1800 formattedCount: Number(this.postView.counts.upvotes),
1803 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1804 count: Number(this.postView.counts.downvotes),
1805 formattedCount: Number(this.postView.counts.downvotes),
1808 return `${points} • ${upvotes} • ${downvotes}`;
1811 get canModOnSelf_(): boolean {
1813 this.postView.creator.id,
1814 this.props.moderators,
1821 get canMod_(): boolean {
1823 this.postView.creator.id,
1824 this.props.moderators,
1829 get canAdmin_(): boolean {
1830 return canAdmin(this.postView.creator.id, this.props.admins);
1833 get creatorIsMod_(): boolean {
1834 return isMod(this.postView.creator.id, this.props.moderators);
1837 get creatorIsAdmin_(): boolean {
1838 return isAdmin(this.postView.creator.id, this.props.admins);