1 import { myAuthRequired, newVote, showScores } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
9 } from "@utils/helpers";
10 import { isImage, isVideo } from "@utils/media";
20 } from "@utils/roles";
21 import classNames from "classnames";
22 import { Component, linkEvent } from "inferno";
23 import { Link } from "inferno-router";
30 CommunityModeratorView,
45 } from "lemmy-js-client";
46 import { relTags } from "../../config";
47 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
48 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
49 import { I18NextService, UserService } from "../../services";
50 import { setupTippy } from "../../tippy";
51 import { Icon, PurgeWarning, Spinner } from "../common/icon";
52 import { MomentTime } from "../common/moment-time";
53 import { PictrsImage } from "../common/pictrs-image";
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}
435 <div className={`vote-bar col-1 pe-0 small text-center`}>
437 className={`btn-animate btn btn-link p-0 ${
438 this.postView.my_vote == 1 ? "text-info" : "text-muted"
440 onClick={linkEvent(this, this.handleUpvote)}
441 data-tippy-content={I18NextService.i18n.t("upvote")}
442 aria-label={I18NextService.i18n.t("upvote")}
443 aria-pressed={this.postView.my_vote === 1}
445 {this.state.upvoteLoading ? (
448 <Icon icon="arrow-up1" classes="upvote" />
453 className={`unselectable pointer text-muted px-1 post-score`}
454 data-tippy-content={this.pointsTippy}
456 {numToSI(this.postView.counts.score)}
459 <div className="p-1"></div>
461 {this.props.enableDownvotes && (
463 className={`btn-animate btn btn-link p-0 ${
464 this.postView.my_vote == -1 ? "text-danger" : "text-muted"
466 onClick={linkEvent(this, this.handleDownvote)}
467 data-tippy-content={I18NextService.i18n.t("downvote")}
468 aria-label={I18NextService.i18n.t("downvote")}
469 aria-pressed={this.postView.my_vote === -1}
471 {this.state.downvoteLoading ? (
474 <Icon icon="arrow-down1" classes="downvote" />
483 const post = this.postView.post;
486 className={`d-inline ${
487 !post.featured_community && !post.featured_local
491 to={`/post/${post.id}`}
492 title={I18NextService.i18n.t("comments")}
496 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
503 const post = this.postView.post;
504 const url = post.url;
508 <div className="post-title overflow-hidden">
509 <h5 className="d-inline">
510 {url && this.props.showBody ? (
513 !post.featured_community && !post.featured_local
520 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
526 {(url && isImage(url)) ||
527 (post.thumbnail_url && (
529 className="btn btn-sm text-monospace text-muted d-inline-block"
530 data-tippy-content={I18NextService.i18n.t("expand_here")}
531 onClick={linkEvent(this, this.handleImageExpandClick)}
535 !this.state.imageExpanded ? "plus-square" : "minus-square"
537 classes="icon-inline"
542 <small className="ms-2 badge text-bg-secondary">
543 {I18NextService.i18n.t("removed")}
548 className="unselectable pointer ms-2 text-muted font-italic"
549 data-tippy-content={I18NextService.i18n.t("deleted")}
551 <Icon icon="trash" classes="icon-inline text-danger" />
556 className="unselectable pointer ms-2 text-muted font-italic"
557 data-tippy-content={I18NextService.i18n.t("locked")}
559 <Icon icon="lock" classes="icon-inline text-danger" />
562 {post.featured_community && (
564 className="unselectable pointer ms-2 text-muted font-italic"
565 data-tippy-content={I18NextService.i18n.t(
566 "featured_in_community"
568 aria-label={I18NextService.i18n.t("featured_in_community")}
570 <Icon icon="pin" classes="icon-inline text-primary" />
573 {post.featured_local && (
575 className="unselectable pointer ms-2 text-muted font-italic"
576 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
577 aria-label={I18NextService.i18n.t("featured_in_local")}
579 <Icon icon="pin" classes="icon-inline text-secondary" />
583 <small className="ms-2 badge text-bg-danger">
584 {I18NextService.i18n.t("nsfw")}
588 {url && this.urlLine()}
594 const post = this.postView.post;
595 const url = post.url;
598 <p className="d-flex text-muted align-items-center gap-1 small m-0">
599 {url && !(hostname(url) === getExternalHost()) && (
601 className="text-muted font-italic"
614 const dupes = this.props.crossPosts;
615 return dupes && dupes.length > 0 ? (
616 <ul className="list-inline mb-1 small text-muted">
618 <li className="list-inline-item me-2">
619 {I18NextService.i18n.t("cross_posted_to")}
622 <li key={pv.post.id} className="list-inline-item me-2">
623 <Link to={`/post/${pv.post.id}`}>
626 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
637 commentsLine(mobile = false) {
638 const post = this.postView.post;
641 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
642 {this.commentsButton}
645 className="btn btn-sm btn-animate text-muted py-0"
646 onClick={linkEvent(this, this.handleShare)}
649 <Icon icon="share" inline />
654 className="btn btn-sm btn-animate text-muted py-0"
655 title={I18NextService.i18n.t("link")}
658 <Icon icon="fedilink" inline />
661 {mobile && !this.props.viewOnly && this.mobileVotes}
662 {UserService.Instance.myUserInfo &&
663 !this.props.viewOnly &&
669 showPreviewButton() {
670 const post_view = this.postView;
671 const body = post_view.post.body;
675 className="btn btn-sm btn-animate text-muted py-0"
676 data-tippy-content={body && mdNoImages.render(body)}
677 data-tippy-allowHtml={true}
678 onClick={linkEvent(this, this.handleShowBody)}
682 classes={classNames("icon-inline me-1", {
683 "text-success": this.state.showBody,
691 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
692 // Possible enhancement: Make each button a component.
693 const post_view = this.postView;
694 const post = post_view.post;
699 {this.crossPostButton}
702 * If there is a URL, or if the post has a body and we were told not to
703 * show the body, show the MetadataCard/body toggle.
705 {(post.url || (post.body && !this.props.showBody)) &&
706 this.showPreviewButton()}
708 {this.showBody && post_view.post.body && this.viewSourceButton}
710 <div className="dropdown">
712 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
713 onClick={linkEvent(this, this.handleShowAdvanced)}
714 data-tippy-content={I18NextService.i18n.t("more")}
715 data-bs-toggle="dropdown"
716 aria-expanded="false"
717 aria-controls="advancedButtonsDropdown"
718 aria-label={I18NextService.i18n.t("more")}
720 <Icon icon="more-vertical" inline />
723 <ul className="dropdown-menu" id="advancedButtonsDropdown">
726 <li>{this.reportButton}</li>
727 <li>{this.blockButton}</li>
731 <li>{this.editButton}</li>
732 <li>{this.deleteButton}</li>
736 {/* Any mod can do these, not limited to hierarchy*/}
737 {(amMod(this.props.moderators) || amAdmin()) && (
740 <hr className="dropdown-divider" />
742 <li>{this.lockButton}</li>
743 {this.featureButtons}
747 {(this.canMod_ || this.canAdmin_) && (
748 <li>{this.modRemoveButton}</li>
756 get commentsButton() {
757 const post_view = this.postView;
758 const title = I18NextService.i18n.t("number_of_comments", {
759 count: Number(post_view.counts.comments),
760 formattedCount: Number(post_view.counts.comments),
765 className="btn btn-link btn-sm text-muted ps-0"
767 to={`/post/${post_view.post.id}?scrollToComments=true`}
768 data-tippy-content={title}
770 <span className="me-1">
771 <Icon icon="message-square" classes="me-1" inline />
772 {post_view.counts.comments}
774 {this.unreadCount && (
775 <span className="text-muted fst-italic">
776 ({this.unreadCount} {I18NextService.i18n.t("new")})
783 get unreadCount(): number | undefined {
784 const pv = this.postView;
785 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
787 : pv.unread_comments;
792 const tippy = showScores()
793 ? { "data-tippy-content": this.pointsTippy }
799 className={`btn-animate btn py-0 px-1 ${
800 this.postView.my_vote === 1 ? "text-info" : "text-muted"
803 onClick={linkEvent(this, this.handleUpvote)}
804 aria-label={I18NextService.i18n.t("upvote")}
805 aria-pressed={this.postView.my_vote === 1}
807 {this.state.upvoteLoading ? (
811 <Icon icon="arrow-up1" classes="icon-inline small" />
813 <span className="ms-2">
814 {numToSI(this.postView.counts.upvotes)}
820 {this.props.enableDownvotes && (
822 className={`ms-2 btn-animate btn py-0 px-1 ${
823 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
825 onClick={linkEvent(this, this.handleDownvote)}
827 aria-label={I18NextService.i18n.t("downvote")}
828 aria-pressed={this.postView.my_vote === -1}
830 {this.state.downvoteLoading ? (
834 <Icon icon="arrow-down1" classes="icon-inline small" />
837 className={classNames("ms-2", {
838 invisible: this.postView.counts.downvotes === 0,
841 {numToSI(this.postView.counts.downvotes)}
854 const saved = this.postView.saved;
856 ? I18NextService.i18n.t("unsave")
857 : I18NextService.i18n.t("save");
860 className="btn btn-sm btn-animate text-muted py-0"
861 onClick={linkEvent(this, this.handleSavePostClick)}
862 data-tippy-content={label}
865 {this.state.saveLoading ? (
870 classes={classNames({ "text-warning": saved })}
878 get crossPostButton() {
881 className="btn btn-sm btn-animate text-muted py-0"
883 /* Empty string properties are required to satisfy type*/
884 pathname: "/create_post",
885 state: { ...this.crossPostParams },
890 title={I18NextService.i18n.t("cross_post")}
891 data-tippy-content={I18NextService.i18n.t("cross_post")}
892 aria-label={I18NextService.i18n.t("cross_post")}
894 <Icon icon="copy" inline />
902 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
903 onClick={linkEvent(this, this.handleShowReportDialog)}
904 aria-label={I18NextService.i18n.t("show_report_dialog")}
906 <Icon classes="me-1" icon="flag" inline />
907 {I18NextService.i18n.t("create_report")}
915 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
916 onClick={linkEvent(this, this.handleBlockPersonClick)}
917 aria-label={I18NextService.i18n.t("block_user")}
919 {this.state.blockLoading ? (
922 <Icon classes="me-1" icon="slash" inline />
924 {I18NextService.i18n.t("block_user")}
932 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
933 onClick={linkEvent(this, this.handleEditClick)}
934 aria-label={I18NextService.i18n.t("edit")}
936 <Icon classes="me-1" icon="edit" inline />
937 {I18NextService.i18n.t("edit")}
943 const deleted = this.postView.post.deleted;
944 const label = !deleted
945 ? I18NextService.i18n.t("delete")
946 : I18NextService.i18n.t("restore");
949 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
950 onClick={linkEvent(this, this.handleDeleteClick)}
953 {this.state.deleteLoading ? (
959 classes={classNames("me-1", { "text-danger": deleted })}
969 get viewSourceButton() {
972 className="btn btn-sm btn-animate text-muted py-0"
973 onClick={linkEvent(this, this.handleViewSource)}
974 data-tippy-content={I18NextService.i18n.t("view_source")}
975 aria-label={I18NextService.i18n.t("view_source")}
979 classes={classNames({ "text-success": this.state.viewSource })}
987 const locked = this.postView.post.locked;
989 ? I18NextService.i18n.t("unlock")
990 : I18NextService.i18n.t("lock");
993 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
994 onClick={linkEvent(this, this.handleModLock)}
997 {this.state.lockLoading ? (
1003 classes={classNames("me-1", { "text-danger": locked })}
1006 {capitalizeFirstLetter(label)}
1013 get featureButtons() {
1014 const featuredCommunity = this.postView.post.featured_community;
1015 const labelCommunity = featuredCommunity
1016 ? I18NextService.i18n.t("unfeature_from_community")
1017 : I18NextService.i18n.t("feature_in_community");
1019 const featuredLocal = this.postView.post.featured_local;
1020 const labelLocal = featuredLocal
1021 ? I18NextService.i18n.t("unfeature_from_local")
1022 : I18NextService.i18n.t("feature_in_local");
1027 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1028 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
1029 data-tippy-content={labelCommunity}
1030 aria-label={labelCommunity}
1032 {this.state.featureCommunityLoading ? (
1038 classes={classNames("me-1", {
1039 "text-success": featuredCommunity,
1043 {I18NextService.i18n.t("community")}
1051 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1052 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1053 data-tippy-content={labelLocal}
1054 aria-label={labelLocal}
1056 {this.state.featureLocalLoading ? (
1062 classes={classNames("me-1", {
1063 "text-success": featuredLocal,
1067 {I18NextService.i18n.t("local")}
1077 get modRemoveButton() {
1078 const removed = this.postView.post.removed;
1081 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1084 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1087 {/* TODO: Find an icon for this. */}
1088 {this.state.removeLoading ? (
1091 I18NextService.i18n.t("remove")
1093 I18NextService.i18n.t("restore")
1100 * Mod/Admin actions to be taken against the author.
1104 const post_view = this.postView;
1106 this.state.showAdvanced && (
1110 {!this.creatorIsMod_ &&
1111 (!post_view.creator_banned_from_community ? (
1113 className="btn btn-link btn-animate text-muted py-0"
1116 this.handleModBanFromCommunityShow
1118 aria-label={I18NextService.i18n.t("ban_from_community")}
1120 {I18NextService.i18n.t("ban_from_community")}
1124 className="btn btn-link btn-animate text-muted py-0"
1127 this.handleModBanFromCommunitySubmit
1129 aria-label={I18NextService.i18n.t("unban")}
1131 {this.state.banLoading ? (
1134 I18NextService.i18n.t("unban")
1138 {!post_view.creator_banned_from_community && (
1140 className="btn btn-link btn-animate text-muted py-0"
1141 onClick={linkEvent(this, this.handleAddModToCommunity)}
1144 ? I18NextService.i18n.t("remove_as_mod")
1145 : I18NextService.i18n.t("appoint_as_mod")
1148 {this.state.addModLoading ? (
1150 ) : this.creatorIsMod_ ? (
1151 I18NextService.i18n.t("remove_as_mod")
1153 I18NextService.i18n.t("appoint_as_mod")
1159 {/* Community creators and admins can transfer community to another mod */}
1160 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1162 this.creatorIsMod_ &&
1163 (!this.state.showConfirmTransferCommunity ? (
1165 className="btn btn-link btn-animate text-muted py-0"
1168 this.handleShowConfirmTransferCommunity
1170 aria-label={I18NextService.i18n.t("transfer_community")}
1172 {I18NextService.i18n.t("transfer_community")}
1177 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1178 aria-label={I18NextService.i18n.t("are_you_sure")}
1180 {I18NextService.i18n.t("are_you_sure")}
1183 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1184 aria-label={I18NextService.i18n.t("yes")}
1185 onClick={linkEvent(this, this.handleTransferCommunity)}
1187 {this.state.transferLoading ? (
1190 I18NextService.i18n.t("yes")
1194 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1197 this.handleCancelShowConfirmTransferCommunity
1199 aria-label={I18NextService.i18n.t("no")}
1201 {I18NextService.i18n.t("no")}
1205 {/* Admins can ban from all, and appoint other admins */}
1206 {this.canAdmin_ && (
1208 {!this.creatorIsAdmin_ && (
1210 {!isBanned(post_view.creator) ? (
1212 className="btn btn-link btn-animate text-muted py-0"
1213 onClick={linkEvent(this, this.handleModBanShow)}
1214 aria-label={I18NextService.i18n.t("ban_from_site")}
1216 {I18NextService.i18n.t("ban_from_site")}
1220 className="btn btn-link btn-animate text-muted py-0"
1221 onClick={linkEvent(this, this.handleModBanSubmit)}
1222 aria-label={I18NextService.i18n.t("unban_from_site")}
1224 {this.state.banLoading ? (
1227 I18NextService.i18n.t("unban_from_site")
1232 className="btn btn-link btn-animate text-muted py-0"
1233 onClick={linkEvent(this, this.handlePurgePersonShow)}
1234 aria-label={I18NextService.i18n.t("purge_user")}
1236 {I18NextService.i18n.t("purge_user")}
1239 className="btn btn-link btn-animate text-muted py-0"
1240 onClick={linkEvent(this, this.handlePurgePostShow)}
1241 aria-label={I18NextService.i18n.t("purge_post")}
1243 {I18NextService.i18n.t("purge_post")}
1247 {!isBanned(post_view.creator) && post_view.creator.local && (
1249 className="btn btn-link btn-animate text-muted py-0"
1250 onClick={linkEvent(this, this.handleAddAdmin)}
1252 this.creatorIsAdmin_
1253 ? I18NextService.i18n.t("remove_as_admin")
1254 : I18NextService.i18n.t("appoint_as_admin")
1257 {this.state.addAdminLoading ? (
1259 ) : this.creatorIsAdmin_ ? (
1260 I18NextService.i18n.t("remove_as_admin")
1262 I18NextService.i18n.t("appoint_as_admin")
1273 removeAndBanDialogs() {
1274 const post = this.postView;
1275 const purgeTypeText =
1276 this.state.purgeType == PurgeType.Post
1277 ? I18NextService.i18n.t("purge_post")
1278 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1281 {this.state.showRemoveDialog && (
1283 className="form-inline"
1284 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1287 className="visually-hidden"
1288 htmlFor="post-listing-remove-reason"
1290 {I18NextService.i18n.t("reason")}
1294 id="post-listing-remove-reason"
1295 className="form-control me-2"
1296 placeholder={I18NextService.i18n.t("reason")}
1297 value={this.state.removeReason}
1298 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1302 className="btn btn-secondary"
1303 aria-label={I18NextService.i18n.t("remove_post")}
1305 {this.state.removeLoading ? (
1308 I18NextService.i18n.t("remove_post")
1313 {this.state.showBanDialog && (
1314 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1315 <div className="mb-3 row col-12">
1317 className="col-form-label"
1318 htmlFor="post-listing-ban-reason"
1320 {I18NextService.i18n.t("reason")}
1324 id="post-listing-ban-reason"
1325 className="form-control me-2"
1326 placeholder={I18NextService.i18n.t("reason")}
1327 value={this.state.banReason}
1328 onInput={linkEvent(this, this.handleModBanReasonChange)}
1330 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1331 {I18NextService.i18n.t("expires")}
1335 id={`mod-ban-expires`}
1336 className="form-control me-2"
1337 placeholder={I18NextService.i18n.t("number_of_days")}
1338 value={this.state.banExpireDays}
1339 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1341 <div className="input-group mb-3">
1342 <div className="form-check">
1344 className="form-check-input"
1345 id="mod-ban-remove-data"
1347 checked={this.state.removeData}
1348 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1351 className="form-check-label"
1352 htmlFor="mod-ban-remove-data"
1353 title={I18NextService.i18n.t("remove_content_more")}
1355 {I18NextService.i18n.t("remove_content")}
1360 {/* TODO hold off on expires until later */}
1361 {/* <div class="mb-3 row"> */}
1362 {/* <label class="col-form-label">Expires</label> */}
1363 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1365 <div className="mb-3 row">
1368 className="btn btn-secondary"
1369 aria-label={I18NextService.i18n.t("ban")}
1371 {this.state.banLoading ? (
1375 {I18NextService.i18n.t("ban")} {post.creator.name}
1382 {this.state.showReportDialog && (
1384 className="form-inline"
1385 onSubmit={linkEvent(this, this.handleReportSubmit)}
1387 <label className="visually-hidden" htmlFor="post-report-reason">
1388 {I18NextService.i18n.t("reason")}
1392 id="post-report-reason"
1393 className="form-control me-2"
1394 placeholder={I18NextService.i18n.t("reason")}
1396 value={this.state.reportReason}
1397 onInput={linkEvent(this, this.handleReportReasonChange)}
1401 className="btn btn-secondary"
1402 aria-label={I18NextService.i18n.t("create_report")}
1404 {this.state.reportLoading ? (
1407 I18NextService.i18n.t("create_report")
1412 {this.state.showPurgeDialog && (
1414 className="form-inline"
1415 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1418 <label className="visually-hidden" htmlFor="purge-reason">
1419 {I18NextService.i18n.t("reason")}
1424 className="form-control me-2"
1425 placeholder={I18NextService.i18n.t("reason")}
1426 value={this.state.purgeReason}
1427 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1429 {this.state.purgeLoading ? (
1434 className="btn btn-secondary"
1435 aria-label={purgeTypeText}
1437 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1447 const post = this.postView.post;
1448 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1449 <div className="row">
1450 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1451 {this.postTitleLine()}
1453 <div className="col-4">
1454 {/* Post body prev or thumbnail */}
1455 {!this.state.imageExpanded && this.thumbnail()}
1459 this.postTitleLine()
1463 showMobilePreview() {
1464 const { body, id } = this.postView.post;
1466 return !this.showBody && body ? (
1467 <Link className="text-body" to={`/post/${id}`}>
1468 <div className="md-div mb-1 preview-lines">{body}</div>
1478 {/* The mobile view*/}
1479 <div className="d-block d-sm-none">
1480 <article className="row post-container">
1481 <div className="col-12">
1482 {this.createdLine()}
1484 {/* If it has a thumbnail, do a right aligned thumbnail */}
1485 {this.mobileThumbnail()}
1487 {/* Show a preview of the post body */}
1488 {this.showMobilePreview()}
1490 {this.commentsLine(true)}
1491 {this.userActionsLine()}
1492 {this.duplicatesLine()}
1493 {this.removeAndBanDialogs()}
1498 {/* The larger view*/}
1499 <div className="d-none d-sm-block">
1500 <article className="row post-container">
1501 {!this.props.viewOnly && this.voteBar()}
1502 <div className="col-sm-2 pe-0 post-media">
1503 <div className="">{this.thumbnail()}</div>
1505 <div className="col-12 col-sm-9">
1506 <div className="row">
1507 <div className="col-12">
1508 {this.postTitleLine()}
1509 {this.createdLine()}
1510 {this.commentsLine()}
1511 {this.duplicatesLine()}
1512 {this.userActionsLine()}
1513 {this.removeAndBanDialogs()}
1523 private get myPost(): boolean {
1525 this.postView.creator.id ==
1526 UserService.Instance.myUserInfo?.local_user_view.person.id
1529 handleEditClick(i: PostListing) {
1530 i.setState({ showEdit: true });
1533 handleEditCancel() {
1534 this.setState({ showEdit: false });
1537 // The actual editing is done in the receive for post
1538 handleEditPost(form: EditPost) {
1539 this.setState({ showEdit: false });
1540 this.props.onPostEdit(form);
1543 handleShare(i: PostListing) {
1544 const { name, body, id } = i.props.post_view.post;
1547 text: body?.slice(0, 50),
1548 url: `${getHttpBase()}/post/${id}`,
1552 handleShowReportDialog(i: PostListing) {
1553 i.setState({ showReportDialog: !i.state.showReportDialog });
1556 handleReportReasonChange(i: PostListing, event: any) {
1557 i.setState({ reportReason: event.target.value });
1560 handleReportSubmit(i: PostListing, event: any) {
1561 event.preventDefault();
1562 i.setState({ reportLoading: true });
1563 i.props.onPostReport({
1564 post_id: i.postView.post.id,
1565 reason: i.state.reportReason ?? "",
1566 auth: myAuthRequired(),
1570 handleBlockPersonClick(i: PostListing) {
1571 i.setState({ blockLoading: true });
1572 i.props.onBlockPerson({
1573 person_id: i.postView.creator.id,
1575 auth: myAuthRequired(),
1579 handleDeleteClick(i: PostListing) {
1580 i.setState({ deleteLoading: true });
1581 i.props.onDeletePost({
1582 post_id: i.postView.post.id,
1583 deleted: !i.postView.post.deleted,
1584 auth: myAuthRequired(),
1588 handleSavePostClick(i: PostListing) {
1589 i.setState({ saveLoading: true });
1590 i.props.onSavePost({
1591 post_id: i.postView.post.id,
1592 save: !i.postView.saved,
1593 auth: myAuthRequired(),
1597 get crossPostParams(): PostFormParams {
1598 const queryParams: PostFormParams = {};
1599 const { name, url } = this.postView.post;
1601 queryParams.name = name;
1604 queryParams.url = url;
1607 const crossPostBody = this.crossPostBody();
1608 if (crossPostBody) {
1609 queryParams.body = crossPostBody;
1615 crossPostBody(): string | undefined {
1616 const post = this.postView.post;
1617 const body = post.body;
1620 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1622 }\n\n${body.replace(/^/gm, "> ")}`
1626 get showBody(): boolean {
1627 return this.props.showBody || this.state.showBody;
1630 handleModRemoveShow(i: PostListing) {
1632 showRemoveDialog: !i.state.showRemoveDialog,
1633 showBanDialog: false,
1637 handleModRemoveReasonChange(i: PostListing, event: any) {
1638 i.setState({ removeReason: event.target.value });
1641 handleModRemoveDataChange(i: PostListing, event: any) {
1642 i.setState({ removeData: event.target.checked });
1645 handleModRemoveSubmit(i: PostListing, event: any) {
1646 event.preventDefault();
1647 i.setState({ removeLoading: true });
1648 i.props.onRemovePost({
1649 post_id: i.postView.post.id,
1650 removed: !i.postView.post.removed,
1651 auth: myAuthRequired(),
1655 handleModLock(i: PostListing) {
1656 i.setState({ lockLoading: true });
1657 i.props.onLockPost({
1658 post_id: i.postView.post.id,
1659 locked: !i.postView.post.locked,
1660 auth: myAuthRequired(),
1664 handleModFeaturePostLocal(i: PostListing) {
1665 i.setState({ featureLocalLoading: true });
1666 i.props.onFeaturePost({
1667 post_id: i.postView.post.id,
1668 featured: !i.postView.post.featured_local,
1669 feature_type: "Local",
1670 auth: myAuthRequired(),
1674 handleModFeaturePostCommunity(i: PostListing) {
1675 i.setState({ featureCommunityLoading: true });
1676 i.props.onFeaturePost({
1677 post_id: i.postView.post.id,
1678 featured: !i.postView.post.featured_community,
1679 feature_type: "Community",
1680 auth: myAuthRequired(),
1684 handleModBanFromCommunityShow(i: PostListing) {
1686 showBanDialog: true,
1687 banType: BanType.Community,
1688 showRemoveDialog: false,
1692 handleModBanShow(i: PostListing) {
1694 showBanDialog: true,
1695 banType: BanType.Site,
1696 showRemoveDialog: false,
1700 handlePurgePersonShow(i: PostListing) {
1702 showPurgeDialog: true,
1703 purgeType: PurgeType.Person,
1704 showRemoveDialog: false,
1708 handlePurgePostShow(i: PostListing) {
1710 showPurgeDialog: true,
1711 purgeType: PurgeType.Post,
1712 showRemoveDialog: false,
1716 handlePurgeReasonChange(i: PostListing, event: any) {
1717 i.setState({ purgeReason: event.target.value });
1720 handlePurgeSubmit(i: PostListing, event: any) {
1721 event.preventDefault();
1722 i.setState({ purgeLoading: true });
1723 if (i.state.purgeType == PurgeType.Person) {
1724 i.props.onPurgePerson({
1725 person_id: i.postView.creator.id,
1726 reason: i.state.purgeReason,
1727 auth: myAuthRequired(),
1729 } else if (i.state.purgeType == PurgeType.Post) {
1730 i.props.onPurgePost({
1731 post_id: i.postView.post.id,
1732 reason: i.state.purgeReason,
1733 auth: myAuthRequired(),
1738 handleModBanReasonChange(i: PostListing, event: any) {
1739 i.setState({ banReason: event.target.value });
1742 handleModBanExpireDaysChange(i: PostListing, event: any) {
1743 i.setState({ banExpireDays: event.target.value });
1746 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1747 i.setState({ banType: BanType.Community });
1748 i.handleModBanBothSubmit(i, event);
1751 handleModBanSubmit(i: PostListing, event: any) {
1752 i.setState({ banType: BanType.Site });
1753 i.handleModBanBothSubmit(i, event);
1756 handleModBanBothSubmit(i: PostListing, event: any) {
1757 event.preventDefault();
1758 i.setState({ banLoading: true });
1760 const ban = !i.props.post_view.creator_banned_from_community;
1761 // If its an unban, restore all their data
1763 i.setState({ removeData: false });
1765 const person_id = i.props.post_view.creator.id;
1766 const remove_data = i.state.removeData;
1767 const reason = i.state.banReason;
1768 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1770 if (i.state.banType == BanType.Community) {
1771 const community_id = i.postView.community.id;
1772 i.props.onBanPersonFromCommunity({
1779 auth: myAuthRequired(),
1782 i.props.onBanPerson({
1788 auth: myAuthRequired(),
1793 handleAddModToCommunity(i: PostListing) {
1794 i.setState({ addModLoading: true });
1795 i.props.onAddModToCommunity({
1796 community_id: i.postView.community.id,
1797 person_id: i.postView.creator.id,
1798 added: !i.creatorIsMod_,
1799 auth: myAuthRequired(),
1803 handleAddAdmin(i: PostListing) {
1804 i.setState({ addAdminLoading: true });
1805 i.props.onAddAdmin({
1806 person_id: i.postView.creator.id,
1807 added: !i.creatorIsAdmin_,
1808 auth: myAuthRequired(),
1812 handleShowConfirmTransferCommunity(i: PostListing) {
1813 i.setState({ showConfirmTransferCommunity: true });
1816 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1817 i.setState({ showConfirmTransferCommunity: false });
1820 handleTransferCommunity(i: PostListing) {
1821 i.setState({ transferLoading: true });
1822 i.props.onTransferCommunity({
1823 community_id: i.postView.community.id,
1824 person_id: i.postView.creator.id,
1825 auth: myAuthRequired(),
1829 handleShowConfirmTransferSite(i: PostListing) {
1830 i.setState({ showConfirmTransferSite: true });
1833 handleCancelShowConfirmTransferSite(i: PostListing) {
1834 i.setState({ showConfirmTransferSite: false });
1837 handleImageExpandClick(i: PostListing, event: any) {
1838 event.preventDefault();
1839 i.setState({ imageExpanded: !i.state.imageExpanded });
1843 handleViewSource(i: PostListing) {
1844 i.setState({ viewSource: !i.state.viewSource });
1847 handleShowAdvanced(i: PostListing) {
1848 i.setState({ showAdvanced: !i.state.showAdvanced });
1852 handleShowMoreMobile(i: PostListing) {
1854 showMoreMobile: !i.state.showMoreMobile,
1855 showAdvanced: !i.state.showAdvanced,
1860 handleShowBody(i: PostListing) {
1861 i.setState({ showBody: !i.state.showBody });
1865 handleUpvote(i: PostListing) {
1866 i.setState({ upvoteLoading: true });
1867 i.props.onPostVote({
1868 post_id: i.postView.post.id,
1869 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1870 auth: myAuthRequired(),
1874 handleDownvote(i: PostListing) {
1875 i.setState({ downvoteLoading: true });
1876 i.props.onPostVote({
1877 post_id: i.postView.post.id,
1878 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1879 auth: myAuthRequired(),
1883 get pointsTippy(): string {
1884 const points = I18NextService.i18n.t("number_of_points", {
1885 count: Number(this.postView.counts.score),
1886 formattedCount: Number(this.postView.counts.score),
1889 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1890 count: Number(this.postView.counts.upvotes),
1891 formattedCount: Number(this.postView.counts.upvotes),
1894 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1895 count: Number(this.postView.counts.downvotes),
1896 formattedCount: Number(this.postView.counts.downvotes),
1899 return `${points} • ${upvotes} • ${downvotes}`;
1902 get canModOnSelf_(): boolean {
1904 this.postView.creator.id,
1905 this.props.moderators,
1912 get canMod_(): boolean {
1914 this.postView.creator.id,
1915 this.props.moderators,
1920 get canAdmin_(): boolean {
1921 return canAdmin(this.postView.creator.id, this.props.admins);
1924 get creatorIsMod_(): boolean {
1925 return isMod(this.postView.creator.id, this.props.moderators);
1928 get creatorIsAdmin_(): boolean {
1929 return isAdmin(this.postView.creator.id, this.props.admins);