1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
10 CommunityModeratorView,
21 } from "lemmy-js-client";
22 import { externalHost } from "../../env";
23 import { i18n } from "../../i18next";
24 import { BanType } from "../../interfaces";
25 import { UserService, WebSocketService } from "../../services";
43 import { Icon } from "../common/icon";
44 import { MomentTime } from "../common/moment-time";
45 import { PictrsImage } from "../common/pictrs-image";
46 import { CommunityLink } from "../community/community-link";
47 import { PersonListing } from "../person/person-listing";
48 import { MetadataCard } from "./metadata-card";
49 import { PostForm } from "./post-form";
51 interface PostListingState {
53 showRemoveDialog: boolean;
55 showBanDialog: boolean;
58 banExpireDays: number;
60 showConfirmTransferSite: boolean;
61 showConfirmTransferCommunity: boolean;
62 imageExpanded: boolean;
64 showAdvanced: boolean;
65 showMoreMobile: boolean;
67 showReportDialog: boolean;
75 interface PostListingProps {
77 duplicates?: PostView[];
78 showCommunity?: boolean;
80 moderators?: CommunityModeratorView[];
81 admins?: PersonViewSafe[];
82 enableDownvotes: boolean;
87 export class PostListing extends Component<PostListingProps, PostListingState> {
88 private emptyState: PostListingState = {
90 showRemoveDialog: false,
96 banType: BanType.Community,
97 showConfirmTransferSite: false,
98 showConfirmTransferCommunity: false,
102 showMoreMobile: false,
104 showReportDialog: false,
106 my_vote: this.props.post_view.my_vote,
107 score: this.props.post_view.counts.score,
108 upvotes: this.props.post_view.counts.upvotes,
109 downvotes: this.props.post_view.counts.downvotes,
112 constructor(props: any, context: any) {
113 super(props, context);
115 this.state = this.emptyState;
116 this.handlePostLike = this.handlePostLike.bind(this);
117 this.handlePostDisLike = this.handlePostDisLike.bind(this);
118 this.handleEditPost = this.handleEditPost.bind(this);
119 this.handleEditCancel = this.handleEditCancel.bind(this);
122 componentWillReceiveProps(nextProps: PostListingProps) {
123 this.state.my_vote = nextProps.post_view.my_vote;
124 this.state.upvotes = nextProps.post_view.counts.upvotes;
125 this.state.downvotes = nextProps.post_view.counts.downvotes;
126 this.state.score = nextProps.post_view.counts.score;
127 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
128 this.state.imageExpanded = false;
130 this.setState(this.state);
134 let post = this.props.post_view.post;
136 <div class="post-listing">
137 {!this.state.showEdit ? (
140 {this.state.imageExpanded && this.img}
141 {post.url && this.showBody && post.embed_title && (
142 <MetadataCard post={post} />
144 {this.showBody && post.body && this.body()}
149 post_view={this.props.post_view}
150 onEdit={this.handleEditPost}
151 onCancel={this.handleEditCancel}
152 enableNsfw={this.props.enableNsfw}
153 enableDownvotes={this.props.enableDownvotes}
162 let post = this.props.post_view.post;
164 <div class="col-12 card my-2 p-2">
165 {this.state.viewSource ? (
166 <pre>{post.body}</pre>
170 dangerouslySetInnerHTML={mdToHtml(post.body)}
180 <div class="offset-sm-3 my-2 d-none d-sm-block">
181 <a href={this.imageSrc} class="d-inline-block">
182 <PictrsImage src={this.imageSrc} />
185 <div className="my-2 d-block d-sm-none">
187 class="d-inline-block"
188 onClick={linkEvent(this, this.handleImageExpandClick)}
190 <PictrsImage src={this.imageSrc} />
197 imgThumb(src: string) {
198 let post_view = this.props.post_view;
204 nsfw={post_view.post.nsfw || post_view.community.nsfw}
209 get imageSrc(): string {
210 let post = this.props.post_view.post;
211 if (isImage(post.url)) {
212 if (post.url.includes("pictrs")) {
214 } else if (post.thumbnail_url) {
215 return post.thumbnail_url;
219 } else if (post.thumbnail_url) {
220 return post.thumbnail_url;
227 let post = this.props.post_view.post;
229 if (isImage(post.url)) {
233 class="text-body d-inline-block position-relative mb-2"
234 data-tippy-content={i18n.t("expand_here")}
235 onClick={linkEvent(this, this.handleImageExpandClick)}
236 aria-label={i18n.t("expand_here")}
238 {this.imgThumb(this.imageSrc)}
239 <Icon icon="image" classes="mini-overlay" />
242 } else if (post.thumbnail_url) {
245 class="text-body d-inline-block position-relative mb-2"
250 {this.imgThumb(this.imageSrc)}
251 <Icon icon="external-link" classes="mini-overlay" />
254 } else if (post.url) {
255 if (isVideo(post.url)) {
257 <div class="embed-responsive embed-responsive-16by9">
263 class="embed-responsive-item"
265 <source src={post.url} type="video/mp4" />
272 className="text-body"
277 <div class="thumbnail rounded bg-light d-flex justify-content-center">
278 <Icon icon="external-link" classes="d-flex align-items-center" />
286 className="text-body"
287 to={`/post/${post.id}`}
288 title={i18n.t("comments")}
290 <div class="thumbnail rounded bg-light d-flex justify-content-center">
291 <Icon icon="message-square" classes="d-flex align-items-center" />
299 let post_view = this.props.post_view;
301 <ul class="list-inline mb-1 text-muted small">
302 <li className="list-inline-item">
303 <PersonListing person={post_view.creator} />
305 {this.creatorIsMod && (
306 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
308 {this.creatorIsAdmin && (
309 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
311 {post_view.creator.bot_account && (
312 <span className="mx-1 badge badge-light">
313 {i18n.t("bot_account").toLowerCase()}
316 {(post_view.creator_banned_from_community ||
317 isBanned(post_view.creator)) && (
318 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
320 {post_view.creator_blocked && (
321 <span className="mx-1 badge badge-danger">{"blocked"}</span>
323 {this.props.showCommunity && (
325 <span class="mx-1"> {i18n.t("to")} </span>
326 <CommunityLink community={post_view.community} />
330 <li className="list-inline-item">•</li>
331 {post_view.post.url && !(hostname(post_view.post.url) == externalHost) && (
333 <li className="list-inline-item">
335 className="text-muted font-italic"
336 href={post_view.post.url}
337 title={post_view.post.url}
340 {hostname(post_view.post.url)}
343 <li className="list-inline-item">•</li>
346 <li className="list-inline-item">
348 <MomentTime data={post_view.post} />
351 {post_view.post.body && (
353 <li className="list-inline-item">•</li>
354 <li className="list-inline-item">
356 className="text-muted btn btn-sm btn-link p-0"
357 data-tippy-content={md.render(
358 previewLines(post_view.post.body)
360 data-tippy-allowHtml={true}
361 onClick={linkEvent(this, this.handleShowBody)}
363 <Icon icon="book-open" classes="icon-inline mr-1" />
374 <div className={`vote-bar col-1 pr-0 small text-center`}>
376 className={`btn-animate btn btn-link p-0 ${
377 this.state.my_vote == 1 ? "text-info" : "text-muted"
379 onClick={linkEvent(this, this.handlePostLike)}
380 data-tippy-content={i18n.t("upvote")}
381 aria-label={i18n.t("upvote")}
383 <Icon icon="arrow-up1" classes="upvote" />
387 class={`unselectable pointer font-weight-bold text-muted px-1`}
388 data-tippy-content={this.pointsTippy}
390 {numToSI(this.state.score)}
393 <div class="p-1"></div>
395 {this.props.enableDownvotes && (
397 className={`btn-animate btn btn-link p-0 ${
398 this.state.my_vote == -1 ? "text-danger" : "text-muted"
400 onClick={linkEvent(this, this.handlePostDisLike)}
401 data-tippy-content={i18n.t("downvote")}
402 aria-label={i18n.t("downvote")}
404 <Icon icon="arrow-down1" classes="downvote" />
412 let post = this.props.post_view.post;
414 <div className="post-title overflow-hidden">
416 {this.showBody && post.url ? (
418 className={!post.stickied ? "text-body" : "text-primary"}
427 className={!post.stickied ? "text-body" : "text-primary"}
428 to={`/post/${post.id}`}
429 title={i18n.t("comments")}
434 {(isImage(post.url) || post.thumbnail_url) && (
436 class="btn btn-link text-monospace text-muted small d-inline-block ml-2"
437 data-tippy-content={i18n.t("expand_here")}
438 onClick={linkEvent(this, this.handleImageExpandClick)}
442 !this.state.imageExpanded ? "plus-square" : "minus-square"
444 classes="icon-inline"
449 <small className="ml-2 text-muted font-italic">
455 className="unselectable pointer ml-2 text-muted font-italic"
456 data-tippy-content={i18n.t("deleted")}
458 <Icon icon="trash" classes="icon-inline text-danger" />
463 className="unselectable pointer ml-2 text-muted font-italic"
464 data-tippy-content={i18n.t("locked")}
466 <Icon icon="lock" classes="icon-inline text-danger" />
471 className="unselectable pointer ml-2 text-muted font-italic"
472 data-tippy-content={i18n.t("stickied")}
474 <Icon icon="pin" classes="icon-inline text-primary" />
478 <small className="ml-2 text-muted font-italic">
488 let dupes = this.props.duplicates;
491 dupes.length > 0 && (
492 <ul class="list-inline mb-1 small text-muted">
494 <li className="list-inline-item mr-2">
495 {i18n.t("cross_posted_to")}
498 <li className="list-inline-item mr-2">
499 <Link to={`/post/${pv.post.id}`}>
502 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
512 commentsLine(mobile = false) {
513 let post = this.props.post_view.post;
515 <div class="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
516 {this.commentsButton}
519 className="btn btn-link btn-animate text-muted py-0"
520 title={i18n.t("link")}
523 <Icon icon="fedilink" inline />
526 {mobile && !this.props.viewOnly && this.mobileVotes}
527 {UserService.Instance.myUserInfo &&
528 !this.props.viewOnly &&
529 this.postActions(mobile)}
534 postActions(mobile = false) {
535 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
536 // Possible enhancement: Make each button a component.
537 let post_view = this.props.post_view;
541 {this.crossPostButton}
542 {mobile && this.showMoreButton}
543 {(!mobile || this.state.showAdvanced) && (
551 {this.myPost && (this.showBody || this.state.showAdvanced) && (
559 {this.state.showAdvanced && (
561 {this.showBody && post_view.post.body && this.viewSourceButton}
562 {this.canModOnSelf && (
568 {(this.canMod || this.canAdmin || true) && (
569 <>{this.modRemoveButton}</>
573 {!mobile && this.showMoreButton}
578 get commentsButton() {
579 let post_view = this.props.post_view;
581 <button class="btn btn-link text-muted py-0 pl-0">
583 className="text-muted"
584 title={i18n.t("number_of_comments", {
585 count: post_view.counts.comments,
586 formattedCount: post_view.counts.comments,
588 to={`/post/${post_view.post.id}?scrollToComments=true`}
590 <Icon icon="message-square" classes="mr-1" inline />
591 {i18n.t("number_of_comments", {
592 count: post_view.counts.comments,
593 formattedCount: numToSI(post_view.counts.comments),
602 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
607 className={`btn-animate btn py-0 px-1 ${
608 this.state.my_vote == 1 ? "text-info" : "text-muted"
611 onClick={linkEvent(this, this.handlePostLike)}
612 aria-label={i18n.t("upvote")}
614 <Icon icon="arrow-up1" classes="icon-inline small" />
616 <span class="ml-2">{numToSI(this.state.upvotes)}</span>
619 {this.props.enableDownvotes && (
621 className={`ml-2 btn-animate btn py-0 px-1 ${
622 this.state.my_vote == -1 ? "text-danger" : "text-muted"
624 onClick={linkEvent(this, this.handlePostDisLike)}
626 aria-label={i18n.t("downvote")}
628 <Icon icon="arrow-down1" classes="icon-inline small" />
631 class={classNames("ml-2", {
632 invisible: this.state.downvotes === 0,
635 {numToSI(this.state.downvotes)}
646 let saved = this.props.post_view.saved;
647 let label = saved ? i18n.t("unsave") : i18n.t("save");
650 class="btn btn-link btn-animate text-muted py-0"
651 onClick={linkEvent(this, this.handleSavePostClick)}
652 data-tippy-content={label}
657 classes={classNames({ "text-warning": saved })}
664 get crossPostButton() {
667 className="btn btn-link btn-animate text-muted py-0"
668 to={`/create_post${this.crossPostParams}`}
669 title={i18n.t("cross_post")}
671 <Icon icon="copy" inline />
679 class="btn btn-link btn-animate text-muted py-0"
680 onClick={linkEvent(this, this.handleShowReportDialog)}
681 data-tippy-content={i18n.t("show_report_dialog")}
682 aria-label={i18n.t("show_report_dialog")}
684 <Icon icon="flag" inline />
692 class="btn btn-link btn-animate text-muted py-0"
693 onClick={linkEvent(this, this.handleBlockUserClick)}
694 data-tippy-content={i18n.t("block_user")}
695 aria-label={i18n.t("block_user")}
697 <Icon icon="slash" inline />
705 class="btn btn-link btn-animate text-muted py-0"
706 onClick={linkEvent(this, this.handleEditClick)}
707 data-tippy-content={i18n.t("edit")}
708 aria-label={i18n.t("edit")}
710 <Icon icon="edit" inline />
716 let deleted = this.props.post_view.post.deleted;
717 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
720 class="btn btn-link btn-animate text-muted py-0"
721 onClick={linkEvent(this, this.handleDeleteClick)}
722 data-tippy-content={label}
727 classes={classNames({ "text-danger": deleted })}
734 get showMoreButton() {
737 class="btn btn-link btn-animate text-muted py-0"
738 onClick={linkEvent(this, this.handleShowAdvanced)}
739 data-tippy-content={i18n.t("more")}
740 aria-label={i18n.t("more")}
742 <Icon icon="more-vertical" inline />
747 get viewSourceButton() {
750 class="btn btn-link btn-animate text-muted py-0"
751 onClick={linkEvent(this, this.handleViewSource)}
752 data-tippy-content={i18n.t("view_source")}
753 aria-label={i18n.t("view_source")}
757 classes={classNames({ "text-success": this.state.viewSource })}
765 let locked = this.props.post_view.post.locked;
766 let label = locked ? i18n.t("unlock") : i18n.t("lock");
769 class="btn btn-link btn-animate text-muted py-0"
770 onClick={linkEvent(this, this.handleModLock)}
771 data-tippy-content={label}
776 classes={classNames({ "text-danger": locked })}
784 let stickied = this.props.post_view.post.stickied;
785 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
788 class="btn btn-link btn-animate text-muted py-0"
789 onClick={linkEvent(this, this.handleModSticky)}
790 data-tippy-content={label}
795 classes={classNames({ "text-success": stickied })}
802 get modRemoveButton() {
803 let removed = this.props.post_view.post.removed;
806 class="btn btn-link btn-animate text-muted py-0"
809 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
812 {/* TODO: Find an icon for this. */}
813 {!removed ? i18n.t("remove") : i18n.t("restore")}
819 * Mod/Admin actions to be taken against the author.
823 let post_view = this.props.post_view;
825 this.state.showAdvanced && (
829 {!this.creatorIsMod &&
830 (!post_view.creator_banned_from_community ? (
832 class="btn btn-link btn-animate text-muted py-0"
835 this.handleModBanFromCommunityShow
837 aria-label={i18n.t("ban")}
843 class="btn btn-link btn-animate text-muted py-0"
846 this.handleModBanFromCommunitySubmit
848 aria-label={i18n.t("unban")}
853 {!post_view.creator_banned_from_community && (
855 class="btn btn-link btn-animate text-muted py-0"
856 onClick={linkEvent(this, this.handleAddModToCommunity)}
859 ? i18n.t("remove_as_mod")
860 : i18n.t("appoint_as_mod")
864 ? i18n.t("remove_as_mod")
865 : i18n.t("appoint_as_mod")}
870 {/* Community creators and admins can transfer community to another mod */}
871 {(this.amCommunityCreator || this.canAdmin) &&
873 (!this.state.showConfirmTransferCommunity ? (
875 class="btn btn-link btn-animate text-muted py-0"
878 this.handleShowConfirmTransferCommunity
880 aria-label={i18n.t("transfer_community")}
882 {i18n.t("transfer_community")}
887 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
888 aria-label={i18n.t("are_you_sure")}
890 {i18n.t("are_you_sure")}
893 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
894 aria-label={i18n.t("yes")}
895 onClick={linkEvent(this, this.handleTransferCommunity)}
900 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
903 this.handleCancelShowConfirmTransferCommunity
905 aria-label={i18n.t("no")}
911 {/* Admins can ban from all, and appoint other admins */}
914 {!this.creatorIsAdmin &&
915 (!isBanned(post_view.creator) ? (
917 class="btn btn-link btn-animate text-muted py-0"
918 onClick={linkEvent(this, this.handleModBanShow)}
919 aria-label={i18n.t("ban_from_site")}
921 {i18n.t("ban_from_site")}
925 class="btn btn-link btn-animate text-muted py-0"
926 onClick={linkEvent(this, this.handleModBanSubmit)}
927 aria-label={i18n.t("unban_from_site")}
929 {i18n.t("unban_from_site")}
932 {!isBanned(post_view.creator) && post_view.creator.local && (
934 class="btn btn-link btn-animate text-muted py-0"
935 onClick={linkEvent(this, this.handleAddAdmin)}
938 ? i18n.t("remove_as_admin")
939 : i18n.t("appoint_as_admin")
943 ? i18n.t("remove_as_admin")
944 : i18n.t("appoint_as_admin")}
954 removeAndBanDialogs() {
955 let post = this.props.post_view;
958 {this.state.showRemoveDialog && (
961 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
963 <label class="sr-only" htmlFor="post-listing-remove-reason">
968 id="post-listing-remove-reason"
969 class="form-control mr-2"
970 placeholder={i18n.t("reason")}
971 value={this.state.removeReason}
972 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
976 class="btn btn-secondary"
977 aria-label={i18n.t("remove_post")}
979 {i18n.t("remove_post")}
983 {this.state.showBanDialog && (
984 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
985 <div class="form-group row col-12">
986 <label class="col-form-label" htmlFor="post-listing-ban-reason">
991 id="post-listing-ban-reason"
992 class="form-control mr-2"
993 placeholder={i18n.t("reason")}
994 value={this.state.banReason}
995 onInput={linkEvent(this, this.handleModBanReasonChange)}
997 <label class="col-form-label" htmlFor={`mod-ban-expires`}>
1002 id={`mod-ban-expires`}
1003 class="form-control mr-2"
1004 placeholder={i18n.t("number_of_days")}
1005 value={this.state.banExpireDays}
1006 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1008 <div class="form-group">
1009 <div class="form-check">
1011 class="form-check-input"
1012 id="mod-ban-remove-data"
1014 checked={this.state.removeData}
1015 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1018 class="form-check-label"
1019 htmlFor="mod-ban-remove-data"
1020 title={i18n.t("remove_content_more")}
1022 {i18n.t("remove_content")}
1027 {/* TODO hold off on expires until later */}
1028 {/* <div class="form-group row"> */}
1029 {/* <label class="col-form-label">Expires</label> */}
1030 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1032 <div class="form-group row">
1035 class="btn btn-secondary"
1036 aria-label={i18n.t("ban")}
1038 {i18n.t("ban")} {post.creator.name}
1043 {this.state.showReportDialog && (
1046 onSubmit={linkEvent(this, this.handleReportSubmit)}
1048 <label class="sr-only" htmlFor="post-report-reason">
1053 id="post-report-reason"
1054 class="form-control mr-2"
1055 placeholder={i18n.t("reason")}
1057 value={this.state.reportReason}
1058 onInput={linkEvent(this, this.handleReportReasonChange)}
1062 class="btn btn-secondary"
1063 aria-label={i18n.t("create_report")}
1065 {i18n.t("create_report")}
1074 let post = this.props.post_view.post;
1075 return post.thumbnail_url || isImage(post.url) ? (
1077 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1078 {this.postTitleLine()}
1081 {/* Post body prev or thumbnail */}
1082 {!this.state.imageExpanded && this.thumbnail()}
1086 this.postTitleLine()
1090 showMobilePreview() {
1091 let post = this.props.post_view.post;
1096 className="md-div mb-1"
1097 dangerouslySetInnerHTML={{
1098 __html: md.render(previewLines(post.body)),
1108 {/* The mobile view*/}
1109 <div class="d-block d-sm-none">
1111 <div class="col-12">
1112 {this.createdLine()}
1114 {/* If it has a thumbnail, do a right aligned thumbnail */}
1115 {this.mobileThumbnail()}
1117 {/* Show a preview of the post body */}
1118 {this.showMobilePreview()}
1120 {this.commentsLine(true)}
1121 {this.userActionsLine()}
1122 {this.duplicatesLine()}
1123 {this.removeAndBanDialogs()}
1128 {/* The larger view*/}
1129 <div class="d-none d-sm-block">
1131 {!this.props.viewOnly && this.voteBar()}
1132 <div class="col-sm-2 pr-0">
1133 <div class="">{this.thumbnail()}</div>
1135 <div class="col-12 col-sm-9">
1137 <div className="col-12">
1138 {this.postTitleLine()}
1139 {this.createdLine()}
1140 {this.commentsLine()}
1141 {this.duplicatesLine()}
1142 {this.userActionsLine()}
1143 {this.removeAndBanDialogs()}
1153 private get myPost(): boolean {
1155 UserService.Instance.myUserInfo &&
1156 this.props.post_view.creator.id ==
1157 UserService.Instance.myUserInfo.local_user_view.person.id
1161 get creatorIsMod(): boolean {
1163 this.props.moderators &&
1165 this.props.moderators.map(m => m.moderator.id),
1166 this.props.post_view.creator.id
1171 get creatorIsAdmin(): boolean {
1173 this.props.admins &&
1175 this.props.admins.map(a => a.person.id),
1176 this.props.post_view.creator.id
1182 * If the current user is allowed to mod this post.
1183 * The creator of this post is not allowed even if they are a mod.
1185 get canMod(): boolean {
1186 if (this.props.admins && this.props.moderators) {
1187 let adminsThenMods = this.props.admins
1188 .map(a => a.person.id)
1189 .concat(this.props.moderators.map(m => m.moderator.id));
1192 UserService.Instance.myUserInfo,
1194 this.props.post_view.creator.id
1202 * If the current user is allowed to mod this post.
1203 * The creator of this post is allowed if they are a mod.
1205 get canModOnSelf(): boolean {
1206 if (this.props.admins && this.props.moderators) {
1207 let adminsThenMods = this.props.admins
1208 .map(a => a.person.id)
1209 .concat(this.props.moderators.map(m => m.moderator.id));
1212 UserService.Instance.myUserInfo,
1214 this.props.post_view.creator.id,
1222 get canAdmin(): boolean {
1224 this.props.admins &&
1226 UserService.Instance.myUserInfo,
1227 this.props.admins.map(a => a.person.id),
1228 this.props.post_view.creator.id
1233 get amCommunityCreator(): boolean {
1235 this.props.moderators &&
1236 UserService.Instance.myUserInfo &&
1237 this.props.post_view.creator.id !=
1238 UserService.Instance.myUserInfo.local_user_view.person.id &&
1239 UserService.Instance.myUserInfo.local_user_view.person.id ==
1240 this.props.moderators[0].moderator.id
1244 get amSiteCreator(): boolean {
1246 this.props.admins &&
1247 UserService.Instance.myUserInfo &&
1248 this.props.post_view.creator.id !=
1249 UserService.Instance.myUserInfo.local_user_view.person.id &&
1250 UserService.Instance.myUserInfo.local_user_view.person.id ==
1251 this.props.admins[0].person.id
1255 handlePostLike(i: PostListing, event: any) {
1256 event.preventDefault();
1257 if (!UserService.Instance.myUserInfo) {
1258 this.context.router.history.push(`/login`);
1261 let new_vote = i.state.my_vote == 1 ? 0 : 1;
1263 if (i.state.my_vote == 1) {
1266 } else if (i.state.my_vote == -1) {
1267 i.state.downvotes--;
1275 i.state.my_vote = new_vote;
1277 let form: CreatePostLike = {
1278 post_id: i.props.post_view.post.id,
1279 score: i.state.my_vote,
1283 WebSocketService.Instance.send(wsClient.likePost(form));
1284 i.setState(i.state);
1288 handlePostDisLike(i: PostListing, event: any) {
1289 event.preventDefault();
1290 if (!UserService.Instance.myUserInfo) {
1291 this.context.router.history.push(`/login`);
1294 let new_vote = i.state.my_vote == -1 ? 0 : -1;
1296 if (i.state.my_vote == 1) {
1299 i.state.downvotes++;
1300 } else if (i.state.my_vote == -1) {
1301 i.state.downvotes--;
1304 i.state.downvotes++;
1308 i.state.my_vote = new_vote;
1310 let form: CreatePostLike = {
1311 post_id: i.props.post_view.post.id,
1312 score: i.state.my_vote,
1316 WebSocketService.Instance.send(wsClient.likePost(form));
1317 i.setState(i.state);
1321 handleEditClick(i: PostListing) {
1322 i.state.showEdit = true;
1323 i.setState(i.state);
1326 handleEditCancel() {
1327 this.state.showEdit = false;
1328 this.setState(this.state);
1331 // The actual editing is done in the recieve for post
1333 this.state.showEdit = false;
1334 this.setState(this.state);
1337 handleShowReportDialog(i: PostListing) {
1338 i.state.showReportDialog = !i.state.showReportDialog;
1339 i.setState(this.state);
1342 handleReportReasonChange(i: PostListing, event: any) {
1343 i.state.reportReason = event.target.value;
1344 i.setState(i.state);
1347 handleReportSubmit(i: PostListing, event: any) {
1348 event.preventDefault();
1349 let form: CreatePostReport = {
1350 post_id: i.props.post_view.post.id,
1351 reason: i.state.reportReason,
1354 WebSocketService.Instance.send(wsClient.createPostReport(form));
1356 i.state.showReportDialog = false;
1357 i.setState(i.state);
1360 handleBlockUserClick(i: PostListing) {
1361 let blockUserForm: BlockPerson = {
1362 person_id: i.props.post_view.creator.id,
1366 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1369 handleDeleteClick(i: PostListing) {
1370 let deleteForm: DeletePost = {
1371 post_id: i.props.post_view.post.id,
1372 deleted: !i.props.post_view.post.deleted,
1375 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1378 handleSavePostClick(i: PostListing) {
1380 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1381 let form: SavePost = {
1382 post_id: i.props.post_view.post.id,
1387 WebSocketService.Instance.send(wsClient.savePost(form));
1390 get crossPostParams(): string {
1391 let post = this.props.post_view.post;
1392 let params = `?title=${encodeURIComponent(post.name)}`;
1395 params += `&url=${encodeURIComponent(post.url)}`;
1398 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1403 crossPostBody(): string {
1404 let post = this.props.post_view.post;
1405 let body = `${i18n.t("cross_posted_from")} ${
1407 }\n\n${post.body.replace(/^/gm, "> ")}`;
1411 get showBody(): boolean {
1412 return this.props.showBody || this.state.showBody;
1415 handleModRemoveShow(i: PostListing) {
1416 i.state.showRemoveDialog = !i.state.showRemoveDialog;
1417 i.state.showBanDialog = false;
1418 i.setState(i.state);
1421 handleModRemoveReasonChange(i: PostListing, event: any) {
1422 i.state.removeReason = event.target.value;
1423 i.setState(i.state);
1426 handleModRemoveDataChange(i: PostListing, event: any) {
1427 i.state.removeData = event.target.checked;
1428 i.setState(i.state);
1431 handleModRemoveSubmit(i: PostListing, event: any) {
1432 event.preventDefault();
1433 let form: RemovePost = {
1434 post_id: i.props.post_view.post.id,
1435 removed: !i.props.post_view.post.removed,
1436 reason: i.state.removeReason,
1439 WebSocketService.Instance.send(wsClient.removePost(form));
1441 i.state.showRemoveDialog = false;
1442 i.setState(i.state);
1445 handleModLock(i: PostListing) {
1446 let form: LockPost = {
1447 post_id: i.props.post_view.post.id,
1448 locked: !i.props.post_view.post.locked,
1451 WebSocketService.Instance.send(wsClient.lockPost(form));
1454 handleModSticky(i: PostListing) {
1455 let form: StickyPost = {
1456 post_id: i.props.post_view.post.id,
1457 stickied: !i.props.post_view.post.stickied,
1460 WebSocketService.Instance.send(wsClient.stickyPost(form));
1463 handleModBanFromCommunityShow(i: PostListing) {
1464 i.state.showBanDialog = true;
1465 i.state.banType = BanType.Community;
1466 i.state.showRemoveDialog = false;
1467 i.setState(i.state);
1470 handleModBanShow(i: PostListing) {
1471 i.state.showBanDialog = true;
1472 i.state.banType = BanType.Site;
1473 i.state.showRemoveDialog = false;
1474 i.setState(i.state);
1477 handleModBanReasonChange(i: PostListing, event: any) {
1478 i.state.banReason = event.target.value;
1479 i.setState(i.state);
1482 handleModBanExpireDaysChange(i: PostListing, event: any) {
1483 i.state.banExpireDays = event.target.value;
1484 i.setState(i.state);
1487 handleModBanFromCommunitySubmit(i: PostListing) {
1488 i.state.banType = BanType.Community;
1489 i.setState(i.state);
1490 i.handleModBanBothSubmit(i);
1493 handleModBanSubmit(i: PostListing) {
1494 i.state.banType = BanType.Site;
1495 i.setState(i.state);
1496 i.handleModBanBothSubmit(i);
1499 handleModBanBothSubmit(i: PostListing, event?: any) {
1500 if (event) event.preventDefault();
1502 if (i.state.banType == BanType.Community) {
1503 // If its an unban, restore all their data
1504 let ban = !i.props.post_view.creator_banned_from_community;
1506 i.state.removeData = false;
1508 let form: BanFromCommunity = {
1509 person_id: i.props.post_view.creator.id,
1510 community_id: i.props.post_view.community.id,
1512 remove_data: i.state.removeData,
1513 reason: i.state.banReason,
1514 expires: futureDaysToUnixTime(i.state.banExpireDays),
1517 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1519 // If its an unban, restore all their data
1520 let ban = !i.props.post_view.creator.banned;
1522 i.state.removeData = false;
1524 let form: BanPerson = {
1525 person_id: i.props.post_view.creator.id,
1527 remove_data: i.state.removeData,
1528 reason: i.state.banReason,
1529 expires: futureDaysToUnixTime(i.state.banExpireDays),
1532 WebSocketService.Instance.send(wsClient.banPerson(form));
1535 i.state.showBanDialog = false;
1536 i.setState(i.state);
1539 handleAddModToCommunity(i: PostListing) {
1540 let form: AddModToCommunity = {
1541 person_id: i.props.post_view.creator.id,
1542 community_id: i.props.post_view.community.id,
1543 added: !i.creatorIsMod,
1546 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1547 i.setState(i.state);
1550 handleAddAdmin(i: PostListing) {
1551 let form: AddAdmin = {
1552 person_id: i.props.post_view.creator.id,
1553 added: !i.creatorIsAdmin,
1556 WebSocketService.Instance.send(wsClient.addAdmin(form));
1557 i.setState(i.state);
1560 handleShowConfirmTransferCommunity(i: PostListing) {
1561 i.state.showConfirmTransferCommunity = true;
1562 i.setState(i.state);
1565 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1566 i.state.showConfirmTransferCommunity = false;
1567 i.setState(i.state);
1570 handleTransferCommunity(i: PostListing) {
1571 let form: TransferCommunity = {
1572 community_id: i.props.post_view.community.id,
1573 person_id: i.props.post_view.creator.id,
1576 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1577 i.state.showConfirmTransferCommunity = false;
1578 i.setState(i.state);
1581 handleShowConfirmTransferSite(i: PostListing) {
1582 i.state.showConfirmTransferSite = true;
1583 i.setState(i.state);
1586 handleCancelShowConfirmTransferSite(i: PostListing) {
1587 i.state.showConfirmTransferSite = false;
1588 i.setState(i.state);
1591 handleImageExpandClick(i: PostListing, event: any) {
1592 event.preventDefault();
1593 i.state.imageExpanded = !i.state.imageExpanded;
1594 i.setState(i.state);
1598 handleViewSource(i: PostListing) {
1599 i.state.viewSource = !i.state.viewSource;
1600 i.setState(i.state);
1603 handleShowAdvanced(i: PostListing) {
1604 i.state.showAdvanced = !i.state.showAdvanced;
1605 i.setState(i.state);
1609 handleShowMoreMobile(i: PostListing) {
1610 i.state.showMoreMobile = !i.state.showMoreMobile;
1611 i.state.showAdvanced = !i.state.showAdvanced;
1612 i.setState(i.state);
1616 handleShowBody(i: PostListing) {
1617 i.state.showBody = !i.state.showBody;
1618 i.setState(i.state);
1622 get pointsTippy(): string {
1623 let points = i18n.t("number_of_points", {
1624 count: this.state.score,
1625 formattedCount: this.state.score,
1628 let upvotes = i18n.t("number_of_upvotes", {
1629 count: this.state.upvotes,
1630 formattedCount: this.state.upvotes,
1633 let downvotes = i18n.t("number_of_downvotes", {
1634 count: this.state.downvotes,
1635 formattedCount: this.state.downvotes,
1638 return `${points} • ${upvotes} • ${downvotes}`;