1 import { myAuthRequired } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
29 CommunityModeratorView,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
51 } from "../../interfaces";
52 import { mdToHtml, mdToHtmlInline } from "../../markdown";
53 import { I18NextService, UserService } from "../../services";
54 import { setupTippy } from "../../tippy";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { UserBadges } from "../common/user-badges";
59 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
60 import { CommunityLink } from "../community/community-link";
61 import { PersonListing } from "../person/person-listing";
62 import { MetadataCard } from "./metadata-card";
63 import { PostForm } from "./post-form";
65 interface PostListingState {
67 showRemoveDialog: boolean;
68 showPurgeDialog: boolean;
70 purgeType?: PurgeType;
71 purgeLoading: boolean;
72 removeReason?: string;
73 showBanDialog: boolean;
75 banExpireDays?: number;
78 showConfirmTransferSite: boolean;
79 showConfirmTransferCommunity: boolean;
80 imageExpanded: boolean;
82 showAdvanced: boolean;
83 showMoreMobile: boolean;
85 showReportDialog: boolean;
86 reportReason?: string;
87 reportLoading: boolean;
88 blockLoading: boolean;
90 deleteLoading: boolean;
91 removeLoading: boolean;
93 featureCommunityLoading: boolean;
94 featureLocalLoading: boolean;
96 addModLoading: boolean;
97 addAdminLoading: boolean;
98 transferLoading: boolean;
101 interface PostListingProps {
103 crossPosts?: PostView[];
104 moderators?: CommunityModeratorView[];
105 admins?: PersonView[];
106 allLanguages: Language[];
107 siteLanguages: number[];
108 showCommunity?: boolean;
110 * Controls whether to show both the body *and* the metadata preview card
114 enableDownvotes?: boolean;
115 enableNsfw?: boolean;
117 onPostEdit(form: EditPost): void;
118 onPostVote(form: CreatePostLike): void;
119 onPostReport(form: CreatePostReport): void;
120 onBlockPerson(form: BlockPerson): void;
121 onLockPost(form: LockPost): void;
122 onDeletePost(form: DeletePost): void;
123 onRemovePost(form: RemovePost): void;
124 onSavePost(form: SavePost): void;
125 onFeaturePost(form: FeaturePost): void;
126 onPurgePerson(form: PurgePerson): void;
127 onPurgePost(form: PurgePost): void;
128 onBanPersonFromCommunity(form: BanFromCommunity): void;
129 onBanPerson(form: BanPerson): void;
130 onAddModToCommunity(form: AddModToCommunity): void;
131 onAddAdmin(form: AddAdmin): void;
132 onTransferCommunity(form: TransferCommunity): void;
135 export class PostListing extends Component<PostListingProps, PostListingState> {
136 state: PostListingState = {
138 showRemoveDialog: false,
139 showPurgeDialog: false,
140 purgeType: PurgeType.Person,
141 showBanDialog: false,
142 banType: BanType.Community,
144 showConfirmTransferSite: false,
145 showConfirmTransferCommunity: false,
146 imageExpanded: false,
149 showMoreMobile: false,
151 showReportDialog: false,
153 reportLoading: false,
156 deleteLoading: false,
157 removeLoading: false,
159 featureCommunityLoading: false,
160 featureLocalLoading: false,
162 addModLoading: false,
163 addAdminLoading: false,
164 transferLoading: false,
167 constructor(props: any, context: any) {
168 super(props, context);
170 this.handleEditPost = this.handleEditPost.bind(this);
171 this.handleEditCancel = this.handleEditCancel.bind(this);
174 componentWillReceiveProps(nextProps: PostListingProps) {
175 if (this.props !== nextProps) {
178 reportLoading: false,
181 deleteLoading: false,
182 removeLoading: false,
184 featureCommunityLoading: false,
185 featureLocalLoading: false,
187 addModLoading: false,
188 addAdminLoading: false,
189 transferLoading: false,
194 get postView(): PostView {
195 return this.props.post_view;
199 const post = this.postView.post;
202 <div className="post-listing mt-2">
203 {!this.state.showEdit ? (
206 {this.state.imageExpanded && !this.props.hideImage && this.img}
207 {this.showBody && post.url && post.embed_title && (
208 <MetadataCard post={post} />
210 {this.showBody && this.body()}
214 post_view={this.postView}
215 crossPosts={this.props.crossPosts}
216 onEdit={this.handleEditPost}
217 onCancel={this.handleEditCancel}
218 enableNsfw={this.props.enableNsfw}
219 enableDownvotes={this.props.enableDownvotes}
220 allLanguages={this.props.allLanguages}
221 siteLanguages={this.props.siteLanguages}
229 const body = this.postView.post.body;
231 <article id="postContent" className="col-12 card my-2 p-2">
232 {this.state.viewSource ? (
235 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
247 <div className="offset-sm-3 my-2 d-none d-sm-block">
248 <a href={this.imageSrc} className="d-inline-block">
249 <PictrsImage src={this.imageSrc} />
252 <div className="my-2 d-block d-sm-none">
255 className="p-0 border-0 bg-transparent d-inline-block"
256 onClick={linkEvent(this, this.handleImageExpandClick)}
258 <PictrsImage src={this.imageSrc} />
265 const { post } = this.postView;
266 const { url } = post;
268 // if direct video link
269 if (url && isVideo(url)) {
271 <div className="embed-responsive mt-3">
272 <video muted controls className="embed-responsive-item col-12">
273 <source src={url} type="video/mp4" />
279 // if embedded video link
280 if (url && post.embed_video_url) {
282 <div className="ratio ratio-16x9">
285 className="post-metadata-iframe"
286 src={post.embed_video_url}
287 title={post.embed_title}
296 imgThumb(src: string) {
297 const post_view = this.postView;
303 nsfw={post_view.post.nsfw || post_view.community.nsfw}
308 get imageSrc(): string | undefined {
309 const post = this.postView.post;
310 const url = post.url;
311 const thumbnail = post.thumbnail_url;
315 } else if (url && isImage(url)) {
323 const post = this.postView.post;
324 const url = post.url;
325 const thumbnail = post.thumbnail_url;
327 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
331 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0 bg-transparent"
332 data-tippy-content={I18NextService.i18n.t("expand_here")}
333 onClick={linkEvent(this, this.handleImageExpandClick)}
334 aria-label={I18NextService.i18n.t("expand_here")}
336 {this.imgThumb(this.imageSrc)}
339 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
343 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
346 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0"
351 {this.imgThumb(this.imageSrc)}
354 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
359 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
362 className="text-body"
366 data-tippy-content={I18NextService.i18n.t("expand_here")}
367 onClick={linkEvent(this, this.handleImageExpandClick)}
368 aria-label={I18NextService.i18n.t("expand_here")}
370 <div className="thumbnail rounded bg-light d-flex justify-content-center">
371 <Icon icon="play" classes="d-flex align-items-center" />
377 <a className="text-body" href={url} title={url} rel={relTags}>
378 <div className="thumbnail rounded bg-light d-flex justify-content-center">
379 <Icon icon="external-link" classes="d-flex align-items-center" />
387 className="text-body"
388 to={`/post/${post.id}`}
389 title={I18NextService.i18n.t("comments")}
391 <div className="thumbnail rounded bg-light d-flex justify-content-center">
392 <Icon icon="message-square" classes="d-flex align-items-center" />
400 const post_view = this.postView;
403 <div className="small mb-1 mb-md-0">
404 <PersonListing person={post_view.creator} />
407 isMod={this.creatorIsMod_}
408 isAdmin={this.creatorIsAdmin_}
409 isBot={post_view.creator.bot_account}
411 {this.props.showCommunity && (
414 {I18NextService.i18n.t("to")}{" "}
415 <CommunityLink community={post_view.community} />
418 {post_view.post.language_id !== 0 && (
419 <span className="mx-1 badge text-bg-light">
421 this.props.allLanguages.find(
422 lang => lang.id === post_view.post.language_id
429 published={post_view.post.published}
430 updated={post_view.post.updated}
437 const post = this.postView.post;
440 className={`d-inline ${
441 !post.featured_community && !post.featured_local
445 to={`/post/${post.id}`}
446 title={I18NextService.i18n.t("comments")}
450 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
457 const post = this.postView.post;
458 const url = post.url;
462 <div className="post-title">
463 <h1 className="h5 d-inline text-break">
464 {url && this.props.showBody ? (
467 !post.featured_community && !post.featured_local
474 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
482 * If there is (a) a URL and an embed title, or (b) a post body, and
483 * we were not told to show the body by the parent component, show the
484 * MetadataCard/body toggle.
486 {!this.props.showBody &&
487 ((post.url && post.embed_title) || post.body) &&
488 this.showPreviewButton()}
491 <small className="ms-2 badge text-bg-secondary">
492 {I18NextService.i18n.t("removed")}
498 className="unselectable pointer ms-2 text-muted fst-italic"
499 data-tippy-content={I18NextService.i18n.t("deleted")}
501 <Icon icon="trash" classes="icon-inline text-danger" />
507 className="unselectable pointer ms-2 text-muted fst-italic"
508 data-tippy-content={I18NextService.i18n.t("locked")}
510 <Icon icon="lock" classes="icon-inline text-danger" />
514 {post.featured_community && (
516 className="unselectable pointer ms-2 text-muted fst-italic"
517 data-tippy-content={I18NextService.i18n.t(
518 "featured_in_community"
520 aria-label={I18NextService.i18n.t("featured_in_community")}
522 <Icon icon="pin" classes="icon-inline text-primary" />
526 {post.featured_local && (
528 className="unselectable pointer ms-2 text-muted fst-italic"
529 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
530 aria-label={I18NextService.i18n.t("featured_in_local")}
532 <Icon icon="pin" classes="icon-inline text-secondary" />
537 <small className="ms-2 badge text-bg-danger">
538 {I18NextService.i18n.t("nsfw")}
542 {url && this.urlLine()}
548 const post = this.postView.post;
549 const url = post.url;
552 <p className="small m-0">
553 {url && !(hostname(url) === getExternalHost()) && (
555 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
568 const dupes = this.props.crossPosts;
569 return dupes && dupes.length > 0 ? (
570 <ul className="list-inline mb-1 small text-muted">
572 <li className="list-inline-item me-2">
573 {I18NextService.i18n.t("cross_posted_to")}
576 <li key={pv.post.id} className="list-inline-item me-2">
577 <Link to={`/post/${pv.post.id}`}>
580 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
591 commentsLine(mobile = false) {
592 const post = this.postView.post;
595 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
596 {this.commentsButton}
599 className="btn btn-sm btn-link btn-animate text-muted py-0"
600 onClick={linkEvent(this, this.handleShare)}
603 <Icon icon="share" inline />
608 className="btn btn-sm btn-link btn-animate text-muted py-0"
609 title={I18NextService.i18n.t("link")}
612 <Icon icon="fedilink" inline />
615 {mobile && !this.props.viewOnly && (
617 voteContentType={VoteContentType.Post}
618 id={this.postView.post.id}
619 onVote={this.props.onPostVote}
620 enableDownvotes={this.props.enableDownvotes}
621 counts={this.postView.counts}
622 my_vote={this.postView.my_vote}
625 {UserService.Instance.myUserInfo &&
626 !this.props.viewOnly &&
633 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
634 // Possible enhancement: Make each button a component.
635 const post_view = this.postView;
636 const post = post_view.post;
641 {this.crossPostButton}
643 {this.props.showBody && post_view.post.body && this.viewSourceButton}
645 <div className="dropdown">
647 className="btn btn-sm btn-link btn-animate text-muted py-0 dropdown-toggle"
648 onClick={linkEvent(this, this.handleShowAdvanced)}
649 data-tippy-content={I18NextService.i18n.t("more")}
650 data-bs-toggle="dropdown"
651 aria-expanded="false"
652 aria-controls={`advancedButtonsDropdown${post.id}`}
653 aria-label={I18NextService.i18n.t("more")}
655 <Icon icon="more-vertical" inline />
659 className="dropdown-menu"
660 id={`advancedButtonsDropdown${post.id}`}
664 <li>{this.reportButton}</li>
665 <li>{this.blockButton}</li>
669 <li>{this.editButton}</li>
670 <li>{this.deleteButton}</li>
674 {/* Any mod can do these, not limited to hierarchy*/}
675 {(amMod(this.props.moderators) || amAdmin()) && (
678 <hr className="dropdown-divider" />
680 <li>{this.lockButton}</li>
681 {this.featureButtons}
685 {(this.canMod_ || this.canAdmin_) && (
686 <li>{this.modRemoveButton}</li>
692 <hr className="dropdown-divider" />
694 {!this.creatorIsMod_ &&
695 (!post_view.creator_banned_from_community ? (
696 <li>{this.modBanFromCommunityButton}</li>
698 <li>{this.modUnbanFromCommunityButton}</li>
700 {!post_view.creator_banned_from_community && (
701 <li>{this.addModToCommunityButton}</li>
706 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
708 this.creatorIsMod_ && <li>{this.transferCommunityButton}</li>}
710 {/* Admins can ban from all, and appoint other admins */}
714 <hr className="dropdown-divider" />
716 {!this.creatorIsAdmin_ && (
718 {!isBanned(post_view.creator) ? (
719 <li>{this.modBanButton}</li>
721 <li>{this.modUnbanButton}</li>
723 <li>{this.purgePersonButton}</li>
724 <li>{this.purgePostButton}</li>
727 {!isBanned(post_view.creator) && post_view.creator.local && (
728 <li>{this.toggleAdminButton}</li>
738 get commentsButton() {
739 const post_view = this.postView;
740 const title = I18NextService.i18n.t("number_of_comments", {
741 count: Number(post_view.counts.comments),
742 formattedCount: Number(post_view.counts.comments),
747 className="btn btn-link btn-sm text-muted ps-0"
749 to={`/post/${post_view.post.id}?scrollToComments=true`}
750 data-tippy-content={title}
752 <Icon icon="message-square" classes="me-1" inline />
753 {post_view.counts.comments}
754 {this.unreadCount && (
757 <span className="fst-italic">
758 ({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;
774 const saved = this.postView.saved;
776 ? I18NextService.i18n.t("unsave")
777 : I18NextService.i18n.t("save");
780 className="btn btn-sm btn-link btn-animate text-muted py-0"
781 onClick={linkEvent(this, this.handleSavePostClick)}
782 data-tippy-content={label}
785 {this.state.saveLoading ? (
790 classes={classNames({ "text-warning": saved })}
798 get crossPostButton() {
801 className="btn btn-sm btn-link btn-animate text-muted py-0"
803 /* Empty string properties are required to satisfy type*/
804 pathname: "/create_post",
805 state: { ...this.crossPostParams },
810 title={I18NextService.i18n.t("cross_post")}
811 data-tippy-content={I18NextService.i18n.t("cross_post")}
812 aria-label={I18NextService.i18n.t("cross_post")}
814 <Icon icon="copy" inline />
822 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
823 onClick={linkEvent(this, this.handleShowReportDialog)}
824 aria-label={I18NextService.i18n.t("show_report_dialog")}
826 <Icon classes="me-1" icon="flag" inline />
827 {I18NextService.i18n.t("create_report")}
835 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
836 onClick={linkEvent(this, this.handleBlockPersonClick)}
837 aria-label={I18NextService.i18n.t("block_user")}
839 {this.state.blockLoading ? (
842 <Icon classes="me-1" icon="slash" inline />
844 {I18NextService.i18n.t("block_user")}
852 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
853 onClick={linkEvent(this, this.handleEditClick)}
854 aria-label={I18NextService.i18n.t("edit")}
856 <Icon classes="me-1" icon="edit" inline />
857 {I18NextService.i18n.t("edit")}
863 const deleted = this.postView.post.deleted;
864 const label = !deleted
865 ? I18NextService.i18n.t("delete")
866 : I18NextService.i18n.t("restore");
869 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
870 onClick={linkEvent(this, this.handleDeleteClick)}
872 {this.state.deleteLoading ? (
878 classes={classNames("me-1", { "text-danger": deleted })}
888 get viewSourceButton() {
891 className="btn btn-sm btn-link btn-animate text-muted py-0"
892 onClick={linkEvent(this, this.handleViewSource)}
893 data-tippy-content={I18NextService.i18n.t("view_source")}
894 aria-label={I18NextService.i18n.t("view_source")}
898 classes={classNames({ "text-success": this.state.viewSource })}
906 const locked = this.postView.post.locked;
908 ? I18NextService.i18n.t("unlock")
909 : I18NextService.i18n.t("lock");
912 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
913 onClick={linkEvent(this, this.handleModLock)}
916 {this.state.lockLoading ? (
922 classes={classNames("me-1", { "text-danger": locked })}
925 {capitalizeFirstLetter(label)}
932 get featureButtons() {
933 const featuredCommunity = this.postView.post.featured_community;
934 const labelCommunity = featuredCommunity
935 ? I18NextService.i18n.t("unfeature_from_community")
936 : I18NextService.i18n.t("feature_in_community");
938 const featuredLocal = this.postView.post.featured_local;
939 const labelLocal = featuredLocal
940 ? I18NextService.i18n.t("unfeature_from_local")
941 : I18NextService.i18n.t("feature_in_local");
946 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
947 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
948 data-tippy-content={labelCommunity}
949 aria-label={labelCommunity}
951 {this.state.featureCommunityLoading ? (
957 classes={classNames("me-1", {
958 "text-success": featuredCommunity,
962 {I18NextService.i18n.t("community")}
970 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
971 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
972 data-tippy-content={labelLocal}
973 aria-label={labelLocal}
975 {this.state.featureLocalLoading ? (
981 classes={classNames("me-1", {
982 "text-success": featuredLocal,
986 {I18NextService.i18n.t("local")}
996 get modBanFromCommunityButton() {
999 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1000 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
1002 {I18NextService.i18n.t("ban_from_community")}
1007 get modUnbanFromCommunityButton() {
1010 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1011 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
1013 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1018 get addModToCommunityButton() {
1021 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1022 onClick={linkEvent(this, this.handleAddModToCommunity)}
1024 {this.state.addModLoading ? (
1026 ) : this.creatorIsMod_ ? (
1027 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_mod"))
1029 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_mod"))
1035 get modBanButton() {
1038 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1039 onClick={linkEvent(this, this.handleModBanShow)}
1041 {capitalizeFirstLetter(I18NextService.i18n.t("ban_from_site"))}
1046 get modUnbanButton() {
1049 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1050 onClick={linkEvent(this, this.handleModBanSubmit)}
1052 {this.state.banLoading ? (
1055 capitalizeFirstLetter(I18NextService.i18n.t("unban_from_site"))
1061 get purgePersonButton() {
1064 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1065 onClick={linkEvent(this, this.handlePurgePersonShow)}
1067 {capitalizeFirstLetter(I18NextService.i18n.t("purge_user"))}
1072 get purgePostButton() {
1075 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1076 onClick={linkEvent(this, this.handlePurgePostShow)}
1078 {capitalizeFirstLetter(I18NextService.i18n.t("purge_post"))}
1083 get toggleAdminButton() {
1086 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1087 onClick={linkEvent(this, this.handleAddAdmin)}
1089 {this.state.addAdminLoading ? (
1091 ) : this.creatorIsAdmin_ ? (
1092 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_admin"))
1094 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_admin"))
1100 get transferCommunityButton() {
1103 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1104 onClick={linkEvent(this, this.handleShowConfirmTransferCommunity)}
1106 {capitalizeFirstLetter(I18NextService.i18n.t("transfer_community"))}
1111 get modRemoveButton() {
1112 const removed = this.postView.post.removed;
1115 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1118 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1121 {/* TODO: Find an icon for this. */}
1122 {this.state.removeLoading ? (
1125 capitalizeFirstLetter(I18NextService.i18n.t("remove_post"))
1128 {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "}
1129 {I18NextService.i18n.t("post")}
1136 removeAndBanDialogs() {
1137 const post = this.postView;
1138 const purgeTypeText =
1139 this.state.purgeType == PurgeType.Post
1140 ? I18NextService.i18n.t("purge_post")
1141 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1144 {this.state.showRemoveDialog && (
1146 className="form-inline"
1147 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1150 className="visually-hidden"
1151 htmlFor="post-listing-remove-reason"
1153 {I18NextService.i18n.t("reason")}
1157 id="post-listing-remove-reason"
1158 className="form-control me-2"
1159 placeholder={I18NextService.i18n.t("reason")}
1160 value={this.state.removeReason}
1161 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1163 <button type="submit" className="btn btn-secondary">
1164 {this.state.removeLoading ? (
1167 I18NextService.i18n.t("remove_post")
1172 {this.state.showConfirmTransferCommunity && (
1174 <button className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0">
1175 {I18NextService.i18n.t("are_you_sure")}
1178 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
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 {this.state.showBanDialog && (
1200 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1201 <div className="mb-3 row col-12">
1203 className="col-form-label"
1204 htmlFor="post-listing-ban-reason"
1206 {I18NextService.i18n.t("reason")}
1210 id="post-listing-ban-reason"
1211 className="form-control me-2"
1212 placeholder={I18NextService.i18n.t("reason")}
1213 value={this.state.banReason}
1214 onInput={linkEvent(this, this.handleModBanReasonChange)}
1216 <label className="col-form-label" htmlFor="mod-ban-expires">
1217 {I18NextService.i18n.t("expires")}
1221 id="mod-ban-expires"
1222 className="form-control me-2"
1223 placeholder={I18NextService.i18n.t("number_of_days")}
1224 value={this.state.banExpireDays}
1225 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1227 <div className="input-group mb-3">
1228 <div className="form-check">
1230 className="form-check-input"
1231 id="mod-ban-remove-data"
1233 checked={this.state.removeData}
1234 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1237 className="form-check-label"
1238 htmlFor="mod-ban-remove-data"
1239 title={I18NextService.i18n.t("remove_content_more")}
1241 {I18NextService.i18n.t("remove_content")}
1246 {/* TODO hold off on expires until later */}
1247 {/* <div class="mb-3 row"> */}
1248 {/* <label class="col-form-label">Expires</label> */}
1249 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1251 <div className="mb-3 row">
1252 <button type="submit" className="btn btn-secondary">
1253 {this.state.banLoading ? (
1257 {I18NextService.i18n.t("ban")} {post.creator.name}
1264 {this.state.showReportDialog && (
1266 className="form-inline"
1267 onSubmit={linkEvent(this, this.handleReportSubmit)}
1269 <label className="visually-hidden" htmlFor="post-report-reason">
1270 {I18NextService.i18n.t("reason")}
1274 id="post-report-reason"
1275 className="form-control me-2"
1276 placeholder={I18NextService.i18n.t("reason")}
1278 value={this.state.reportReason}
1279 onInput={linkEvent(this, this.handleReportReasonChange)}
1281 <button type="submit" className="btn btn-secondary">
1282 {this.state.reportLoading ? (
1285 I18NextService.i18n.t("create_report")
1290 {this.state.showPurgeDialog && (
1292 className="form-inline"
1293 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1296 <label className="visually-hidden" htmlFor="purge-reason">
1297 {I18NextService.i18n.t("reason")}
1302 className="form-control me-2"
1303 placeholder={I18NextService.i18n.t("reason")}
1304 value={this.state.purgeReason}
1305 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1307 {this.state.purgeLoading ? (
1310 <button type="submit" className="btn btn-secondary">
1311 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1321 const post = this.postView.post;
1322 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1323 <div className="row">
1324 <div className={`${this.state.imageExpanded ? "col-12" : "col-9"}`}>
1325 {this.postTitleLine()}
1327 <div className="col-3 mobile-thumbnail-container">
1328 {/* Post thumbnail */}
1329 {!this.state.imageExpanded && this.thumbnail()}
1333 this.postTitleLine()
1337 showPreviewButton() {
1341 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1342 onClick={linkEvent(this, this.handleShowBody)}
1345 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1346 classes="icon-inline"
1355 {/* The mobile view*/}
1356 <div className="d-block d-sm-none">
1357 <article className="row post-container">
1358 <div className="col-12">
1359 {this.createdLine()}
1361 {/* If it has a thumbnail, do a right aligned thumbnail */}
1362 {this.mobileThumbnail()}
1364 {this.commentsLine(true)}
1365 {this.duplicatesLine()}
1366 {this.removeAndBanDialogs()}
1371 {/* The larger view*/}
1372 <div className="d-none d-sm-block">
1373 <article className="row post-container">
1374 {!this.props.viewOnly && (
1375 <div className="col flex-grow-0">
1377 voteContentType={VoteContentType.Post}
1378 id={this.postView.post.id}
1379 onVote={this.props.onPostVote}
1380 enableDownvotes={this.props.enableDownvotes}
1381 counts={this.postView.counts}
1382 my_vote={this.postView.my_vote}
1386 <div className="col flex-grow-1">
1387 <div className="row">
1388 <div className="col flex-grow-0 px-0">
1389 <div className="">{this.thumbnail()}</div>
1391 <div className="col flex-grow-1">
1392 {this.postTitleLine()}
1393 {this.createdLine()}
1394 {this.commentsLine()}
1395 {this.duplicatesLine()}
1396 {this.removeAndBanDialogs()}
1406 private get myPost(): boolean {
1408 this.postView.creator.id ==
1409 UserService.Instance.myUserInfo?.local_user_view.person.id
1413 handleEditClick(i: PostListing) {
1414 i.setState({ showEdit: true });
1417 handleEditCancel() {
1418 this.setState({ showEdit: false });
1421 // The actual editing is done in the receive for post
1422 handleEditPost(form: EditPost) {
1423 this.setState({ showEdit: false });
1424 this.props.onPostEdit(form);
1427 handleShare(i: PostListing) {
1428 const { name, body, id } = i.props.post_view.post;
1431 text: body?.slice(0, 50),
1432 url: `${getHttpBase()}/post/${id}`,
1436 handleShowReportDialog(i: PostListing) {
1437 i.setState({ showReportDialog: !i.state.showReportDialog });
1440 handleReportReasonChange(i: PostListing, event: any) {
1441 i.setState({ reportReason: event.target.value });
1444 handleReportSubmit(i: PostListing, event: any) {
1445 event.preventDefault();
1446 i.setState({ reportLoading: true });
1447 i.props.onPostReport({
1448 post_id: i.postView.post.id,
1449 reason: i.state.reportReason ?? "",
1450 auth: myAuthRequired(),
1454 handleBlockPersonClick(i: PostListing) {
1455 i.setState({ blockLoading: true });
1456 i.props.onBlockPerson({
1457 person_id: i.postView.creator.id,
1459 auth: myAuthRequired(),
1463 handleDeleteClick(i: PostListing) {
1464 i.setState({ deleteLoading: true });
1465 i.props.onDeletePost({
1466 post_id: i.postView.post.id,
1467 deleted: !i.postView.post.deleted,
1468 auth: myAuthRequired(),
1472 handleSavePostClick(i: PostListing) {
1473 i.setState({ saveLoading: true });
1474 i.props.onSavePost({
1475 post_id: i.postView.post.id,
1476 save: !i.postView.saved,
1477 auth: myAuthRequired(),
1481 get crossPostParams(): PostFormParams {
1482 const queryParams: PostFormParams = {};
1483 const { name, url } = this.postView.post;
1485 queryParams.name = name;
1488 queryParams.url = url;
1491 const crossPostBody = this.crossPostBody();
1492 if (crossPostBody) {
1493 queryParams.body = crossPostBody;
1499 crossPostBody(): string | undefined {
1500 const post = this.postView.post;
1501 const body = post.body;
1504 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1506 }\n\n${body.replace(/^/gm, "> ")}`
1510 get showBody(): boolean {
1511 return this.props.showBody || this.state.showBody;
1514 handleModRemoveShow(i: PostListing) {
1516 showRemoveDialog: !i.state.showRemoveDialog,
1517 showBanDialog: false,
1521 handleModRemoveReasonChange(i: PostListing, event: any) {
1522 i.setState({ removeReason: event.target.value });
1525 handleModRemoveDataChange(i: PostListing, event: any) {
1526 i.setState({ removeData: event.target.checked });
1529 handleModRemoveSubmit(i: PostListing, event: any) {
1530 event.preventDefault();
1531 i.setState({ removeLoading: true });
1532 i.props.onRemovePost({
1533 post_id: i.postView.post.id,
1534 removed: !i.postView.post.removed,
1535 auth: myAuthRequired(),
1536 reason: i.state.removeReason,
1540 handleModLock(i: PostListing) {
1541 i.setState({ lockLoading: true });
1542 i.props.onLockPost({
1543 post_id: i.postView.post.id,
1544 locked: !i.postView.post.locked,
1545 auth: myAuthRequired(),
1549 handleModFeaturePostLocal(i: PostListing) {
1550 i.setState({ featureLocalLoading: true });
1551 i.props.onFeaturePost({
1552 post_id: i.postView.post.id,
1553 featured: !i.postView.post.featured_local,
1554 feature_type: "Local",
1555 auth: myAuthRequired(),
1559 handleModFeaturePostCommunity(i: PostListing) {
1560 i.setState({ featureCommunityLoading: true });
1561 i.props.onFeaturePost({
1562 post_id: i.postView.post.id,
1563 featured: !i.postView.post.featured_community,
1564 feature_type: "Community",
1565 auth: myAuthRequired(),
1569 handleModBanFromCommunityShow(i: PostListing) {
1571 showBanDialog: true,
1572 banType: BanType.Community,
1573 showRemoveDialog: false,
1577 handleModBanShow(i: PostListing) {
1579 showBanDialog: true,
1580 banType: BanType.Site,
1581 showRemoveDialog: false,
1585 handlePurgePersonShow(i: PostListing) {
1587 showPurgeDialog: true,
1588 purgeType: PurgeType.Person,
1589 showRemoveDialog: false,
1593 handlePurgePostShow(i: PostListing) {
1595 showPurgeDialog: true,
1596 purgeType: PurgeType.Post,
1597 showRemoveDialog: false,
1601 handlePurgeReasonChange(i: PostListing, event: any) {
1602 i.setState({ purgeReason: event.target.value });
1605 handlePurgeSubmit(i: PostListing, event: any) {
1606 event.preventDefault();
1607 i.setState({ purgeLoading: true });
1608 if (i.state.purgeType === PurgeType.Person) {
1609 i.props.onPurgePerson({
1610 person_id: i.postView.creator.id,
1611 reason: i.state.purgeReason,
1612 auth: myAuthRequired(),
1614 } else if (i.state.purgeType === PurgeType.Post) {
1615 i.props.onPurgePost({
1616 post_id: i.postView.post.id,
1617 reason: i.state.purgeReason,
1618 auth: myAuthRequired(),
1623 handleModBanReasonChange(i: PostListing, event: any) {
1624 i.setState({ banReason: event.target.value });
1627 handleModBanExpireDaysChange(i: PostListing, event: any) {
1628 i.setState({ banExpireDays: event.target.value });
1631 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1632 i.setState({ banType: BanType.Community });
1633 i.handleModBanBothSubmit(i, event);
1636 handleModBanSubmit(i: PostListing, event: any) {
1637 i.setState({ banType: BanType.Site });
1638 i.handleModBanBothSubmit(i, event);
1641 handleModBanBothSubmit(i: PostListing, event: any) {
1642 event.preventDefault();
1643 i.setState({ banLoading: true });
1645 const ban = !i.props.post_view.creator_banned_from_community;
1646 // If its an unban, restore all their data
1648 i.setState({ removeData: false });
1650 const person_id = i.props.post_view.creator.id;
1651 const remove_data = i.state.removeData;
1652 const reason = i.state.banReason;
1653 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1655 if (i.state.banType == BanType.Community) {
1656 const community_id = i.postView.community.id;
1657 i.props.onBanPersonFromCommunity({
1664 auth: myAuthRequired(),
1667 i.props.onBanPerson({
1673 auth: myAuthRequired(),
1678 handleAddModToCommunity(i: PostListing) {
1679 i.setState({ addModLoading: true });
1680 i.props.onAddModToCommunity({
1681 community_id: i.postView.community.id,
1682 person_id: i.postView.creator.id,
1683 added: !i.creatorIsMod_,
1684 auth: myAuthRequired(),
1688 handleAddAdmin(i: PostListing) {
1689 i.setState({ addAdminLoading: true });
1690 i.props.onAddAdmin({
1691 person_id: i.postView.creator.id,
1692 added: !i.creatorIsAdmin_,
1693 auth: myAuthRequired(),
1697 handleShowConfirmTransferCommunity(i: PostListing) {
1698 i.setState({ showConfirmTransferCommunity: true });
1701 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1702 i.setState({ showConfirmTransferCommunity: false });
1705 handleTransferCommunity(i: PostListing) {
1706 i.setState({ transferLoading: true });
1707 i.props.onTransferCommunity({
1708 community_id: i.postView.community.id,
1709 person_id: i.postView.creator.id,
1710 auth: myAuthRequired(),
1714 handleShowConfirmTransferSite(i: PostListing) {
1715 i.setState({ showConfirmTransferSite: true });
1718 handleCancelShowConfirmTransferSite(i: PostListing) {
1719 i.setState({ showConfirmTransferSite: false });
1722 handleImageExpandClick(i: PostListing, event: any) {
1723 event.preventDefault();
1724 i.setState({ imageExpanded: !i.state.imageExpanded });
1728 handleViewSource(i: PostListing) {
1729 i.setState({ viewSource: !i.state.viewSource });
1732 handleShowAdvanced(i: PostListing) {
1733 i.setState({ showAdvanced: !i.state.showAdvanced });
1737 handleShowMoreMobile(i: PostListing) {
1739 showMoreMobile: !i.state.showMoreMobile,
1740 showAdvanced: !i.state.showAdvanced,
1745 handleShowBody(i: PostListing) {
1746 i.setState({ showBody: !i.state.showBody });
1750 get pointsTippy(): string {
1751 const points = I18NextService.i18n.t("number_of_points", {
1752 count: Number(this.postView.counts.score),
1753 formattedCount: Number(this.postView.counts.score),
1756 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1757 count: Number(this.postView.counts.upvotes),
1758 formattedCount: Number(this.postView.counts.upvotes),
1761 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1762 count: Number(this.postView.counts.downvotes),
1763 formattedCount: Number(this.postView.counts.downvotes),
1766 return `${points} • ${upvotes} • ${downvotes}`;
1769 get canModOnSelf_(): boolean {
1771 this.postView.creator.id,
1772 this.props.moderators,
1779 get canMod_(): boolean {
1781 this.postView.creator.id,
1782 this.props.moderators,
1787 get canAdmin_(): boolean {
1788 return canAdmin(this.postView.creator.id, this.props.admins);
1791 get creatorIsMod_(): boolean {
1792 return isMod(this.postView.creator.id, this.props.moderators);
1795 get creatorIsAdmin_(): boolean {
1796 return isAdmin(this.postView.creator.id, this.props.admins);