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) {
514 <div class="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
515 {this.commentsButton}
516 {mobile && !this.props.viewOnly && this.mobileVotes}
517 {UserService.Instance.myUserInfo &&
518 !this.props.viewOnly &&
519 this.postActions(mobile)}
524 postActions(mobile = false) {
525 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
526 // Possible enhancement: Make each button a component.
527 let post_view = this.props.post_view;
531 {this.crossPostButton}
532 {mobile && this.showMoreButton}
533 {(!mobile || this.state.showAdvanced) && (
541 {this.myPost && (this.showBody || this.state.showAdvanced) && (
549 {this.state.showAdvanced && (
551 {this.showBody && post_view.post.body && this.viewSourceButton}
552 {this.canModOnSelf && (
558 {(this.canMod || this.canAdmin || true) && (
559 <>{this.modRemoveButton}</>
563 {!mobile && this.showMoreButton}
568 get commentsButton() {
569 let post_view = this.props.post_view;
571 <button class="btn btn-link text-muted py-0 pl-0">
573 className="text-muted"
574 title={i18n.t("number_of_comments", {
575 count: post_view.counts.comments,
576 formattedCount: post_view.counts.comments,
578 to={`/post/${post_view.post.id}?scrollToComments=true`}
580 <Icon icon="message-square" classes="mr-1" inline />
581 {i18n.t("number_of_comments", {
582 count: post_view.counts.comments,
583 formattedCount: numToSI(post_view.counts.comments),
592 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
597 className={`btn-animate btn py-0 px-1 ${
598 this.state.my_vote == 1 ? "text-info" : "text-muted"
601 onClick={linkEvent(this, this.handlePostLike)}
602 aria-label={i18n.t("upvote")}
604 <Icon icon="arrow-up1" classes="icon-inline small" />
606 <span class="ml-2">{numToSI(this.state.upvotes)}</span>
609 {this.props.enableDownvotes && (
611 className={`ml-2 btn-animate btn py-0 px-1 ${
612 this.state.my_vote == -1 ? "text-danger" : "text-muted"
614 onClick={linkEvent(this, this.handlePostDisLike)}
616 aria-label={i18n.t("downvote")}
618 <Icon icon="arrow-down1" classes="icon-inline small" />
621 class={classNames("ml-2", {
622 invisible: this.state.downvotes === 0,
625 {numToSI(this.state.downvotes)}
636 let saved = this.props.post_view.saved;
637 let label = saved ? i18n.t("unsave") : i18n.t("save");
640 class="btn btn-link btn-animate text-muted py-0"
641 onClick={linkEvent(this, this.handleSavePostClick)}
642 data-tippy-content={label}
647 classes={classNames({ "text-warning": saved })}
654 get crossPostButton() {
657 className="btn btn-link btn-animate text-muted py-0"
658 to={`/create_post${this.crossPostParams}`}
659 title={i18n.t("cross_post")}
661 <Icon icon="copy" inline />
669 class="btn btn-link btn-animate text-muted py-0"
670 onClick={linkEvent(this, this.handleShowReportDialog)}
671 data-tippy-content={i18n.t("show_report_dialog")}
672 aria-label={i18n.t("show_report_dialog")}
674 <Icon icon="flag" inline />
682 class="btn btn-link btn-animate text-muted py-0"
683 onClick={linkEvent(this, this.handleBlockUserClick)}
684 data-tippy-content={i18n.t("block_user")}
685 aria-label={i18n.t("block_user")}
687 <Icon icon="slash" inline />
695 class="btn btn-link btn-animate text-muted py-0"
696 onClick={linkEvent(this, this.handleEditClick)}
697 data-tippy-content={i18n.t("edit")}
698 aria-label={i18n.t("edit")}
700 <Icon icon="edit" inline />
706 let deleted = this.props.post_view.post.deleted;
707 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
710 class="btn btn-link btn-animate text-muted py-0"
711 onClick={linkEvent(this, this.handleDeleteClick)}
712 data-tippy-content={label}
717 classes={classNames({ "text-danger": deleted })}
724 get showMoreButton() {
727 class="btn btn-link btn-animate text-muted py-0"
728 onClick={linkEvent(this, this.handleShowAdvanced)}
729 data-tippy-content={i18n.t("more")}
730 aria-label={i18n.t("more")}
732 <Icon icon="more-vertical" inline />
737 get viewSourceButton() {
740 class="btn btn-link btn-animate text-muted py-0"
741 onClick={linkEvent(this, this.handleViewSource)}
742 data-tippy-content={i18n.t("view_source")}
743 aria-label={i18n.t("view_source")}
747 classes={classNames({ "text-success": this.state.viewSource })}
755 let locked = this.props.post_view.post.locked;
756 let label = locked ? i18n.t("unlock") : i18n.t("lock");
759 class="btn btn-link btn-animate text-muted py-0"
760 onClick={linkEvent(this, this.handleModLock)}
761 data-tippy-content={label}
766 classes={classNames({ "text-danger": locked })}
774 let stickied = this.props.post_view.post.stickied;
775 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
778 class="btn btn-link btn-animate text-muted py-0"
779 onClick={linkEvent(this, this.handleModSticky)}
780 data-tippy-content={label}
785 classes={classNames({ "text-success": stickied })}
792 get modRemoveButton() {
793 let removed = this.props.post_view.post.removed;
796 class="btn btn-link btn-animate text-muted py-0"
799 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
802 {/* TODO: Find an icon for this. */}
803 {!removed ? i18n.t("remove") : i18n.t("restore")}
809 * Mod/Admin actions to be taken against the author.
813 let post_view = this.props.post_view;
815 this.state.showAdvanced && (
819 {!this.creatorIsMod &&
820 (!post_view.creator_banned_from_community ? (
822 class="btn btn-link btn-animate text-muted py-0"
825 this.handleModBanFromCommunityShow
827 aria-label={i18n.t("ban")}
833 class="btn btn-link btn-animate text-muted py-0"
836 this.handleModBanFromCommunitySubmit
838 aria-label={i18n.t("unban")}
843 {!post_view.creator_banned_from_community && (
845 class="btn btn-link btn-animate text-muted py-0"
846 onClick={linkEvent(this, this.handleAddModToCommunity)}
849 ? i18n.t("remove_as_mod")
850 : i18n.t("appoint_as_mod")
854 ? i18n.t("remove_as_mod")
855 : i18n.t("appoint_as_mod")}
860 {/* Community creators and admins can transfer community to another mod */}
861 {(this.amCommunityCreator || this.canAdmin) &&
863 (!this.state.showConfirmTransferCommunity ? (
865 class="btn btn-link btn-animate text-muted py-0"
868 this.handleShowConfirmTransferCommunity
870 aria-label={i18n.t("transfer_community")}
872 {i18n.t("transfer_community")}
877 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
878 aria-label={i18n.t("are_you_sure")}
880 {i18n.t("are_you_sure")}
883 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
884 aria-label={i18n.t("yes")}
885 onClick={linkEvent(this, this.handleTransferCommunity)}
890 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
893 this.handleCancelShowConfirmTransferCommunity
895 aria-label={i18n.t("no")}
901 {/* Admins can ban from all, and appoint other admins */}
904 {!this.creatorIsAdmin &&
905 (!isBanned(post_view.creator) ? (
907 class="btn btn-link btn-animate text-muted py-0"
908 onClick={linkEvent(this, this.handleModBanShow)}
909 aria-label={i18n.t("ban_from_site")}
911 {i18n.t("ban_from_site")}
915 class="btn btn-link btn-animate text-muted py-0"
916 onClick={linkEvent(this, this.handleModBanSubmit)}
917 aria-label={i18n.t("unban_from_site")}
919 {i18n.t("unban_from_site")}
922 {!isBanned(post_view.creator) && post_view.creator.local && (
924 class="btn btn-link btn-animate text-muted py-0"
925 onClick={linkEvent(this, this.handleAddAdmin)}
928 ? i18n.t("remove_as_admin")
929 : i18n.t("appoint_as_admin")
933 ? i18n.t("remove_as_admin")
934 : i18n.t("appoint_as_admin")}
944 removeAndBanDialogs() {
945 let post = this.props.post_view;
948 {this.state.showRemoveDialog && (
951 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
953 <label class="sr-only" htmlFor="post-listing-remove-reason">
958 id="post-listing-remove-reason"
959 class="form-control mr-2"
960 placeholder={i18n.t("reason")}
961 value={this.state.removeReason}
962 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
966 class="btn btn-secondary"
967 aria-label={i18n.t("remove_post")}
969 {i18n.t("remove_post")}
973 {this.state.showBanDialog && (
974 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
975 <div class="form-group row col-12">
976 <label class="col-form-label" htmlFor="post-listing-ban-reason">
981 id="post-listing-ban-reason"
982 class="form-control mr-2"
983 placeholder={i18n.t("reason")}
984 value={this.state.banReason}
985 onInput={linkEvent(this, this.handleModBanReasonChange)}
987 <label class="col-form-label" htmlFor={`mod-ban-expires`}>
992 id={`mod-ban-expires`}
993 class="form-control mr-2"
994 placeholder={i18n.t("number_of_days")}
995 value={this.state.banExpireDays}
996 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
998 <div class="form-group">
999 <div class="form-check">
1001 class="form-check-input"
1002 id="mod-ban-remove-data"
1004 checked={this.state.removeData}
1005 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1008 class="form-check-label"
1009 htmlFor="mod-ban-remove-data"
1010 title={i18n.t("remove_content_more")}
1012 {i18n.t("remove_content")}
1017 {/* TODO hold off on expires until later */}
1018 {/* <div class="form-group row"> */}
1019 {/* <label class="col-form-label">Expires</label> */}
1020 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1022 <div class="form-group row">
1025 class="btn btn-secondary"
1026 aria-label={i18n.t("ban")}
1028 {i18n.t("ban")} {post.creator.name}
1033 {this.state.showReportDialog && (
1036 onSubmit={linkEvent(this, this.handleReportSubmit)}
1038 <label class="sr-only" htmlFor="post-report-reason">
1043 id="post-report-reason"
1044 class="form-control mr-2"
1045 placeholder={i18n.t("reason")}
1047 value={this.state.reportReason}
1048 onInput={linkEvent(this, this.handleReportReasonChange)}
1052 class="btn btn-secondary"
1053 aria-label={i18n.t("create_report")}
1055 {i18n.t("create_report")}
1064 let post = this.props.post_view.post;
1065 return post.thumbnail_url || isImage(post.url) ? (
1067 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1068 {this.postTitleLine()}
1071 {/* Post body prev or thumbnail */}
1072 {!this.state.imageExpanded && this.thumbnail()}
1076 this.postTitleLine()
1080 showMobilePreview() {
1081 let post = this.props.post_view.post;
1086 className="md-div mb-1"
1087 dangerouslySetInnerHTML={{
1088 __html: md.render(previewLines(post.body)),
1098 {/* The mobile view*/}
1099 <div class="d-block d-sm-none">
1101 <div class="col-12">
1102 {this.createdLine()}
1104 {/* If it has a thumbnail, do a right aligned thumbnail */}
1105 {this.mobileThumbnail()}
1107 {/* Show a preview of the post body */}
1108 {this.showMobilePreview()}
1110 {this.commentsLine(true)}
1111 {this.userActionsLine()}
1112 {this.duplicatesLine()}
1113 {this.removeAndBanDialogs()}
1118 {/* The larger view*/}
1119 <div class="d-none d-sm-block">
1121 {!this.props.viewOnly && this.voteBar()}
1122 <div class="col-sm-2 pr-0">
1123 <div class="">{this.thumbnail()}</div>
1125 <div class="col-12 col-sm-9">
1127 <div className="col-12">
1128 {this.postTitleLine()}
1129 {this.createdLine()}
1130 {this.commentsLine()}
1131 {this.duplicatesLine()}
1132 {this.userActionsLine()}
1133 {this.removeAndBanDialogs()}
1143 private get myPost(): boolean {
1145 UserService.Instance.myUserInfo &&
1146 this.props.post_view.creator.id ==
1147 UserService.Instance.myUserInfo.local_user_view.person.id
1151 get creatorIsMod(): boolean {
1153 this.props.moderators &&
1155 this.props.moderators.map(m => m.moderator.id),
1156 this.props.post_view.creator.id
1161 get creatorIsAdmin(): boolean {
1163 this.props.admins &&
1165 this.props.admins.map(a => a.person.id),
1166 this.props.post_view.creator.id
1172 * If the current user is allowed to mod this post.
1173 * The creator of this post is not allowed even if they are a mod.
1175 get canMod(): boolean {
1176 if (this.props.admins && this.props.moderators) {
1177 let adminsThenMods = this.props.admins
1178 .map(a => a.person.id)
1179 .concat(this.props.moderators.map(m => m.moderator.id));
1182 UserService.Instance.myUserInfo,
1184 this.props.post_view.creator.id
1192 * If the current user is allowed to mod this post.
1193 * The creator of this post is allowed if they are a mod.
1195 get canModOnSelf(): boolean {
1196 if (this.props.admins && this.props.moderators) {
1197 let adminsThenMods = this.props.admins
1198 .map(a => a.person.id)
1199 .concat(this.props.moderators.map(m => m.moderator.id));
1202 UserService.Instance.myUserInfo,
1204 this.props.post_view.creator.id,
1212 get canAdmin(): boolean {
1214 this.props.admins &&
1216 UserService.Instance.myUserInfo,
1217 this.props.admins.map(a => a.person.id),
1218 this.props.post_view.creator.id
1223 get amCommunityCreator(): boolean {
1225 this.props.moderators &&
1226 UserService.Instance.myUserInfo &&
1227 this.props.post_view.creator.id !=
1228 UserService.Instance.myUserInfo.local_user_view.person.id &&
1229 UserService.Instance.myUserInfo.local_user_view.person.id ==
1230 this.props.moderators[0].moderator.id
1234 get amSiteCreator(): boolean {
1236 this.props.admins &&
1237 UserService.Instance.myUserInfo &&
1238 this.props.post_view.creator.id !=
1239 UserService.Instance.myUserInfo.local_user_view.person.id &&
1240 UserService.Instance.myUserInfo.local_user_view.person.id ==
1241 this.props.admins[0].person.id
1245 handlePostLike(i: PostListing, event: any) {
1246 event.preventDefault();
1247 if (!UserService.Instance.myUserInfo) {
1248 this.context.router.history.push(`/login`);
1251 let new_vote = i.state.my_vote == 1 ? 0 : 1;
1253 if (i.state.my_vote == 1) {
1256 } else if (i.state.my_vote == -1) {
1257 i.state.downvotes--;
1265 i.state.my_vote = new_vote;
1267 let form: CreatePostLike = {
1268 post_id: i.props.post_view.post.id,
1269 score: i.state.my_vote,
1273 WebSocketService.Instance.send(wsClient.likePost(form));
1274 i.setState(i.state);
1278 handlePostDisLike(i: PostListing, event: any) {
1279 event.preventDefault();
1280 if (!UserService.Instance.myUserInfo) {
1281 this.context.router.history.push(`/login`);
1284 let new_vote = i.state.my_vote == -1 ? 0 : -1;
1286 if (i.state.my_vote == 1) {
1289 i.state.downvotes++;
1290 } else if (i.state.my_vote == -1) {
1291 i.state.downvotes--;
1294 i.state.downvotes++;
1298 i.state.my_vote = new_vote;
1300 let form: CreatePostLike = {
1301 post_id: i.props.post_view.post.id,
1302 score: i.state.my_vote,
1306 WebSocketService.Instance.send(wsClient.likePost(form));
1307 i.setState(i.state);
1311 handleEditClick(i: PostListing) {
1312 i.state.showEdit = true;
1313 i.setState(i.state);
1316 handleEditCancel() {
1317 this.state.showEdit = false;
1318 this.setState(this.state);
1321 // The actual editing is done in the recieve for post
1323 this.state.showEdit = false;
1324 this.setState(this.state);
1327 handleShowReportDialog(i: PostListing) {
1328 i.state.showReportDialog = !i.state.showReportDialog;
1329 i.setState(this.state);
1332 handleReportReasonChange(i: PostListing, event: any) {
1333 i.state.reportReason = event.target.value;
1334 i.setState(i.state);
1337 handleReportSubmit(i: PostListing, event: any) {
1338 event.preventDefault();
1339 let form: CreatePostReport = {
1340 post_id: i.props.post_view.post.id,
1341 reason: i.state.reportReason,
1344 WebSocketService.Instance.send(wsClient.createPostReport(form));
1346 i.state.showReportDialog = false;
1347 i.setState(i.state);
1350 handleBlockUserClick(i: PostListing) {
1351 let blockUserForm: BlockPerson = {
1352 person_id: i.props.post_view.creator.id,
1356 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1359 handleDeleteClick(i: PostListing) {
1360 let deleteForm: DeletePost = {
1361 post_id: i.props.post_view.post.id,
1362 deleted: !i.props.post_view.post.deleted,
1365 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1368 handleSavePostClick(i: PostListing) {
1370 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1371 let form: SavePost = {
1372 post_id: i.props.post_view.post.id,
1377 WebSocketService.Instance.send(wsClient.savePost(form));
1380 get crossPostParams(): string {
1381 let post = this.props.post_view.post;
1382 let params = `?title=${encodeURIComponent(post.name)}`;
1385 params += `&url=${encodeURIComponent(post.url)}`;
1388 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1393 crossPostBody(): string {
1394 let post = this.props.post_view.post;
1395 let body = `${i18n.t("cross_posted_from")} ${
1397 }\n\n${post.body.replace(/^/gm, "> ")}`;
1401 get showBody(): boolean {
1402 return this.props.showBody || this.state.showBody;
1405 handleModRemoveShow(i: PostListing) {
1406 i.state.showRemoveDialog = !i.state.showRemoveDialog;
1407 i.state.showBanDialog = false;
1408 i.setState(i.state);
1411 handleModRemoveReasonChange(i: PostListing, event: any) {
1412 i.state.removeReason = event.target.value;
1413 i.setState(i.state);
1416 handleModRemoveDataChange(i: PostListing, event: any) {
1417 i.state.removeData = event.target.checked;
1418 i.setState(i.state);
1421 handleModRemoveSubmit(i: PostListing, event: any) {
1422 event.preventDefault();
1423 let form: RemovePost = {
1424 post_id: i.props.post_view.post.id,
1425 removed: !i.props.post_view.post.removed,
1426 reason: i.state.removeReason,
1429 WebSocketService.Instance.send(wsClient.removePost(form));
1431 i.state.showRemoveDialog = false;
1432 i.setState(i.state);
1435 handleModLock(i: PostListing) {
1436 let form: LockPost = {
1437 post_id: i.props.post_view.post.id,
1438 locked: !i.props.post_view.post.locked,
1441 WebSocketService.Instance.send(wsClient.lockPost(form));
1444 handleModSticky(i: PostListing) {
1445 let form: StickyPost = {
1446 post_id: i.props.post_view.post.id,
1447 stickied: !i.props.post_view.post.stickied,
1450 WebSocketService.Instance.send(wsClient.stickyPost(form));
1453 handleModBanFromCommunityShow(i: PostListing) {
1454 i.state.showBanDialog = true;
1455 i.state.banType = BanType.Community;
1456 i.state.showRemoveDialog = false;
1457 i.setState(i.state);
1460 handleModBanShow(i: PostListing) {
1461 i.state.showBanDialog = true;
1462 i.state.banType = BanType.Site;
1463 i.state.showRemoveDialog = false;
1464 i.setState(i.state);
1467 handleModBanReasonChange(i: PostListing, event: any) {
1468 i.state.banReason = event.target.value;
1469 i.setState(i.state);
1472 handleModBanExpireDaysChange(i: PostListing, event: any) {
1473 i.state.banExpireDays = event.target.value;
1474 i.setState(i.state);
1477 handleModBanFromCommunitySubmit(i: PostListing) {
1478 i.state.banType = BanType.Community;
1479 i.setState(i.state);
1480 i.handleModBanBothSubmit(i);
1483 handleModBanSubmit(i: PostListing) {
1484 i.state.banType = BanType.Site;
1485 i.setState(i.state);
1486 i.handleModBanBothSubmit(i);
1489 handleModBanBothSubmit(i: PostListing, event?: any) {
1490 if (event) event.preventDefault();
1492 if (i.state.banType == BanType.Community) {
1493 // If its an unban, restore all their data
1494 let ban = !i.props.post_view.creator_banned_from_community;
1496 i.state.removeData = false;
1498 let form: BanFromCommunity = {
1499 person_id: i.props.post_view.creator.id,
1500 community_id: i.props.post_view.community.id,
1502 remove_data: i.state.removeData,
1503 reason: i.state.banReason,
1504 expires: futureDaysToUnixTime(i.state.banExpireDays),
1507 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1509 // If its an unban, restore all their data
1510 let ban = !i.props.post_view.creator.banned;
1512 i.state.removeData = false;
1514 let form: BanPerson = {
1515 person_id: i.props.post_view.creator.id,
1517 remove_data: i.state.removeData,
1518 reason: i.state.banReason,
1519 expires: futureDaysToUnixTime(i.state.banExpireDays),
1522 WebSocketService.Instance.send(wsClient.banPerson(form));
1525 i.state.showBanDialog = false;
1526 i.setState(i.state);
1529 handleAddModToCommunity(i: PostListing) {
1530 let form: AddModToCommunity = {
1531 person_id: i.props.post_view.creator.id,
1532 community_id: i.props.post_view.community.id,
1533 added: !i.creatorIsMod,
1536 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1537 i.setState(i.state);
1540 handleAddAdmin(i: PostListing) {
1541 let form: AddAdmin = {
1542 person_id: i.props.post_view.creator.id,
1543 added: !i.creatorIsAdmin,
1546 WebSocketService.Instance.send(wsClient.addAdmin(form));
1547 i.setState(i.state);
1550 handleShowConfirmTransferCommunity(i: PostListing) {
1551 i.state.showConfirmTransferCommunity = true;
1552 i.setState(i.state);
1555 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1556 i.state.showConfirmTransferCommunity = false;
1557 i.setState(i.state);
1560 handleTransferCommunity(i: PostListing) {
1561 let form: TransferCommunity = {
1562 community_id: i.props.post_view.community.id,
1563 person_id: i.props.post_view.creator.id,
1566 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1567 i.state.showConfirmTransferCommunity = false;
1568 i.setState(i.state);
1571 handleShowConfirmTransferSite(i: PostListing) {
1572 i.state.showConfirmTransferSite = true;
1573 i.setState(i.state);
1576 handleCancelShowConfirmTransferSite(i: PostListing) {
1577 i.state.showConfirmTransferSite = false;
1578 i.setState(i.state);
1581 handleImageExpandClick(i: PostListing, event: any) {
1582 event.preventDefault();
1583 i.state.imageExpanded = !i.state.imageExpanded;
1584 i.setState(i.state);
1588 handleViewSource(i: PostListing) {
1589 i.state.viewSource = !i.state.viewSource;
1590 i.setState(i.state);
1593 handleShowAdvanced(i: PostListing) {
1594 i.state.showAdvanced = !i.state.showAdvanced;
1595 i.setState(i.state);
1599 handleShowMoreMobile(i: PostListing) {
1600 i.state.showMoreMobile = !i.state.showMoreMobile;
1601 i.state.showAdvanced = !i.state.showAdvanced;
1602 i.setState(i.state);
1606 handleShowBody(i: PostListing) {
1607 i.state.showBody = !i.state.showBody;
1608 i.setState(i.state);
1612 get pointsTippy(): string {
1613 let points = i18n.t("number_of_points", {
1614 count: this.state.score,
1615 formattedCount: this.state.score,
1618 let upvotes = i18n.t("number_of_upvotes", {
1619 count: this.state.upvotes,
1620 formattedCount: this.state.upvotes,
1623 let downvotes = i18n.t("number_of_downvotes", {
1624 count: this.state.downvotes,
1625 formattedCount: this.state.downvotes,
1628 return `${points} • ${upvotes} • ${downvotes}`;