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 <span className="small">
385 <PersonListing person={post_view.creator} />
386 {this.creatorIsMod_ && (
387 <span className="mx-1 badge text-bg-light">
388 {I18NextService.i18n.t("mod")}
391 {this.creatorIsAdmin_ && (
392 <span className="mx-1 badge text-bg-light">
393 {I18NextService.i18n.t("admin")}
396 {post_view.creator.bot_account && (
397 <span className="mx-1 badge text-bg-light">
398 {I18NextService.i18n.t("bot_account").toLowerCase()}
401 {this.props.showCommunity && (
404 {I18NextService.i18n.t("to")}{" "}
405 <CommunityLink community={post_view.community} />
408 {post_view.post.language_id !== 0 && (
409 <span className="mx-1 badge text-bg-light">
411 this.props.allLanguages.find(
412 lang => lang.id === post_view.post.language_id
419 published={post_view.post.published}
420 updated={post_view.post.updated}
428 <div className={`vote-bar col-1 pe-0 small text-center`}>
430 className={`btn-animate btn btn-link p-0 ${
431 this.postView.my_vote == 1 ? "text-info" : "text-muted"
433 onClick={linkEvent(this, this.handleUpvote)}
434 data-tippy-content={I18NextService.i18n.t("upvote")}
435 aria-label={I18NextService.i18n.t("upvote")}
436 aria-pressed={this.postView.my_vote === 1}
438 {this.state.upvoteLoading ? (
441 <Icon icon="arrow-up1" classes="upvote" />
446 className={`unselectable pointer text-muted px-1 post-score`}
447 data-tippy-content={this.pointsTippy}
449 {numToSI(this.postView.counts.score)}
452 <div className="p-1"></div>
454 {this.props.enableDownvotes && (
456 className={`btn-animate btn btn-link p-0 ${
457 this.postView.my_vote == -1 ? "text-danger" : "text-muted"
459 onClick={linkEvent(this, this.handleDownvote)}
460 data-tippy-content={I18NextService.i18n.t("downvote")}
461 aria-label={I18NextService.i18n.t("downvote")}
462 aria-pressed={this.postView.my_vote === -1}
464 {this.state.downvoteLoading ? (
467 <Icon icon="arrow-down1" classes="downvote" />
476 const post = this.postView.post;
479 className={`d-inline ${
480 !post.featured_community && !post.featured_local
484 to={`/post/${post.id}`}
485 title={I18NextService.i18n.t("comments")}
489 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
496 const post = this.postView.post;
497 const url = post.url;
501 <div className="post-title overflow-hidden">
502 <h5 className="d-inline">
503 {url && this.props.showBody ? (
506 !post.featured_community && !post.featured_local
513 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
519 {(url && isImage(url)) ||
520 (post.thumbnail_url && (
522 className="btn btn-sm text-monospace text-muted d-inline-block"
523 data-tippy-content={I18NextService.i18n.t("expand_here")}
524 onClick={linkEvent(this, this.handleImageExpandClick)}
528 !this.state.imageExpanded ? "plus-square" : "minus-square"
530 classes="icon-inline"
535 <small className="ms-2 badge text-bg-secondary">
536 {I18NextService.i18n.t("removed")}
541 className="unselectable pointer ms-2 text-muted fst-italic"
542 data-tippy-content={I18NextService.i18n.t("deleted")}
544 <Icon icon="trash" classes="icon-inline text-danger" />
549 className="unselectable pointer ms-2 text-muted fst-italic"
550 data-tippy-content={I18NextService.i18n.t("locked")}
552 <Icon icon="lock" classes="icon-inline text-danger" />
555 {post.featured_community && (
557 className="unselectable pointer ms-2 text-muted fst-italic"
558 data-tippy-content={I18NextService.i18n.t(
559 "featured_in_community"
561 aria-label={I18NextService.i18n.t("featured_in_community")}
563 <Icon icon="pin" classes="icon-inline text-primary" />
566 {post.featured_local && (
568 className="unselectable pointer ms-2 text-muted fst-italic"
569 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
570 aria-label={I18NextService.i18n.t("featured_in_local")}
572 <Icon icon="pin" classes="icon-inline text-secondary" />
576 <small className="ms-2 badge text-bg-danger">
577 {I18NextService.i18n.t("nsfw")}
581 {url && this.urlLine()}
587 const post = this.postView.post;
588 const url = post.url;
591 <p className="d-flex text-muted align-items-center gap-1 small m-0">
592 {url && !(hostname(url) === getExternalHost()) && (
594 className="text-muted fst-italic"
607 const dupes = this.props.crossPosts;
608 return dupes && dupes.length > 0 ? (
609 <ul className="list-inline mb-1 small text-muted">
611 <li className="list-inline-item me-2">
612 {I18NextService.i18n.t("cross_posted_to")}
615 <li key={pv.post.id} className="list-inline-item me-2">
616 <Link to={`/post/${pv.post.id}`}>
619 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
630 commentsLine(mobile = false) {
631 const post = this.postView.post;
634 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
635 {this.commentsButton}
638 className="btn btn-sm btn-animate text-muted py-0"
639 onClick={linkEvent(this, this.handleShare)}
642 <Icon icon="share" inline />
647 className="btn btn-sm btn-animate text-muted py-0"
648 title={I18NextService.i18n.t("link")}
651 <Icon icon="fedilink" inline />
654 {mobile && !this.props.viewOnly && this.mobileVotes}
655 {UserService.Instance.myUserInfo &&
656 !this.props.viewOnly &&
662 showPreviewButton() {
663 const post_view = this.postView;
664 const body = post_view.post.body;
668 className="btn btn-sm btn-animate text-muted py-0"
669 data-tippy-content={body && mdNoImages.render(body)}
670 data-tippy-allowHtml={true}
671 onClick={linkEvent(this, this.handleShowBody)}
675 classes={classNames("icon-inline me-1", {
676 "text-success": this.state.showBody,
684 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
685 // Possible enhancement: Make each button a component.
686 const post_view = this.postView;
687 const post = post_view.post;
692 {this.crossPostButton}
695 * If there is a URL, or if the post has a body and we were told not to
696 * show the body, show the MetadataCard/body toggle.
698 {(post.url || (post.body && !this.props.showBody)) &&
699 this.showPreviewButton()}
701 {this.showBody && post_view.post.body && this.viewSourceButton}
703 <div className="dropdown">
705 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
706 onClick={linkEvent(this, this.handleShowAdvanced)}
707 data-tippy-content={I18NextService.i18n.t("more")}
708 data-bs-toggle="dropdown"
709 aria-expanded="false"
710 aria-controls={`advancedButtonsDropdown${post.id}`}
711 aria-label={I18NextService.i18n.t("more")}
713 <Icon icon="more-vertical" inline />
717 className="dropdown-menu"
718 id={`advancedButtonsDropdown${post.id}`}
722 <li>{this.reportButton}</li>
723 <li>{this.blockButton}</li>
727 <li>{this.editButton}</li>
728 <li>{this.deleteButton}</li>
732 {/* Any mod can do these, not limited to hierarchy*/}
733 {(amMod(this.props.moderators) || amAdmin()) && (
736 <hr className="dropdown-divider" />
738 <li>{this.lockButton}</li>
739 {this.featureButtons}
743 {(this.canMod_ || this.canAdmin_) && (
744 <li>{this.modRemoveButton}</li>
752 get commentsButton() {
753 const post_view = this.postView;
754 const title = I18NextService.i18n.t("number_of_comments", {
755 count: Number(post_view.counts.comments),
756 formattedCount: Number(post_view.counts.comments),
761 className="btn btn-link btn-sm text-muted ps-0"
763 to={`/post/${post_view.post.id}?scrollToComments=true`}
764 data-tippy-content={title}
766 <Icon icon="message-square" classes="me-1" inline />
767 {post_view.counts.comments}
768 {this.unreadCount && (
769 <span className="text-muted fst-italic">
770 ({this.unreadCount} {I18NextService.i18n.t("new")})
777 get unreadCount(): number | undefined {
778 const pv = this.postView;
779 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
781 : pv.unread_comments;
786 const tippy = showScores()
787 ? { "data-tippy-content": this.pointsTippy }
793 className={`btn-animate btn py-0 px-1 ${
794 this.postView.my_vote === 1 ? "text-info" : "text-muted"
797 onClick={linkEvent(this, this.handleUpvote)}
798 aria-label={I18NextService.i18n.t("upvote")}
799 aria-pressed={this.postView.my_vote === 1}
801 {this.state.upvoteLoading ? (
805 <Icon icon="arrow-up1" classes="icon-inline small" />
807 <span className="ms-2">
808 {numToSI(this.postView.counts.upvotes)}
814 {this.props.enableDownvotes && (
816 className={`ms-2 btn-animate btn py-0 px-1 ${
817 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
819 onClick={linkEvent(this, this.handleDownvote)}
821 aria-label={I18NextService.i18n.t("downvote")}
822 aria-pressed={this.postView.my_vote === -1}
824 {this.state.downvoteLoading ? (
828 <Icon icon="arrow-down1" classes="icon-inline small" />
831 className={classNames("ms-2", {
832 invisible: this.postView.counts.downvotes === 0,
835 {numToSI(this.postView.counts.downvotes)}
848 const saved = this.postView.saved;
850 ? I18NextService.i18n.t("unsave")
851 : I18NextService.i18n.t("save");
854 className="btn btn-sm btn-animate text-muted py-0"
855 onClick={linkEvent(this, this.handleSavePostClick)}
856 data-tippy-content={label}
859 {this.state.saveLoading ? (
864 classes={classNames({ "text-warning": saved })}
872 get crossPostButton() {
875 className="btn btn-sm btn-animate text-muted py-0"
877 /* Empty string properties are required to satisfy type*/
878 pathname: "/create_post",
879 state: { ...this.crossPostParams },
884 title={I18NextService.i18n.t("cross_post")}
885 data-tippy-content={I18NextService.i18n.t("cross_post")}
886 aria-label={I18NextService.i18n.t("cross_post")}
888 <Icon icon="copy" inline />
896 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
897 onClick={linkEvent(this, this.handleShowReportDialog)}
898 aria-label={I18NextService.i18n.t("show_report_dialog")}
900 <Icon classes="me-1" icon="flag" inline />
901 {I18NextService.i18n.t("create_report")}
909 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
910 onClick={linkEvent(this, this.handleBlockPersonClick)}
911 aria-label={I18NextService.i18n.t("block_user")}
913 {this.state.blockLoading ? (
916 <Icon classes="me-1" icon="slash" inline />
918 {I18NextService.i18n.t("block_user")}
926 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
927 onClick={linkEvent(this, this.handleEditClick)}
928 aria-label={I18NextService.i18n.t("edit")}
930 <Icon classes="me-1" icon="edit" inline />
931 {I18NextService.i18n.t("edit")}
937 const deleted = this.postView.post.deleted;
938 const label = !deleted
939 ? I18NextService.i18n.t("delete")
940 : I18NextService.i18n.t("restore");
943 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
944 onClick={linkEvent(this, this.handleDeleteClick)}
947 {this.state.deleteLoading ? (
953 classes={classNames("me-1", { "text-danger": deleted })}
963 get viewSourceButton() {
966 className="btn btn-sm btn-animate text-muted py-0"
967 onClick={linkEvent(this, this.handleViewSource)}
968 data-tippy-content={I18NextService.i18n.t("view_source")}
969 aria-label={I18NextService.i18n.t("view_source")}
973 classes={classNames({ "text-success": this.state.viewSource })}
981 const locked = this.postView.post.locked;
983 ? I18NextService.i18n.t("unlock")
984 : I18NextService.i18n.t("lock");
987 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
988 onClick={linkEvent(this, this.handleModLock)}
991 {this.state.lockLoading ? (
997 classes={classNames("me-1", { "text-danger": locked })}
1000 {capitalizeFirstLetter(label)}
1007 get featureButtons() {
1008 const featuredCommunity = this.postView.post.featured_community;
1009 const labelCommunity = featuredCommunity
1010 ? I18NextService.i18n.t("unfeature_from_community")
1011 : I18NextService.i18n.t("feature_in_community");
1013 const featuredLocal = this.postView.post.featured_local;
1014 const labelLocal = featuredLocal
1015 ? I18NextService.i18n.t("unfeature_from_local")
1016 : I18NextService.i18n.t("feature_in_local");
1021 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1022 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
1023 data-tippy-content={labelCommunity}
1024 aria-label={labelCommunity}
1026 {this.state.featureCommunityLoading ? (
1032 classes={classNames("me-1", {
1033 "text-success": featuredCommunity,
1037 {I18NextService.i18n.t("community")}
1045 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1046 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1047 data-tippy-content={labelLocal}
1048 aria-label={labelLocal}
1050 {this.state.featureLocalLoading ? (
1056 classes={classNames("me-1", {
1057 "text-success": featuredLocal,
1061 {I18NextService.i18n.t("local")}
1071 get modRemoveButton() {
1072 const removed = this.postView.post.removed;
1075 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1078 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1081 {/* TODO: Find an icon for this. */}
1082 {this.state.removeLoading ? (
1085 I18NextService.i18n.t("remove")
1087 I18NextService.i18n.t("restore")
1094 * Mod/Admin actions to be taken against the author.
1098 const post_view = this.postView;
1100 this.state.showAdvanced && (
1101 <div className="mt-3">
1104 {!this.creatorIsMod_ &&
1105 (!post_view.creator_banned_from_community ? (
1107 className="btn btn-link btn-animate text-muted py-0"
1110 this.handleModBanFromCommunityShow
1112 aria-label={I18NextService.i18n.t("ban_from_community")}
1114 {I18NextService.i18n.t("ban_from_community")}
1118 className="btn btn-link btn-animate text-muted py-0"
1121 this.handleModBanFromCommunitySubmit
1123 aria-label={I18NextService.i18n.t("unban")}
1125 {this.state.banLoading ? (
1128 I18NextService.i18n.t("unban")
1132 {!post_view.creator_banned_from_community && (
1134 className="btn btn-link btn-animate text-muted py-0"
1135 onClick={linkEvent(this, this.handleAddModToCommunity)}
1138 ? I18NextService.i18n.t("remove_as_mod")
1139 : I18NextService.i18n.t("appoint_as_mod")
1142 {this.state.addModLoading ? (
1144 ) : this.creatorIsMod_ ? (
1145 I18NextService.i18n.t("remove_as_mod")
1147 I18NextService.i18n.t("appoint_as_mod")
1153 {/* Community creators and admins can transfer community to another mod */}
1154 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1156 this.creatorIsMod_ &&
1157 (!this.state.showConfirmTransferCommunity ? (
1159 className="btn btn-link btn-animate text-muted py-0"
1162 this.handleShowConfirmTransferCommunity
1164 aria-label={I18NextService.i18n.t("transfer_community")}
1166 {I18NextService.i18n.t("transfer_community")}
1171 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1172 aria-label={I18NextService.i18n.t("are_you_sure")}
1174 {I18NextService.i18n.t("are_you_sure")}
1177 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1178 aria-label={I18NextService.i18n.t("yes")}
1179 onClick={linkEvent(this, this.handleTransferCommunity)}
1181 {this.state.transferLoading ? (
1184 I18NextService.i18n.t("yes")
1188 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1191 this.handleCancelShowConfirmTransferCommunity
1193 aria-label={I18NextService.i18n.t("no")}
1195 {I18NextService.i18n.t("no")}
1199 {/* Admins can ban from all, and appoint other admins */}
1200 {this.canAdmin_ && (
1202 {!this.creatorIsAdmin_ && (
1204 {!isBanned(post_view.creator) ? (
1206 className="btn btn-link btn-animate text-muted py-0"
1207 onClick={linkEvent(this, this.handleModBanShow)}
1208 aria-label={I18NextService.i18n.t("ban_from_site")}
1210 {I18NextService.i18n.t("ban_from_site")}
1214 className="btn btn-link btn-animate text-muted py-0"
1215 onClick={linkEvent(this, this.handleModBanSubmit)}
1216 aria-label={I18NextService.i18n.t("unban_from_site")}
1218 {this.state.banLoading ? (
1221 I18NextService.i18n.t("unban_from_site")
1226 className="btn btn-link btn-animate text-muted py-0"
1227 onClick={linkEvent(this, this.handlePurgePersonShow)}
1228 aria-label={I18NextService.i18n.t("purge_user")}
1230 {I18NextService.i18n.t("purge_user")}
1233 className="btn btn-link btn-animate text-muted py-0"
1234 onClick={linkEvent(this, this.handlePurgePostShow)}
1235 aria-label={I18NextService.i18n.t("purge_post")}
1237 {I18NextService.i18n.t("purge_post")}
1241 {!isBanned(post_view.creator) && post_view.creator.local && (
1243 className="btn btn-link btn-animate text-muted py-0"
1244 onClick={linkEvent(this, this.handleAddAdmin)}
1246 this.creatorIsAdmin_
1247 ? I18NextService.i18n.t("remove_as_admin")
1248 : I18NextService.i18n.t("appoint_as_admin")
1251 {this.state.addAdminLoading ? (
1253 ) : this.creatorIsAdmin_ ? (
1254 I18NextService.i18n.t("remove_as_admin")
1256 I18NextService.i18n.t("appoint_as_admin")
1267 removeAndBanDialogs() {
1268 const post = this.postView;
1269 const purgeTypeText =
1270 this.state.purgeType == PurgeType.Post
1271 ? I18NextService.i18n.t("purge_post")
1272 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1275 {this.state.showRemoveDialog && (
1277 className="form-inline"
1278 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1281 className="visually-hidden"
1282 htmlFor="post-listing-remove-reason"
1284 {I18NextService.i18n.t("reason")}
1288 id="post-listing-remove-reason"
1289 className="form-control me-2"
1290 placeholder={I18NextService.i18n.t("reason")}
1291 value={this.state.removeReason}
1292 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1296 className="btn btn-secondary"
1297 aria-label={I18NextService.i18n.t("remove_post")}
1299 {this.state.removeLoading ? (
1302 I18NextService.i18n.t("remove_post")
1307 {this.state.showBanDialog && (
1308 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1309 <div className="mb-3 row col-12">
1311 className="col-form-label"
1312 htmlFor="post-listing-ban-reason"
1314 {I18NextService.i18n.t("reason")}
1318 id="post-listing-ban-reason"
1319 className="form-control me-2"
1320 placeholder={I18NextService.i18n.t("reason")}
1321 value={this.state.banReason}
1322 onInput={linkEvent(this, this.handleModBanReasonChange)}
1324 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1325 {I18NextService.i18n.t("expires")}
1329 id={`mod-ban-expires`}
1330 className="form-control me-2"
1331 placeholder={I18NextService.i18n.t("number_of_days")}
1332 value={this.state.banExpireDays}
1333 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1335 <div className="input-group mb-3">
1336 <div className="form-check">
1338 className="form-check-input"
1339 id="mod-ban-remove-data"
1341 checked={this.state.removeData}
1342 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1345 className="form-check-label"
1346 htmlFor="mod-ban-remove-data"
1347 title={I18NextService.i18n.t("remove_content_more")}
1349 {I18NextService.i18n.t("remove_content")}
1354 {/* TODO hold off on expires until later */}
1355 {/* <div class="mb-3 row"> */}
1356 {/* <label class="col-form-label">Expires</label> */}
1357 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1359 <div className="mb-3 row">
1362 className="btn btn-secondary"
1363 aria-label={I18NextService.i18n.t("ban")}
1365 {this.state.banLoading ? (
1369 {I18NextService.i18n.t("ban")} {post.creator.name}
1376 {this.state.showReportDialog && (
1378 className="form-inline"
1379 onSubmit={linkEvent(this, this.handleReportSubmit)}
1381 <label className="visually-hidden" htmlFor="post-report-reason">
1382 {I18NextService.i18n.t("reason")}
1386 id="post-report-reason"
1387 className="form-control me-2"
1388 placeholder={I18NextService.i18n.t("reason")}
1390 value={this.state.reportReason}
1391 onInput={linkEvent(this, this.handleReportReasonChange)}
1395 className="btn btn-secondary"
1396 aria-label={I18NextService.i18n.t("create_report")}
1398 {this.state.reportLoading ? (
1401 I18NextService.i18n.t("create_report")
1406 {this.state.showPurgeDialog && (
1408 className="form-inline"
1409 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1412 <label className="visually-hidden" htmlFor="purge-reason">
1413 {I18NextService.i18n.t("reason")}
1418 className="form-control me-2"
1419 placeholder={I18NextService.i18n.t("reason")}
1420 value={this.state.purgeReason}
1421 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1423 {this.state.purgeLoading ? (
1428 className="btn btn-secondary"
1429 aria-label={purgeTypeText}
1431 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1441 const post = this.postView.post;
1442 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1443 <div className="row">
1444 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1445 {this.postTitleLine()}
1447 <div className="col-4">
1448 {/* Post body prev or thumbnail */}
1449 {!this.state.imageExpanded && this.thumbnail()}
1453 this.postTitleLine()
1458 const { body, id } = this.postView.post;
1460 return !this.showBody && body ? (
1461 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1462 <div className="md-div mb-1 preview-lines">{body}</div>
1472 {/* The mobile view*/}
1473 <div className="d-block d-sm-none">
1474 <article className="row post-container">
1475 <div className="col-12">
1476 {this.createdLine()}
1478 {/* If it has a thumbnail, do a right aligned thumbnail */}
1479 {this.mobileThumbnail()}
1481 {/* Show a preview of the post body */}
1482 {this.showBodyPreview()}
1484 {this.commentsLine(true)}
1485 {this.userActionsLine()}
1486 {this.duplicatesLine()}
1487 {this.removeAndBanDialogs()}
1492 {/* The larger view*/}
1493 <div className="d-none d-sm-block">
1494 <article className="row post-container">
1495 {!this.props.viewOnly && this.voteBar()}
1496 <div className="col-sm-2 pe-0 post-media">
1497 <div className="">{this.thumbnail()}</div>
1499 <div className="col-12 col-sm-9">
1500 <div className="row">
1501 <div className="col-12">
1502 {this.postTitleLine()}
1503 {this.createdLine()}
1504 {this.showBodyPreview()}
1505 {this.commentsLine()}
1506 {this.duplicatesLine()}
1507 {this.userActionsLine()}
1508 {this.removeAndBanDialogs()}
1518 private get myPost(): boolean {
1520 this.postView.creator.id ==
1521 UserService.Instance.myUserInfo?.local_user_view.person.id
1524 handleEditClick(i: PostListing) {
1525 i.setState({ showEdit: true });
1528 handleEditCancel() {
1529 this.setState({ showEdit: false });
1532 // The actual editing is done in the receive for post
1533 handleEditPost(form: EditPost) {
1534 this.setState({ showEdit: false });
1535 this.props.onPostEdit(form);
1538 handleShare(i: PostListing) {
1539 const { name, body, id } = i.props.post_view.post;
1542 text: body?.slice(0, 50),
1543 url: `${getHttpBase()}/post/${id}`,
1547 handleShowReportDialog(i: PostListing) {
1548 i.setState({ showReportDialog: !i.state.showReportDialog });
1551 handleReportReasonChange(i: PostListing, event: any) {
1552 i.setState({ reportReason: event.target.value });
1555 handleReportSubmit(i: PostListing, event: any) {
1556 event.preventDefault();
1557 i.setState({ reportLoading: true });
1558 i.props.onPostReport({
1559 post_id: i.postView.post.id,
1560 reason: i.state.reportReason ?? "",
1561 auth: myAuthRequired(),
1565 handleBlockPersonClick(i: PostListing) {
1566 i.setState({ blockLoading: true });
1567 i.props.onBlockPerson({
1568 person_id: i.postView.creator.id,
1570 auth: myAuthRequired(),
1574 handleDeleteClick(i: PostListing) {
1575 i.setState({ deleteLoading: true });
1576 i.props.onDeletePost({
1577 post_id: i.postView.post.id,
1578 deleted: !i.postView.post.deleted,
1579 auth: myAuthRequired(),
1583 handleSavePostClick(i: PostListing) {
1584 i.setState({ saveLoading: true });
1585 i.props.onSavePost({
1586 post_id: i.postView.post.id,
1587 save: !i.postView.saved,
1588 auth: myAuthRequired(),
1592 get crossPostParams(): PostFormParams {
1593 const queryParams: PostFormParams = {};
1594 const { name, url } = this.postView.post;
1596 queryParams.name = name;
1599 queryParams.url = url;
1602 const crossPostBody = this.crossPostBody();
1603 if (crossPostBody) {
1604 queryParams.body = crossPostBody;
1610 crossPostBody(): string | undefined {
1611 const post = this.postView.post;
1612 const body = post.body;
1615 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1617 }\n\n${body.replace(/^/gm, "> ")}`
1621 get showBody(): boolean {
1622 return this.props.showBody || this.state.showBody;
1625 handleModRemoveShow(i: PostListing) {
1627 showRemoveDialog: !i.state.showRemoveDialog,
1628 showBanDialog: false,
1632 handleModRemoveReasonChange(i: PostListing, event: any) {
1633 i.setState({ removeReason: event.target.value });
1636 handleModRemoveDataChange(i: PostListing, event: any) {
1637 i.setState({ removeData: event.target.checked });
1640 handleModRemoveSubmit(i: PostListing, event: any) {
1641 event.preventDefault();
1642 i.setState({ removeLoading: true });
1643 i.props.onRemovePost({
1644 post_id: i.postView.post.id,
1645 removed: !i.postView.post.removed,
1646 auth: myAuthRequired(),
1650 handleModLock(i: PostListing) {
1651 i.setState({ lockLoading: true });
1652 i.props.onLockPost({
1653 post_id: i.postView.post.id,
1654 locked: !i.postView.post.locked,
1655 auth: myAuthRequired(),
1659 handleModFeaturePostLocal(i: PostListing) {
1660 i.setState({ featureLocalLoading: true });
1661 i.props.onFeaturePost({
1662 post_id: i.postView.post.id,
1663 featured: !i.postView.post.featured_local,
1664 feature_type: "Local",
1665 auth: myAuthRequired(),
1669 handleModFeaturePostCommunity(i: PostListing) {
1670 i.setState({ featureCommunityLoading: true });
1671 i.props.onFeaturePost({
1672 post_id: i.postView.post.id,
1673 featured: !i.postView.post.featured_community,
1674 feature_type: "Community",
1675 auth: myAuthRequired(),
1679 handleModBanFromCommunityShow(i: PostListing) {
1681 showBanDialog: true,
1682 banType: BanType.Community,
1683 showRemoveDialog: false,
1687 handleModBanShow(i: PostListing) {
1689 showBanDialog: true,
1690 banType: BanType.Site,
1691 showRemoveDialog: false,
1695 handlePurgePersonShow(i: PostListing) {
1697 showPurgeDialog: true,
1698 purgeType: PurgeType.Person,
1699 showRemoveDialog: false,
1703 handlePurgePostShow(i: PostListing) {
1705 showPurgeDialog: true,
1706 purgeType: PurgeType.Post,
1707 showRemoveDialog: false,
1711 handlePurgeReasonChange(i: PostListing, event: any) {
1712 i.setState({ purgeReason: event.target.value });
1715 handlePurgeSubmit(i: PostListing, event: any) {
1716 event.preventDefault();
1717 i.setState({ purgeLoading: true });
1718 if (i.state.purgeType == PurgeType.Person) {
1719 i.props.onPurgePerson({
1720 person_id: i.postView.creator.id,
1721 reason: i.state.purgeReason,
1722 auth: myAuthRequired(),
1724 } else if (i.state.purgeType == PurgeType.Post) {
1725 i.props.onPurgePost({
1726 post_id: i.postView.post.id,
1727 reason: i.state.purgeReason,
1728 auth: myAuthRequired(),
1733 handleModBanReasonChange(i: PostListing, event: any) {
1734 i.setState({ banReason: event.target.value });
1737 handleModBanExpireDaysChange(i: PostListing, event: any) {
1738 i.setState({ banExpireDays: event.target.value });
1741 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1742 i.setState({ banType: BanType.Community });
1743 i.handleModBanBothSubmit(i, event);
1746 handleModBanSubmit(i: PostListing, event: any) {
1747 i.setState({ banType: BanType.Site });
1748 i.handleModBanBothSubmit(i, event);
1751 handleModBanBothSubmit(i: PostListing, event: any) {
1752 event.preventDefault();
1753 i.setState({ banLoading: true });
1755 const ban = !i.props.post_view.creator_banned_from_community;
1756 // If its an unban, restore all their data
1758 i.setState({ removeData: false });
1760 const person_id = i.props.post_view.creator.id;
1761 const remove_data = i.state.removeData;
1762 const reason = i.state.banReason;
1763 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1765 if (i.state.banType == BanType.Community) {
1766 const community_id = i.postView.community.id;
1767 i.props.onBanPersonFromCommunity({
1774 auth: myAuthRequired(),
1777 i.props.onBanPerson({
1783 auth: myAuthRequired(),
1788 handleAddModToCommunity(i: PostListing) {
1789 i.setState({ addModLoading: true });
1790 i.props.onAddModToCommunity({
1791 community_id: i.postView.community.id,
1792 person_id: i.postView.creator.id,
1793 added: !i.creatorIsMod_,
1794 auth: myAuthRequired(),
1798 handleAddAdmin(i: PostListing) {
1799 i.setState({ addAdminLoading: true });
1800 i.props.onAddAdmin({
1801 person_id: i.postView.creator.id,
1802 added: !i.creatorIsAdmin_,
1803 auth: myAuthRequired(),
1807 handleShowConfirmTransferCommunity(i: PostListing) {
1808 i.setState({ showConfirmTransferCommunity: true });
1811 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1812 i.setState({ showConfirmTransferCommunity: false });
1815 handleTransferCommunity(i: PostListing) {
1816 i.setState({ transferLoading: true });
1817 i.props.onTransferCommunity({
1818 community_id: i.postView.community.id,
1819 person_id: i.postView.creator.id,
1820 auth: myAuthRequired(),
1824 handleShowConfirmTransferSite(i: PostListing) {
1825 i.setState({ showConfirmTransferSite: true });
1828 handleCancelShowConfirmTransferSite(i: PostListing) {
1829 i.setState({ showConfirmTransferSite: false });
1832 handleImageExpandClick(i: PostListing, event: any) {
1833 event.preventDefault();
1834 i.setState({ imageExpanded: !i.state.imageExpanded });
1838 handleViewSource(i: PostListing) {
1839 i.setState({ viewSource: !i.state.viewSource });
1842 handleShowAdvanced(i: PostListing) {
1843 i.setState({ showAdvanced: !i.state.showAdvanced });
1847 handleShowMoreMobile(i: PostListing) {
1849 showMoreMobile: !i.state.showMoreMobile,
1850 showAdvanced: !i.state.showAdvanced,
1855 handleShowBody(i: PostListing) {
1856 i.setState({ showBody: !i.state.showBody });
1860 handleUpvote(i: PostListing) {
1861 i.setState({ upvoteLoading: true });
1862 i.props.onPostVote({
1863 post_id: i.postView.post.id,
1864 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1865 auth: myAuthRequired(),
1869 handleDownvote(i: PostListing) {
1870 i.setState({ downvoteLoading: true });
1871 i.props.onPostVote({
1872 post_id: i.postView.post.id,
1873 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1874 auth: myAuthRequired(),
1878 get pointsTippy(): string {
1879 const points = I18NextService.i18n.t("number_of_points", {
1880 count: Number(this.postView.counts.score),
1881 formattedCount: Number(this.postView.counts.score),
1884 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1885 count: Number(this.postView.counts.upvotes),
1886 formattedCount: Number(this.postView.counts.upvotes),
1889 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1890 count: Number(this.postView.counts.downvotes),
1891 formattedCount: Number(this.postView.counts.downvotes),
1894 return `${points} • ${upvotes} • ${downvotes}`;
1897 get canModOnSelf_(): boolean {
1899 this.postView.creator.id,
1900 this.props.moderators,
1907 get canMod_(): boolean {
1909 this.postView.creator.id,
1910 this.props.moderators,
1915 get canAdmin_(): boolean {
1916 return canAdmin(this.postView.creator.id, this.props.admins);
1919 get creatorIsMod_(): boolean {
1920 return isMod(this.postView.creator.id, this.props.moderators);
1923 get creatorIsAdmin_(): boolean {
1924 return isAdmin(this.postView.creator.id, this.props.admins);