1 import { Component, linkEvent } from "inferno";
2 import { Link } from "inferno-router";
8 CommunityModeratorView,
19 } from "lemmy-js-client";
20 import { externalHost } from "../../env";
21 import { i18n } from "../../i18next";
22 import { BanType } from "../../interfaces";
23 import { UserService, WebSocketService } from "../../services";
39 import { Icon } from "../common/icon";
40 import { MomentTime } from "../common/moment-time";
41 import { PictrsImage } from "../common/pictrs-image";
42 import { CommunityLink } from "../community/community-link";
43 import { PersonListing } from "../person/person-listing";
44 import { IFramelyCard } from "./iframely-card";
45 import { PostForm } from "./post-form";
47 interface PostListingState {
49 showRemoveDialog: boolean;
51 showBanDialog: boolean;
56 showConfirmTransferSite: boolean;
57 showConfirmTransferCommunity: boolean;
58 imageExpanded: boolean;
60 showAdvanced: boolean;
61 showMoreMobile: boolean;
69 interface PostListingProps {
71 duplicates?: PostView[];
72 showCommunity?: boolean;
74 moderators?: CommunityModeratorView[];
75 admins?: PersonViewSafe[];
76 enableDownvotes: boolean;
80 export class PostListing extends Component<PostListingProps, PostListingState> {
81 private emptyState: PostListingState = {
83 showRemoveDialog: false,
89 banType: BanType.Community,
90 showConfirmTransferSite: false,
91 showConfirmTransferCommunity: false,
95 showMoreMobile: false,
97 my_vote: this.props.post_view.my_vote,
98 score: this.props.post_view.counts.score,
99 upvotes: this.props.post_view.counts.upvotes,
100 downvotes: this.props.post_view.counts.downvotes,
103 constructor(props: any, context: any) {
104 super(props, context);
106 this.state = this.emptyState;
107 this.handlePostLike = this.handlePostLike.bind(this);
108 this.handlePostDisLike = this.handlePostDisLike.bind(this);
109 this.handleEditPost = this.handleEditPost.bind(this);
110 this.handleEditCancel = this.handleEditCancel.bind(this);
113 componentWillReceiveProps(nextProps: PostListingProps) {
114 this.state.my_vote = nextProps.post_view.my_vote;
115 this.state.upvotes = nextProps.post_view.counts.upvotes;
116 this.state.downvotes = nextProps.post_view.counts.downvotes;
117 this.state.score = nextProps.post_view.counts.score;
118 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
119 this.state.imageExpanded = false;
121 this.setState(this.state);
127 {!this.state.showEdit ? (
135 post_view={this.props.post_view}
136 onEdit={this.handleEditPost}
137 onCancel={this.handleEditCancel}
138 enableNsfw={this.props.enableNsfw}
139 enableDownvotes={this.props.enableDownvotes}
148 let post = this.props.post_view.post;
152 {post.url && this.showBody && post.embed_title && (
153 <IFramelyCard post={post} />
157 (this.state.viewSource ? (
158 <pre>{post.body}</pre>
162 dangerouslySetInnerHTML={mdToHtml(post.body)}
170 imgThumb(src: string) {
171 let post_view = this.props.post_view;
177 nsfw={post_view.post.nsfw || post_view.community.nsfw}
182 getImageSrc(): string {
183 let post = this.props.post_view.post;
184 if (isImage(post.url)) {
185 if (post.url.includes("pictrs")) {
187 } else if (post.thumbnail_url) {
188 return post.thumbnail_url;
192 } else if (post.thumbnail_url) {
193 return post.thumbnail_url;
200 let post = this.props.post_view.post;
202 if (isImage(post.url)) {
205 class="float-right text-body pointer d-inline-block position-relative mb-2"
206 data-tippy-content={i18n.t("expand_here")}
207 onClick={linkEvent(this, this.handleImageExpandClick)}
209 aria-label={i18n.t("expand_here")}
211 {this.imgThumb(this.getImageSrc())}
212 <Icon icon="image" classes="mini-overlay" />
215 } else if (post.thumbnail_url) {
218 class="float-right text-body d-inline-block position-relative mb-2"
223 {this.imgThumb(this.getImageSrc())}
224 <Icon icon="external-link" classes="mini-overlay" />
227 } else if (post.url) {
228 if (isVideo(post.url)) {
230 <div class="embed-responsive embed-responsive-16by9">
236 class="embed-responsive-item"
238 <source src={post.url} type="video/mp4" />
245 className="text-body"
250 <div class="thumbnail rounded bg-light d-flex justify-content-center">
251 <Icon icon="external-link" classes="d-flex align-items-center" />
259 className="text-body"
260 to={`/post/${post.id}`}
261 title={i18n.t("comments")}
263 <div class="thumbnail rounded bg-light d-flex justify-content-center">
264 <Icon icon="message-square" classes="d-flex align-items-center" />
272 let post_view = this.props.post_view;
274 <ul class="list-inline mb-1 text-muted small">
275 <li className="list-inline-item">
276 <PersonListing person={post_view.creator} />
279 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
282 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
284 {(post_view.creator_banned_from_community ||
285 post_view.creator.banned) && (
286 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
288 {this.props.showCommunity && (
290 <span class="mx-1"> {i18n.t("to")} </span>
291 <CommunityLink community={post_view.community} />
295 <li className="list-inline-item">•</li>
296 {post_view.post.url && !(hostname(post_view.post.url) == externalHost) && (
298 <li className="list-inline-item">
300 className="text-muted font-italic"
301 href={post_view.post.url}
302 title={post_view.post.url}
305 {hostname(post_view.post.url)}
308 <li className="list-inline-item">•</li>
311 <li className="list-inline-item">
313 <MomentTime data={post_view.post} />
316 {post_view.post.body && (
318 <li className="list-inline-item">•</li>
319 <li className="list-inline-item">
321 className="text-muted btn btn-sm btn-link p-0"
322 data-tippy-content={md.render(
323 previewLines(post_view.post.body)
325 data-tippy-allowHtml={true}
326 onClick={linkEvent(this, this.handleShowBody)}
328 <Icon icon="book-open" classes="icon-inline mr-1" />
339 <div className={`vote-bar col-1 pr-0 small text-center`}>
341 className={`btn-animate btn btn-link p-0 ${
342 this.state.my_vote == 1 ? "text-info" : "text-muted"
344 onClick={linkEvent(this, this.handlePostLike)}
345 data-tippy-content={i18n.t("upvote")}
346 aria-label={i18n.t("upvote")}
348 <Icon icon="arrow-up1" classes="upvote" />
352 class={`unselectable pointer font-weight-bold text-muted px-1`}
353 data-tippy-content={this.pointsTippy}
358 <div class="p-1"></div>
360 {this.props.enableDownvotes && (
362 className={`btn-animate btn btn-link p-0 ${
363 this.state.my_vote == -1 ? "text-danger" : "text-muted"
365 onClick={linkEvent(this, this.handlePostDisLike)}
366 data-tippy-content={i18n.t("downvote")}
367 aria-label={i18n.t("downvote")}
369 <Icon icon="arrow-down1" classes="downvote" />
377 let post = this.props.post_view.post;
379 <div className="post-title overflow-hidden">
381 {this.showBody && post.url ? (
383 className={!post.stickied ? "text-body" : "text-primary"}
392 className={!post.stickied ? "text-body" : "text-primary"}
393 to={`/post/${post.id}`}
394 title={i18n.t("comments")}
399 {(isImage(post.url) || post.thumbnail_url) &&
400 (!this.state.imageExpanded ? (
402 class="btn btn-link text-monospace text-muted small d-inline-block ml-2"
403 data-tippy-content={i18n.t("expand_here")}
404 onClick={linkEvent(this, this.handleImageExpandClick)}
406 <Icon icon="plus-square" classes="icon-inline" />
411 class="btn btn-link text-monospace text-muted small d-inline-block ml-2"
412 onClick={linkEvent(this, this.handleImageExpandClick)}
414 <Icon icon="minus-square" classes="icon-inline" />
418 class="btn btn-link d-inline-block"
419 onClick={linkEvent(this, this.handleImageExpandClick)}
421 <PictrsImage src={this.getImageSrc()} />
427 <small className="ml-2 text-muted font-italic">
433 className="unselectable pointer ml-2 text-muted font-italic"
434 data-tippy-content={i18n.t("deleted")}
436 <Icon icon="trash" classes="icon-inline text-danger" />
441 className="unselectable pointer ml-2 text-muted font-italic"
442 data-tippy-content={i18n.t("locked")}
444 <Icon icon="lock" classes="icon-inline text-danger" />
449 className="unselectable pointer ml-2 text-muted font-italic"
450 data-tippy-content={i18n.t("stickied")}
452 <Icon icon="pin" classes="icon-inline text-primary" />
456 <small className="ml-2 text-muted font-italic">
465 commentsLine(mobile = false) {
466 let post_view = this.props.post_view;
468 <div class="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold mb-1">
470 class="btn btn-link text-muted p-0"
473 className="text-muted small"
474 title={i18n.t("number_of_comments", {
475 count: post_view.counts.comments,
477 to={`/post/${post_view.post.id}?scrollToComments=true`}
479 <Icon icon="message-square" classes="icon-inline mr-1" />
480 {i18n.t("number_of_comments", {
481 count: post_view.counts.comments,
487 {this.state.downvotes !== 0 && showScores() && (
489 class="btn text-muted py-0 pr-0"
490 data-tippy-content={this.pointsTippy}
491 aria-label={i18n.t("downvote")}
494 <Icon icon="arrow-down1" classes="icon-inline mr-1" />
495 <span>{this.state.downvotes}</span>
501 class="btn btn-link btn-animate text-muted py-0"
502 onClick={linkEvent(this, this.handleSavePostClick)}
504 post_view.saved ? i18n.t("unsave") : i18n.t("save")
506 aria-label={post_view.saved ? i18n.t("unsave") : i18n.t("save")}
511 classes={`icon-inline ${post_view.saved && "text-warning"}`}
518 {/* This is an expanding spacer for mobile */}
519 <div className="flex-grow-1"></div>
525 className={`btn-animate btn py-0 px-1 ${
526 this.state.my_vote == 1 ? "text-info" : "text-muted"
528 data-tippy-content={this.pointsTippy}
529 onClick={linkEvent(this, this.handlePostLike)}
530 aria-label={i18n.t("upvote")}
532 <Icon icon="arrow-up1" classes="icon-inline small mr-2" />
537 className={`btn-animate btn py-0 px-1 ${
538 this.state.my_vote == 1 ? "text-info" : "text-muted"
540 onClick={linkEvent(this, this.handlePostLike)}
541 aria-label={i18n.t("upvote")}
543 <Icon icon="arrow-up1" classes="icon-inline small" />
546 {this.props.enableDownvotes &&
549 className={`ml-2 btn-animate btn py-0 pl-1 ${
550 this.state.my_vote == -1 ? "text-danger" : "text-muted"
552 onClick={linkEvent(this, this.handlePostDisLike)}
553 data-tippy-content={this.pointsTippy}
554 aria-label={i18n.t("downvote")}
556 <Icon icon="arrow-down1" classes="icon-inline small mr-2" />
557 {this.state.downvotes !== 0 && (
558 <span>{this.state.downvotes}</span>
563 className={`ml-2 btn-animate btn py-0 pl-1 ${
564 this.state.my_vote == -1 ? "text-danger" : "text-muted"
566 onClick={linkEvent(this, this.handlePostDisLike)}
567 aria-label={i18n.t("downvote")}
569 <Icon icon="arrow-down1" classes="icon-inline small" />
574 class="btn btn-link btn-animate text-muted py-0 pl-1 pr-0"
575 onClick={linkEvent(this, this.handleSavePostClick)}
576 aria-label={post_view.saved ? i18n.t("unsave") : i18n.t("save")}
578 post_view.saved ? i18n.t("unsave") : i18n.t("save")
583 classes={`icon-inline ${post_view.saved && "text-warning"}`}
587 {!this.state.showMoreMobile && this.showBody && (
589 class="btn btn-link btn-animate text-muted py-0"
590 onClick={linkEvent(this, this.handleShowMoreMobile)}
591 aria-label={i18n.t("more")}
592 data-tippy-content={i18n.t("more")}
594 <Icon icon="more-vertical" classes="icon-inline" />
597 {this.state.showMoreMobile && this.postActions(mobile)}
605 let dupes = this.props.duplicates;
608 dupes.length > 0 && (
609 <ul class="list-inline mb-1 small text-muted">
611 <li className="list-inline-item mr-2">
612 {i18n.t("cross_posted_to")}
615 <li className="list-inline-item mr-2">
616 <Link to={`/post/${pv.post.id}`}>
619 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
629 postActions(mobile = false) {
630 let post_view = this.props.post_view;
632 UserService.Instance.localUserView && (
638 class="btn btn-link btn-animate text-muted py-0 pl-0"
639 onClick={linkEvent(this, this.handleSavePostClick)}
641 post_view.saved ? i18n.t("unsave") : i18n.t("save")
644 post_view.saved ? i18n.t("unsave") : i18n.t("save")
649 classes={`icon-inline ${post_view.saved && "text-warning"}`}
654 className="btn btn-link btn-animate text-muted py-0"
655 to={`/create_post${this.crossPostParams}`}
656 title={i18n.t("cross_post")}
658 <Icon icon="copy" classes="icon-inline" />
662 {this.myPost && this.showBody && (
665 class="btn btn-link btn-animate text-muted py-0"
666 onClick={linkEvent(this, this.handleEditClick)}
667 data-tippy-content={i18n.t("edit")}
668 aria-label={i18n.t("edit")}
670 <Icon icon="edit" classes="icon-inline" />
673 class="btn btn-link btn-animate text-muted py-0"
674 onClick={linkEvent(this, this.handleDeleteClick)}
676 !post_view.post.deleted ? i18n.t("delete") : i18n.t("restore")
679 !post_view.post.deleted ? i18n.t("delete") : i18n.t("restore")
684 classes={`icon-inline ${
685 post_view.post.deleted && "text-danger"
692 {!this.state.showAdvanced && this.showBody ? (
694 class="btn btn-link btn-animate text-muted py-0"
695 onClick={linkEvent(this, this.handleShowAdvanced)}
696 data-tippy-content={i18n.t("more")}
697 aria-label={i18n.t("more")}
699 <Icon icon="more-vertical" classes="icon-inline" />
703 {this.showBody && post_view.post.body && (
705 class="btn btn-link btn-animate text-muted py-0"
706 onClick={linkEvent(this, this.handleViewSource)}
707 data-tippy-content={i18n.t("view_source")}
708 aria-label={i18n.t("view_source")}
712 classes={`icon-inline ${
713 this.state.viewSource && "text-success"
718 {this.canModOnSelf && (
721 class="btn btn-link btn-animate text-muted py-0"
722 onClick={linkEvent(this, this.handleModLock)}
724 post_view.post.locked ? i18n.t("unlock") : i18n.t("lock")
727 post_view.post.locked ? i18n.t("unlock") : i18n.t("lock")
732 classes={`icon-inline ${
733 post_view.post.locked && "text-danger"
738 class="btn btn-link btn-animate text-muted py-0"
739 onClick={linkEvent(this, this.handleModSticky)}
741 post_view.post.stickied
746 post_view.post.stickied
753 classes={`icon-inline ${
754 post_view.post.stickied && "text-success"
760 {/* Mods can ban from community, and appoint as mods to community */}
761 {(this.canMod || this.canAdmin) &&
762 (!post_view.post.removed ? (
764 class="btn btn-link btn-animate text-muted py-0"
765 onClick={linkEvent(this, this.handleModRemoveShow)}
766 aria-label={i18n.t("remove")}
772 class="btn btn-link btn-animate text-muted py-0"
773 onClick={linkEvent(this, this.handleModRemoveSubmit)}
774 aria-label={i18n.t("restore")}
782 (!post_view.creator_banned_from_community ? (
784 class="btn btn-link btn-animate text-muted py-0"
787 this.handleModBanFromCommunityShow
789 aria-label={i18n.t("ban")}
795 class="btn btn-link btn-animate text-muted py-0"
798 this.handleModBanFromCommunitySubmit
800 aria-label={i18n.t("unban")}
805 {!post_view.creator_banned_from_community && (
807 class="btn btn-link btn-animate text-muted py-0"
808 onClick={linkEvent(this, this.handleAddModToCommunity)}
811 ? i18n.t("remove_as_mod")
812 : i18n.t("appoint_as_mod")
816 ? i18n.t("remove_as_mod")
817 : i18n.t("appoint_as_mod")}
822 {/* Community creators and admins can transfer community to another mod */}
823 {(this.amCommunityCreator || this.canAdmin) &&
825 (!this.state.showConfirmTransferCommunity ? (
827 class="btn btn-link btn-animate text-muted py-0"
830 this.handleShowConfirmTransferCommunity
832 aria-label={i18n.t("transfer_community")}
834 {i18n.t("transfer_community")}
839 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
840 aria-label={i18n.t("are_you_sure")}
842 {i18n.t("are_you_sure")}
845 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
846 aria-label={i18n.t("yes")}
847 onClick={linkEvent(this, this.handleTransferCommunity)}
852 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
855 this.handleCancelShowConfirmTransferCommunity
857 aria-label={i18n.t("no")}
863 {/* Admins can ban from all, and appoint other admins */}
867 (!post_view.creator.banned ? (
869 class="btn btn-link btn-animate text-muted py-0"
870 onClick={linkEvent(this, this.handleModBanShow)}
871 aria-label={i18n.t("ban_from_site")}
873 {i18n.t("ban_from_site")}
877 class="btn btn-link btn-animate text-muted py-0"
878 onClick={linkEvent(this, this.handleModBanSubmit)}
879 aria-label={i18n.t("unban_from_site")}
881 {i18n.t("unban_from_site")}
884 {!post_view.creator.banned && post_view.creator.local && (
886 class="btn btn-link btn-animate text-muted py-0"
887 onClick={linkEvent(this, this.handleAddAdmin)}
890 ? i18n.t("remove_as_admin")
891 : i18n.t("appoint_as_admin")
895 ? i18n.t("remove_as_admin")
896 : i18n.t("appoint_as_admin")}
901 {/* Site Creator can transfer to another admin */}
902 {this.amSiteCreator &&
904 (!this.state.showConfirmTransferSite ? (
906 class="btn btn-link btn-animate text-muted py-0"
909 this.handleShowConfirmTransferSite
911 aria-label={i18n.t("transfer_site")}
913 {i18n.t("transfer_site")}
918 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
919 aria-label={i18n.t("are_you_sure")}
921 {i18n.t("are_you_sure")}
924 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
925 onClick={linkEvent(this, this.handleTransferSite)}
926 aria-label={i18n.t("yes")}
931 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
934 this.handleCancelShowConfirmTransferSite
936 aria-label={i18n.t("no")}
949 removeAndBanDialogs() {
950 let post = this.props.post_view;
953 {this.state.showRemoveDialog && (
956 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
958 <label class="sr-only" htmlFor="post-listing-remove-reason">
963 id="post-listing-remove-reason"
964 class="form-control mr-2"
965 placeholder={i18n.t("reason")}
966 value={this.state.removeReason}
967 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
971 class="btn btn-secondary"
972 aria-label={i18n.t("remove_post")}
974 {i18n.t("remove_post")}
978 {this.state.showBanDialog && (
979 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
980 <div class="form-group row">
981 <label class="col-form-label" htmlFor="post-listing-ban-reason">
986 id="post-listing-ban-reason"
987 class="form-control mr-2"
988 placeholder={i18n.t("reason")}
989 value={this.state.banReason}
990 onInput={linkEvent(this, this.handleModBanReasonChange)}
992 <div class="form-group">
993 <div class="form-check">
995 class="form-check-input"
996 id="mod-ban-remove-data"
998 checked={this.state.removeData}
999 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1001 <label class="form-check-label" htmlFor="mod-ban-remove-data">
1002 {i18n.t("remove_posts_comments")}
1007 {/* TODO hold off on expires until later */}
1008 {/* <div class="form-group row"> */}
1009 {/* <label class="col-form-label">Expires</label> */}
1010 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1012 <div class="form-group row">
1015 class="btn btn-secondary"
1016 aria-label={i18n.t("ban")}
1018 {i18n.t("ban")} {post.creator.name}
1028 let post = this.props.post_view.post;
1029 return post.thumbnail_url || isImage(post.url) ? (
1031 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1032 {this.postTitleLine()}
1035 {/* Post body prev or thumbnail */}
1036 {!this.state.imageExpanded && this.thumbnail()}
1040 this.postTitleLine()
1044 showMobilePreview() {
1045 let post = this.props.post_view.post;
1050 className="md-div mb-1"
1051 dangerouslySetInnerHTML={{
1052 __html: md.render(previewLines(post.body)),
1062 {/* The mobile view*/}
1063 <div class="d-block d-sm-none">
1065 <div class="col-12">
1066 {this.createdLine()}
1068 {/* If it has a thumbnail, do a right aligned thumbnail */}
1069 {this.mobileThumbnail()}
1071 {/* Show a preview of the post body */}
1072 {this.showMobilePreview()}
1074 {this.commentsLine(true)}
1075 {this.duplicatesLine()}
1076 {this.removeAndBanDialogs()}
1081 {/* The larger view*/}
1082 <div class="d-none d-sm-block">
1085 {!this.state.imageExpanded && (
1086 <div class="col-sm-2 pr-0">
1087 <div class="">{this.thumbnail()}</div>
1092 this.state.imageExpanded ? "col-12" : "col-12 col-sm-9"
1096 <div className="col-12">
1097 {this.postTitleLine()}
1098 {this.createdLine()}
1099 {this.commentsLine()}
1100 {this.duplicatesLine()}
1101 {this.postActions()}
1102 {this.removeAndBanDialogs()}
1112 private get myPost(): boolean {
1114 UserService.Instance.localUserView &&
1115 this.props.post_view.creator.id ==
1116 UserService.Instance.localUserView.person.id
1120 get isMod(): boolean {
1122 this.props.moderators &&
1124 this.props.moderators.map(m => m.moderator.id),
1125 this.props.post_view.creator.id
1130 get isAdmin(): boolean {
1132 this.props.admins &&
1134 this.props.admins.map(a => a.person.id),
1135 this.props.post_view.creator.id
1140 get canMod(): boolean {
1141 if (this.props.admins && this.props.moderators) {
1142 let adminsThenMods = this.props.admins
1143 .map(a => a.person.id)
1144 .concat(this.props.moderators.map(m => m.moderator.id));
1147 UserService.Instance.localUserView,
1149 this.props.post_view.creator.id
1156 get canModOnSelf(): boolean {
1157 if (this.props.admins && this.props.moderators) {
1158 let adminsThenMods = this.props.admins
1159 .map(a => a.person.id)
1160 .concat(this.props.moderators.map(m => m.moderator.id));
1163 UserService.Instance.localUserView,
1165 this.props.post_view.creator.id,
1173 get canAdmin(): boolean {
1175 this.props.admins &&
1177 UserService.Instance.localUserView,
1178 this.props.admins.map(a => a.person.id),
1179 this.props.post_view.creator.id
1184 get amCommunityCreator(): boolean {
1186 this.props.moderators &&
1187 UserService.Instance.localUserView &&
1188 this.props.post_view.creator.id !=
1189 UserService.Instance.localUserView.person.id &&
1190 UserService.Instance.localUserView.person.id ==
1191 this.props.moderators[0].moderator.id
1195 get amSiteCreator(): boolean {
1197 this.props.admins &&
1198 UserService.Instance.localUserView &&
1199 this.props.post_view.creator.id !=
1200 UserService.Instance.localUserView.person.id &&
1201 UserService.Instance.localUserView.person.id ==
1202 this.props.admins[0].person.id
1206 handlePostLike(i: PostListing, event: any) {
1207 event.preventDefault();
1208 if (!UserService.Instance.localUserView) {
1209 this.context.router.history.push(`/login`);
1212 let new_vote = i.state.my_vote == 1 ? 0 : 1;
1214 if (i.state.my_vote == 1) {
1217 } else if (i.state.my_vote == -1) {
1218 i.state.downvotes--;
1226 i.state.my_vote = new_vote;
1228 let form: CreatePostLike = {
1229 post_id: i.props.post_view.post.id,
1230 score: i.state.my_vote,
1234 WebSocketService.Instance.send(wsClient.likePost(form));
1235 i.setState(i.state);
1239 handlePostDisLike(i: PostListing, event: any) {
1240 event.preventDefault();
1241 if (!UserService.Instance.localUserView) {
1242 this.context.router.history.push(`/login`);
1245 let new_vote = i.state.my_vote == -1 ? 0 : -1;
1247 if (i.state.my_vote == 1) {
1250 i.state.downvotes++;
1251 } else if (i.state.my_vote == -1) {
1252 i.state.downvotes--;
1255 i.state.downvotes++;
1259 i.state.my_vote = new_vote;
1261 let form: CreatePostLike = {
1262 post_id: i.props.post_view.post.id,
1263 score: i.state.my_vote,
1267 WebSocketService.Instance.send(wsClient.likePost(form));
1268 i.setState(i.state);
1272 handleEditClick(i: PostListing) {
1273 i.state.showEdit = true;
1274 i.setState(i.state);
1277 handleEditCancel() {
1278 this.state.showEdit = false;
1279 this.setState(this.state);
1282 // The actual editing is done in the recieve for post
1284 this.state.showEdit = false;
1285 this.setState(this.state);
1288 handleDeleteClick(i: PostListing) {
1289 let deleteForm: DeletePost = {
1290 post_id: i.props.post_view.post.id,
1291 deleted: !i.props.post_view.post.deleted,
1294 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1297 handleSavePostClick(i: PostListing) {
1299 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1300 let form: SavePost = {
1301 post_id: i.props.post_view.post.id,
1306 WebSocketService.Instance.send(wsClient.savePost(form));
1309 get crossPostParams(): string {
1310 let post = this.props.post_view.post;
1311 let params = `?title=${encodeURIComponent(post.name)}`;
1314 params += `&url=${encodeURIComponent(post.url)}`;
1317 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1322 crossPostBody(): string {
1323 let post = this.props.post_view.post;
1324 let body = `${i18n.t("cross_posted_from")} ${
1326 }\n\n${post.body.replace(/^/gm, "> ")}`;
1330 get showBody(): boolean {
1331 return this.props.showBody || this.state.showBody;
1334 handleModRemoveShow(i: PostListing) {
1335 i.state.showRemoveDialog = true;
1336 i.setState(i.state);
1339 handleModRemoveReasonChange(i: PostListing, event: any) {
1340 i.state.removeReason = event.target.value;
1341 i.setState(i.state);
1344 handleModRemoveDataChange(i: PostListing, event: any) {
1345 i.state.removeData = event.target.checked;
1346 i.setState(i.state);
1349 handleModRemoveSubmit(i: PostListing, event: any) {
1350 event.preventDefault();
1351 let form: RemovePost = {
1352 post_id: i.props.post_view.post.id,
1353 removed: !i.props.post_view.post.removed,
1354 reason: i.state.removeReason,
1357 WebSocketService.Instance.send(wsClient.removePost(form));
1359 i.state.showRemoveDialog = false;
1360 i.setState(i.state);
1363 handleModLock(i: PostListing) {
1364 let form: LockPost = {
1365 post_id: i.props.post_view.post.id,
1366 locked: !i.props.post_view.post.locked,
1369 WebSocketService.Instance.send(wsClient.lockPost(form));
1372 handleModSticky(i: PostListing) {
1373 let form: StickyPost = {
1374 post_id: i.props.post_view.post.id,
1375 stickied: !i.props.post_view.post.stickied,
1378 WebSocketService.Instance.send(wsClient.stickyPost(form));
1381 handleModBanFromCommunityShow(i: PostListing) {
1382 i.state.showBanDialog = true;
1383 i.state.banType = BanType.Community;
1384 i.setState(i.state);
1387 handleModBanShow(i: PostListing) {
1388 i.state.showBanDialog = true;
1389 i.state.banType = BanType.Site;
1390 i.setState(i.state);
1393 handleModBanReasonChange(i: PostListing, event: any) {
1394 i.state.banReason = event.target.value;
1395 i.setState(i.state);
1398 handleModBanExpiresChange(i: PostListing, event: any) {
1399 i.state.banExpires = event.target.value;
1400 i.setState(i.state);
1403 handleModBanFromCommunitySubmit(i: PostListing) {
1404 i.state.banType = BanType.Community;
1405 i.setState(i.state);
1406 i.handleModBanBothSubmit(i);
1409 handleModBanSubmit(i: PostListing) {
1410 i.state.banType = BanType.Site;
1411 i.setState(i.state);
1412 i.handleModBanBothSubmit(i);
1415 handleModBanBothSubmit(i: PostListing, event?: any) {
1416 if (event) event.preventDefault();
1418 if (i.state.banType == BanType.Community) {
1419 // If its an unban, restore all their data
1420 let ban = !i.props.post_view.creator_banned_from_community;
1422 i.state.removeData = false;
1424 let form: BanFromCommunity = {
1425 person_id: i.props.post_view.creator.id,
1426 community_id: i.props.post_view.community.id,
1428 remove_data: i.state.removeData,
1429 reason: i.state.banReason,
1430 expires: getUnixTime(i.state.banExpires),
1433 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1435 // If its an unban, restore all their data
1436 let ban = !i.props.post_view.creator.banned;
1438 i.state.removeData = false;
1440 let form: BanPerson = {
1441 person_id: i.props.post_view.creator.id,
1443 remove_data: i.state.removeData,
1444 reason: i.state.banReason,
1445 expires: getUnixTime(i.state.banExpires),
1448 WebSocketService.Instance.send(wsClient.banPerson(form));
1451 i.state.showBanDialog = false;
1452 i.setState(i.state);
1455 handleAddModToCommunity(i: PostListing) {
1456 let form: AddModToCommunity = {
1457 person_id: i.props.post_view.creator.id,
1458 community_id: i.props.post_view.community.id,
1462 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1463 i.setState(i.state);
1466 handleAddAdmin(i: PostListing) {
1467 let form: AddAdmin = {
1468 person_id: i.props.post_view.creator.id,
1472 WebSocketService.Instance.send(wsClient.addAdmin(form));
1473 i.setState(i.state);
1476 handleShowConfirmTransferCommunity(i: PostListing) {
1477 i.state.showConfirmTransferCommunity = true;
1478 i.setState(i.state);
1481 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1482 i.state.showConfirmTransferCommunity = false;
1483 i.setState(i.state);
1486 handleTransferCommunity(i: PostListing) {
1487 let form: TransferCommunity = {
1488 community_id: i.props.post_view.community.id,
1489 person_id: i.props.post_view.creator.id,
1492 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1493 i.state.showConfirmTransferCommunity = false;
1494 i.setState(i.state);
1497 handleShowConfirmTransferSite(i: PostListing) {
1498 i.state.showConfirmTransferSite = true;
1499 i.setState(i.state);
1502 handleCancelShowConfirmTransferSite(i: PostListing) {
1503 i.state.showConfirmTransferSite = false;
1504 i.setState(i.state);
1507 handleTransferSite(i: PostListing) {
1508 let form: TransferSite = {
1509 person_id: i.props.post_view.creator.id,
1512 WebSocketService.Instance.send(wsClient.transferSite(form));
1513 i.state.showConfirmTransferSite = false;
1514 i.setState(i.state);
1517 handleImageExpandClick(i: PostListing) {
1518 i.state.imageExpanded = !i.state.imageExpanded;
1519 i.setState(i.state);
1522 handleViewSource(i: PostListing) {
1523 i.state.viewSource = !i.state.viewSource;
1524 i.setState(i.state);
1527 handleShowAdvanced(i: PostListing) {
1528 i.state.showAdvanced = !i.state.showAdvanced;
1529 i.setState(i.state);
1533 handleShowMoreMobile(i: PostListing) {
1534 i.state.showMoreMobile = !i.state.showMoreMobile;
1535 i.state.showAdvanced = !i.state.showAdvanced;
1536 i.setState(i.state);
1540 handleShowBody(i: PostListing) {
1541 i.state.showBody = !i.state.showBody;
1542 i.setState(i.state);
1546 get pointsTippy(): string {
1547 let points = i18n.t("number_of_points", {
1548 count: this.state.score,
1551 let upvotes = i18n.t("number_of_upvotes", {
1552 count: this.state.upvotes,
1555 let downvotes = i18n.t("number_of_downvotes", {
1556 count: this.state.downvotes,
1559 return `${points} • ${upvotes} • ${downvotes}`;