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;
313 if (url && isImage(url)) {
314 if (url.includes("pictrs")) {
316 } else if (thumbnail) {
321 } else if (thumbnail) {
329 const post = this.postView.post;
330 const url = post.url;
331 const thumbnail = post.thumbnail_url;
333 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
337 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0 bg-transparent"
338 data-tippy-content={I18NextService.i18n.t("expand_here")}
339 onClick={linkEvent(this, this.handleImageExpandClick)}
340 aria-label={I18NextService.i18n.t("expand_here")}
342 {this.imgThumb(this.imageSrc)}
345 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
349 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
352 className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0"
357 {this.imgThumb(this.imageSrc)}
360 classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
365 if ((!this.props.hideImage && isVideo(url)) || post.embed_video_url) {
368 className="text-body"
372 data-tippy-content={I18NextService.i18n.t("expand_here")}
373 onClick={linkEvent(this, this.handleImageExpandClick)}
374 aria-label={I18NextService.i18n.t("expand_here")}
376 <div className="thumbnail rounded bg-light d-flex justify-content-center">
377 <Icon icon="play" classes="d-flex align-items-center" />
383 <a className="text-body" href={url} title={url} rel={relTags}>
384 <div className="thumbnail rounded bg-light d-flex justify-content-center">
385 <Icon icon="external-link" classes="d-flex align-items-center" />
393 className="text-body"
394 to={`/post/${post.id}`}
395 title={I18NextService.i18n.t("comments")}
397 <div className="thumbnail rounded bg-light d-flex justify-content-center">
398 <Icon icon="message-square" classes="d-flex align-items-center" />
406 const post_view = this.postView;
409 <div className="small mb-1 mb-md-0">
410 <PersonListing person={post_view.creator} />
413 isMod={this.creatorIsMod_}
414 isAdmin={this.creatorIsAdmin_}
415 isBot={post_view.creator.bot_account}
417 {this.props.showCommunity && (
420 {I18NextService.i18n.t("to")}{" "}
421 <CommunityLink community={post_view.community} />
424 {post_view.post.language_id !== 0 && (
425 <span className="mx-1 badge text-bg-light">
427 this.props.allLanguages.find(
428 lang => lang.id === post_view.post.language_id
435 published={post_view.post.published}
436 updated={post_view.post.updated}
443 const post = this.postView.post;
446 className={`d-inline ${
447 !post.featured_community && !post.featured_local
451 to={`/post/${post.id}`}
452 title={I18NextService.i18n.t("comments")}
456 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
463 const post = this.postView.post;
464 const url = post.url;
468 <div className="post-title overflow-hidden">
469 <h5 className="d-inline">
470 {url && this.props.showBody ? (
473 !post.featured_community && !post.featured_local
480 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
488 * If there is a URL, an embed title, and we were not told to show the
489 * body by the parent component, show the MetadataCard/body toggle.
491 {!this.props.showBody &&
494 this.showPreviewButton()}
497 <small className="ms-2 badge text-bg-secondary">
498 {I18NextService.i18n.t("removed")}
504 className="unselectable pointer ms-2 text-muted fst-italic"
505 data-tippy-content={I18NextService.i18n.t("deleted")}
507 <Icon icon="trash" classes="icon-inline text-danger" />
513 className="unselectable pointer ms-2 text-muted fst-italic"
514 data-tippy-content={I18NextService.i18n.t("locked")}
516 <Icon icon="lock" classes="icon-inline text-danger" />
520 {post.featured_community && (
522 className="unselectable pointer ms-2 text-muted fst-italic"
523 data-tippy-content={I18NextService.i18n.t(
524 "featured_in_community"
526 aria-label={I18NextService.i18n.t("featured_in_community")}
528 <Icon icon="pin" classes="icon-inline text-primary" />
532 {post.featured_local && (
534 className="unselectable pointer ms-2 text-muted fst-italic"
535 data-tippy-content={I18NextService.i18n.t("featured_in_local")}
536 aria-label={I18NextService.i18n.t("featured_in_local")}
538 <Icon icon="pin" classes="icon-inline text-secondary" />
543 <small className="ms-2 badge text-bg-danger">
544 {I18NextService.i18n.t("nsfw")}
548 {url && this.urlLine()}
554 const post = this.postView.post;
555 const url = post.url;
558 <p className="small m-0">
559 {url && !(hostname(url) === getExternalHost()) && (
561 className="fst-italic link-dark link-opacity-75 link-opacity-100-hover"
574 const dupes = this.props.crossPosts;
575 return dupes && dupes.length > 0 ? (
576 <ul className="list-inline mb-1 small text-muted">
578 <li className="list-inline-item me-2">
579 {I18NextService.i18n.t("cross_posted_to")}
582 <li key={pv.post.id} className="list-inline-item me-2">
583 <Link to={`/post/${pv.post.id}`}>
586 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
597 commentsLine(mobile = false) {
598 const post = this.postView.post;
601 <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
602 {this.commentsButton}
605 className="btn btn-sm btn-animate text-muted py-0"
606 onClick={linkEvent(this, this.handleShare)}
609 <Icon icon="share" inline />
614 className="btn btn-sm btn-animate text-muted py-0"
615 title={I18NextService.i18n.t("link")}
618 <Icon icon="fedilink" inline />
621 {mobile && !this.props.viewOnly && (
623 voteContentType={VoteContentType.Post}
624 id={this.postView.post.id}
625 onVote={this.props.onPostVote}
626 enableDownvotes={this.props.enableDownvotes}
627 counts={this.postView.counts}
628 my_vote={this.postView.my_vote}
631 {UserService.Instance.myUserInfo &&
632 !this.props.viewOnly &&
639 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
640 // Possible enhancement: Make each button a component.
641 const post_view = this.postView;
642 const post = post_view.post;
647 {this.crossPostButton}
649 {this.props.showBody && post_view.post.body && this.viewSourceButton}
651 <div className="dropdown">
653 className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
654 onClick={linkEvent(this, this.handleShowAdvanced)}
655 data-tippy-content={I18NextService.i18n.t("more")}
656 data-bs-toggle="dropdown"
657 aria-expanded="false"
658 aria-controls={`advancedButtonsDropdown${post.id}`}
659 aria-label={I18NextService.i18n.t("more")}
661 <Icon icon="more-vertical" inline />
665 className="dropdown-menu"
666 id={`advancedButtonsDropdown${post.id}`}
670 <li>{this.reportButton}</li>
671 <li>{this.blockButton}</li>
675 <li>{this.editButton}</li>
676 <li>{this.deleteButton}</li>
680 {/* Any mod can do these, not limited to hierarchy*/}
681 {(amMod(this.props.moderators) || amAdmin()) && (
684 <hr className="dropdown-divider" />
686 <li>{this.lockButton}</li>
687 {this.featureButtons}
691 {(this.canMod_ || this.canAdmin_) && (
692 <li>{this.modRemoveButton}</li>
698 <hr className="dropdown-divider" />
700 {!this.creatorIsMod_ &&
701 (!post_view.creator_banned_from_community ? (
702 <li>{this.modBanFromCommunityButton}</li>
704 <li>{this.modUnbanFromCommunityButton}</li>
706 {!post_view.creator_banned_from_community && (
707 <li>{this.addModToCommunityButton}</li>
712 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
714 this.creatorIsMod_ && <li>{this.transferCommunityButton}</li>}
716 {/* Admins can ban from all, and appoint other admins */}
720 <hr className="dropdown-divider" />
722 {!this.creatorIsAdmin_ && (
724 {!isBanned(post_view.creator) ? (
725 <li>{this.modBanButton}</li>
727 <li>{this.modUnbanButton}</li>
729 <li>{this.purgePersonButton}</li>
730 <li>{this.purgePostButton}</li>
733 {!isBanned(post_view.creator) && post_view.creator.local && (
734 <li>{this.toggleAdminButton}</li>
744 get commentsButton() {
745 const post_view = this.postView;
746 const title = I18NextService.i18n.t("number_of_comments", {
747 count: Number(post_view.counts.comments),
748 formattedCount: Number(post_view.counts.comments),
753 className="btn btn-link btn-sm text-muted ps-0"
755 to={`/post/${post_view.post.id}?scrollToComments=true`}
756 data-tippy-content={title}
758 <Icon icon="message-square" classes="me-1" inline />
759 {post_view.counts.comments}
760 {this.unreadCount && (
763 <span className="fst-italic">
764 ({this.unreadCount} {I18NextService.i18n.t("new")})
772 get unreadCount(): number | undefined {
773 const pv = this.postView;
774 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
776 : pv.unread_comments;
780 const saved = this.postView.saved;
782 ? I18NextService.i18n.t("unsave")
783 : I18NextService.i18n.t("save");
786 className="btn btn-sm btn-animate text-muted py-0"
787 onClick={linkEvent(this, this.handleSavePostClick)}
788 data-tippy-content={label}
791 {this.state.saveLoading ? (
796 classes={classNames({ "text-warning": saved })}
804 get crossPostButton() {
807 className="btn btn-sm btn-animate text-muted py-0"
809 /* Empty string properties are required to satisfy type*/
810 pathname: "/create_post",
811 state: { ...this.crossPostParams },
816 title={I18NextService.i18n.t("cross_post")}
817 data-tippy-content={I18NextService.i18n.t("cross_post")}
818 aria-label={I18NextService.i18n.t("cross_post")}
820 <Icon icon="copy" inline />
828 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
829 onClick={linkEvent(this, this.handleShowReportDialog)}
830 aria-label={I18NextService.i18n.t("show_report_dialog")}
832 <Icon classes="me-1" icon="flag" inline />
833 {I18NextService.i18n.t("create_report")}
841 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
842 onClick={linkEvent(this, this.handleBlockPersonClick)}
843 aria-label={I18NextService.i18n.t("block_user")}
845 {this.state.blockLoading ? (
848 <Icon classes="me-1" icon="slash" inline />
850 {I18NextService.i18n.t("block_user")}
858 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
859 onClick={linkEvent(this, this.handleEditClick)}
860 aria-label={I18NextService.i18n.t("edit")}
862 <Icon classes="me-1" icon="edit" inline />
863 {I18NextService.i18n.t("edit")}
869 const deleted = this.postView.post.deleted;
870 const label = !deleted
871 ? I18NextService.i18n.t("delete")
872 : I18NextService.i18n.t("restore");
875 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
876 onClick={linkEvent(this, this.handleDeleteClick)}
878 {this.state.deleteLoading ? (
884 classes={classNames("me-1", { "text-danger": deleted })}
894 get viewSourceButton() {
897 className="btn btn-sm btn-animate text-muted py-0"
898 onClick={linkEvent(this, this.handleViewSource)}
899 data-tippy-content={I18NextService.i18n.t("view_source")}
900 aria-label={I18NextService.i18n.t("view_source")}
904 classes={classNames({ "text-success": this.state.viewSource })}
912 const locked = this.postView.post.locked;
914 ? I18NextService.i18n.t("unlock")
915 : I18NextService.i18n.t("lock");
918 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
919 onClick={linkEvent(this, this.handleModLock)}
922 {this.state.lockLoading ? (
928 classes={classNames("me-1", { "text-danger": locked })}
931 {capitalizeFirstLetter(label)}
938 get featureButtons() {
939 const featuredCommunity = this.postView.post.featured_community;
940 const labelCommunity = featuredCommunity
941 ? I18NextService.i18n.t("unfeature_from_community")
942 : I18NextService.i18n.t("feature_in_community");
944 const featuredLocal = this.postView.post.featured_local;
945 const labelLocal = featuredLocal
946 ? I18NextService.i18n.t("unfeature_from_local")
947 : I18NextService.i18n.t("feature_in_local");
952 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
953 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
954 data-tippy-content={labelCommunity}
955 aria-label={labelCommunity}
957 {this.state.featureCommunityLoading ? (
963 classes={classNames("me-1", {
964 "text-success": featuredCommunity,
968 {I18NextService.i18n.t("community")}
976 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
977 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
978 data-tippy-content={labelLocal}
979 aria-label={labelLocal}
981 {this.state.featureLocalLoading ? (
987 classes={classNames("me-1", {
988 "text-success": featuredLocal,
992 {I18NextService.i18n.t("local")}
1002 get modBanFromCommunityButton() {
1005 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1006 onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
1008 {I18NextService.i18n.t("ban_from_community")}
1013 get modUnbanFromCommunityButton() {
1016 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1017 onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
1019 {this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
1024 get addModToCommunityButton() {
1027 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1028 onClick={linkEvent(this, this.handleAddModToCommunity)}
1030 {this.state.addModLoading ? (
1032 ) : this.creatorIsMod_ ? (
1033 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_mod"))
1035 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_mod"))
1041 get modBanButton() {
1044 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1045 onClick={linkEvent(this, this.handleModBanShow)}
1047 {capitalizeFirstLetter(I18NextService.i18n.t("ban_from_site"))}
1052 get modUnbanButton() {
1055 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1056 onClick={linkEvent(this, this.handleModBanSubmit)}
1058 {this.state.banLoading ? (
1061 capitalizeFirstLetter(I18NextService.i18n.t("unban_from_site"))
1067 get purgePersonButton() {
1070 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1071 onClick={linkEvent(this, this.handlePurgePersonShow)}
1073 {capitalizeFirstLetter(I18NextService.i18n.t("purge_user"))}
1078 get purgePostButton() {
1081 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1082 onClick={linkEvent(this, this.handlePurgePostShow)}
1084 {capitalizeFirstLetter(I18NextService.i18n.t("purge_post"))}
1089 get toggleAdminButton() {
1092 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1093 onClick={linkEvent(this, this.handleAddAdmin)}
1095 {this.state.addAdminLoading ? (
1097 ) : this.creatorIsAdmin_ ? (
1098 capitalizeFirstLetter(I18NextService.i18n.t("remove_as_admin"))
1100 capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_admin"))
1106 get transferCommunityButton() {
1109 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1110 onClick={linkEvent(this, this.handleShowConfirmTransferCommunity)}
1112 {capitalizeFirstLetter(I18NextService.i18n.t("transfer_community"))}
1117 get modRemoveButton() {
1118 const removed = this.postView.post.removed;
1121 className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1124 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1127 {/* TODO: Find an icon for this. */}
1128 {this.state.removeLoading ? (
1131 capitalizeFirstLetter(I18NextService.i18n.t("remove_post"))
1134 {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "}
1135 {I18NextService.i18n.t("post")}
1142 removeAndBanDialogs() {
1143 const post = this.postView;
1144 const purgeTypeText =
1145 this.state.purgeType == PurgeType.Post
1146 ? I18NextService.i18n.t("purge_post")
1147 : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1150 {this.state.showRemoveDialog && (
1152 className="form-inline"
1153 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1156 className="visually-hidden"
1157 htmlFor="post-listing-remove-reason"
1159 {I18NextService.i18n.t("reason")}
1163 id="post-listing-remove-reason"
1164 className="form-control me-2"
1165 placeholder={I18NextService.i18n.t("reason")}
1166 value={this.state.removeReason}
1167 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1169 <button type="submit" className="btn btn-secondary">
1170 {this.state.removeLoading ? (
1173 I18NextService.i18n.t("remove_post")
1178 {this.state.showConfirmTransferCommunity && (
1180 <button className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0">
1181 {I18NextService.i18n.t("are_you_sure")}
1184 className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1185 onClick={linkEvent(this, this.handleTransferCommunity)}
1187 {this.state.transferLoading ? (
1190 I18NextService.i18n.t("yes")
1194 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1197 this.handleCancelShowConfirmTransferCommunity
1199 aria-label={I18NextService.i18n.t("no")}
1201 {I18NextService.i18n.t("no")}
1205 {this.state.showBanDialog && (
1206 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1207 <div className="mb-3 row col-12">
1209 className="col-form-label"
1210 htmlFor="post-listing-ban-reason"
1212 {I18NextService.i18n.t("reason")}
1216 id="post-listing-ban-reason"
1217 className="form-control me-2"
1218 placeholder={I18NextService.i18n.t("reason")}
1219 value={this.state.banReason}
1220 onInput={linkEvent(this, this.handleModBanReasonChange)}
1222 <label className="col-form-label" htmlFor="mod-ban-expires">
1223 {I18NextService.i18n.t("expires")}
1227 id="mod-ban-expires"
1228 className="form-control me-2"
1229 placeholder={I18NextService.i18n.t("number_of_days")}
1230 value={this.state.banExpireDays}
1231 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1233 <div className="input-group mb-3">
1234 <div className="form-check">
1236 className="form-check-input"
1237 id="mod-ban-remove-data"
1239 checked={this.state.removeData}
1240 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1243 className="form-check-label"
1244 htmlFor="mod-ban-remove-data"
1245 title={I18NextService.i18n.t("remove_content_more")}
1247 {I18NextService.i18n.t("remove_content")}
1252 {/* TODO hold off on expires until later */}
1253 {/* <div class="mb-3 row"> */}
1254 {/* <label class="col-form-label">Expires</label> */}
1255 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1257 <div className="mb-3 row">
1258 <button type="submit" className="btn btn-secondary">
1259 {this.state.banLoading ? (
1263 {I18NextService.i18n.t("ban")} {post.creator.name}
1270 {this.state.showReportDialog && (
1272 className="form-inline"
1273 onSubmit={linkEvent(this, this.handleReportSubmit)}
1275 <label className="visually-hidden" htmlFor="post-report-reason">
1276 {I18NextService.i18n.t("reason")}
1280 id="post-report-reason"
1281 className="form-control me-2"
1282 placeholder={I18NextService.i18n.t("reason")}
1284 value={this.state.reportReason}
1285 onInput={linkEvent(this, this.handleReportReasonChange)}
1287 <button type="submit" className="btn btn-secondary">
1288 {this.state.reportLoading ? (
1291 I18NextService.i18n.t("create_report")
1296 {this.state.showPurgeDialog && (
1298 className="form-inline"
1299 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1302 <label className="visually-hidden" htmlFor="purge-reason">
1303 {I18NextService.i18n.t("reason")}
1308 className="form-control me-2"
1309 placeholder={I18NextService.i18n.t("reason")}
1310 value={this.state.purgeReason}
1311 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1313 {this.state.purgeLoading ? (
1316 <button type="submit" className="btn btn-secondary">
1317 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1327 const post = this.postView.post;
1328 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1329 <div className="row">
1330 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1331 {this.postTitleLine()}
1333 <div className="col-4">
1334 {/* Post thumbnail */}
1335 {!this.state.imageExpanded && this.thumbnail()}
1339 this.postTitleLine()
1343 showPreviewButton() {
1347 className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
1348 onClick={linkEvent(this, this.handleShowBody)}
1351 icon={!this.state.showBody ? "plus-square" : "minus-square"}
1352 classes="icon-inline"
1361 {/* The mobile view*/}
1362 <div className="d-block d-sm-none">
1363 <article className="row post-container">
1364 <div className="col-12">
1365 {this.createdLine()}
1367 {/* If it has a thumbnail, do a right aligned thumbnail */}
1368 {this.mobileThumbnail()}
1370 {this.commentsLine(true)}
1371 {this.duplicatesLine()}
1372 {this.removeAndBanDialogs()}
1377 {/* The larger view*/}
1378 <div className="d-none d-sm-block">
1379 <article className="row post-container">
1380 {!this.props.viewOnly && (
1381 <div className="col flex-grow-0">
1383 voteContentType={VoteContentType.Post}
1384 id={this.postView.post.id}
1385 onVote={this.props.onPostVote}
1386 enableDownvotes={this.props.enableDownvotes}
1387 counts={this.postView.counts}
1388 my_vote={this.postView.my_vote}
1392 <div className="col flex-grow-1">
1393 <div className="row">
1394 <div className="col flex-grow-0 px-0">
1395 <div className="">{this.thumbnail()}</div>
1397 <div className="col flex-grow-1">
1398 {this.postTitleLine()}
1399 {this.createdLine()}
1400 {this.commentsLine()}
1401 {this.duplicatesLine()}
1402 {this.removeAndBanDialogs()}
1412 private get myPost(): boolean {
1414 this.postView.creator.id ==
1415 UserService.Instance.myUserInfo?.local_user_view.person.id
1418 handleEditClick(i: PostListing) {
1419 i.setState({ showEdit: true });
1422 handleEditCancel() {
1423 this.setState({ showEdit: false });
1426 // The actual editing is done in the receive for post
1427 handleEditPost(form: EditPost) {
1428 this.setState({ showEdit: false });
1429 this.props.onPostEdit(form);
1432 handleShare(i: PostListing) {
1433 const { name, body, id } = i.props.post_view.post;
1436 text: body?.slice(0, 50),
1437 url: `${getHttpBase()}/post/${id}`,
1441 handleShowReportDialog(i: PostListing) {
1442 i.setState({ showReportDialog: !i.state.showReportDialog });
1445 handleReportReasonChange(i: PostListing, event: any) {
1446 i.setState({ reportReason: event.target.value });
1449 handleReportSubmit(i: PostListing, event: any) {
1450 event.preventDefault();
1451 i.setState({ reportLoading: true });
1452 i.props.onPostReport({
1453 post_id: i.postView.post.id,
1454 reason: i.state.reportReason ?? "",
1455 auth: myAuthRequired(),
1459 handleBlockPersonClick(i: PostListing) {
1460 i.setState({ blockLoading: true });
1461 i.props.onBlockPerson({
1462 person_id: i.postView.creator.id,
1464 auth: myAuthRequired(),
1468 handleDeleteClick(i: PostListing) {
1469 i.setState({ deleteLoading: true });
1470 i.props.onDeletePost({
1471 post_id: i.postView.post.id,
1472 deleted: !i.postView.post.deleted,
1473 auth: myAuthRequired(),
1477 handleSavePostClick(i: PostListing) {
1478 i.setState({ saveLoading: true });
1479 i.props.onSavePost({
1480 post_id: i.postView.post.id,
1481 save: !i.postView.saved,
1482 auth: myAuthRequired(),
1486 get crossPostParams(): PostFormParams {
1487 const queryParams: PostFormParams = {};
1488 const { name, url } = this.postView.post;
1490 queryParams.name = name;
1493 queryParams.url = url;
1496 const crossPostBody = this.crossPostBody();
1497 if (crossPostBody) {
1498 queryParams.body = crossPostBody;
1504 crossPostBody(): string | undefined {
1505 const post = this.postView.post;
1506 const body = post.body;
1509 ? `${I18NextService.i18n.t("cross_posted_from")} ${
1511 }\n\n${body.replace(/^/gm, "> ")}`
1515 get showBody(): boolean {
1516 return this.props.showBody || this.state.showBody;
1519 handleModRemoveShow(i: PostListing) {
1521 showRemoveDialog: !i.state.showRemoveDialog,
1522 showBanDialog: false,
1526 handleModRemoveReasonChange(i: PostListing, event: any) {
1527 i.setState({ removeReason: event.target.value });
1530 handleModRemoveDataChange(i: PostListing, event: any) {
1531 i.setState({ removeData: event.target.checked });
1534 handleModRemoveSubmit(i: PostListing, event: any) {
1535 event.preventDefault();
1536 i.setState({ removeLoading: true });
1537 i.props.onRemovePost({
1538 post_id: i.postView.post.id,
1539 removed: !i.postView.post.removed,
1540 auth: myAuthRequired(),
1544 handleModLock(i: PostListing) {
1545 i.setState({ lockLoading: true });
1546 i.props.onLockPost({
1547 post_id: i.postView.post.id,
1548 locked: !i.postView.post.locked,
1549 auth: myAuthRequired(),
1553 handleModFeaturePostLocal(i: PostListing) {
1554 i.setState({ featureLocalLoading: true });
1555 i.props.onFeaturePost({
1556 post_id: i.postView.post.id,
1557 featured: !i.postView.post.featured_local,
1558 feature_type: "Local",
1559 auth: myAuthRequired(),
1563 handleModFeaturePostCommunity(i: PostListing) {
1564 i.setState({ featureCommunityLoading: true });
1565 i.props.onFeaturePost({
1566 post_id: i.postView.post.id,
1567 featured: !i.postView.post.featured_community,
1568 feature_type: "Community",
1569 auth: myAuthRequired(),
1573 handleModBanFromCommunityShow(i: PostListing) {
1575 showBanDialog: true,
1576 banType: BanType.Community,
1577 showRemoveDialog: false,
1581 handleModBanShow(i: PostListing) {
1583 showBanDialog: true,
1584 banType: BanType.Site,
1585 showRemoveDialog: false,
1589 handlePurgePersonShow(i: PostListing) {
1591 showPurgeDialog: true,
1592 purgeType: PurgeType.Person,
1593 showRemoveDialog: false,
1597 handlePurgePostShow(i: PostListing) {
1599 showPurgeDialog: true,
1600 purgeType: PurgeType.Post,
1601 showRemoveDialog: false,
1605 handlePurgeReasonChange(i: PostListing, event: any) {
1606 i.setState({ purgeReason: event.target.value });
1609 handlePurgeSubmit(i: PostListing, event: any) {
1610 event.preventDefault();
1611 i.setState({ purgeLoading: true });
1612 if (i.state.purgeType == PurgeType.Person) {
1613 i.props.onPurgePerson({
1614 person_id: i.postView.creator.id,
1615 reason: i.state.purgeReason,
1616 auth: myAuthRequired(),
1618 } else if (i.state.purgeType == PurgeType.Post) {
1619 i.props.onPurgePost({
1620 post_id: i.postView.post.id,
1621 reason: i.state.purgeReason,
1622 auth: myAuthRequired(),
1627 handleModBanReasonChange(i: PostListing, event: any) {
1628 i.setState({ banReason: event.target.value });
1631 handleModBanExpireDaysChange(i: PostListing, event: any) {
1632 i.setState({ banExpireDays: event.target.value });
1635 handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1636 i.setState({ banType: BanType.Community });
1637 i.handleModBanBothSubmit(i, event);
1640 handleModBanSubmit(i: PostListing, event: any) {
1641 i.setState({ banType: BanType.Site });
1642 i.handleModBanBothSubmit(i, event);
1645 handleModBanBothSubmit(i: PostListing, event: any) {
1646 event.preventDefault();
1647 i.setState({ banLoading: true });
1649 const ban = !i.props.post_view.creator_banned_from_community;
1650 // If its an unban, restore all their data
1652 i.setState({ removeData: false });
1654 const person_id = i.props.post_view.creator.id;
1655 const remove_data = i.state.removeData;
1656 const reason = i.state.banReason;
1657 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1659 if (i.state.banType == BanType.Community) {
1660 const community_id = i.postView.community.id;
1661 i.props.onBanPersonFromCommunity({
1668 auth: myAuthRequired(),
1671 i.props.onBanPerson({
1677 auth: myAuthRequired(),
1682 handleAddModToCommunity(i: PostListing) {
1683 i.setState({ addModLoading: true });
1684 i.props.onAddModToCommunity({
1685 community_id: i.postView.community.id,
1686 person_id: i.postView.creator.id,
1687 added: !i.creatorIsMod_,
1688 auth: myAuthRequired(),
1692 handleAddAdmin(i: PostListing) {
1693 i.setState({ addAdminLoading: true });
1694 i.props.onAddAdmin({
1695 person_id: i.postView.creator.id,
1696 added: !i.creatorIsAdmin_,
1697 auth: myAuthRequired(),
1701 handleShowConfirmTransferCommunity(i: PostListing) {
1702 i.setState({ showConfirmTransferCommunity: true });
1705 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1706 i.setState({ showConfirmTransferCommunity: false });
1709 handleTransferCommunity(i: PostListing) {
1710 i.setState({ transferLoading: true });
1711 i.props.onTransferCommunity({
1712 community_id: i.postView.community.id,
1713 person_id: i.postView.creator.id,
1714 auth: myAuthRequired(),
1718 handleShowConfirmTransferSite(i: PostListing) {
1719 i.setState({ showConfirmTransferSite: true });
1722 handleCancelShowConfirmTransferSite(i: PostListing) {
1723 i.setState({ showConfirmTransferSite: false });
1726 handleImageExpandClick(i: PostListing, event: any) {
1727 event.preventDefault();
1728 i.setState({ imageExpanded: !i.state.imageExpanded });
1732 handleViewSource(i: PostListing) {
1733 i.setState({ viewSource: !i.state.viewSource });
1736 handleShowAdvanced(i: PostListing) {
1737 i.setState({ showAdvanced: !i.state.showAdvanced });
1741 handleShowMoreMobile(i: PostListing) {
1743 showMoreMobile: !i.state.showMoreMobile,
1744 showAdvanced: !i.state.showAdvanced,
1749 handleShowBody(i: PostListing) {
1750 i.setState({ showBody: !i.state.showBody });
1754 get pointsTippy(): string {
1755 const points = I18NextService.i18n.t("number_of_points", {
1756 count: Number(this.postView.counts.score),
1757 formattedCount: Number(this.postView.counts.score),
1760 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1761 count: Number(this.postView.counts.upvotes),
1762 formattedCount: Number(this.postView.counts.upvotes),
1765 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1766 count: Number(this.postView.counts.downvotes),
1767 formattedCount: Number(this.postView.counts.downvotes),
1770 return `${points} • ${upvotes} • ${downvotes}`;
1773 get canModOnSelf_(): boolean {
1775 this.postView.creator.id,
1776 this.props.moderators,
1783 get canMod_(): boolean {
1785 this.postView.creator.id,
1786 this.props.moderators,
1791 get canAdmin_(): boolean {
1792 return canAdmin(this.postView.creator.id, this.props.admins);
1795 get creatorIsMod_(): boolean {
1796 return isMod(this.postView.creator.id, this.props.moderators);
1799 get creatorIsAdmin_(): boolean {
1800 return isAdmin(this.postView.creator.id, this.props.admins);