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 font-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 font-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 font-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 font-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 font-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"
711 aria-label={I18NextService.i18n.t("more")}
713 <Icon icon="more-vertical" inline />
716 <ul className="dropdown-menu" id="advancedButtonsDropdown">
719 <li>{this.reportButton}</li>
720 <li>{this.blockButton}</li>
724 <li>{this.editButton}</li>
725 <li>{this.deleteButton}</li>
729 {/* Any mod can do these, not limited to hierarchy*/}
730 {(amMod(this.props.moderators) || amAdmin()) && (
733 <hr className="dropdown-divider" />
735 <li>{this.lockButton}</li>
736 {this.featureButtons}
740 {(this.canMod_ || this.canAdmin_) && (
741 <li>{this.modRemoveButton}</li>
749 get commentsButton() {
750 const post_view = this.postView;
751 const title = I18NextService.i18n.t("number_of_comments", {
752 count: Number(post_view.counts.comments),
753 formattedCount: Number(post_view.counts.comments),
758 className="btn btn-link btn-sm text-muted ps-0"
760 to={`/post/${post_view.post.id}?scrollToComments=true`}
761 data-tippy-content={title}
763 <Icon icon="message-square" classes="me-1" inline />
764 {post_view.counts.comments}
765 {this.unreadCount && (
766 <span className="text-muted fst-italic">
767 ({this.unreadCount} {I18NextService.i18n.t("new")})
774 get unreadCount(): number | undefined {
775 const pv = this.postView;
776 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
778 : pv.unread_comments;
783 const tippy = showScores()
784 ? { "data-tippy-content": this.pointsTippy }
790 className={`btn-animate btn py-0 px-1 ${
791 this.postView.my_vote === 1 ? "text-info" : "text-muted"
794 onClick={linkEvent(this, this.handleUpvote)}
795 aria-label={I18NextService.i18n.t("upvote")}
796 aria-pressed={this.postView.my_vote === 1}
798 {this.state.upvoteLoading ? (
802 <Icon icon="arrow-up1" classes="icon-inline small" />
804 <span className="ms-2">
805 {numToSI(this.postView.counts.upvotes)}
811 {this.props.enableDownvotes && (
813 className={`ms-2 btn-animate btn py-0 px-1 ${
814 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
816 onClick={linkEvent(this, this.handleDownvote)}
818 aria-label={I18NextService.i18n.t("downvote")}
819 aria-pressed={this.postView.my_vote === -1}
821 {this.state.downvoteLoading ? (
825 <Icon icon="arrow-down1" classes="icon-inline small" />
828 className={classNames("ms-2", {
829 invisible: this.postView.counts.downvotes === 0,
832 {numToSI(this.postView.counts.downvotes)}
845 const saved = this.postView.saved;
847 ? I18NextService.i18n.t("unsave")
848 : I18NextService.i18n.t("save");
851 className="btn btn-sm btn-animate text-muted py-0"
852 onClick={linkEvent(this, this.handleSavePostClick)}
853 data-tippy-content={label}
856 {this.state.saveLoading ? (
861 classes={classNames({ "text-warning": saved })}
869 get crossPostButton() {
872 className="btn btn-sm btn-animate text-muted py-0"
874 /* Empty string properties are required to satisfy type*/
875 pathname: "/create_post",
876 state: { ...this.crossPostParams },
881 title={I18NextService.i18n.t("cross_post")}
882 data-tippy-content={I18NextService.i18n.t("cross_post")}
883 aria-label={I18NextService.i18n.t("cross_post")}
885 <Icon icon="copy" inline />
893 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
894 onClick={linkEvent(this, this.handleShowReportDialog)}
895 aria-label={I18NextService.i18n.t("show_report_dialog")}
897 <Icon classes="me-1" icon="flag" inline />
898 {I18NextService.i18n.t("create_report")}
906 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
907 onClick={linkEvent(this, this.handleBlockPersonClick)}
908 aria-label={I18NextService.i18n.t("block_user")}
910 {this.state.blockLoading ? (
913 <Icon classes="me-1" icon="slash" inline />
915 {I18NextService.i18n.t("block_user")}
923 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
924 onClick={linkEvent(this, this.handleEditClick)}
925 aria-label={I18NextService.i18n.t("edit")}
927 <Icon classes="me-1" icon="edit" inline />
928 {I18NextService.i18n.t("edit")}
934 const deleted = this.postView.post.deleted;
935 const label = !deleted
936 ? I18NextService.i18n.t("delete")
937 : I18NextService.i18n.t("restore");
940 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
941 onClick={linkEvent(this, this.handleDeleteClick)}
944 {this.state.deleteLoading ? (
950 classes={classNames("me-1", { "text-danger": deleted })}
960 get viewSourceButton() {
963 className="btn btn-sm btn-animate text-muted py-0"
964 onClick={linkEvent(this, this.handleViewSource)}
965 data-tippy-content={I18NextService.i18n.t("view_source")}
966 aria-label={I18NextService.i18n.t("view_source")}
970 classes={classNames({ "text-success": this.state.viewSource })}
978 const locked = this.postView.post.locked;
980 ? I18NextService.i18n.t("unlock")
981 : I18NextService.i18n.t("lock");
984 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
985 onClick={linkEvent(this, this.handleModLock)}
988 {this.state.lockLoading ? (
994 classes={classNames("me-1", { "text-danger": locked })}
997 {capitalizeFirstLetter(label)}
1004 get featureButtons() {
1005 const featuredCommunity = this.postView.post.featured_community;
1006 const labelCommunity = featuredCommunity
1007 ? I18NextService.i18n.t("unfeature_from_community")
1008 : I18NextService.i18n.t("feature_in_community");
1010 const featuredLocal = this.postView.post.featured_local;
1011 const labelLocal = featuredLocal
1012 ? I18NextService.i18n.t("unfeature_from_local")
1013 : I18NextService.i18n.t("feature_in_local");
1018 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1019 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
1020 data-tippy-content={labelCommunity}
1021 aria-label={labelCommunity}
1023 {this.state.featureCommunityLoading ? (
1029 classes={classNames("me-1", {
1030 "text-success": featuredCommunity,
1034 {I18NextService.i18n.t("community")}
1042 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1043 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1044 data-tippy-content={labelLocal}
1045 aria-label={labelLocal}
1047 {this.state.featureLocalLoading ? (
1053 classes={classNames("me-1", {
1054 "text-success": featuredLocal,
1058 {I18NextService.i18n.t("local")}
1068 get modRemoveButton() {
1069 const removed = this.postView.post.removed;
1072 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1075 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1078 {/* TODO: Find an icon for this. */}
1079 {this.state.removeLoading ? (
1082 I18NextService.i18n.t("remove")
1084 I18NextService.i18n.t("restore")
1091 * Mod/Admin actions to be taken against the author.
1095 const post_view = this.postView;
1097 this.state.showAdvanced && (
1098 <div className="mt-3">
1101 {!this.creatorIsMod_ &&
1102 (!post_view.creator_banned_from_community ? (
1104 className="btn btn-link btn-animate text-muted py-0"
1107 this.handleModBanFromCommunityShow
1109 aria-label={I18NextService.i18n.t("ban_from_community")}
1111 {I18NextService.i18n.t("ban_from_community")}
1115 className="btn btn-link btn-animate text-muted py-0"
1118 this.handleModBanFromCommunitySubmit
1120 aria-label={I18NextService.i18n.t("unban")}
1122 {this.state.banLoading ? (
1125 I18NextService.i18n.t("unban")
1129 {!post_view.creator_banned_from_community && (
1131 className="btn btn-link btn-animate text-muted py-0"
1132 onClick={linkEvent(this, this.handleAddModToCommunity)}
1135 ? I18NextService.i18n.t("remove_as_mod")
1136 : I18NextService.i18n.t("appoint_as_mod")
1139 {this.state.addModLoading ? (
1141 ) : this.creatorIsMod_ ? (
1142 I18NextService.i18n.t("remove_as_mod")
1144 I18NextService.i18n.t("appoint_as_mod")
1150 {/* Community creators and admins can transfer community to another mod */}
1151 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1153 this.creatorIsMod_ &&
1154 (!this.state.showConfirmTransferCommunity ? (
1156 className="btn btn-link btn-animate text-muted py-0"
1159 this.handleShowConfirmTransferCommunity
1161 aria-label={I18NextService.i18n.t("transfer_community")}
1163 {I18NextService.i18n.t("transfer_community")}
1168 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1169 aria-label={I18NextService.i18n.t("are_you_sure")}
1171 {I18NextService.i18n.t("are_you_sure")}
1174 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1175 aria-label={I18NextService.i18n.t("yes")}
1176 onClick={linkEvent(this, this.handleTransferCommunity)}
1178 {this.state.transferLoading ? (
1181 I18NextService.i18n.t("yes")
1185 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1188 this.handleCancelShowConfirmTransferCommunity
1190 aria-label={I18NextService.i18n.t("no")}
1192 {I18NextService.i18n.t("no")}
1196 {/* Admins can ban from all, and appoint other admins */}
1197 {this.canAdmin_ && (
1199 {!this.creatorIsAdmin_ && (
1201 {!isBanned(post_view.creator) ? (
1203 className="btn btn-link btn-animate text-muted py-0"
1204 onClick={linkEvent(this, this.handleModBanShow)}
1205 aria-label={I18NextService.i18n.t("ban_from_site")}
1207 {I18NextService.i18n.t("ban_from_site")}
1211 className="btn btn-link btn-animate text-muted py-0"
1212 onClick={linkEvent(this, this.handleModBanSubmit)}
1213 aria-label={I18NextService.i18n.t("unban_from_site")}
1215 {this.state.banLoading ? (
1218 I18NextService.i18n.t("unban_from_site")
1223 className="btn btn-link btn-animate text-muted py-0"
1224 onClick={linkEvent(this, this.handlePurgePersonShow)}
1225 aria-label={I18NextService.i18n.t("purge_user")}
1227 {I18NextService.i18n.t("purge_user")}
1230 className="btn btn-link btn-animate text-muted py-0"
1231 onClick={linkEvent(this, this.handlePurgePostShow)}
1232 aria-label={I18NextService.i18n.t("purge_post")}
1234 {I18NextService.i18n.t("purge_post")}
1238 {!isBanned(post_view.creator) && post_view.creator.local && (
1240 className="btn btn-link btn-animate text-muted py-0"
1241 onClick={linkEvent(this, this.handleAddAdmin)}
1243 this.creatorIsAdmin_
1244 ? I18NextService.i18n.t("remove_as_admin")
1245 : I18NextService.i18n.t("appoint_as_admin")
1248 {this.state.addAdminLoading ? (
1250 ) : this.creatorIsAdmin_ ? (
1251 I18NextService.i18n.t("remove_as_admin")
1253 I18NextService.i18n.t("appoint_as_admin")
1264 removeAndBanDialogs() {
1265 const post = this.postView;
1266 const purgeTypeText =
1267 this.state.purgeType == PurgeType.Post
1268 ? I18NextService.i18n.t("purge_post")
1269 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1272 {this.state.showRemoveDialog && (
1274 className="form-inline"
1275 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1278 className="visually-hidden"
1279 htmlFor="post-listing-remove-reason"
1281 {I18NextService.i18n.t("reason")}
1285 id="post-listing-remove-reason"
1286 className="form-control me-2"
1287 placeholder={I18NextService.i18n.t("reason")}
1288 value={this.state.removeReason}
1289 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1293 className="btn btn-secondary"
1294 aria-label={I18NextService.i18n.t("remove_post")}
1296 {this.state.removeLoading ? (
1299 I18NextService.i18n.t("remove_post")
1304 {this.state.showBanDialog && (
1305 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1306 <div className="mb-3 row col-12">
1308 className="col-form-label"
1309 htmlFor="post-listing-ban-reason"
1311 {I18NextService.i18n.t("reason")}
1315 id="post-listing-ban-reason"
1316 className="form-control me-2"
1317 placeholder={I18NextService.i18n.t("reason")}
1318 value={this.state.banReason}
1319 onInput={linkEvent(this, this.handleModBanReasonChange)}
1321 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1322 {I18NextService.i18n.t("expires")}
1326 id={`mod-ban-expires`}
1327 className="form-control me-2"
1328 placeholder={I18NextService.i18n.t("number_of_days")}
1329 value={this.state.banExpireDays}
1330 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1332 <div className="input-group mb-3">
1333 <div className="form-check">
1335 className="form-check-input"
1336 id="mod-ban-remove-data"
1338 checked={this.state.removeData}
1339 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1342 className="form-check-label"
1343 htmlFor="mod-ban-remove-data"
1344 title={I18NextService.i18n.t("remove_content_more")}
1346 {I18NextService.i18n.t("remove_content")}
1351 {/* TODO hold off on expires until later */}
1352 {/* <div class="mb-3 row"> */}
1353 {/* <label class="col-form-label">Expires</label> */}
1354 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1356 <div className="mb-3 row">
1359 className="btn btn-secondary"
1360 aria-label={I18NextService.i18n.t("ban")}
1362 {this.state.banLoading ? (
1366 {I18NextService.i18n.t("ban")} {post.creator.name}
1373 {this.state.showReportDialog && (
1375 className="form-inline"
1376 onSubmit={linkEvent(this, this.handleReportSubmit)}
1378 <label className="visually-hidden" htmlFor="post-report-reason">
1379 {I18NextService.i18n.t("reason")}
1383 id="post-report-reason"
1384 className="form-control me-2"
1385 placeholder={I18NextService.i18n.t("reason")}
1387 value={this.state.reportReason}
1388 onInput={linkEvent(this, this.handleReportReasonChange)}
1392 className="btn btn-secondary"
1393 aria-label={I18NextService.i18n.t("create_report")}
1395 {this.state.reportLoading ? (
1398 I18NextService.i18n.t("create_report")
1403 {this.state.showPurgeDialog && (
1405 className="form-inline"
1406 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1409 <label className="visually-hidden" htmlFor="purge-reason">
1410 {I18NextService.i18n.t("reason")}
1415 className="form-control me-2"
1416 placeholder={I18NextService.i18n.t("reason")}
1417 value={this.state.purgeReason}
1418 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1420 {this.state.purgeLoading ? (
1425 className="btn btn-secondary"
1426 aria-label={purgeTypeText}
1428 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1438 const post = this.postView.post;
1439 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1440 <div className="row">
1441 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1442 {this.postTitleLine()}
1444 <div className="col-4">
1445 {/* Post body prev or thumbnail */}
1446 {!this.state.imageExpanded && this.thumbnail()}
1450 this.postTitleLine()
1455 const { body, id } = this.postView.post;
1457 return !this.showBody && body ? (
1458 <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
1459 <div className="md-div mb-1 preview-lines">{body}</div>
1469 {/* The mobile view*/}
1470 <div className="d-block d-sm-none">
1471 <article className="row post-container">
1472 <div className="col-12">
1473 {this.createdLine()}
1475 {/* If it has a thumbnail, do a right aligned thumbnail */}
1476 {this.mobileThumbnail()}
1478 {/* Show a preview of the post body */}
1479 {this.showBodyPreview()}
1481 {this.commentsLine(true)}
1482 {this.userActionsLine()}
1483 {this.duplicatesLine()}
1484 {this.removeAndBanDialogs()}
1489 {/* The larger view*/}
1490 <div className="d-none d-sm-block">
1491 <article className="row post-container">
1492 {!this.props.viewOnly && this.voteBar()}
1493 <div className="col-sm-2 pe-0 post-media">
1494 <div className="">{this.thumbnail()}</div>
1496 <div className="col-12 col-sm-9">
1497 <div className="row">
1498 <div className="col-12">
1499 {this.postTitleLine()}
1500 {this.createdLine()}
1501 {this.showBodyPreview()}
1502 {this.commentsLine()}
1503 {this.duplicatesLine()}
1504 {this.userActionsLine()}
1505 {this.removeAndBanDialogs()}
1515 private get myPost(): boolean {
1517 this.postView.creator.id ==
1518 UserService.Instance.myUserInfo?.local_user_view.person.id
1521 handleEditClick(i: PostListing) {
1522 i.setState({ showEdit: true });
1525 handleEditCancel() {
1526 this.setState({ showEdit: false });
1529 // The actual editing is done in the receive for post
1530 handleEditPost(form: EditPost) {
1531 this.setState({ showEdit: false });
1532 this.props.onPostEdit(form);
1535 handleShare(i: PostListing) {
1536 const { name, body, id } = i.props.post_view.post;
1539 text: body?.slice(0, 50),
1540 url: `${getHttpBase()}/post/${id}`,
1544 handleShowReportDialog(i: PostListing) {
1545 i.setState({ showReportDialog: !i.state.showReportDialog });
1548 handleReportReasonChange(i: PostListing, event: any) {
1549 i.setState({ reportReason: event.target.value });
1552 handleReportSubmit(i: PostListing, event: any) {
1553 event.preventDefault();
1554 i.setState({ reportLoading: true });
1555 i.props.onPostReport({
1556 post_id: i.postView.post.id,
1557 reason: i.state.reportReason ?? "",
1558 auth: myAuthRequired(),
1562 handleBlockPersonClick(i: PostListing) {
1563 i.setState({ blockLoading: true });
1564 i.props.onBlockPerson({
1565 person_id: i.postView.creator.id,
1567 auth: myAuthRequired(),
1571 handleDeleteClick(i: PostListing) {
1572 i.setState({ deleteLoading: true });
1573 i.props.onDeletePost({
1574 post_id: i.postView.post.id,
1575 deleted: !i.postView.post.deleted,
1576 auth: myAuthRequired(),
1580 handleSavePostClick(i: PostListing) {
1581 i.setState({ saveLoading: true });
1582 i.props.onSavePost({
1583 post_id: i.postView.post.id,
1584 save: !i.postView.saved,
1585 auth: myAuthRequired(),
1589 get crossPostParams(): PostFormParams {
1590 const queryParams: PostFormParams = {};
1591 const { name, url } = this.postView.post;
1593 queryParams.name = name;
1596 queryParams.url = url;
1599 const crossPostBody = this.crossPostBody();
1600 if (crossPostBody) {
1601 queryParams.body = crossPostBody;
1607 crossPostBody(): string | undefined {
1608 const post = this.postView.post;
1609 const body = post.body;
1612 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1614 }\n\n${body.replace(/^/gm, "> ")}`
1618 get showBody(): boolean {
1619 return this.props.showBody || this.state.showBody;
1622 handleModRemoveShow(i: PostListing) {
1624 showRemoveDialog: !i.state.showRemoveDialog,
1625 showBanDialog: false,
1629 handleModRemoveReasonChange(i: PostListing, event: any) {
1630 i.setState({ removeReason: event.target.value });
1633 handleModRemoveDataChange(i: PostListing, event: any) {
1634 i.setState({ removeData: event.target.checked });
1637 handleModRemoveSubmit(i: PostListing, event: any) {
1638 event.preventDefault();
1639 i.setState({ removeLoading: true });
1640 i.props.onRemovePost({
1641 post_id: i.postView.post.id,
1642 removed: !i.postView.post.removed,
1643 auth: myAuthRequired(),
1647 handleModLock(i: PostListing) {
1648 i.setState({ lockLoading: true });
1649 i.props.onLockPost({
1650 post_id: i.postView.post.id,
1651 locked: !i.postView.post.locked,
1652 auth: myAuthRequired(),
1656 handleModFeaturePostLocal(i: PostListing) {
1657 i.setState({ featureLocalLoading: true });
1658 i.props.onFeaturePost({
1659 post_id: i.postView.post.id,
1660 featured: !i.postView.post.featured_local,
1661 feature_type: "Local",
1662 auth: myAuthRequired(),
1666 handleModFeaturePostCommunity(i: PostListing) {
1667 i.setState({ featureCommunityLoading: true });
1668 i.props.onFeaturePost({
1669 post_id: i.postView.post.id,
1670 featured: !i.postView.post.featured_community,
1671 feature_type: "Community",
1672 auth: myAuthRequired(),
1676 handleModBanFromCommunityShow(i: PostListing) {
1678 showBanDialog: true,
1679 banType: BanType.Community,
1680 showRemoveDialog: false,
1684 handleModBanShow(i: PostListing) {
1686 showBanDialog: true,
1687 banType: BanType.Site,
1688 showRemoveDialog: false,
1692 handlePurgePersonShow(i: PostListing) {
1694 showPurgeDialog: true,
1695 purgeType: PurgeType.Person,
1696 showRemoveDialog: false,
1700 handlePurgePostShow(i: PostListing) {
1702 showPurgeDialog: true,
1703 purgeType: PurgeType.Post,
1704 showRemoveDialog: false,
1708 handlePurgeReasonChange(i: PostListing, event: any) {
1709 i.setState({ purgeReason: event.target.value });
1712 handlePurgeSubmit(i: PostListing, event: any) {
1713 event.preventDefault();
1714 i.setState({ purgeLoading: true });
1715 if (i.state.purgeType == PurgeType.Person) {
1716 i.props.onPurgePerson({
1717 person_id: i.postView.creator.id,
1718 reason: i.state.purgeReason,
1719 auth: myAuthRequired(),
1721 } else if (i.state.purgeType == PurgeType.Post) {
1722 i.props.onPurgePost({
1723 post_id: i.postView.post.id,
1724 reason: i.state.purgeReason,
1725 auth: myAuthRequired(),
1730 handleModBanReasonChange(i: PostListing, event: any) {
1731 i.setState({ banReason: event.target.value });
1734 handleModBanExpireDaysChange(i: PostListing, event: any) {
1735 i.setState({ banExpireDays: event.target.value });
1738 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1739 i.setState({ banType: BanType.Community });
1740 i.handleModBanBothSubmit(i, event);
1743 handleModBanSubmit(i: PostListing, event: any) {
1744 i.setState({ banType: BanType.Site });
1745 i.handleModBanBothSubmit(i, event);
1748 handleModBanBothSubmit(i: PostListing, event: any) {
1749 event.preventDefault();
1750 i.setState({ banLoading: true });
1752 const ban = !i.props.post_view.creator_banned_from_community;
1753 // If its an unban, restore all their data
1755 i.setState({ removeData: false });
1757 const person_id = i.props.post_view.creator.id;
1758 const remove_data = i.state.removeData;
1759 const reason = i.state.banReason;
1760 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1762 if (i.state.banType == BanType.Community) {
1763 const community_id = i.postView.community.id;
1764 i.props.onBanPersonFromCommunity({
1771 auth: myAuthRequired(),
1774 i.props.onBanPerson({
1780 auth: myAuthRequired(),
1785 handleAddModToCommunity(i: PostListing) {
1786 i.setState({ addModLoading: true });
1787 i.props.onAddModToCommunity({
1788 community_id: i.postView.community.id,
1789 person_id: i.postView.creator.id,
1790 added: !i.creatorIsMod_,
1791 auth: myAuthRequired(),
1795 handleAddAdmin(i: PostListing) {
1796 i.setState({ addAdminLoading: true });
1797 i.props.onAddAdmin({
1798 person_id: i.postView.creator.id,
1799 added: !i.creatorIsAdmin_,
1800 auth: myAuthRequired(),
1804 handleShowConfirmTransferCommunity(i: PostListing) {
1805 i.setState({ showConfirmTransferCommunity: true });
1808 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1809 i.setState({ showConfirmTransferCommunity: false });
1812 handleTransferCommunity(i: PostListing) {
1813 i.setState({ transferLoading: true });
1814 i.props.onTransferCommunity({
1815 community_id: i.postView.community.id,
1816 person_id: i.postView.creator.id,
1817 auth: myAuthRequired(),
1821 handleShowConfirmTransferSite(i: PostListing) {
1822 i.setState({ showConfirmTransferSite: true });
1825 handleCancelShowConfirmTransferSite(i: PostListing) {
1826 i.setState({ showConfirmTransferSite: false });
1829 handleImageExpandClick(i: PostListing, event: any) {
1830 event.preventDefault();
1831 i.setState({ imageExpanded: !i.state.imageExpanded });
1835 handleViewSource(i: PostListing) {
1836 i.setState({ viewSource: !i.state.viewSource });
1839 handleShowAdvanced(i: PostListing) {
1840 i.setState({ showAdvanced: !i.state.showAdvanced });
1844 handleShowMoreMobile(i: PostListing) {
1846 showMoreMobile: !i.state.showMoreMobile,
1847 showAdvanced: !i.state.showAdvanced,
1852 handleShowBody(i: PostListing) {
1853 i.setState({ showBody: !i.state.showBody });
1857 handleUpvote(i: PostListing) {
1858 i.setState({ upvoteLoading: true });
1859 i.props.onPostVote({
1860 post_id: i.postView.post.id,
1861 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1862 auth: myAuthRequired(),
1866 handleDownvote(i: PostListing) {
1867 i.setState({ downvoteLoading: true });
1868 i.props.onPostVote({
1869 post_id: i.postView.post.id,
1870 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1871 auth: myAuthRequired(),
1875 get pointsTippy(): string {
1876 const points = I18NextService.i18n.t("number_of_points", {
1877 count: Number(this.postView.counts.score),
1878 formattedCount: Number(this.postView.counts.score),
1881 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1882 count: Number(this.postView.counts.upvotes),
1883 formattedCount: Number(this.postView.counts.upvotes),
1886 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1887 count: Number(this.postView.counts.downvotes),
1888 formattedCount: Number(this.postView.counts.downvotes),
1891 return `${points} • ${upvotes} • ${downvotes}`;
1894 get canModOnSelf_(): boolean {
1896 this.postView.creator.id,
1897 this.props.moderators,
1904 get canMod_(): boolean {
1906 this.postView.creator.id,
1907 this.props.moderators,
1912 get canAdmin_(): boolean {
1913 return canAdmin(this.postView.creator.id, this.props.admins);
1916 get creatorIsMod_(): boolean {
1917 return isMod(this.postView.creator.id, this.props.moderators);
1920 get creatorIsAdmin_(): boolean {
1921 return isAdmin(this.postView.creator.id, this.props.admins);