1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
10 CommunityModeratorView,
24 } from "lemmy-js-client";
25 import { getExternalHost } from "../../env";
26 import { i18n } from "../../i18next";
27 import { BanType, PostFormParams, PurgeType } from "../../interfaces";
28 import { UserService, WebSocketService } from "../../services";
52 import { Icon, PurgeWarning, Spinner } from "../common/icon";
53 import { MomentTime } from "../common/moment-time";
54 import { PictrsImage } from "../common/pictrs-image";
55 import { CommunityLink } from "../community/community-link";
56 import { PersonListing } from "../person/person-listing";
57 import { MetadataCard } from "./metadata-card";
58 import { PostForm } from "./post-form";
60 interface PostListingState {
62 showRemoveDialog: boolean;
63 showPurgeDialog: boolean;
65 purgeType?: PurgeType;
66 purgeLoading: boolean;
67 removeReason?: string;
68 showBanDialog: boolean;
70 banExpireDays?: number;
73 showConfirmTransferSite: boolean;
74 showConfirmTransferCommunity: boolean;
75 imageExpanded: boolean;
77 showAdvanced: boolean;
78 showMoreMobile: boolean;
80 showReportDialog: boolean;
81 reportReason?: string;
88 interface PostListingProps {
90 duplicates?: PostView[];
91 moderators?: CommunityModeratorView[];
92 admins?: PersonView[];
93 allLanguages: Language[];
94 siteLanguages: number[];
95 showCommunity?: boolean;
98 enableDownvotes?: boolean;
103 export class PostListing extends Component<PostListingProps, PostListingState> {
104 state: PostListingState = {
106 showRemoveDialog: false,
107 showPurgeDialog: false,
108 purgeType: PurgeType.Person,
110 showBanDialog: false,
111 banType: BanType.Community,
113 showConfirmTransferSite: false,
114 showConfirmTransferCommunity: false,
115 imageExpanded: false,
118 showMoreMobile: false,
120 showReportDialog: false,
121 my_vote: this.props.post_view.my_vote,
122 score: this.props.post_view.counts.score,
123 upvotes: this.props.post_view.counts.upvotes,
124 downvotes: this.props.post_view.counts.downvotes,
127 constructor(props: any, context: any) {
128 super(props, context);
130 this.handlePostLike = this.handlePostLike.bind(this);
131 this.handlePostDisLike = this.handlePostDisLike.bind(this);
132 this.handleEditPost = this.handleEditPost.bind(this);
133 this.handleEditCancel = this.handleEditCancel.bind(this);
136 componentWillReceiveProps(nextProps: PostListingProps) {
138 my_vote: nextProps.post_view.my_vote,
139 upvotes: nextProps.post_view.counts.upvotes,
140 downvotes: nextProps.post_view.counts.downvotes,
141 score: nextProps.post_view.counts.score,
143 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
144 this.setState({ imageExpanded: false });
149 const post = this.props.post_view.post;
152 <div className="post-listing">
153 {!this.state.showEdit ? (
156 {this.state.imageExpanded && !this.props.hideImage && this.img}
157 {post.url && this.showBody && post.embed_title && (
158 <MetadataCard post={post} />
160 {this.showBody && this.body()}
163 <div className="col-12">
165 post_view={this.props.post_view}
166 onEdit={this.handleEditPost}
167 onCancel={this.handleEditCancel}
168 enableNsfw={this.props.enableNsfw}
169 enableDownvotes={this.props.enableDownvotes}
170 allLanguages={this.props.allLanguages}
171 siteLanguages={this.props.siteLanguages}
180 let body = this.props.post_view.post.body;
182 <div className="col-12 card my-2 p-2">
183 {this.state.viewSource ? (
186 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
195 let src = this.imageSrc;
198 <div className="offset-sm-3 my-2 d-none d-sm-block">
199 <a href={src} className="d-inline-block">
200 <PictrsImage src={src} />
203 <div className="my-2 d-block d-sm-none">
205 className="d-inline-block"
206 onClick={linkEvent(this, this.handleImageExpandClick)}
208 <PictrsImage src={src} />
217 imgThumb(src: string) {
218 let post_view = this.props.post_view;
224 nsfw={post_view.post.nsfw || post_view.community.nsfw}
229 get imageSrc(): string | undefined {
230 let post = this.props.post_view.post;
232 let thumbnail = post.thumbnail_url;
234 if (url && isImage(url)) {
235 if (url.includes("pictrs")) {
237 } else if (thumbnail) {
242 } else if (thumbnail) {
250 let post = this.props.post_view.post;
252 let thumbnail = post.thumbnail_url;
254 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
258 className="text-body d-inline-block position-relative mb-2"
259 data-tippy-content={i18n.t("expand_here")}
260 onClick={linkEvent(this, this.handleImageExpandClick)}
261 aria-label={i18n.t("expand_here")}
263 {this.imgThumb(this.imageSrc)}
264 <Icon icon="image" classes="mini-overlay" />
267 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
270 className="text-body d-inline-block position-relative mb-2"
275 {this.imgThumb(this.imageSrc)}
276 <Icon icon="external-link" classes="mini-overlay" />
280 if (!this.props.hideImage && isVideo(url)) {
282 <div className="embed-responsive embed-responsive-16by9">
288 className="embed-responsive-item"
290 <source src={url} type="video/mp4" />
296 <a className="text-body" href={url} title={url} rel={relTags}>
297 <div className="thumbnail rounded bg-light d-flex justify-content-center">
298 <Icon icon="external-link" classes="d-flex align-items-center" />
306 className="text-body"
307 to={`/post/${post.id}`}
308 title={i18n.t("comments")}
310 <div className="thumbnail rounded bg-light d-flex justify-content-center">
311 <Icon icon="message-square" classes="d-flex align-items-center" />
319 let post_view = this.props.post_view;
320 let url = post_view.post.url;
321 let body = post_view.post.body;
323 <ul className="list-inline mb-1 text-muted small">
324 <li className="list-inline-item">
325 <PersonListing person={post_view.creator} />
327 {this.creatorIsMod_ && (
328 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
330 {this.creatorIsAdmin_ && (
331 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
333 {post_view.creator.bot_account && (
334 <span className="mx-1 badge badge-light">
335 {i18n.t("bot_account").toLowerCase()}
338 {(post_view.creator_banned_from_community ||
339 isBanned(post_view.creator)) && (
340 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
342 {post_view.creator_blocked && (
343 <span className="mx-1 badge badge-danger">{"blocked"}</span>
345 {this.props.showCommunity && (
347 <span className="mx-1"> {i18n.t("to")} </span>
348 <CommunityLink community={post_view.community} />
352 <li className="list-inline-item">•</li>
353 {url && !(hostname(url) === getExternalHost()) && (
355 <li className="list-inline-item">
357 className="text-muted font-italic"
365 <li className="list-inline-item">•</li>
368 <li className="list-inline-item">
371 published={post_view.post.published}
372 updated={post_view.post.updated}
378 <li className="list-inline-item">•</li>
379 <li className="list-inline-item">
381 className="text-muted btn btn-sm btn-link p-0"
382 data-tippy-content={mdNoImages.render(body)}
383 data-tippy-allowHtml={true}
384 onClick={linkEvent(this, this.handleShowBody)}
386 <Icon icon="book-open" classes="icon-inline mr-1" />
397 <div className={`vote-bar col-1 pr-0 small text-center`}>
399 className={`btn-animate btn btn-link p-0 ${
400 this.state.my_vote == 1 ? "text-info" : "text-muted"
402 onClick={this.handlePostLike}
403 data-tippy-content={i18n.t("upvote")}
404 aria-label={i18n.t("upvote")}
406 <Icon icon="arrow-up1" classes="upvote" />
410 className={`unselectable pointer font-weight-bold text-muted px-1`}
411 data-tippy-content={this.pointsTippy}
413 {numToSI(this.state.score)}
416 <div className="p-1"></div>
418 {this.props.enableDownvotes && (
420 className={`btn-animate btn btn-link p-0 ${
421 this.state.my_vote == -1 ? "text-danger" : "text-muted"
423 onClick={this.handlePostDisLike}
424 data-tippy-content={i18n.t("downvote")}
425 aria-label={i18n.t("downvote")}
427 <Icon icon="arrow-down1" classes="downvote" />
435 let post = this.props.post_view.post;
438 className={`d-inline-block ${
439 !post.featured_community && !post.featured_local
443 to={`/post/${post.id}`}
444 title={i18n.t("comments")}
447 className="d-inline-block"
448 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
455 let post = this.props.post_view.post;
459 <div className="post-title overflow-hidden">
462 this.props.showBody ? (
464 className={`d-inline-block ${
465 !post.featured_community && !post.featured_local
474 className="d-inline-block"
475 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
484 {(url && isImage(url)) ||
485 (post.thumbnail_url && (
487 className="btn btn-link text-monospace text-muted small d-inline-block"
488 data-tippy-content={i18n.t("expand_here")}
489 onClick={linkEvent(this, this.handleImageExpandClick)}
493 !this.state.imageExpanded ? "plus-square" : "minus-square"
495 classes="icon-inline"
500 <small className="ml-2 text-muted font-italic">
506 className="unselectable pointer ml-2 text-muted font-italic"
507 data-tippy-content={i18n.t("deleted")}
509 <Icon icon="trash" classes="icon-inline text-danger" />
514 className="unselectable pointer ml-2 text-muted font-italic"
515 data-tippy-content={i18n.t("locked")}
517 <Icon icon="lock" classes="icon-inline text-danger" />
520 {post.featured_community && (
522 className="unselectable pointer ml-2 text-muted font-italic"
523 data-tippy-content={i18n.t("featured")}
525 <Icon icon="pin" classes="icon-inline text-primary" />
528 {post.featured_local && (
530 className="unselectable pointer ml-2 text-muted font-italic"
531 data-tippy-content={i18n.t("featured")}
533 <Icon icon="pin" classes="icon-inline text-secondary" />
537 <small className="ml-2 text-muted font-italic">
547 let dupes = this.props.duplicates;
548 return dupes && dupes.length > 0 ? (
549 <ul className="list-inline mb-1 small text-muted">
551 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
553 <li key={pv.post.id} className="list-inline-item mr-2">
554 <Link to={`/post/${pv.post.id}`}>
557 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
568 commentsLine(mobile = false) {
569 let post = this.props.post_view.post;
571 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
572 {this.commentsButton}
575 className="btn btn-link btn-animate text-muted py-0"
576 title={i18n.t("link")}
579 <Icon icon="fedilink" inline />
582 {mobile && !this.props.viewOnly && this.mobileVotes}
583 {UserService.Instance.myUserInfo &&
584 !this.props.viewOnly &&
585 this.postActions(mobile)}
590 postActions(mobile = false) {
591 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
592 // Possible enhancement: Make each button a component.
593 let post_view = this.props.post_view;
597 {this.crossPostButton}
598 {mobile && this.showMoreButton}
599 {(!mobile || this.state.showAdvanced) && (
607 {this.myPost && (this.showBody || this.state.showAdvanced) && (
615 {this.state.showAdvanced && (
617 {this.showBody && post_view.post.body && this.viewSourceButton}
618 {/* Any mod can do these, not limited to hierarchy*/}
619 {(amMod(this.props.moderators) || amAdmin()) && (
625 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
628 {!mobile && this.showMoreButton}
633 get commentsButton() {
634 let post_view = this.props.post_view;
636 <button className="btn btn-link text-muted py-0 pl-0">
638 className="text-muted"
639 title={i18n.t("number_of_comments", {
640 count: Number(post_view.counts.comments),
641 formattedCount: Number(post_view.counts.comments),
643 to={`/post/${post_view.post.id}?scrollToComments=true`}
645 <Icon icon="message-square" classes="mr-1" inline />
646 <span className="mr-2">
647 {i18n.t("number_of_comments", {
648 count: Number(post_view.counts.comments),
649 formattedCount: numToSI(post_view.counts.comments),
652 {this.unreadCount && (
653 <span className="small text-warning">
654 ({this.unreadCount} {i18n.t("new")})
662 get unreadCount(): bigint | undefined {
663 let pv = this.props.post_view;
664 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0n
666 : pv.unread_comments;
671 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
676 className={`btn-animate btn py-0 px-1 ${
677 this.state.my_vote == 1 ? "text-info" : "text-muted"
680 onClick={this.handlePostLike}
681 aria-label={i18n.t("upvote")}
683 <Icon icon="arrow-up1" classes="icon-inline small" />
685 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
688 {this.props.enableDownvotes && (
690 className={`ml-2 btn-animate btn py-0 px-1 ${
691 this.state.my_vote == -1 ? "text-danger" : "text-muted"
693 onClick={this.handlePostDisLike}
695 aria-label={i18n.t("downvote")}
697 <Icon icon="arrow-down1" classes="icon-inline small" />
700 className={classNames("ml-2", {
701 invisible: this.state.downvotes === 0n,
704 {numToSI(this.state.downvotes)}
715 let saved = this.props.post_view.saved;
716 let label = saved ? i18n.t("unsave") : i18n.t("save");
719 className="btn btn-link btn-animate text-muted py-0"
720 onClick={linkEvent(this, this.handleSavePostClick)}
721 data-tippy-content={label}
726 classes={classNames({ "text-warning": saved })}
733 get crossPostButton() {
736 className="btn btn-link btn-animate text-muted py-0"
738 /* Empty string properties are required to satisfy type*/
739 pathname: "/create_post",
740 state: { ...this.crossPostParams },
745 title={i18n.t("cross_post")}
747 <Icon icon="copy" inline />
755 className="btn btn-link btn-animate text-muted py-0"
756 onClick={linkEvent(this, this.handleShowReportDialog)}
757 data-tippy-content={i18n.t("show_report_dialog")}
758 aria-label={i18n.t("show_report_dialog")}
760 <Icon icon="flag" inline />
768 className="btn btn-link btn-animate text-muted py-0"
769 onClick={linkEvent(this, this.handleBlockUserClick)}
770 data-tippy-content={i18n.t("block_user")}
771 aria-label={i18n.t("block_user")}
773 <Icon icon="slash" inline />
781 className="btn btn-link btn-animate text-muted py-0"
782 onClick={linkEvent(this, this.handleEditClick)}
783 data-tippy-content={i18n.t("edit")}
784 aria-label={i18n.t("edit")}
786 <Icon icon="edit" inline />
792 let deleted = this.props.post_view.post.deleted;
793 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
796 className="btn btn-link btn-animate text-muted py-0"
797 onClick={linkEvent(this, this.handleDeleteClick)}
798 data-tippy-content={label}
803 classes={classNames({ "text-danger": deleted })}
810 get showMoreButton() {
813 className="btn btn-link btn-animate text-muted py-0"
814 onClick={linkEvent(this, this.handleShowAdvanced)}
815 data-tippy-content={i18n.t("more")}
816 aria-label={i18n.t("more")}
818 <Icon icon="more-vertical" inline />
823 get viewSourceButton() {
826 className="btn btn-link btn-animate text-muted py-0"
827 onClick={linkEvent(this, this.handleViewSource)}
828 data-tippy-content={i18n.t("view_source")}
829 aria-label={i18n.t("view_source")}
833 classes={classNames({ "text-success": this.state.viewSource })}
841 let locked = this.props.post_view.post.locked;
842 let label = locked ? i18n.t("unlock") : i18n.t("lock");
845 className="btn btn-link btn-animate text-muted py-0"
846 onClick={linkEvent(this, this.handleModLock)}
847 data-tippy-content={label}
852 classes={classNames({ "text-danger": locked })}
859 get featureButton() {
860 const featuredCommunity = this.props.post_view.post.featured_community;
861 const labelCommunity = featuredCommunity
862 ? i18n.t("unfeature_from_community")
863 : i18n.t("feature_in_community");
865 const featuredLocal = this.props.post_view.post.featured_local;
866 const labelLocal = featuredLocal
867 ? i18n.t("unfeature_from_local")
868 : i18n.t("feature_in_local");
872 className="btn btn-link btn-animate text-muted py-0 pl-0"
873 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
874 data-tippy-content={labelCommunity}
875 aria-label={labelCommunity}
879 classes={classNames({ "text-success": featuredCommunity })}
886 className="btn btn-link btn-animate text-muted py-0"
887 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
888 data-tippy-content={labelLocal}
889 aria-label={labelLocal}
893 classes={classNames({ "text-success": featuredLocal })}
903 get modRemoveButton() {
904 let removed = this.props.post_view.post.removed;
907 className="btn btn-link btn-animate text-muted py-0"
910 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
913 {/* TODO: Find an icon for this. */}
914 {!removed ? i18n.t("remove") : i18n.t("restore")}
920 * Mod/Admin actions to be taken against the author.
924 let post_view = this.props.post_view;
926 this.state.showAdvanced && (
930 {!this.creatorIsMod_ &&
931 (!post_view.creator_banned_from_community ? (
933 className="btn btn-link btn-animate text-muted py-0"
936 this.handleModBanFromCommunityShow
938 aria-label={i18n.t("ban_from_community")}
940 {i18n.t("ban_from_community")}
944 className="btn btn-link btn-animate text-muted py-0"
947 this.handleModBanFromCommunitySubmit
949 aria-label={i18n.t("unban")}
954 {!post_view.creator_banned_from_community && (
956 className="btn btn-link btn-animate text-muted py-0"
957 onClick={linkEvent(this, this.handleAddModToCommunity)}
960 ? i18n.t("remove_as_mod")
961 : i18n.t("appoint_as_mod")
965 ? i18n.t("remove_as_mod")
966 : i18n.t("appoint_as_mod")}
971 {/* Community creators and admins can transfer community to another mod */}
972 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
974 this.creatorIsMod_ &&
975 (!this.state.showConfirmTransferCommunity ? (
977 className="btn btn-link btn-animate text-muted py-0"
980 this.handleShowConfirmTransferCommunity
982 aria-label={i18n.t("transfer_community")}
984 {i18n.t("transfer_community")}
989 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
990 aria-label={i18n.t("are_you_sure")}
992 {i18n.t("are_you_sure")}
995 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
996 aria-label={i18n.t("yes")}
997 onClick={linkEvent(this, this.handleTransferCommunity)}
1002 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1005 this.handleCancelShowConfirmTransferCommunity
1007 aria-label={i18n.t("no")}
1013 {/* Admins can ban from all, and appoint other admins */}
1014 {this.canAdmin_ && (
1016 {!this.creatorIsAdmin_ && (
1018 {!isBanned(post_view.creator) ? (
1020 className="btn btn-link btn-animate text-muted py-0"
1021 onClick={linkEvent(this, this.handleModBanShow)}
1022 aria-label={i18n.t("ban_from_site")}
1024 {i18n.t("ban_from_site")}
1028 className="btn btn-link btn-animate text-muted py-0"
1029 onClick={linkEvent(this, this.handleModBanSubmit)}
1030 aria-label={i18n.t("unban_from_site")}
1032 {i18n.t("unban_from_site")}
1036 className="btn btn-link btn-animate text-muted py-0"
1037 onClick={linkEvent(this, this.handlePurgePersonShow)}
1038 aria-label={i18n.t("purge_user")}
1040 {i18n.t("purge_user")}
1043 className="btn btn-link btn-animate text-muted py-0"
1044 onClick={linkEvent(this, this.handlePurgePostShow)}
1045 aria-label={i18n.t("purge_post")}
1047 {i18n.t("purge_post")}
1051 {!isBanned(post_view.creator) && post_view.creator.local && (
1053 className="btn btn-link btn-animate text-muted py-0"
1054 onClick={linkEvent(this, this.handleAddAdmin)}
1056 this.creatorIsAdmin_
1057 ? i18n.t("remove_as_admin")
1058 : i18n.t("appoint_as_admin")
1061 {this.creatorIsAdmin_
1062 ? i18n.t("remove_as_admin")
1063 : i18n.t("appoint_as_admin")}
1073 removeAndBanDialogs() {
1074 let post = this.props.post_view;
1076 this.state.purgeType == PurgeType.Post
1077 ? i18n.t("purge_post")
1078 : `${i18n.t("purge")} ${post.creator.name}`;
1081 {this.state.showRemoveDialog && (
1083 className="form-inline"
1084 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1086 <label className="sr-only" htmlFor="post-listing-remove-reason">
1091 id="post-listing-remove-reason"
1092 className="form-control mr-2"
1093 placeholder={i18n.t("reason")}
1094 value={this.state.removeReason}
1095 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1099 className="btn btn-secondary"
1100 aria-label={i18n.t("remove_post")}
1102 {i18n.t("remove_post")}
1106 {this.state.showBanDialog && (
1107 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1108 <div className="form-group row col-12">
1110 className="col-form-label"
1111 htmlFor="post-listing-ban-reason"
1117 id="post-listing-ban-reason"
1118 className="form-control mr-2"
1119 placeholder={i18n.t("reason")}
1120 value={this.state.banReason}
1121 onInput={linkEvent(this, this.handleModBanReasonChange)}
1123 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1128 id={`mod-ban-expires`}
1129 className="form-control mr-2"
1130 placeholder={i18n.t("number_of_days")}
1131 value={this.state.banExpireDays}
1132 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1134 <div className="form-group">
1135 <div className="form-check">
1137 className="form-check-input"
1138 id="mod-ban-remove-data"
1140 checked={this.state.removeData}
1141 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1144 className="form-check-label"
1145 htmlFor="mod-ban-remove-data"
1146 title={i18n.t("remove_content_more")}
1148 {i18n.t("remove_content")}
1153 {/* TODO hold off on expires until later */}
1154 {/* <div class="form-group row"> */}
1155 {/* <label class="col-form-label">Expires</label> */}
1156 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1158 <div className="form-group row">
1161 className="btn btn-secondary"
1162 aria-label={i18n.t("ban")}
1164 {i18n.t("ban")} {post.creator.name}
1169 {this.state.showReportDialog && (
1171 className="form-inline"
1172 onSubmit={linkEvent(this, this.handleReportSubmit)}
1174 <label className="sr-only" htmlFor="post-report-reason">
1179 id="post-report-reason"
1180 className="form-control mr-2"
1181 placeholder={i18n.t("reason")}
1183 value={this.state.reportReason}
1184 onInput={linkEvent(this, this.handleReportReasonChange)}
1188 className="btn btn-secondary"
1189 aria-label={i18n.t("create_report")}
1191 {i18n.t("create_report")}
1195 {this.state.showPurgeDialog && (
1197 className="form-inline"
1198 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1201 <label className="sr-only" htmlFor="purge-reason">
1207 className="form-control mr-2"
1208 placeholder={i18n.t("reason")}
1209 value={this.state.purgeReason}
1210 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1212 {this.state.purgeLoading ? (
1217 className="btn btn-secondary"
1218 aria-label={purgeTypeText}
1230 let post = this.props.post_view.post;
1231 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1232 <div className="row">
1233 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1234 {this.postTitleLine()}
1236 <div className="col-4">
1237 {/* Post body prev or thumbnail */}
1238 {!this.state.imageExpanded && this.thumbnail()}
1242 this.postTitleLine()
1246 showMobilePreview() {
1247 let body = this.props.post_view.post.body;
1248 return !this.showBody && body ? (
1249 <div className="md-div mb-1 preview-lines">{body}</div>
1258 {/* The mobile view*/}
1259 <div className="d-block d-sm-none">
1260 <div className="row">
1261 <div className="col-12">
1262 {this.createdLine()}
1264 {/* If it has a thumbnail, do a right aligned thumbnail */}
1265 {this.mobileThumbnail()}
1267 {/* Show a preview of the post body */}
1268 {this.showMobilePreview()}
1270 {this.commentsLine(true)}
1271 {this.userActionsLine()}
1272 {this.duplicatesLine()}
1273 {this.removeAndBanDialogs()}
1278 {/* The larger view*/}
1279 <div className="d-none d-sm-block">
1280 <div className="row">
1281 {!this.props.viewOnly && this.voteBar()}
1282 <div className="col-sm-2 pr-0">
1283 <div className="">{this.thumbnail()}</div>
1285 <div className="col-12 col-sm-9">
1286 <div className="row">
1287 <div className="col-12">
1288 {this.postTitleLine()}
1289 {this.createdLine()}
1290 {this.commentsLine()}
1291 {this.duplicatesLine()}
1292 {this.userActionsLine()}
1293 {this.removeAndBanDialogs()}
1303 private get myPost(): boolean {
1305 this.props.post_view.creator.id ==
1306 UserService.Instance.myUserInfo?.local_user_view.person.id
1310 handlePostLike(event: any) {
1311 event.preventDefault();
1312 if (!UserService.Instance.myUserInfo) {
1313 this.context.router.history.push(`/login`);
1316 let myVote = this.state.my_vote;
1317 let newVote = myVote == 1 ? 0 : 1;
1321 score: this.state.score - 1n,
1322 upvotes: this.state.upvotes - 1n,
1324 } else if (myVote == -1) {
1326 score: this.state.score + 2n,
1327 upvotes: this.state.upvotes + 1n,
1328 downvotes: this.state.downvotes - 1n,
1332 score: this.state.score + 1n,
1333 upvotes: this.state.upvotes + 1n,
1337 this.setState({ my_vote: newVote });
1339 let auth = myAuth();
1341 let form: CreatePostLike = {
1342 post_id: this.props.post_view.post.id,
1347 WebSocketService.Instance.send(wsClient.likePost(form));
1348 this.setState(this.state);
1353 handlePostDisLike(event: any) {
1354 event.preventDefault();
1355 if (!UserService.Instance.myUserInfo) {
1356 this.context.router.history.push(`/login`);
1359 let myVote = this.state.my_vote;
1360 let newVote = myVote == -1 ? 0 : -1;
1364 score: this.state.score - 2n,
1365 upvotes: this.state.upvotes - 1n,
1366 downvotes: this.state.downvotes + 1n,
1368 } else if (myVote == -1) {
1370 score: this.state.score + 1n,
1371 downvotes: this.state.downvotes - 1n,
1375 score: this.state.score - 1n,
1376 downvotes: this.state.downvotes + 1n,
1380 this.setState({ my_vote: newVote });
1382 let auth = myAuth();
1384 let form: CreatePostLike = {
1385 post_id: this.props.post_view.post.id,
1390 WebSocketService.Instance.send(wsClient.likePost(form));
1391 this.setState(this.state);
1396 handleEditClick(i: PostListing) {
1397 i.setState({ showEdit: true });
1400 handleEditCancel() {
1401 this.setState({ showEdit: false });
1404 // The actual editing is done in the recieve for post
1406 this.setState({ showEdit: false });
1409 handleShowReportDialog(i: PostListing) {
1410 i.setState({ showReportDialog: !i.state.showReportDialog });
1413 handleReportReasonChange(i: PostListing, event: any) {
1414 i.setState({ reportReason: event.target.value });
1417 handleReportSubmit(i: PostListing, event: any) {
1418 event.preventDefault();
1419 let auth = myAuth();
1420 let reason = i.state.reportReason;
1421 if (auth && reason) {
1422 let form: CreatePostReport = {
1423 post_id: i.props.post_view.post.id,
1427 WebSocketService.Instance.send(wsClient.createPostReport(form));
1429 i.setState({ showReportDialog: false });
1433 handleBlockUserClick(i: PostListing) {
1434 let auth = myAuth();
1436 let blockUserForm: BlockPerson = {
1437 person_id: i.props.post_view.creator.id,
1441 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1445 handleDeleteClick(i: PostListing) {
1446 let auth = myAuth();
1448 let deleteForm: DeletePost = {
1449 post_id: i.props.post_view.post.id,
1450 deleted: !i.props.post_view.post.deleted,
1453 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1457 handleSavePostClick(i: PostListing) {
1458 let auth = myAuth();
1461 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1462 let form: SavePost = {
1463 post_id: i.props.post_view.post.id,
1467 WebSocketService.Instance.send(wsClient.savePost(form));
1471 get crossPostParams(): PostFormParams {
1472 const queryParams: PostFormParams = {};
1473 const { name, url } = this.props.post_view.post;
1475 queryParams.name = name;
1478 queryParams.url = url;
1481 const crossPostBody = this.crossPostBody();
1482 if (crossPostBody) {
1483 queryParams.body = crossPostBody;
1489 crossPostBody(): string | undefined {
1490 let post = this.props.post_view.post;
1491 let body = post.body;
1494 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1501 get showBody(): boolean {
1502 return this.props.showBody || this.state.showBody;
1505 handleModRemoveShow(i: PostListing) {
1507 showRemoveDialog: !i.state.showRemoveDialog,
1508 showBanDialog: false,
1512 handleModRemoveReasonChange(i: PostListing, event: any) {
1513 i.setState({ removeReason: event.target.value });
1516 handleModRemoveDataChange(i: PostListing, event: any) {
1517 i.setState({ removeData: event.target.checked });
1520 handleModRemoveSubmit(i: PostListing, event: any) {
1521 event.preventDefault();
1523 let auth = myAuth();
1525 let form: RemovePost = {
1526 post_id: i.props.post_view.post.id,
1527 removed: !i.props.post_view.post.removed,
1528 reason: i.state.removeReason,
1531 WebSocketService.Instance.send(wsClient.removePost(form));
1532 i.setState({ showRemoveDialog: false });
1536 handleModLock(i: PostListing) {
1537 let auth = myAuth();
1539 let form: LockPost = {
1540 post_id: i.props.post_view.post.id,
1541 locked: !i.props.post_view.post.locked,
1544 WebSocketService.Instance.send(wsClient.lockPost(form));
1548 handleModFeaturePostLocal(i: PostListing) {
1549 let auth = myAuth();
1551 let form: FeaturePost = {
1552 post_id: i.props.post_view.post.id,
1553 feature_type: "Local",
1554 featured: !i.props.post_view.post.featured_local,
1557 WebSocketService.Instance.send(wsClient.featurePost(form));
1561 handleModFeaturePostCommunity(i: PostListing) {
1562 let auth = myAuth();
1564 let form: FeaturePost = {
1565 post_id: i.props.post_view.post.id,
1566 feature_type: "Community",
1567 featured: !i.props.post_view.post.featured_community,
1570 WebSocketService.Instance.send(wsClient.featurePost(form));
1574 handleModBanFromCommunityShow(i: PostListing) {
1576 showBanDialog: true,
1577 banType: BanType.Community,
1578 showRemoveDialog: false,
1582 handleModBanShow(i: PostListing) {
1584 showBanDialog: true,
1585 banType: BanType.Site,
1586 showRemoveDialog: false,
1590 handlePurgePersonShow(i: PostListing) {
1592 showPurgeDialog: true,
1593 purgeType: PurgeType.Person,
1594 showRemoveDialog: false,
1598 handlePurgePostShow(i: PostListing) {
1600 showPurgeDialog: true,
1601 purgeType: PurgeType.Post,
1602 showRemoveDialog: false,
1606 handlePurgeReasonChange(i: PostListing, event: any) {
1607 i.setState({ purgeReason: event.target.value });
1610 handlePurgeSubmit(i: PostListing, event: any) {
1611 event.preventDefault();
1613 let auth = myAuth();
1615 if (i.state.purgeType == PurgeType.Person) {
1616 let form: PurgePerson = {
1617 person_id: i.props.post_view.creator.id,
1618 reason: i.state.purgeReason,
1621 WebSocketService.Instance.send(wsClient.purgePerson(form));
1622 } else if (i.state.purgeType == PurgeType.Post) {
1623 let form: PurgePost = {
1624 post_id: i.props.post_view.post.id,
1625 reason: i.state.purgeReason,
1628 WebSocketService.Instance.send(wsClient.purgePost(form));
1631 i.setState({ purgeLoading: true });
1635 handleModBanReasonChange(i: PostListing, event: any) {
1636 i.setState({ banReason: event.target.value });
1639 handleModBanExpireDaysChange(i: PostListing, event: any) {
1640 i.setState({ banExpireDays: event.target.value });
1643 handleModBanFromCommunitySubmit(i: PostListing) {
1644 i.setState({ banType: BanType.Community });
1645 i.handleModBanBothSubmit(i);
1648 handleModBanSubmit(i: PostListing) {
1649 i.setState({ banType: BanType.Site });
1650 i.handleModBanBothSubmit(i);
1653 handleModBanBothSubmit(i: PostListing, event?: any) {
1654 if (event) event.preventDefault();
1655 let auth = myAuth();
1657 let ban = !i.props.post_view.creator_banned_from_community;
1658 let person_id = i.props.post_view.creator.id;
1659 let remove_data = i.state.removeData;
1660 let reason = i.state.banReason;
1661 let expires = futureDaysToUnixTime(i.state.banExpireDays);
1663 if (i.state.banType == BanType.Community) {
1664 // If its an unban, restore all their data
1666 i.setState({ removeData: false });
1669 let form: BanFromCommunity = {
1671 community_id: i.props.post_view.community.id,
1678 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1680 // If its an unban, restore all their data
1681 let ban = !i.props.post_view.creator.banned;
1683 i.setState({ removeData: false });
1685 let form: BanPerson = {
1693 WebSocketService.Instance.send(wsClient.banPerson(form));
1696 i.setState({ showBanDialog: false });
1700 handleAddModToCommunity(i: PostListing) {
1701 let auth = myAuth();
1703 let form: AddModToCommunity = {
1704 person_id: i.props.post_view.creator.id,
1705 community_id: i.props.post_view.community.id,
1706 added: !i.creatorIsMod_,
1709 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1710 i.setState(i.state);
1714 handleAddAdmin(i: PostListing) {
1715 let auth = myAuth();
1717 let form: AddAdmin = {
1718 person_id: i.props.post_view.creator.id,
1719 added: !i.creatorIsAdmin_,
1722 WebSocketService.Instance.send(wsClient.addAdmin(form));
1723 i.setState(i.state);
1727 handleShowConfirmTransferCommunity(i: PostListing) {
1728 i.setState({ showConfirmTransferCommunity: true });
1731 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1732 i.setState({ showConfirmTransferCommunity: false });
1735 handleTransferCommunity(i: PostListing) {
1736 let auth = myAuth();
1738 let form: TransferCommunity = {
1739 community_id: i.props.post_view.community.id,
1740 person_id: i.props.post_view.creator.id,
1743 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1744 i.setState({ showConfirmTransferCommunity: false });
1748 handleShowConfirmTransferSite(i: PostListing) {
1749 i.setState({ showConfirmTransferSite: true });
1752 handleCancelShowConfirmTransferSite(i: PostListing) {
1753 i.setState({ showConfirmTransferSite: false });
1756 handleImageExpandClick(i: PostListing, event: any) {
1757 event.preventDefault();
1758 i.setState({ imageExpanded: !i.state.imageExpanded });
1762 handleViewSource(i: PostListing) {
1763 i.setState({ viewSource: !i.state.viewSource });
1766 handleShowAdvanced(i: PostListing) {
1767 i.setState({ showAdvanced: !i.state.showAdvanced });
1771 handleShowMoreMobile(i: PostListing) {
1773 showMoreMobile: !i.state.showMoreMobile,
1774 showAdvanced: !i.state.showAdvanced,
1779 handleShowBody(i: PostListing) {
1780 i.setState({ showBody: !i.state.showBody });
1784 get pointsTippy(): string {
1785 let points = i18n.t("number_of_points", {
1786 count: Number(this.state.score),
1787 formattedCount: Number(this.state.score),
1790 let upvotes = i18n.t("number_of_upvotes", {
1791 count: Number(this.state.upvotes),
1792 formattedCount: Number(this.state.upvotes),
1795 let downvotes = i18n.t("number_of_downvotes", {
1796 count: Number(this.state.downvotes),
1797 formattedCount: Number(this.state.downvotes),
1800 return `${points} • ${upvotes} • ${downvotes}`;
1803 get canModOnSelf_(): boolean {
1805 this.props.post_view.creator.id,
1806 this.props.moderators,
1813 get canMod_(): boolean {
1815 this.props.post_view.creator.id,
1816 this.props.moderators,
1821 get canAdmin_(): boolean {
1822 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1825 get creatorIsMod_(): boolean {
1826 return isMod(this.props.post_view.creator.id, this.props.moderators);
1829 get creatorIsAdmin_(): boolean {
1830 return isAdmin(this.props.post_view.creator.id, this.props.admins);