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)} />
242 return this.imageSrc ? (
244 <div className="offset-sm-3 my-2 d-none d-sm-block">
245 <a href={this.imageSrc} className="d-inline-block">
246 <PictrsImage src={this.imageSrc} />
249 <div className="my-2 d-block d-sm-none">
251 className="d-inline-block"
252 onClick={linkEvent(this, this.handleImageExpandClick)}
254 <PictrsImage src={this.imageSrc} />
263 imgThumb(src: string) {
264 const post_view = this.postView;
270 nsfw={post_view.post.nsfw || post_view.community.nsfw}
275 get imageSrc(): string | undefined {
276 const post = this.postView.post;
277 const url = post.url;
278 const thumbnail = post.thumbnail_url;
280 if (url && isImage(url)) {
281 if (url.includes("pictrs")) {
283 } else if (thumbnail) {
288 } else if (thumbnail) {
296 const post = this.postView.post;
297 const url = post.url;
298 const thumbnail = post.thumbnail_url;
300 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
304 className="text-body d-inline-block position-relative mb-2"
305 data-tippy-content={I18NextService.i18n.t("expand_here")}
306 onClick={linkEvent(this, this.handleImageExpandClick)}
307 aria-label={I18NextService.i18n.t("expand_here")}
309 {this.imgThumb(this.imageSrc)}
310 <Icon icon="image" classes="mini-overlay" />
313 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
316 className="text-body d-inline-block position-relative mb-2"
321 {this.imgThumb(this.imageSrc)}
322 <Icon icon="external-link" classes="mini-overlay" />
326 if (!this.props.hideImage && isVideo(url)) {
328 <div className="embed-responsive embed-responsive-16by9">
334 className="embed-responsive-item"
336 <source src={url} type="video/mp4" />
342 <a className="text-body" href={url} title={url} rel={relTags}>
343 <div className="thumbnail rounded bg-light d-flex justify-content-center">
344 <Icon icon="external-link" classes="d-flex align-items-center" />
352 className="text-body"
353 to={`/post/${post.id}`}
354 title={I18NextService.i18n.t("comments")}
356 <div className="thumbnail rounded bg-light d-flex justify-content-center">
357 <Icon icon="message-square" classes="d-flex align-items-center" />
365 const post_view = this.postView;
367 <ul className="list-inline mb-1 text-muted small mt-2">
368 <li className="list-inline-item">
369 <PersonListing person={post_view.creator} />
371 {this.creatorIsMod_ && (
372 <span className="mx-1 badge text-bg-light">
373 {I18NextService.i18n.t("mod")}
376 {this.creatorIsAdmin_ && (
377 <span className="mx-1 badge text-bg-light">
378 {I18NextService.i18n.t("admin")}
381 {post_view.creator.bot_account && (
382 <span className="mx-1 badge text-bg-light">
383 {I18NextService.i18n.t("bot_account").toLowerCase()}
386 {this.props.showCommunity && (
389 {I18NextService.i18n.t("to")}{" "}
390 <CommunityLink community={post_view.community} />
394 {post_view.post.language_id !== 0 && (
395 <span className="mx-1 badge text-bg-light">
397 this.props.allLanguages.find(
398 lang => lang.id === post_view.post.language_id
403 <li className="list-inline-item">•</li>
404 <li className="list-inline-item">
407 published={post_view.post.published}
408 updated={post_view.post.updated}
418 <div className={`vote-bar col-1 pe-0 small text-center`}>
420 className={`btn-animate btn btn-link p-0 ${
421 this.postView.my_vote == 1 ? "text-info" : "text-muted"
423 onClick={linkEvent(this, this.handleUpvote)}
424 data-tippy-content={I18NextService.i18n.t("upvote")}
425 aria-label={I18NextService.i18n.t("upvote")}
426 aria-pressed={this.postView.my_vote === 1}
428 {this.state.upvoteLoading ? (
431 <Icon icon="arrow-up1" classes="upvote" />
436 className={`unselectable pointer text-muted px-1 post-score`}
437 data-tippy-content={this.pointsTippy}
439 {numToSI(this.postView.counts.score)}
442 <div className="p-1"></div>
444 {this.props.enableDownvotes && (
446 className={`btn-animate btn btn-link p-0 ${
447 this.postView.my_vote == -1 ? "text-danger" : "text-muted"
449 onClick={linkEvent(this, this.handleDownvote)}
450 data-tippy-content={I18NextService.i18n.t("downvote")}
451 aria-label={I18NextService.i18n.t("downvote")}
452 aria-pressed={this.postView.my_vote === -1}
454 {this.state.downvoteLoading ? (
457 <Icon icon="arrow-down1" classes="downvote" />
466 const post = this.postView.post;
469 className={`d-inline ${
470 !post.featured_community && !post.featured_local
474 to={`/post/${post.id}`}
475 title={I18NextService.i18n.t("comments")}
479 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
486 const post = this.postView.post;
487 const url = post.url;
491 <div className="post-title overflow-hidden">
492 <h5 className="d-inline">
493 {url && this.props.showBody ? (
496 !post.featured_community && !post.featured_local
503 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
509 {(url && isImage(url)) ||
510 (post.thumbnail_url && (
512 className="btn btn-sm text-monospace text-muted d-inline-block"
513 data-tippy-content={I18NextService.i18n.t("expand_here")}
514 onClick={linkEvent(this, this.handleImageExpandClick)}
518 !this.state.imageExpanded ? "plus-square" : "minus-square"
520 classes="icon-inline"
525 <small className="ms-2 badge text-bg-secondary">
526 {I18NextService.i18n.t("removed")}
531 className="unselectable pointer ms-2 text-muted font-italic"
532 data-tippy-content={I18NextService.i18n.t("deleted")}
534 <Icon icon="trash" classes="icon-inline text-danger" />
539 className="unselectable pointer ms-2 text-muted font-italic"
540 data-tippy-content={I18NextService.i18n.t("locked")}
542 <Icon icon="lock" classes="icon-inline text-danger" />
545 {post.featured_community && (
547 className="unselectable pointer ms-2 text-muted font-italic"
548 data-tippy-content={I18NextService.i18n.t(
549 "featured_in_community"
551 aria-label={I18NextService.i18n.t("featured_in_community")}
553 <Icon icon="pin" classes="icon-inline text-primary" />
556 {post.featured_local && (
558 className="unselectable pointer ms-2 text-muted font-italic"
559 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
560 aria-label={I18NextService.i18n.t("featured_in_local")}
562 <Icon icon="pin" classes="icon-inline text-secondary" />
566 <small className="ms-2 badge text-bg-danger">
567 {I18NextService.i18n.t("nsfw")}
571 {url && this.urlLine()}
577 const post = this.postView.post;
578 const url = post.url;
581 <p className="d-flex text-muted align-items-center gap-1 small m-0">
582 {url && !(hostname(url) === getExternalHost()) && (
584 className="text-muted font-italic"
597 const dupes = this.props.crossPosts;
598 return dupes && dupes.length > 0 ? (
599 <ul className="list-inline mb-1 small text-muted">
601 <li className="list-inline-item me-2">
602 {I18NextService.i18n.t("cross_posted_to")}
605 <li key={pv.post.id} className="list-inline-item me-2">
606 <Link to={`/post/${pv.post.id}`}>
609 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
620 commentsLine(mobile = false) {
621 const post = this.postView.post;
624 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
625 {this.commentsButton}
628 className="btn btn-sm btn-animate text-muted py-0"
629 onClick={linkEvent(this, this.handleShare)}
632 <Icon icon="share" inline />
637 className="btn btn-sm btn-animate text-muted py-0"
638 title={I18NextService.i18n.t("link")}
641 <Icon icon="fedilink" inline />
644 {mobile && !this.props.viewOnly && this.mobileVotes}
645 {UserService.Instance.myUserInfo &&
646 !this.props.viewOnly &&
652 showPreviewButton() {
653 const post_view = this.postView;
654 const body = post_view.post.body;
658 className="btn btn-sm btn-animate text-muted py-0"
659 data-tippy-content={body && mdNoImages.render(body)}
660 data-tippy-allowHtml={true}
661 onClick={linkEvent(this, this.handleShowBody)}
665 classes={classNames("icon-inline me-1", {
666 "text-success": this.state.showBody,
674 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
675 // Possible enhancement: Make each button a component.
676 const post_view = this.postView;
677 const post = post_view.post;
682 {this.crossPostButton}
685 * If there is a URL, or if the post has a body and we were told not to
686 * show the body, show the MetadataCard/body toggle.
688 {(post.url || (post.body && !this.props.showBody)) &&
689 this.showPreviewButton()}
691 {this.showBody && post_view.post.body && this.viewSourceButton}
693 <div className="dropdown">
695 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
696 onClick={linkEvent(this, this.handleShowAdvanced)}
697 data-tippy-content={I18NextService.i18n.t("more")}
698 data-bs-toggle="dropdown"
699 aria-expanded="false"
700 aria-controls="advancedButtonsDropdown"
701 aria-label={I18NextService.i18n.t("more")}
703 <Icon icon="more-vertical" inline />
706 <ul className="dropdown-menu" id="advancedButtonsDropdown">
709 <li>{this.reportButton}</li>
710 <li>{this.blockButton}</li>
714 <li>{this.editButton}</li>
715 <li>{this.deleteButton}</li>
719 {/* Any mod can do these, not limited to hierarchy*/}
720 {(amMod(this.props.moderators) || amAdmin()) && (
723 <hr className="dropdown-divider" />
725 <li>{this.lockButton}</li>
726 {this.featureButtons}
730 {(this.canMod_ || this.canAdmin_) && (
731 <li>{this.modRemoveButton}</li>
739 get commentsButton() {
740 const post_view = this.postView;
741 const title = I18NextService.i18n.t("number_of_comments", {
742 count: Number(post_view.counts.comments),
743 formattedCount: Number(post_view.counts.comments),
748 className="btn btn-link btn-sm text-muted ps-0"
750 to={`/post/${post_view.post.id}?scrollToComments=true`}
751 data-tippy-content={title}
753 <span className="me-1">
754 <Icon icon="message-square" classes="me-1" inline />
755 {post_view.counts.comments}
757 {this.unreadCount && (
758 <span className="text-muted fst-italic">
759 ({this.unreadCount} {I18NextService.i18n.t("new")})
766 get unreadCount(): number | undefined {
767 const pv = this.postView;
768 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
770 : pv.unread_comments;
775 const tippy = showScores()
776 ? { "data-tippy-content": this.pointsTippy }
782 className={`btn-animate btn py-0 px-1 ${
783 this.postView.my_vote === 1 ? "text-info" : "text-muted"
786 onClick={linkEvent(this, this.handleUpvote)}
787 aria-label={I18NextService.i18n.t("upvote")}
788 aria-pressed={this.postView.my_vote === 1}
790 {this.state.upvoteLoading ? (
794 <Icon icon="arrow-up1" classes="icon-inline small" />
796 <span className="ms-2">
797 {numToSI(this.postView.counts.upvotes)}
803 {this.props.enableDownvotes && (
805 className={`ms-2 btn-animate btn py-0 px-1 ${
806 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
808 onClick={linkEvent(this, this.handleDownvote)}
810 aria-label={I18NextService.i18n.t("downvote")}
811 aria-pressed={this.postView.my_vote === -1}
813 {this.state.downvoteLoading ? (
817 <Icon icon="arrow-down1" classes="icon-inline small" />
820 className={classNames("ms-2", {
821 invisible: this.postView.counts.downvotes === 0,
824 {numToSI(this.postView.counts.downvotes)}
837 const saved = this.postView.saved;
839 ? I18NextService.i18n.t("unsave")
840 : I18NextService.i18n.t("save");
843 className="btn btn-sm btn-animate text-muted py-0"
844 onClick={linkEvent(this, this.handleSavePostClick)}
845 data-tippy-content={label}
848 {this.state.saveLoading ? (
853 classes={classNames({ "text-warning": saved })}
861 get crossPostButton() {
864 className="btn btn-sm btn-animate text-muted py-0"
866 /* Empty string properties are required to satisfy type*/
867 pathname: "/create_post",
868 state: { ...this.crossPostParams },
873 title={I18NextService.i18n.t("cross_post")}
874 data-tippy-content={I18NextService.i18n.t("cross_post")}
875 aria-label={I18NextService.i18n.t("cross_post")}
877 <Icon icon="copy" inline />
885 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
886 onClick={linkEvent(this, this.handleShowReportDialog)}
887 aria-label={I18NextService.i18n.t("show_report_dialog")}
889 <Icon classes="me-1" icon="flag" inline />
890 {I18NextService.i18n.t("create_report")}
898 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
899 onClick={linkEvent(this, this.handleBlockPersonClick)}
900 aria-label={I18NextService.i18n.t("block_user")}
902 {this.state.blockLoading ? (
905 <Icon classes="me-1" icon="slash" inline />
907 {I18NextService.i18n.t("block_user")}
915 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
916 onClick={linkEvent(this, this.handleEditClick)}
917 aria-label={I18NextService.i18n.t("edit")}
919 <Icon classes="me-1" icon="edit" inline />
920 {I18NextService.i18n.t("edit")}
926 const deleted = this.postView.post.deleted;
927 const label = !deleted
928 ? I18NextService.i18n.t("delete")
929 : I18NextService.i18n.t("restore");
932 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
933 onClick={linkEvent(this, this.handleDeleteClick)}
936 {this.state.deleteLoading ? (
942 classes={classNames("me-1", { "text-danger": deleted })}
952 get viewSourceButton() {
955 className="btn btn-sm btn-animate text-muted py-0"
956 onClick={linkEvent(this, this.handleViewSource)}
957 data-tippy-content={I18NextService.i18n.t("view_source")}
958 aria-label={I18NextService.i18n.t("view_source")}
962 classes={classNames({ "text-success": this.state.viewSource })}
970 const locked = this.postView.post.locked;
972 ? I18NextService.i18n.t("unlock")
973 : I18NextService.i18n.t("lock");
976 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
977 onClick={linkEvent(this, this.handleModLock)}
980 {this.state.lockLoading ? (
986 classes={classNames("me-1", { "text-danger": locked })}
989 {capitalizeFirstLetter(label)}
996 get featureButtons() {
997 const featuredCommunity = this.postView.post.featured_community;
998 const labelCommunity = featuredCommunity
999 ? I18NextService.i18n.t("unfeature_from_community")
1000 : I18NextService.i18n.t("feature_in_community");
1002 const featuredLocal = this.postView.post.featured_local;
1003 const labelLocal = featuredLocal
1004 ? I18NextService.i18n.t("unfeature_from_local")
1005 : I18NextService.i18n.t("feature_in_local");
1010 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1011 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
1012 data-tippy-content={labelCommunity}
1013 aria-label={labelCommunity}
1015 {this.state.featureCommunityLoading ? (
1021 classes={classNames("me-1", {
1022 "text-success": featuredCommunity,
1026 {I18NextService.i18n.t("community")}
1034 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1035 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1036 data-tippy-content={labelLocal}
1037 aria-label={labelLocal}
1039 {this.state.featureLocalLoading ? (
1045 classes={classNames("me-1", {
1046 "text-success": featuredLocal,
1050 {I18NextService.i18n.t("local")}
1060 get modRemoveButton() {
1061 const removed = this.postView.post.removed;
1064 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1067 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1070 {/* TODO: Find an icon for this. */}
1071 {this.state.removeLoading ? (
1074 I18NextService.i18n.t("remove")
1076 I18NextService.i18n.t("restore")
1083 * Mod/Admin actions to be taken against the author.
1087 const post_view = this.postView;
1089 this.state.showAdvanced && (
1093 {!this.creatorIsMod_ &&
1094 (!post_view.creator_banned_from_community ? (
1096 className="btn btn-link btn-animate text-muted py-0"
1099 this.handleModBanFromCommunityShow
1101 aria-label={I18NextService.i18n.t("ban_from_community")}
1103 {I18NextService.i18n.t("ban_from_community")}
1107 className="btn btn-link btn-animate text-muted py-0"
1110 this.handleModBanFromCommunitySubmit
1112 aria-label={I18NextService.i18n.t("unban")}
1114 {this.state.banLoading ? (
1117 I18NextService.i18n.t("unban")
1121 {!post_view.creator_banned_from_community && (
1123 className="btn btn-link btn-animate text-muted py-0"
1124 onClick={linkEvent(this, this.handleAddModToCommunity)}
1127 ? I18NextService.i18n.t("remove_as_mod")
1128 : I18NextService.i18n.t("appoint_as_mod")
1131 {this.state.addModLoading ? (
1133 ) : this.creatorIsMod_ ? (
1134 I18NextService.i18n.t("remove_as_mod")
1136 I18NextService.i18n.t("appoint_as_mod")
1142 {/* Community creators and admins can transfer community to another mod */}
1143 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1145 this.creatorIsMod_ &&
1146 (!this.state.showConfirmTransferCommunity ? (
1148 className="btn btn-link btn-animate text-muted py-0"
1151 this.handleShowConfirmTransferCommunity
1153 aria-label={I18NextService.i18n.t("transfer_community")}
1155 {I18NextService.i18n.t("transfer_community")}
1160 className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1161 aria-label={I18NextService.i18n.t("are_you_sure")}
1163 {I18NextService.i18n.t("are_you_sure")}
1166 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1167 aria-label={I18NextService.i18n.t("yes")}
1168 onClick={linkEvent(this, this.handleTransferCommunity)}
1170 {this.state.transferLoading ? (
1173 I18NextService.i18n.t("yes")
1177 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1180 this.handleCancelShowConfirmTransferCommunity
1182 aria-label={I18NextService.i18n.t("no")}
1184 {I18NextService.i18n.t("no")}
1188 {/* Admins can ban from all, and appoint other admins */}
1189 {this.canAdmin_ && (
1191 {!this.creatorIsAdmin_ && (
1193 {!isBanned(post_view.creator) ? (
1195 className="btn btn-link btn-animate text-muted py-0"
1196 onClick={linkEvent(this, this.handleModBanShow)}
1197 aria-label={I18NextService.i18n.t("ban_from_site")}
1199 {I18NextService.i18n.t("ban_from_site")}
1203 className="btn btn-link btn-animate text-muted py-0"
1204 onClick={linkEvent(this, this.handleModBanSubmit)}
1205 aria-label={I18NextService.i18n.t("unban_from_site")}
1207 {this.state.banLoading ? (
1210 I18NextService.i18n.t("unban_from_site")
1215 className="btn btn-link btn-animate text-muted py-0"
1216 onClick={linkEvent(this, this.handlePurgePersonShow)}
1217 aria-label={I18NextService.i18n.t("purge_user")}
1219 {I18NextService.i18n.t("purge_user")}
1222 className="btn btn-link btn-animate text-muted py-0"
1223 onClick={linkEvent(this, this.handlePurgePostShow)}
1224 aria-label={I18NextService.i18n.t("purge_post")}
1226 {I18NextService.i18n.t("purge_post")}
1230 {!isBanned(post_view.creator) && post_view.creator.local && (
1232 className="btn btn-link btn-animate text-muted py-0"
1233 onClick={linkEvent(this, this.handleAddAdmin)}
1235 this.creatorIsAdmin_
1236 ? I18NextService.i18n.t("remove_as_admin")
1237 : I18NextService.i18n.t("appoint_as_admin")
1240 {this.state.addAdminLoading ? (
1242 ) : this.creatorIsAdmin_ ? (
1243 I18NextService.i18n.t("remove_as_admin")
1245 I18NextService.i18n.t("appoint_as_admin")
1256 removeAndBanDialogs() {
1257 const post = this.postView;
1258 const purgeTypeText =
1259 this.state.purgeType == PurgeType.Post
1260 ? I18NextService.i18n.t("purge_post")
1261 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1264 {this.state.showRemoveDialog && (
1266 className="form-inline"
1267 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1270 className="visually-hidden"
1271 htmlFor="post-listing-remove-reason"
1273 {I18NextService.i18n.t("reason")}
1277 id="post-listing-remove-reason"
1278 className="form-control me-2"
1279 placeholder={I18NextService.i18n.t("reason")}
1280 value={this.state.removeReason}
1281 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1285 className="btn btn-secondary"
1286 aria-label={I18NextService.i18n.t("remove_post")}
1288 {this.state.removeLoading ? (
1291 I18NextService.i18n.t("remove_post")
1296 {this.state.showBanDialog && (
1297 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1298 <div className="mb-3 row col-12">
1300 className="col-form-label"
1301 htmlFor="post-listing-ban-reason"
1303 {I18NextService.i18n.t("reason")}
1307 id="post-listing-ban-reason"
1308 className="form-control me-2"
1309 placeholder={I18NextService.i18n.t("reason")}
1310 value={this.state.banReason}
1311 onInput={linkEvent(this, this.handleModBanReasonChange)}
1313 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1314 {I18NextService.i18n.t("expires")}
1318 id={`mod-ban-expires`}
1319 className="form-control me-2"
1320 placeholder={I18NextService.i18n.t("number_of_days")}
1321 value={this.state.banExpireDays}
1322 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1324 <div className="input-group mb-3">
1325 <div className="form-check">
1327 className="form-check-input"
1328 id="mod-ban-remove-data"
1330 checked={this.state.removeData}
1331 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1334 className="form-check-label"
1335 htmlFor="mod-ban-remove-data"
1336 title={I18NextService.i18n.t("remove_content_more")}
1338 {I18NextService.i18n.t("remove_content")}
1343 {/* TODO hold off on expires until later */}
1344 {/* <div class="mb-3 row"> */}
1345 {/* <label class="col-form-label">Expires</label> */}
1346 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1348 <div className="mb-3 row">
1351 className="btn btn-secondary"
1352 aria-label={I18NextService.i18n.t("ban")}
1354 {this.state.banLoading ? (
1358 {I18NextService.i18n.t("ban")} {post.creator.name}
1365 {this.state.showReportDialog && (
1367 className="form-inline"
1368 onSubmit={linkEvent(this, this.handleReportSubmit)}
1370 <label className="visually-hidden" htmlFor="post-report-reason">
1371 {I18NextService.i18n.t("reason")}
1375 id="post-report-reason"
1376 className="form-control me-2"
1377 placeholder={I18NextService.i18n.t("reason")}
1379 value={this.state.reportReason}
1380 onInput={linkEvent(this, this.handleReportReasonChange)}
1384 className="btn btn-secondary"
1385 aria-label={I18NextService.i18n.t("create_report")}
1387 {this.state.reportLoading ? (
1390 I18NextService.i18n.t("create_report")
1395 {this.state.showPurgeDialog && (
1397 className="form-inline"
1398 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1401 <label className="visually-hidden" htmlFor="purge-reason">
1402 {I18NextService.i18n.t("reason")}
1407 className="form-control me-2"
1408 placeholder={I18NextService.i18n.t("reason")}
1409 value={this.state.purgeReason}
1410 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1412 {this.state.purgeLoading ? (
1417 className="btn btn-secondary"
1418 aria-label={purgeTypeText}
1420 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1430 const post = this.postView.post;
1431 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1432 <div className="row">
1433 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1434 {this.postTitleLine()}
1436 <div className="col-4">
1437 {/* Post body prev or thumbnail */}
1438 {!this.state.imageExpanded && this.thumbnail()}
1442 this.postTitleLine()
1446 showMobilePreview() {
1447 const { body, id } = this.postView.post;
1449 return !this.showBody && body ? (
1450 <Link className="text-body" to={`/post/${id}`}>
1451 <div className="md-div mb-1 preview-lines">{body}</div>
1461 {/* The mobile view*/}
1462 <div className="d-block d-sm-none">
1463 <article className="row post-container">
1464 <div className="col-12">
1465 {this.createdLine()}
1467 {/* If it has a thumbnail, do a right aligned thumbnail */}
1468 {this.mobileThumbnail()}
1470 {/* Show a preview of the post body */}
1471 {this.showMobilePreview()}
1473 {this.commentsLine(true)}
1474 {this.userActionsLine()}
1475 {this.duplicatesLine()}
1476 {this.removeAndBanDialogs()}
1481 {/* The larger view*/}
1482 <div className="d-none d-sm-block">
1483 <article className="row post-container">
1484 {!this.props.viewOnly && this.voteBar()}
1485 <div className="col-sm-2 pe-0 post-media">
1486 <div className="">{this.thumbnail()}</div>
1488 <div className="col-12 col-sm-9">
1489 <div className="row">
1490 <div className="col-12">
1491 {this.postTitleLine()}
1492 {this.createdLine()}
1493 {this.commentsLine()}
1494 {this.duplicatesLine()}
1495 {this.userActionsLine()}
1496 {this.removeAndBanDialogs()}
1506 private get myPost(): boolean {
1508 this.postView.creator.id ==
1509 UserService.Instance.myUserInfo?.local_user_view.person.id
1512 handleEditClick(i: PostListing) {
1513 i.setState({ showEdit: true });
1516 handleEditCancel() {
1517 this.setState({ showEdit: false });
1520 // The actual editing is done in the receive for post
1521 handleEditPost(form: EditPost) {
1522 this.setState({ showEdit: false });
1523 this.props.onPostEdit(form);
1526 handleShare(i: PostListing) {
1527 const { name, body, id } = i.props.post_view.post;
1530 text: body?.slice(0, 50),
1531 url: `${getHttpBase()}/post/${id}`,
1535 handleShowReportDialog(i: PostListing) {
1536 i.setState({ showReportDialog: !i.state.showReportDialog });
1539 handleReportReasonChange(i: PostListing, event: any) {
1540 i.setState({ reportReason: event.target.value });
1543 handleReportSubmit(i: PostListing, event: any) {
1544 event.preventDefault();
1545 i.setState({ reportLoading: true });
1546 i.props.onPostReport({
1547 post_id: i.postView.post.id,
1548 reason: i.state.reportReason ?? "",
1549 auth: myAuthRequired(),
1553 handleBlockPersonClick(i: PostListing) {
1554 i.setState({ blockLoading: true });
1555 i.props.onBlockPerson({
1556 person_id: i.postView.creator.id,
1558 auth: myAuthRequired(),
1562 handleDeleteClick(i: PostListing) {
1563 i.setState({ deleteLoading: true });
1564 i.props.onDeletePost({
1565 post_id: i.postView.post.id,
1566 deleted: !i.postView.post.deleted,
1567 auth: myAuthRequired(),
1571 handleSavePostClick(i: PostListing) {
1572 i.setState({ saveLoading: true });
1573 i.props.onSavePost({
1574 post_id: i.postView.post.id,
1575 save: !i.postView.saved,
1576 auth: myAuthRequired(),
1580 get crossPostParams(): PostFormParams {
1581 const queryParams: PostFormParams = {};
1582 const { name, url } = this.postView.post;
1584 queryParams.name = name;
1587 queryParams.url = url;
1590 const crossPostBody = this.crossPostBody();
1591 if (crossPostBody) {
1592 queryParams.body = crossPostBody;
1598 crossPostBody(): string | undefined {
1599 const post = this.postView.post;
1600 const body = post.body;
1603 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1605 }\n\n${body.replace(/^/gm, "> ")}`
1609 get showBody(): boolean {
1610 return this.props.showBody || this.state.showBody;
1613 handleModRemoveShow(i: PostListing) {
1615 showRemoveDialog: !i.state.showRemoveDialog,
1616 showBanDialog: false,
1620 handleModRemoveReasonChange(i: PostListing, event: any) {
1621 i.setState({ removeReason: event.target.value });
1624 handleModRemoveDataChange(i: PostListing, event: any) {
1625 i.setState({ removeData: event.target.checked });
1628 handleModRemoveSubmit(i: PostListing, event: any) {
1629 event.preventDefault();
1630 i.setState({ removeLoading: true });
1631 i.props.onRemovePost({
1632 post_id: i.postView.post.id,
1633 removed: !i.postView.post.removed,
1634 auth: myAuthRequired(),
1638 handleModLock(i: PostListing) {
1639 i.setState({ lockLoading: true });
1640 i.props.onLockPost({
1641 post_id: i.postView.post.id,
1642 locked: !i.postView.post.locked,
1643 auth: myAuthRequired(),
1647 handleModFeaturePostLocal(i: PostListing) {
1648 i.setState({ featureLocalLoading: true });
1649 i.props.onFeaturePost({
1650 post_id: i.postView.post.id,
1651 featured: !i.postView.post.featured_local,
1652 feature_type: "Local",
1653 auth: myAuthRequired(),
1657 handleModFeaturePostCommunity(i: PostListing) {
1658 i.setState({ featureCommunityLoading: true });
1659 i.props.onFeaturePost({
1660 post_id: i.postView.post.id,
1661 featured: !i.postView.post.featured_community,
1662 feature_type: "Community",
1663 auth: myAuthRequired(),
1667 handleModBanFromCommunityShow(i: PostListing) {
1669 showBanDialog: true,
1670 banType: BanType.Community,
1671 showRemoveDialog: false,
1675 handleModBanShow(i: PostListing) {
1677 showBanDialog: true,
1678 banType: BanType.Site,
1679 showRemoveDialog: false,
1683 handlePurgePersonShow(i: PostListing) {
1685 showPurgeDialog: true,
1686 purgeType: PurgeType.Person,
1687 showRemoveDialog: false,
1691 handlePurgePostShow(i: PostListing) {
1693 showPurgeDialog: true,
1694 purgeType: PurgeType.Post,
1695 showRemoveDialog: false,
1699 handlePurgeReasonChange(i: PostListing, event: any) {
1700 i.setState({ purgeReason: event.target.value });
1703 handlePurgeSubmit(i: PostListing, event: any) {
1704 event.preventDefault();
1705 i.setState({ purgeLoading: true });
1706 if (i.state.purgeType == PurgeType.Person) {
1707 i.props.onPurgePerson({
1708 person_id: i.postView.creator.id,
1709 reason: i.state.purgeReason,
1710 auth: myAuthRequired(),
1712 } else if (i.state.purgeType == PurgeType.Post) {
1713 i.props.onPurgePost({
1714 post_id: i.postView.post.id,
1715 reason: i.state.purgeReason,
1716 auth: myAuthRequired(),
1721 handleModBanReasonChange(i: PostListing, event: any) {
1722 i.setState({ banReason: event.target.value });
1725 handleModBanExpireDaysChange(i: PostListing, event: any) {
1726 i.setState({ banExpireDays: event.target.value });
1729 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1730 i.setState({ banType: BanType.Community });
1731 i.handleModBanBothSubmit(i, event);
1734 handleModBanSubmit(i: PostListing, event: any) {
1735 i.setState({ banType: BanType.Site });
1736 i.handleModBanBothSubmit(i, event);
1739 handleModBanBothSubmit(i: PostListing, event: any) {
1740 event.preventDefault();
1741 i.setState({ banLoading: true });
1743 const ban = !i.props.post_view.creator_banned_from_community;
1744 // If its an unban, restore all their data
1746 i.setState({ removeData: false });
1748 const person_id = i.props.post_view.creator.id;
1749 const remove_data = i.state.removeData;
1750 const reason = i.state.banReason;
1751 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1753 if (i.state.banType == BanType.Community) {
1754 const community_id = i.postView.community.id;
1755 i.props.onBanPersonFromCommunity({
1762 auth: myAuthRequired(),
1765 i.props.onBanPerson({
1771 auth: myAuthRequired(),
1776 handleAddModToCommunity(i: PostListing) {
1777 i.setState({ addModLoading: true });
1778 i.props.onAddModToCommunity({
1779 community_id: i.postView.community.id,
1780 person_id: i.postView.creator.id,
1781 added: !i.creatorIsMod_,
1782 auth: myAuthRequired(),
1786 handleAddAdmin(i: PostListing) {
1787 i.setState({ addAdminLoading: true });
1788 i.props.onAddAdmin({
1789 person_id: i.postView.creator.id,
1790 added: !i.creatorIsAdmin_,
1791 auth: myAuthRequired(),
1795 handleShowConfirmTransferCommunity(i: PostListing) {
1796 i.setState({ showConfirmTransferCommunity: true });
1799 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1800 i.setState({ showConfirmTransferCommunity: false });
1803 handleTransferCommunity(i: PostListing) {
1804 i.setState({ transferLoading: true });
1805 i.props.onTransferCommunity({
1806 community_id: i.postView.community.id,
1807 person_id: i.postView.creator.id,
1808 auth: myAuthRequired(),
1812 handleShowConfirmTransferSite(i: PostListing) {
1813 i.setState({ showConfirmTransferSite: true });
1816 handleCancelShowConfirmTransferSite(i: PostListing) {
1817 i.setState({ showConfirmTransferSite: false });
1820 handleImageExpandClick(i: PostListing, event: any) {
1821 event.preventDefault();
1822 i.setState({ imageExpanded: !i.state.imageExpanded });
1826 handleViewSource(i: PostListing) {
1827 i.setState({ viewSource: !i.state.viewSource });
1830 handleShowAdvanced(i: PostListing) {
1831 i.setState({ showAdvanced: !i.state.showAdvanced });
1835 handleShowMoreMobile(i: PostListing) {
1837 showMoreMobile: !i.state.showMoreMobile,
1838 showAdvanced: !i.state.showAdvanced,
1843 handleShowBody(i: PostListing) {
1844 i.setState({ showBody: !i.state.showBody });
1848 handleUpvote(i: PostListing) {
1849 i.setState({ upvoteLoading: true });
1850 i.props.onPostVote({
1851 post_id: i.postView.post.id,
1852 score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1853 auth: myAuthRequired(),
1857 handleDownvote(i: PostListing) {
1858 i.setState({ downvoteLoading: true });
1859 i.props.onPostVote({
1860 post_id: i.postView.post.id,
1861 score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1862 auth: myAuthRequired(),
1866 get pointsTippy(): string {
1867 const points = I18NextService.i18n.t("number_of_points", {
1868 count: Number(this.postView.counts.score),
1869 formattedCount: Number(this.postView.counts.score),
1872 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1873 count: Number(this.postView.counts.upvotes),
1874 formattedCount: Number(this.postView.counts.upvotes),
1877 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1878 count: Number(this.postView.counts.downvotes),
1879 formattedCount: Number(this.postView.counts.downvotes),
1882 return `${points} • ${upvotes} • ${downvotes}`;
1885 get canModOnSelf_(): boolean {
1887 this.postView.creator.id,
1888 this.props.moderators,
1895 get canMod_(): boolean {
1897 this.postView.creator.id,
1898 this.props.moderators,
1903 get canAdmin_(): boolean {
1904 return canAdmin(this.postView.creator.id, this.props.admins);
1907 get creatorIsMod_(): boolean {
1908 return isMod(this.postView.creator.id, this.props.moderators);
1911 get creatorIsAdmin_(): boolean {
1912 return isAdmin(this.postView.creator.id, this.props.admins);