1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
10 CommunityModeratorView,
25 } from "lemmy-js-client";
26 import { externalHost } from "../../env";
27 import { i18n } from "../../i18next";
28 import { BanType, PurgeType } from "../../interfaces";
29 import { UserService, WebSocketService } from "../../services";
53 import { Icon, PurgeWarning, Spinner } from "../common/icon";
54 import { MomentTime } from "../common/moment-time";
55 import { PictrsImage } from "../common/pictrs-image";
56 import { CommunityLink } from "../community/community-link";
57 import { PersonListing } from "../person/person-listing";
58 import { MetadataCard } from "./metadata-card";
59 import { PostForm } from "./post-form";
61 interface PostListingState {
63 showRemoveDialog: boolean;
64 showPurgeDialog: boolean;
66 purgeType?: PurgeType;
67 purgeLoading: boolean;
68 removeReason?: string;
69 showBanDialog: boolean;
71 banExpireDays?: number;
74 showConfirmTransferSite: boolean;
75 showConfirmTransferCommunity: boolean;
76 imageExpanded: boolean;
78 showAdvanced: boolean;
79 showMoreMobile: boolean;
81 showReportDialog: boolean;
82 reportReason?: string;
89 interface PostListingProps {
91 duplicates?: PostView[];
92 moderators?: CommunityModeratorView[];
93 admins?: PersonViewSafe[];
94 allLanguages: Language[];
95 siteLanguages: number[];
96 showCommunity?: boolean;
99 enableDownvotes?: boolean;
100 enableNsfw?: boolean;
104 export class PostListing extends Component<PostListingProps, PostListingState> {
105 state: PostListingState = {
107 showRemoveDialog: false,
108 showPurgeDialog: false,
109 purgeType: PurgeType.Person,
111 showBanDialog: false,
112 banType: BanType.Community,
114 showConfirmTransferSite: false,
115 showConfirmTransferCommunity: false,
116 imageExpanded: false,
119 showMoreMobile: false,
121 showReportDialog: false,
122 my_vote: this.props.post_view.my_vote,
123 score: this.props.post_view.counts.score,
124 upvotes: this.props.post_view.counts.upvotes,
125 downvotes: this.props.post_view.counts.downvotes,
128 constructor(props: any, context: any) {
129 super(props, context);
131 this.handlePostLike = this.handlePostLike.bind(this);
132 this.handlePostDisLike = this.handlePostDisLike.bind(this);
133 this.handleEditPost = this.handleEditPost.bind(this);
134 this.handleEditCancel = this.handleEditCancel.bind(this);
137 componentWillReceiveProps(nextProps: PostListingProps) {
139 my_vote: nextProps.post_view.my_vote,
140 upvotes: nextProps.post_view.counts.upvotes,
141 downvotes: nextProps.post_view.counts.downvotes,
142 score: nextProps.post_view.counts.score,
144 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
145 this.setState({ imageExpanded: false });
150 let 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) == externalHost) && (
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: post_view.counts.comments,
641 formattedCount: 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: 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(): number | undefined {
663 let pv = this.props.post_view;
664 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
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 === 0,
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"
737 to={`/create_post${this.crossPostParams}`}
738 title={i18n.t("cross_post")}
740 <Icon icon="copy" inline />
748 className="btn btn-link btn-animate text-muted py-0"
749 onClick={linkEvent(this, this.handleShowReportDialog)}
750 data-tippy-content={i18n.t("show_report_dialog")}
751 aria-label={i18n.t("show_report_dialog")}
753 <Icon icon="flag" inline />
761 className="btn btn-link btn-animate text-muted py-0"
762 onClick={linkEvent(this, this.handleBlockUserClick)}
763 data-tippy-content={i18n.t("block_user")}
764 aria-label={i18n.t("block_user")}
766 <Icon icon="slash" inline />
774 className="btn btn-link btn-animate text-muted py-0"
775 onClick={linkEvent(this, this.handleEditClick)}
776 data-tippy-content={i18n.t("edit")}
777 aria-label={i18n.t("edit")}
779 <Icon icon="edit" inline />
785 let deleted = this.props.post_view.post.deleted;
786 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
789 className="btn btn-link btn-animate text-muted py-0"
790 onClick={linkEvent(this, this.handleDeleteClick)}
791 data-tippy-content={label}
796 classes={classNames({ "text-danger": deleted })}
803 get showMoreButton() {
806 className="btn btn-link btn-animate text-muted py-0"
807 onClick={linkEvent(this, this.handleShowAdvanced)}
808 data-tippy-content={i18n.t("more")}
809 aria-label={i18n.t("more")}
811 <Icon icon="more-vertical" inline />
816 get viewSourceButton() {
819 className="btn btn-link btn-animate text-muted py-0"
820 onClick={linkEvent(this, this.handleViewSource)}
821 data-tippy-content={i18n.t("view_source")}
822 aria-label={i18n.t("view_source")}
826 classes={classNames({ "text-success": this.state.viewSource })}
834 let locked = this.props.post_view.post.locked;
835 let label = locked ? i18n.t("unlock") : i18n.t("lock");
838 className="btn btn-link btn-animate text-muted py-0"
839 onClick={linkEvent(this, this.handleModLock)}
840 data-tippy-content={label}
845 classes={classNames({ "text-danger": locked })}
852 get featureButton() {
853 const featuredCommunity = this.props.post_view.post.featured_community;
854 const labelCommunity = featuredCommunity
855 ? i18n.t("unfeature_from_community")
856 : i18n.t("feature_in_community");
858 const featuredLocal = this.props.post_view.post.featured_local;
859 const labelLocal = featuredLocal
860 ? i18n.t("unfeature_from_local")
861 : i18n.t("feature_in_local");
865 className="btn btn-link btn-animate text-muted py-0 pl-0"
866 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
867 data-tippy-content={labelCommunity}
868 aria-label={labelCommunity}
872 classes={classNames({ "text-success": featuredCommunity })}
879 className="btn btn-link btn-animate text-muted py-0"
880 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
881 data-tippy-content={labelLocal}
882 aria-label={labelLocal}
886 classes={classNames({ "text-success": featuredLocal })}
896 get modRemoveButton() {
897 let removed = this.props.post_view.post.removed;
900 className="btn btn-link btn-animate text-muted py-0"
903 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
906 {/* TODO: Find an icon for this. */}
907 {!removed ? i18n.t("remove") : i18n.t("restore")}
913 * Mod/Admin actions to be taken against the author.
917 let post_view = this.props.post_view;
919 this.state.showAdvanced && (
923 {!this.creatorIsMod_ &&
924 (!post_view.creator_banned_from_community ? (
926 className="btn btn-link btn-animate text-muted py-0"
929 this.handleModBanFromCommunityShow
931 aria-label={i18n.t("ban_from_community")}
933 {i18n.t("ban_from_community")}
937 className="btn btn-link btn-animate text-muted py-0"
940 this.handleModBanFromCommunitySubmit
942 aria-label={i18n.t("unban")}
947 {!post_view.creator_banned_from_community && (
949 className="btn btn-link btn-animate text-muted py-0"
950 onClick={linkEvent(this, this.handleAddModToCommunity)}
953 ? i18n.t("remove_as_mod")
954 : i18n.t("appoint_as_mod")
958 ? i18n.t("remove_as_mod")
959 : i18n.t("appoint_as_mod")}
964 {/* Community creators and admins can transfer community to another mod */}
965 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
967 this.creatorIsMod_ &&
968 (!this.state.showConfirmTransferCommunity ? (
970 className="btn btn-link btn-animate text-muted py-0"
973 this.handleShowConfirmTransferCommunity
975 aria-label={i18n.t("transfer_community")}
977 {i18n.t("transfer_community")}
982 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
983 aria-label={i18n.t("are_you_sure")}
985 {i18n.t("are_you_sure")}
988 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
989 aria-label={i18n.t("yes")}
990 onClick={linkEvent(this, this.handleTransferCommunity)}
995 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
998 this.handleCancelShowConfirmTransferCommunity
1000 aria-label={i18n.t("no")}
1006 {/* Admins can ban from all, and appoint other admins */}
1007 {this.canAdmin_ && (
1009 {!this.creatorIsAdmin_ && (
1011 {!isBanned(post_view.creator) ? (
1013 className="btn btn-link btn-animate text-muted py-0"
1014 onClick={linkEvent(this, this.handleModBanShow)}
1015 aria-label={i18n.t("ban_from_site")}
1017 {i18n.t("ban_from_site")}
1021 className="btn btn-link btn-animate text-muted py-0"
1022 onClick={linkEvent(this, this.handleModBanSubmit)}
1023 aria-label={i18n.t("unban_from_site")}
1025 {i18n.t("unban_from_site")}
1029 className="btn btn-link btn-animate text-muted py-0"
1030 onClick={linkEvent(this, this.handlePurgePersonShow)}
1031 aria-label={i18n.t("purge_user")}
1033 {i18n.t("purge_user")}
1036 className="btn btn-link btn-animate text-muted py-0"
1037 onClick={linkEvent(this, this.handlePurgePostShow)}
1038 aria-label={i18n.t("purge_post")}
1040 {i18n.t("purge_post")}
1044 {!isBanned(post_view.creator) && post_view.creator.local && (
1046 className="btn btn-link btn-animate text-muted py-0"
1047 onClick={linkEvent(this, this.handleAddAdmin)}
1049 this.creatorIsAdmin_
1050 ? i18n.t("remove_as_admin")
1051 : i18n.t("appoint_as_admin")
1054 {this.creatorIsAdmin_
1055 ? i18n.t("remove_as_admin")
1056 : i18n.t("appoint_as_admin")}
1066 removeAndBanDialogs() {
1067 let post = this.props.post_view;
1069 this.state.purgeType == PurgeType.Post
1070 ? i18n.t("purge_post")
1071 : `${i18n.t("purge")} ${post.creator.name}`;
1074 {this.state.showRemoveDialog && (
1076 className="form-inline"
1077 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1079 <label className="sr-only" htmlFor="post-listing-remove-reason">
1084 id="post-listing-remove-reason"
1085 className="form-control mr-2"
1086 placeholder={i18n.t("reason")}
1087 value={this.state.removeReason}
1088 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1092 className="btn btn-secondary"
1093 aria-label={i18n.t("remove_post")}
1095 {i18n.t("remove_post")}
1099 {this.state.showBanDialog && (
1100 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1101 <div className="form-group row col-12">
1103 className="col-form-label"
1104 htmlFor="post-listing-ban-reason"
1110 id="post-listing-ban-reason"
1111 className="form-control mr-2"
1112 placeholder={i18n.t("reason")}
1113 value={this.state.banReason}
1114 onInput={linkEvent(this, this.handleModBanReasonChange)}
1116 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1121 id={`mod-ban-expires`}
1122 className="form-control mr-2"
1123 placeholder={i18n.t("number_of_days")}
1124 value={this.state.banExpireDays}
1125 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1127 <div className="form-group">
1128 <div className="form-check">
1130 className="form-check-input"
1131 id="mod-ban-remove-data"
1133 checked={this.state.removeData}
1134 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1137 className="form-check-label"
1138 htmlFor="mod-ban-remove-data"
1139 title={i18n.t("remove_content_more")}
1141 {i18n.t("remove_content")}
1146 {/* TODO hold off on expires until later */}
1147 {/* <div class="form-group row"> */}
1148 {/* <label class="col-form-label">Expires</label> */}
1149 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1151 <div className="form-group row">
1154 className="btn btn-secondary"
1155 aria-label={i18n.t("ban")}
1157 {i18n.t("ban")} {post.creator.name}
1162 {this.state.showReportDialog && (
1164 className="form-inline"
1165 onSubmit={linkEvent(this, this.handleReportSubmit)}
1167 <label className="sr-only" htmlFor="post-report-reason">
1172 id="post-report-reason"
1173 className="form-control mr-2"
1174 placeholder={i18n.t("reason")}
1176 value={this.state.reportReason}
1177 onInput={linkEvent(this, this.handleReportReasonChange)}
1181 className="btn btn-secondary"
1182 aria-label={i18n.t("create_report")}
1184 {i18n.t("create_report")}
1188 {this.state.showPurgeDialog && (
1190 className="form-inline"
1191 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1194 <label className="sr-only" htmlFor="purge-reason">
1200 className="form-control mr-2"
1201 placeholder={i18n.t("reason")}
1202 value={this.state.purgeReason}
1203 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1205 {this.state.purgeLoading ? (
1210 className="btn btn-secondary"
1211 aria-label={purgeTypeText}
1223 let post = this.props.post_view.post;
1224 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1225 <div className="row">
1226 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1227 {this.postTitleLine()}
1229 <div className="col-4">
1230 {/* Post body prev or thumbnail */}
1231 {!this.state.imageExpanded && this.thumbnail()}
1235 this.postTitleLine()
1239 showMobilePreview() {
1240 let body = this.props.post_view.post.body;
1241 return !this.showBody && body ? (
1242 <div className="md-div mb-1 preview-lines">{body}</div>
1251 {/* The mobile view*/}
1252 <div className="d-block d-sm-none">
1253 <div className="row">
1254 <div className="col-12">
1255 {this.createdLine()}
1257 {/* If it has a thumbnail, do a right aligned thumbnail */}
1258 {this.mobileThumbnail()}
1260 {/* Show a preview of the post body */}
1261 {this.showMobilePreview()}
1263 {this.commentsLine(true)}
1264 {this.userActionsLine()}
1265 {this.duplicatesLine()}
1266 {this.removeAndBanDialogs()}
1271 {/* The larger view*/}
1272 <div className="d-none d-sm-block">
1273 <div className="row">
1274 {!this.props.viewOnly && this.voteBar()}
1275 <div className="col-sm-2 pr-0">
1276 <div className="">{this.thumbnail()}</div>
1278 <div className="col-12 col-sm-9">
1279 <div className="row">
1280 <div className="col-12">
1281 {this.postTitleLine()}
1282 {this.createdLine()}
1283 {this.commentsLine()}
1284 {this.duplicatesLine()}
1285 {this.userActionsLine()}
1286 {this.removeAndBanDialogs()}
1296 private get myPost(): boolean {
1298 this.props.post_view.creator.id ==
1299 UserService.Instance.myUserInfo?.local_user_view.person.id
1303 handlePostLike(event: any) {
1304 event.preventDefault();
1305 if (!UserService.Instance.myUserInfo) {
1306 this.context.router.history.push(`/login`);
1309 let myVote = this.state.my_vote;
1310 let newVote = myVote == 1 ? 0 : 1;
1314 score: this.state.score - 1,
1315 upvotes: this.state.upvotes - 1,
1317 } else if (myVote == -1) {
1319 score: this.state.score + 2,
1320 upvotes: this.state.upvotes + 1,
1321 downvotes: this.state.downvotes - 1,
1325 score: this.state.score + 1,
1326 upvotes: this.state.upvotes + 1,
1330 this.setState({ my_vote: newVote });
1332 let auth = myAuth();
1334 let form: CreatePostLike = {
1335 post_id: this.props.post_view.post.id,
1340 WebSocketService.Instance.send(wsClient.likePost(form));
1341 this.setState(this.state);
1346 handlePostDisLike(event: any) {
1347 event.preventDefault();
1348 if (!UserService.Instance.myUserInfo) {
1349 this.context.router.history.push(`/login`);
1352 let myVote = this.state.my_vote;
1353 let newVote = myVote == -1 ? 0 : -1;
1357 score: this.state.score - 2,
1358 upvotes: this.state.upvotes - 1,
1359 downvotes: this.state.downvotes + 1,
1361 } else if (myVote == -1) {
1363 score: this.state.score + 1,
1364 downvotes: this.state.downvotes - 1,
1368 score: this.state.score - 1,
1369 downvotes: this.state.downvotes + 1,
1373 this.setState({ my_vote: newVote });
1375 let auth = myAuth();
1377 let form: CreatePostLike = {
1378 post_id: this.props.post_view.post.id,
1383 WebSocketService.Instance.send(wsClient.likePost(form));
1384 this.setState(this.state);
1389 handleEditClick(i: PostListing) {
1390 i.setState({ showEdit: true });
1393 handleEditCancel() {
1394 this.setState({ showEdit: false });
1397 // The actual editing is done in the recieve for post
1399 this.setState({ showEdit: false });
1402 handleShowReportDialog(i: PostListing) {
1403 i.setState({ showReportDialog: !i.state.showReportDialog });
1406 handleReportReasonChange(i: PostListing, event: any) {
1407 i.setState({ reportReason: event.target.value });
1410 handleReportSubmit(i: PostListing, event: any) {
1411 event.preventDefault();
1412 let auth = myAuth();
1413 let reason = i.state.reportReason;
1414 if (auth && reason) {
1415 let form: CreatePostReport = {
1416 post_id: i.props.post_view.post.id,
1420 WebSocketService.Instance.send(wsClient.createPostReport(form));
1422 i.setState({ showReportDialog: false });
1426 handleBlockUserClick(i: PostListing) {
1427 let auth = myAuth();
1429 let blockUserForm: BlockPerson = {
1430 person_id: i.props.post_view.creator.id,
1434 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1438 handleDeleteClick(i: PostListing) {
1439 let auth = myAuth();
1441 let deleteForm: DeletePost = {
1442 post_id: i.props.post_view.post.id,
1443 deleted: !i.props.post_view.post.deleted,
1446 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1450 handleSavePostClick(i: PostListing) {
1451 let auth = myAuth();
1454 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1455 let form: SavePost = {
1456 post_id: i.props.post_view.post.id,
1460 WebSocketService.Instance.send(wsClient.savePost(form));
1464 get crossPostParams(): string {
1465 let post = this.props.post_view.post;
1466 let params = `?title=${encodeURIComponent(post.name)}`;
1469 params += `&url=${encodeURIComponent(post.url)}`;
1471 let crossPostBody = this.crossPostBody();
1472 if (crossPostBody) {
1473 params += `&body=${encodeURIComponent(crossPostBody)}`;
1478 crossPostBody(): string | undefined {
1479 let post = this.props.post_view.post;
1480 let body = post.body;
1483 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1490 get showBody(): boolean {
1491 return this.props.showBody || this.state.showBody;
1494 handleModRemoveShow(i: PostListing) {
1496 showRemoveDialog: !i.state.showRemoveDialog,
1497 showBanDialog: false,
1501 handleModRemoveReasonChange(i: PostListing, event: any) {
1502 i.setState({ removeReason: event.target.value });
1505 handleModRemoveDataChange(i: PostListing, event: any) {
1506 i.setState({ removeData: event.target.checked });
1509 handleModRemoveSubmit(i: PostListing, event: any) {
1510 event.preventDefault();
1512 let auth = myAuth();
1514 let form: RemovePost = {
1515 post_id: i.props.post_view.post.id,
1516 removed: !i.props.post_view.post.removed,
1517 reason: i.state.removeReason,
1520 WebSocketService.Instance.send(wsClient.removePost(form));
1521 i.setState({ showRemoveDialog: false });
1525 handleModLock(i: PostListing) {
1526 let auth = myAuth();
1528 let form: LockPost = {
1529 post_id: i.props.post_view.post.id,
1530 locked: !i.props.post_view.post.locked,
1533 WebSocketService.Instance.send(wsClient.lockPost(form));
1537 handleModFeaturePostLocal(i: PostListing) {
1538 let auth = myAuth();
1540 let form: FeaturePost = {
1541 post_id: i.props.post_view.post.id,
1542 feature_type: PostFeatureType.Local,
1543 featured: !i.props.post_view.post.featured_local,
1546 WebSocketService.Instance.send(wsClient.featurePost(form));
1550 handleModFeaturePostCommunity(i: PostListing) {
1551 let auth = myAuth();
1553 let form: FeaturePost = {
1554 post_id: i.props.post_view.post.id,
1555 feature_type: PostFeatureType.Community,
1556 featured: !i.props.post_view.post.featured_community,
1559 WebSocketService.Instance.send(wsClient.featurePost(form));
1563 handleModBanFromCommunityShow(i: PostListing) {
1565 showBanDialog: true,
1566 banType: BanType.Community,
1567 showRemoveDialog: false,
1571 handleModBanShow(i: PostListing) {
1573 showBanDialog: true,
1574 banType: BanType.Site,
1575 showRemoveDialog: false,
1579 handlePurgePersonShow(i: PostListing) {
1581 showPurgeDialog: true,
1582 purgeType: PurgeType.Person,
1583 showRemoveDialog: false,
1587 handlePurgePostShow(i: PostListing) {
1589 showPurgeDialog: true,
1590 purgeType: PurgeType.Post,
1591 showRemoveDialog: false,
1595 handlePurgeReasonChange(i: PostListing, event: any) {
1596 i.setState({ purgeReason: event.target.value });
1599 handlePurgeSubmit(i: PostListing, event: any) {
1600 event.preventDefault();
1602 let auth = myAuth();
1604 if (i.state.purgeType == PurgeType.Person) {
1605 let form: PurgePerson = {
1606 person_id: i.props.post_view.creator.id,
1607 reason: i.state.purgeReason,
1610 WebSocketService.Instance.send(wsClient.purgePerson(form));
1611 } else if (i.state.purgeType == PurgeType.Post) {
1612 let form: PurgePost = {
1613 post_id: i.props.post_view.post.id,
1614 reason: i.state.purgeReason,
1617 WebSocketService.Instance.send(wsClient.purgePost(form));
1620 i.setState({ purgeLoading: true });
1624 handleModBanReasonChange(i: PostListing, event: any) {
1625 i.setState({ banReason: event.target.value });
1628 handleModBanExpireDaysChange(i: PostListing, event: any) {
1629 i.setState({ banExpireDays: event.target.value });
1632 handleModBanFromCommunitySubmit(i: PostListing) {
1633 i.setState({ banType: BanType.Community });
1634 i.handleModBanBothSubmit(i);
1637 handleModBanSubmit(i: PostListing) {
1638 i.setState({ banType: BanType.Site });
1639 i.handleModBanBothSubmit(i);
1642 handleModBanBothSubmit(i: PostListing, event?: any) {
1643 if (event) event.preventDefault();
1644 let auth = myAuth();
1646 let ban = !i.props.post_view.creator_banned_from_community;
1647 let person_id = i.props.post_view.creator.id;
1648 let remove_data = i.state.removeData;
1649 let reason = i.state.banReason;
1650 let expires = futureDaysToUnixTime(i.state.banExpireDays);
1652 if (i.state.banType == BanType.Community) {
1653 // If its an unban, restore all their data
1655 i.setState({ removeData: false });
1658 let form: BanFromCommunity = {
1660 community_id: i.props.post_view.community.id,
1667 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1669 // If its an unban, restore all their data
1670 let ban = !i.props.post_view.creator.banned;
1672 i.setState({ removeData: false });
1674 let form: BanPerson = {
1682 WebSocketService.Instance.send(wsClient.banPerson(form));
1685 i.setState({ showBanDialog: false });
1689 handleAddModToCommunity(i: PostListing) {
1690 let auth = myAuth();
1692 let form: AddModToCommunity = {
1693 person_id: i.props.post_view.creator.id,
1694 community_id: i.props.post_view.community.id,
1695 added: !i.creatorIsMod_,
1698 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1699 i.setState(i.state);
1703 handleAddAdmin(i: PostListing) {
1704 let auth = myAuth();
1706 let form: AddAdmin = {
1707 person_id: i.props.post_view.creator.id,
1708 added: !i.creatorIsAdmin_,
1711 WebSocketService.Instance.send(wsClient.addAdmin(form));
1712 i.setState(i.state);
1716 handleShowConfirmTransferCommunity(i: PostListing) {
1717 i.setState({ showConfirmTransferCommunity: true });
1720 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1721 i.setState({ showConfirmTransferCommunity: false });
1724 handleTransferCommunity(i: PostListing) {
1725 let auth = myAuth();
1727 let form: TransferCommunity = {
1728 community_id: i.props.post_view.community.id,
1729 person_id: i.props.post_view.creator.id,
1732 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1733 i.setState({ showConfirmTransferCommunity: false });
1737 handleShowConfirmTransferSite(i: PostListing) {
1738 i.setState({ showConfirmTransferSite: true });
1741 handleCancelShowConfirmTransferSite(i: PostListing) {
1742 i.setState({ showConfirmTransferSite: false });
1745 handleImageExpandClick(i: PostListing, event: any) {
1746 event.preventDefault();
1747 i.setState({ imageExpanded: !i.state.imageExpanded });
1751 handleViewSource(i: PostListing) {
1752 i.setState({ viewSource: !i.state.viewSource });
1755 handleShowAdvanced(i: PostListing) {
1756 i.setState({ showAdvanced: !i.state.showAdvanced });
1760 handleShowMoreMobile(i: PostListing) {
1762 showMoreMobile: !i.state.showMoreMobile,
1763 showAdvanced: !i.state.showAdvanced,
1768 handleShowBody(i: PostListing) {
1769 i.setState({ showBody: !i.state.showBody });
1773 get pointsTippy(): string {
1774 let points = i18n.t("number_of_points", {
1775 count: this.state.score,
1776 formattedCount: this.state.score,
1779 let upvotes = i18n.t("number_of_upvotes", {
1780 count: this.state.upvotes,
1781 formattedCount: this.state.upvotes,
1784 let downvotes = i18n.t("number_of_downvotes", {
1785 count: this.state.downvotes,
1786 formattedCount: this.state.downvotes,
1789 return `${points} • ${upvotes} • ${downvotes}`;
1792 get canModOnSelf_(): boolean {
1794 this.props.post_view.creator.id,
1795 this.props.moderators,
1802 get canMod_(): boolean {
1804 this.props.post_view.creator.id,
1805 this.props.moderators,
1810 get canAdmin_(): boolean {
1811 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1814 get creatorIsMod_(): boolean {
1815 return isMod(this.props.post_view.creator.id, this.props.moderators);
1818 get creatorIsAdmin_(): boolean {
1819 return isAdmin(this.props.post_view.creator.id, this.props.admins);