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, PostFormParams, 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 const post = this.props.post_view.post;
153 <div className="post-listing">
154 {!this.state.showEdit ? (
157 {this.state.imageExpanded && !this.props.hideImage && this.img}
158 {post.url && this.showBody && post.embed_title && (
159 <MetadataCard post={post} />
161 {this.showBody && this.body()}
164 <div className="col-12">
166 post_view={this.props.post_view}
167 onEdit={this.handleEditPost}
168 onCancel={this.handleEditCancel}
169 enableNsfw={this.props.enableNsfw}
170 enableDownvotes={this.props.enableDownvotes}
171 allLanguages={this.props.allLanguages}
172 siteLanguages={this.props.siteLanguages}
181 let body = this.props.post_view.post.body;
183 <div className="col-12 card my-2 p-2">
184 {this.state.viewSource ? (
187 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
196 let src = this.imageSrc;
199 <div className="offset-sm-3 my-2 d-none d-sm-block">
200 <a href={src} className="d-inline-block">
201 <PictrsImage src={src} />
204 <div className="my-2 d-block d-sm-none">
206 className="d-inline-block"
207 onClick={linkEvent(this, this.handleImageExpandClick)}
209 <PictrsImage src={src} />
218 imgThumb(src: string) {
219 let post_view = this.props.post_view;
225 nsfw={post_view.post.nsfw || post_view.community.nsfw}
230 get imageSrc(): string | undefined {
231 let post = this.props.post_view.post;
233 let thumbnail = post.thumbnail_url;
235 if (url && isImage(url)) {
236 if (url.includes("pictrs")) {
238 } else if (thumbnail) {
243 } else if (thumbnail) {
251 let post = this.props.post_view.post;
253 let thumbnail = post.thumbnail_url;
255 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
259 className="text-body d-inline-block position-relative mb-2"
260 data-tippy-content={i18n.t("expand_here")}
261 onClick={linkEvent(this, this.handleImageExpandClick)}
262 aria-label={i18n.t("expand_here")}
264 {this.imgThumb(this.imageSrc)}
265 <Icon icon="image" classes="mini-overlay" />
268 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
271 className="text-body d-inline-block position-relative mb-2"
276 {this.imgThumb(this.imageSrc)}
277 <Icon icon="external-link" classes="mini-overlay" />
281 if (!this.props.hideImage && isVideo(url)) {
283 <div className="embed-responsive embed-responsive-16by9">
289 className="embed-responsive-item"
291 <source src={url} type="video/mp4" />
297 <a className="text-body" href={url} title={url} rel={relTags}>
298 <div className="thumbnail rounded bg-light d-flex justify-content-center">
299 <Icon icon="external-link" classes="d-flex align-items-center" />
307 className="text-body"
308 to={`/post/${post.id}`}
309 title={i18n.t("comments")}
311 <div className="thumbnail rounded bg-light d-flex justify-content-center">
312 <Icon icon="message-square" classes="d-flex align-items-center" />
320 let post_view = this.props.post_view;
321 let url = post_view.post.url;
322 let body = post_view.post.body;
324 <ul className="list-inline mb-1 text-muted small">
325 <li className="list-inline-item">
326 <PersonListing person={post_view.creator} />
328 {this.creatorIsMod_ && (
329 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
331 {this.creatorIsAdmin_ && (
332 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
334 {post_view.creator.bot_account && (
335 <span className="mx-1 badge badge-light">
336 {i18n.t("bot_account").toLowerCase()}
339 {(post_view.creator_banned_from_community ||
340 isBanned(post_view.creator)) && (
341 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
343 {post_view.creator_blocked && (
344 <span className="mx-1 badge badge-danger">{"blocked"}</span>
346 {this.props.showCommunity && (
348 <span className="mx-1"> {i18n.t("to")} </span>
349 <CommunityLink community={post_view.community} />
353 <li className="list-inline-item">•</li>
354 {url && !(hostname(url) == externalHost) && (
356 <li className="list-inline-item">
358 className="text-muted font-italic"
366 <li className="list-inline-item">•</li>
369 <li className="list-inline-item">
372 published={post_view.post.published}
373 updated={post_view.post.updated}
379 <li className="list-inline-item">•</li>
380 <li className="list-inline-item">
382 className="text-muted btn btn-sm btn-link p-0"
383 data-tippy-content={mdNoImages.render(body)}
384 data-tippy-allowHtml={true}
385 onClick={linkEvent(this, this.handleShowBody)}
387 <Icon icon="book-open" classes="icon-inline mr-1" />
398 <div className={`vote-bar col-1 pr-0 small text-center`}>
400 className={`btn-animate btn btn-link p-0 ${
401 this.state.my_vote == 1 ? "text-info" : "text-muted"
403 onClick={this.handlePostLike}
404 data-tippy-content={i18n.t("upvote")}
405 aria-label={i18n.t("upvote")}
407 <Icon icon="arrow-up1" classes="upvote" />
411 className={`unselectable pointer font-weight-bold text-muted px-1`}
412 data-tippy-content={this.pointsTippy}
414 {numToSI(this.state.score)}
417 <div className="p-1"></div>
419 {this.props.enableDownvotes && (
421 className={`btn-animate btn btn-link p-0 ${
422 this.state.my_vote == -1 ? "text-danger" : "text-muted"
424 onClick={this.handlePostDisLike}
425 data-tippy-content={i18n.t("downvote")}
426 aria-label={i18n.t("downvote")}
428 <Icon icon="arrow-down1" classes="downvote" />
436 let post = this.props.post_view.post;
439 className={`d-inline-block ${
440 !post.featured_community && !post.featured_local
444 to={`/post/${post.id}`}
445 title={i18n.t("comments")}
448 className="d-inline-block"
449 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
456 let post = this.props.post_view.post;
460 <div className="post-title overflow-hidden">
463 this.props.showBody ? (
465 className={`d-inline-block ${
466 !post.featured_community && !post.featured_local
475 className="d-inline-block"
476 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
485 {(url && isImage(url)) ||
486 (post.thumbnail_url && (
488 className="btn btn-link text-monospace text-muted small d-inline-block"
489 data-tippy-content={i18n.t("expand_here")}
490 onClick={linkEvent(this, this.handleImageExpandClick)}
494 !this.state.imageExpanded ? "plus-square" : "minus-square"
496 classes="icon-inline"
501 <small className="ml-2 text-muted font-italic">
507 className="unselectable pointer ml-2 text-muted font-italic"
508 data-tippy-content={i18n.t("deleted")}
510 <Icon icon="trash" classes="icon-inline text-danger" />
515 className="unselectable pointer ml-2 text-muted font-italic"
516 data-tippy-content={i18n.t("locked")}
518 <Icon icon="lock" classes="icon-inline text-danger" />
521 {post.featured_community && (
523 className="unselectable pointer ml-2 text-muted font-italic"
524 data-tippy-content={i18n.t("featured")}
526 <Icon icon="pin" classes="icon-inline text-primary" />
529 {post.featured_local && (
531 className="unselectable pointer ml-2 text-muted font-italic"
532 data-tippy-content={i18n.t("featured")}
534 <Icon icon="pin" classes="icon-inline text-secondary" />
538 <small className="ml-2 text-muted font-italic">
548 let dupes = this.props.duplicates;
549 return dupes && dupes.length > 0 ? (
550 <ul className="list-inline mb-1 small text-muted">
552 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
554 <li key={pv.post.id} className="list-inline-item mr-2">
555 <Link to={`/post/${pv.post.id}`}>
558 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
569 commentsLine(mobile = false) {
570 let post = this.props.post_view.post;
572 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
573 {this.commentsButton}
576 className="btn btn-link btn-animate text-muted py-0"
577 title={i18n.t("link")}
580 <Icon icon="fedilink" inline />
583 {mobile && !this.props.viewOnly && this.mobileVotes}
584 {UserService.Instance.myUserInfo &&
585 !this.props.viewOnly &&
586 this.postActions(mobile)}
591 postActions(mobile = false) {
592 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
593 // Possible enhancement: Make each button a component.
594 let post_view = this.props.post_view;
598 {this.crossPostButton}
599 {mobile && this.showMoreButton}
600 {(!mobile || this.state.showAdvanced) && (
608 {this.myPost && (this.showBody || this.state.showAdvanced) && (
616 {this.state.showAdvanced && (
618 {this.showBody && post_view.post.body && this.viewSourceButton}
619 {/* Any mod can do these, not limited to hierarchy*/}
620 {(amMod(this.props.moderators) || amAdmin()) && (
626 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
629 {!mobile && this.showMoreButton}
634 get commentsButton() {
635 let post_view = this.props.post_view;
637 <button className="btn btn-link text-muted py-0 pl-0">
639 className="text-muted"
640 title={i18n.t("number_of_comments", {
641 count: post_view.counts.comments,
642 formattedCount: post_view.counts.comments,
644 to={`/post/${post_view.post.id}?scrollToComments=true`}
646 <Icon icon="message-square" classes="mr-1" inline />
647 <span className="mr-2">
648 {i18n.t("number_of_comments", {
649 count: post_view.counts.comments,
650 formattedCount: numToSI(post_view.counts.comments),
653 {this.unreadCount && (
654 <span className="small text-warning">
655 ({this.unreadCount} {i18n.t("new")})
663 get unreadCount(): number | undefined {
664 let pv = this.props.post_view;
665 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
667 : pv.unread_comments;
672 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
677 className={`btn-animate btn py-0 px-1 ${
678 this.state.my_vote == 1 ? "text-info" : "text-muted"
681 onClick={this.handlePostLike}
682 aria-label={i18n.t("upvote")}
684 <Icon icon="arrow-up1" classes="icon-inline small" />
686 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
689 {this.props.enableDownvotes && (
691 className={`ml-2 btn-animate btn py-0 px-1 ${
692 this.state.my_vote == -1 ? "text-danger" : "text-muted"
694 onClick={this.handlePostDisLike}
696 aria-label={i18n.t("downvote")}
698 <Icon icon="arrow-down1" classes="icon-inline small" />
701 className={classNames("ml-2", {
702 invisible: this.state.downvotes === 0,
705 {numToSI(this.state.downvotes)}
716 let saved = this.props.post_view.saved;
717 let label = saved ? i18n.t("unsave") : i18n.t("save");
720 className="btn btn-link btn-animate text-muted py-0"
721 onClick={linkEvent(this, this.handleSavePostClick)}
722 data-tippy-content={label}
727 classes={classNames({ "text-warning": saved })}
734 get crossPostButton() {
737 className="btn btn-link btn-animate text-muted py-0"
739 /* Empty string properties are required to satisfy type*/
740 pathname: "/create_post",
741 state: { ...this.crossPostParams },
746 title={i18n.t("cross_post")}
748 <Icon icon="copy" inline />
756 className="btn btn-link btn-animate text-muted py-0"
757 onClick={linkEvent(this, this.handleShowReportDialog)}
758 data-tippy-content={i18n.t("show_report_dialog")}
759 aria-label={i18n.t("show_report_dialog")}
761 <Icon icon="flag" inline />
769 className="btn btn-link btn-animate text-muted py-0"
770 onClick={linkEvent(this, this.handleBlockUserClick)}
771 data-tippy-content={i18n.t("block_user")}
772 aria-label={i18n.t("block_user")}
774 <Icon icon="slash" inline />
782 className="btn btn-link btn-animate text-muted py-0"
783 onClick={linkEvent(this, this.handleEditClick)}
784 data-tippy-content={i18n.t("edit")}
785 aria-label={i18n.t("edit")}
787 <Icon icon="edit" inline />
793 let deleted = this.props.post_view.post.deleted;
794 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
797 className="btn btn-link btn-animate text-muted py-0"
798 onClick={linkEvent(this, this.handleDeleteClick)}
799 data-tippy-content={label}
804 classes={classNames({ "text-danger": deleted })}
811 get showMoreButton() {
814 className="btn btn-link btn-animate text-muted py-0"
815 onClick={linkEvent(this, this.handleShowAdvanced)}
816 data-tippy-content={i18n.t("more")}
817 aria-label={i18n.t("more")}
819 <Icon icon="more-vertical" inline />
824 get viewSourceButton() {
827 className="btn btn-link btn-animate text-muted py-0"
828 onClick={linkEvent(this, this.handleViewSource)}
829 data-tippy-content={i18n.t("view_source")}
830 aria-label={i18n.t("view_source")}
834 classes={classNames({ "text-success": this.state.viewSource })}
842 let locked = this.props.post_view.post.locked;
843 let label = locked ? i18n.t("unlock") : i18n.t("lock");
846 className="btn btn-link btn-animate text-muted py-0"
847 onClick={linkEvent(this, this.handleModLock)}
848 data-tippy-content={label}
853 classes={classNames({ "text-danger": locked })}
860 get featureButton() {
861 const featuredCommunity = this.props.post_view.post.featured_community;
862 const labelCommunity = featuredCommunity
863 ? i18n.t("unfeature_from_community")
864 : i18n.t("feature_in_community");
866 const featuredLocal = this.props.post_view.post.featured_local;
867 const labelLocal = featuredLocal
868 ? i18n.t("unfeature_from_local")
869 : i18n.t("feature_in_local");
873 className="btn btn-link btn-animate text-muted py-0 pl-0"
874 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
875 data-tippy-content={labelCommunity}
876 aria-label={labelCommunity}
880 classes={classNames({ "text-success": featuredCommunity })}
887 className="btn btn-link btn-animate text-muted py-0"
888 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
889 data-tippy-content={labelLocal}
890 aria-label={labelLocal}
894 classes={classNames({ "text-success": featuredLocal })}
904 get modRemoveButton() {
905 let removed = this.props.post_view.post.removed;
908 className="btn btn-link btn-animate text-muted py-0"
911 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
914 {/* TODO: Find an icon for this. */}
915 {!removed ? i18n.t("remove") : i18n.t("restore")}
921 * Mod/Admin actions to be taken against the author.
925 let post_view = this.props.post_view;
927 this.state.showAdvanced && (
931 {!this.creatorIsMod_ &&
932 (!post_view.creator_banned_from_community ? (
934 className="btn btn-link btn-animate text-muted py-0"
937 this.handleModBanFromCommunityShow
939 aria-label={i18n.t("ban_from_community")}
941 {i18n.t("ban_from_community")}
945 className="btn btn-link btn-animate text-muted py-0"
948 this.handleModBanFromCommunitySubmit
950 aria-label={i18n.t("unban")}
955 {!post_view.creator_banned_from_community && (
957 className="btn btn-link btn-animate text-muted py-0"
958 onClick={linkEvent(this, this.handleAddModToCommunity)}
961 ? i18n.t("remove_as_mod")
962 : i18n.t("appoint_as_mod")
966 ? i18n.t("remove_as_mod")
967 : i18n.t("appoint_as_mod")}
972 {/* Community creators and admins can transfer community to another mod */}
973 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
975 this.creatorIsMod_ &&
976 (!this.state.showConfirmTransferCommunity ? (
978 className="btn btn-link btn-animate text-muted py-0"
981 this.handleShowConfirmTransferCommunity
983 aria-label={i18n.t("transfer_community")}
985 {i18n.t("transfer_community")}
990 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
991 aria-label={i18n.t("are_you_sure")}
993 {i18n.t("are_you_sure")}
996 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
997 aria-label={i18n.t("yes")}
998 onClick={linkEvent(this, this.handleTransferCommunity)}
1003 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1006 this.handleCancelShowConfirmTransferCommunity
1008 aria-label={i18n.t("no")}
1014 {/* Admins can ban from all, and appoint other admins */}
1015 {this.canAdmin_ && (
1017 {!this.creatorIsAdmin_ && (
1019 {!isBanned(post_view.creator) ? (
1021 className="btn btn-link btn-animate text-muted py-0"
1022 onClick={linkEvent(this, this.handleModBanShow)}
1023 aria-label={i18n.t("ban_from_site")}
1025 {i18n.t("ban_from_site")}
1029 className="btn btn-link btn-animate text-muted py-0"
1030 onClick={linkEvent(this, this.handleModBanSubmit)}
1031 aria-label={i18n.t("unban_from_site")}
1033 {i18n.t("unban_from_site")}
1037 className="btn btn-link btn-animate text-muted py-0"
1038 onClick={linkEvent(this, this.handlePurgePersonShow)}
1039 aria-label={i18n.t("purge_user")}
1041 {i18n.t("purge_user")}
1044 className="btn btn-link btn-animate text-muted py-0"
1045 onClick={linkEvent(this, this.handlePurgePostShow)}
1046 aria-label={i18n.t("purge_post")}
1048 {i18n.t("purge_post")}
1052 {!isBanned(post_view.creator) && post_view.creator.local && (
1054 className="btn btn-link btn-animate text-muted py-0"
1055 onClick={linkEvent(this, this.handleAddAdmin)}
1057 this.creatorIsAdmin_
1058 ? i18n.t("remove_as_admin")
1059 : i18n.t("appoint_as_admin")
1062 {this.creatorIsAdmin_
1063 ? i18n.t("remove_as_admin")
1064 : i18n.t("appoint_as_admin")}
1074 removeAndBanDialogs() {
1075 let post = this.props.post_view;
1077 this.state.purgeType == PurgeType.Post
1078 ? i18n.t("purge_post")
1079 : `${i18n.t("purge")} ${post.creator.name}`;
1082 {this.state.showRemoveDialog && (
1084 className="form-inline"
1085 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1087 <label className="sr-only" htmlFor="post-listing-remove-reason">
1092 id="post-listing-remove-reason"
1093 className="form-control mr-2"
1094 placeholder={i18n.t("reason")}
1095 value={this.state.removeReason}
1096 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1100 className="btn btn-secondary"
1101 aria-label={i18n.t("remove_post")}
1103 {i18n.t("remove_post")}
1107 {this.state.showBanDialog && (
1108 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1109 <div className="form-group row col-12">
1111 className="col-form-label"
1112 htmlFor="post-listing-ban-reason"
1118 id="post-listing-ban-reason"
1119 className="form-control mr-2"
1120 placeholder={i18n.t("reason")}
1121 value={this.state.banReason}
1122 onInput={linkEvent(this, this.handleModBanReasonChange)}
1124 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1129 id={`mod-ban-expires`}
1130 className="form-control mr-2"
1131 placeholder={i18n.t("number_of_days")}
1132 value={this.state.banExpireDays}
1133 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1135 <div className="form-group">
1136 <div className="form-check">
1138 className="form-check-input"
1139 id="mod-ban-remove-data"
1141 checked={this.state.removeData}
1142 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1145 className="form-check-label"
1146 htmlFor="mod-ban-remove-data"
1147 title={i18n.t("remove_content_more")}
1149 {i18n.t("remove_content")}
1154 {/* TODO hold off on expires until later */}
1155 {/* <div class="form-group row"> */}
1156 {/* <label class="col-form-label">Expires</label> */}
1157 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1159 <div className="form-group row">
1162 className="btn btn-secondary"
1163 aria-label={i18n.t("ban")}
1165 {i18n.t("ban")} {post.creator.name}
1170 {this.state.showReportDialog && (
1172 className="form-inline"
1173 onSubmit={linkEvent(this, this.handleReportSubmit)}
1175 <label className="sr-only" htmlFor="post-report-reason">
1180 id="post-report-reason"
1181 className="form-control mr-2"
1182 placeholder={i18n.t("reason")}
1184 value={this.state.reportReason}
1185 onInput={linkEvent(this, this.handleReportReasonChange)}
1189 className="btn btn-secondary"
1190 aria-label={i18n.t("create_report")}
1192 {i18n.t("create_report")}
1196 {this.state.showPurgeDialog && (
1198 className="form-inline"
1199 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1202 <label className="sr-only" htmlFor="purge-reason">
1208 className="form-control mr-2"
1209 placeholder={i18n.t("reason")}
1210 value={this.state.purgeReason}
1211 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1213 {this.state.purgeLoading ? (
1218 className="btn btn-secondary"
1219 aria-label={purgeTypeText}
1231 let post = this.props.post_view.post;
1232 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1233 <div className="row">
1234 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1235 {this.postTitleLine()}
1237 <div className="col-4">
1238 {/* Post body prev or thumbnail */}
1239 {!this.state.imageExpanded && this.thumbnail()}
1243 this.postTitleLine()
1247 showMobilePreview() {
1248 let body = this.props.post_view.post.body;
1249 return !this.showBody && body ? (
1250 <div className="md-div mb-1 preview-lines">{body}</div>
1259 {/* The mobile view*/}
1260 <div className="d-block d-sm-none">
1261 <div className="row">
1262 <div className="col-12">
1263 {this.createdLine()}
1265 {/* If it has a thumbnail, do a right aligned thumbnail */}
1266 {this.mobileThumbnail()}
1268 {/* Show a preview of the post body */}
1269 {this.showMobilePreview()}
1271 {this.commentsLine(true)}
1272 {this.userActionsLine()}
1273 {this.duplicatesLine()}
1274 {this.removeAndBanDialogs()}
1279 {/* The larger view*/}
1280 <div className="d-none d-sm-block">
1281 <div className="row">
1282 {!this.props.viewOnly && this.voteBar()}
1283 <div className="col-sm-2 pr-0">
1284 <div className="">{this.thumbnail()}</div>
1286 <div className="col-12 col-sm-9">
1287 <div className="row">
1288 <div className="col-12">
1289 {this.postTitleLine()}
1290 {this.createdLine()}
1291 {this.commentsLine()}
1292 {this.duplicatesLine()}
1293 {this.userActionsLine()}
1294 {this.removeAndBanDialogs()}
1304 private get myPost(): boolean {
1306 this.props.post_view.creator.id ==
1307 UserService.Instance.myUserInfo?.local_user_view.person.id
1311 handlePostLike(event: any) {
1312 event.preventDefault();
1313 if (!UserService.Instance.myUserInfo) {
1314 this.context.router.history.push(`/login`);
1317 let myVote = this.state.my_vote;
1318 let newVote = myVote == 1 ? 0 : 1;
1322 score: this.state.score - 1,
1323 upvotes: this.state.upvotes - 1,
1325 } else if (myVote == -1) {
1327 score: this.state.score + 2,
1328 upvotes: this.state.upvotes + 1,
1329 downvotes: this.state.downvotes - 1,
1333 score: this.state.score + 1,
1334 upvotes: this.state.upvotes + 1,
1338 this.setState({ my_vote: newVote });
1340 let auth = myAuth();
1342 let form: CreatePostLike = {
1343 post_id: this.props.post_view.post.id,
1348 WebSocketService.Instance.send(wsClient.likePost(form));
1349 this.setState(this.state);
1354 handlePostDisLike(event: any) {
1355 event.preventDefault();
1356 if (!UserService.Instance.myUserInfo) {
1357 this.context.router.history.push(`/login`);
1360 let myVote = this.state.my_vote;
1361 let newVote = myVote == -1 ? 0 : -1;
1365 score: this.state.score - 2,
1366 upvotes: this.state.upvotes - 1,
1367 downvotes: this.state.downvotes + 1,
1369 } else if (myVote == -1) {
1371 score: this.state.score + 1,
1372 downvotes: this.state.downvotes - 1,
1376 score: this.state.score - 1,
1377 downvotes: this.state.downvotes + 1,
1381 this.setState({ my_vote: newVote });
1383 let auth = myAuth();
1385 let form: CreatePostLike = {
1386 post_id: this.props.post_view.post.id,
1391 WebSocketService.Instance.send(wsClient.likePost(form));
1392 this.setState(this.state);
1397 handleEditClick(i: PostListing) {
1398 i.setState({ showEdit: true });
1401 handleEditCancel() {
1402 this.setState({ showEdit: false });
1405 // The actual editing is done in the recieve for post
1407 this.setState({ showEdit: false });
1410 handleShowReportDialog(i: PostListing) {
1411 i.setState({ showReportDialog: !i.state.showReportDialog });
1414 handleReportReasonChange(i: PostListing, event: any) {
1415 i.setState({ reportReason: event.target.value });
1418 handleReportSubmit(i: PostListing, event: any) {
1419 event.preventDefault();
1420 let auth = myAuth();
1421 let reason = i.state.reportReason;
1422 if (auth && reason) {
1423 let form: CreatePostReport = {
1424 post_id: i.props.post_view.post.id,
1428 WebSocketService.Instance.send(wsClient.createPostReport(form));
1430 i.setState({ showReportDialog: false });
1434 handleBlockUserClick(i: PostListing) {
1435 let auth = myAuth();
1437 let blockUserForm: BlockPerson = {
1438 person_id: i.props.post_view.creator.id,
1442 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1446 handleDeleteClick(i: PostListing) {
1447 let auth = myAuth();
1449 let deleteForm: DeletePost = {
1450 post_id: i.props.post_view.post.id,
1451 deleted: !i.props.post_view.post.deleted,
1454 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1458 handleSavePostClick(i: PostListing) {
1459 let auth = myAuth();
1462 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1463 let form: SavePost = {
1464 post_id: i.props.post_view.post.id,
1468 WebSocketService.Instance.send(wsClient.savePost(form));
1472 get crossPostParams(): PostFormParams {
1473 const queryParams: PostFormParams = {};
1474 const { name, url } = this.props.post_view.post;
1476 queryParams.name = name;
1479 queryParams.url = url;
1482 const crossPostBody = this.crossPostBody();
1483 if (crossPostBody) {
1484 queryParams.body = crossPostBody;
1490 crossPostBody(): string | undefined {
1491 let post = this.props.post_view.post;
1492 let body = post.body;
1495 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1502 get showBody(): boolean {
1503 return this.props.showBody || this.state.showBody;
1506 handleModRemoveShow(i: PostListing) {
1508 showRemoveDialog: !i.state.showRemoveDialog,
1509 showBanDialog: false,
1513 handleModRemoveReasonChange(i: PostListing, event: any) {
1514 i.setState({ removeReason: event.target.value });
1517 handleModRemoveDataChange(i: PostListing, event: any) {
1518 i.setState({ removeData: event.target.checked });
1521 handleModRemoveSubmit(i: PostListing, event: any) {
1522 event.preventDefault();
1524 let auth = myAuth();
1526 let form: RemovePost = {
1527 post_id: i.props.post_view.post.id,
1528 removed: !i.props.post_view.post.removed,
1529 reason: i.state.removeReason,
1532 WebSocketService.Instance.send(wsClient.removePost(form));
1533 i.setState({ showRemoveDialog: false });
1537 handleModLock(i: PostListing) {
1538 let auth = myAuth();
1540 let form: LockPost = {
1541 post_id: i.props.post_view.post.id,
1542 locked: !i.props.post_view.post.locked,
1545 WebSocketService.Instance.send(wsClient.lockPost(form));
1549 handleModFeaturePostLocal(i: PostListing) {
1550 let auth = myAuth();
1552 let form: FeaturePost = {
1553 post_id: i.props.post_view.post.id,
1554 feature_type: PostFeatureType.Local,
1555 featured: !i.props.post_view.post.featured_local,
1558 WebSocketService.Instance.send(wsClient.featurePost(form));
1562 handleModFeaturePostCommunity(i: PostListing) {
1563 let auth = myAuth();
1565 let form: FeaturePost = {
1566 post_id: i.props.post_view.post.id,
1567 feature_type: PostFeatureType.Community,
1568 featured: !i.props.post_view.post.featured_community,
1571 WebSocketService.Instance.send(wsClient.featurePost(form));
1575 handleModBanFromCommunityShow(i: PostListing) {
1577 showBanDialog: true,
1578 banType: BanType.Community,
1579 showRemoveDialog: false,
1583 handleModBanShow(i: PostListing) {
1585 showBanDialog: true,
1586 banType: BanType.Site,
1587 showRemoveDialog: false,
1591 handlePurgePersonShow(i: PostListing) {
1593 showPurgeDialog: true,
1594 purgeType: PurgeType.Person,
1595 showRemoveDialog: false,
1599 handlePurgePostShow(i: PostListing) {
1601 showPurgeDialog: true,
1602 purgeType: PurgeType.Post,
1603 showRemoveDialog: false,
1607 handlePurgeReasonChange(i: PostListing, event: any) {
1608 i.setState({ purgeReason: event.target.value });
1611 handlePurgeSubmit(i: PostListing, event: any) {
1612 event.preventDefault();
1614 let auth = myAuth();
1616 if (i.state.purgeType == PurgeType.Person) {
1617 let form: PurgePerson = {
1618 person_id: i.props.post_view.creator.id,
1619 reason: i.state.purgeReason,
1622 WebSocketService.Instance.send(wsClient.purgePerson(form));
1623 } else if (i.state.purgeType == PurgeType.Post) {
1624 let form: PurgePost = {
1625 post_id: i.props.post_view.post.id,
1626 reason: i.state.purgeReason,
1629 WebSocketService.Instance.send(wsClient.purgePost(form));
1632 i.setState({ purgeLoading: true });
1636 handleModBanReasonChange(i: PostListing, event: any) {
1637 i.setState({ banReason: event.target.value });
1640 handleModBanExpireDaysChange(i: PostListing, event: any) {
1641 i.setState({ banExpireDays: event.target.value });
1644 handleModBanFromCommunitySubmit(i: PostListing) {
1645 i.setState({ banType: BanType.Community });
1646 i.handleModBanBothSubmit(i);
1649 handleModBanSubmit(i: PostListing) {
1650 i.setState({ banType: BanType.Site });
1651 i.handleModBanBothSubmit(i);
1654 handleModBanBothSubmit(i: PostListing, event?: any) {
1655 if (event) event.preventDefault();
1656 let auth = myAuth();
1658 let ban = !i.props.post_view.creator_banned_from_community;
1659 let person_id = i.props.post_view.creator.id;
1660 let remove_data = i.state.removeData;
1661 let reason = i.state.banReason;
1662 let expires = futureDaysToUnixTime(i.state.banExpireDays);
1664 if (i.state.banType == BanType.Community) {
1665 // If its an unban, restore all their data
1667 i.setState({ removeData: false });
1670 let form: BanFromCommunity = {
1672 community_id: i.props.post_view.community.id,
1679 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1681 // If its an unban, restore all their data
1682 let ban = !i.props.post_view.creator.banned;
1684 i.setState({ removeData: false });
1686 let form: BanPerson = {
1694 WebSocketService.Instance.send(wsClient.banPerson(form));
1697 i.setState({ showBanDialog: false });
1701 handleAddModToCommunity(i: PostListing) {
1702 let auth = myAuth();
1704 let form: AddModToCommunity = {
1705 person_id: i.props.post_view.creator.id,
1706 community_id: i.props.post_view.community.id,
1707 added: !i.creatorIsMod_,
1710 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1711 i.setState(i.state);
1715 handleAddAdmin(i: PostListing) {
1716 let auth = myAuth();
1718 let form: AddAdmin = {
1719 person_id: i.props.post_view.creator.id,
1720 added: !i.creatorIsAdmin_,
1723 WebSocketService.Instance.send(wsClient.addAdmin(form));
1724 i.setState(i.state);
1728 handleShowConfirmTransferCommunity(i: PostListing) {
1729 i.setState({ showConfirmTransferCommunity: true });
1732 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1733 i.setState({ showConfirmTransferCommunity: false });
1736 handleTransferCommunity(i: PostListing) {
1737 let auth = myAuth();
1739 let form: TransferCommunity = {
1740 community_id: i.props.post_view.community.id,
1741 person_id: i.props.post_view.creator.id,
1744 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1745 i.setState({ showConfirmTransferCommunity: false });
1749 handleShowConfirmTransferSite(i: PostListing) {
1750 i.setState({ showConfirmTransferSite: true });
1753 handleCancelShowConfirmTransferSite(i: PostListing) {
1754 i.setState({ showConfirmTransferSite: false });
1757 handleImageExpandClick(i: PostListing, event: any) {
1758 event.preventDefault();
1759 i.setState({ imageExpanded: !i.state.imageExpanded });
1763 handleViewSource(i: PostListing) {
1764 i.setState({ viewSource: !i.state.viewSource });
1767 handleShowAdvanced(i: PostListing) {
1768 i.setState({ showAdvanced: !i.state.showAdvanced });
1772 handleShowMoreMobile(i: PostListing) {
1774 showMoreMobile: !i.state.showMoreMobile,
1775 showAdvanced: !i.state.showAdvanced,
1780 handleShowBody(i: PostListing) {
1781 i.setState({ showBody: !i.state.showBody });
1785 get pointsTippy(): string {
1786 let points = i18n.t("number_of_points", {
1787 count: this.state.score,
1788 formattedCount: this.state.score,
1791 let upvotes = i18n.t("number_of_upvotes", {
1792 count: this.state.upvotes,
1793 formattedCount: this.state.upvotes,
1796 let downvotes = i18n.t("number_of_downvotes", {
1797 count: this.state.downvotes,
1798 formattedCount: this.state.downvotes,
1801 return `${points} • ${upvotes} • ${downvotes}`;
1804 get canModOnSelf_(): boolean {
1806 this.props.post_view.creator.id,
1807 this.props.moderators,
1814 get canMod_(): boolean {
1816 this.props.post_view.creator.id,
1817 this.props.moderators,
1822 get canAdmin_(): boolean {
1823 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1826 get creatorIsMod_(): boolean {
1827 return isMod(this.props.post_view.creator.id, this.props.moderators);
1830 get creatorIsAdmin_(): boolean {
1831 return isAdmin(this.props.post_view.creator.id, this.props.admins);