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 <a className="ml-2" title={i18n.t("link")} href={post.ap_id}>
450 <Icon icon="fedilink" />
454 <small className="ml-2 text-muted font-italic">
460 className="unselectable pointer ml-2 text-muted font-italic"
461 data-tippy-content={i18n.t("deleted")}
463 <Icon icon="trash" classes="icon-inline text-danger" />
468 className="unselectable pointer ml-2 text-muted font-italic"
469 data-tippy-content={i18n.t("locked")}
471 <Icon icon="lock" classes="icon-inline text-danger" />
476 className="unselectable pointer ml-2 text-muted font-italic"
477 data-tippy-content={i18n.t("stickied")}
479 <Icon icon="pin" classes="icon-inline text-primary" />
483 <small className="ml-2 text-muted font-italic">
493 let dupes = this.props.duplicates;
496 dupes.length > 0 && (
497 <ul class="list-inline mb-1 small text-muted">
499 <li className="list-inline-item mr-2">
500 {i18n.t("cross_posted_to")}
503 <li className="list-inline-item mr-2">
504 <Link to={`/post/${pv.post.id}`}>
507 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
517 commentsLine(mobile = false) {
519 <div class="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
520 {this.commentsButton}
521 {mobile && !this.props.viewOnly && this.mobileVotes}
522 {UserService.Instance.myUserInfo &&
523 !this.props.viewOnly &&
524 this.postActions(mobile)}
529 postActions(mobile = false) {
530 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
531 // Possible enhancement: Make each button a component.
532 let post_view = this.props.post_view;
536 {this.crossPostButton}
537 {mobile && this.showMoreButton}
538 {(!mobile || this.state.showAdvanced) && (
546 {this.myPost && (this.showBody || this.state.showAdvanced) && (
554 {this.state.showAdvanced && (
556 {this.showBody && post_view.post.body && this.viewSourceButton}
557 {this.canModOnSelf && (
563 {(this.canMod || this.canAdmin || true) && (
564 <>{this.modRemoveButton}</>
568 {!mobile && this.showMoreButton}
573 get commentsButton() {
574 let post_view = this.props.post_view;
576 <button class="btn btn-link text-muted py-0 pl-0">
578 className="text-muted"
579 title={i18n.t("number_of_comments", {
580 count: post_view.counts.comments,
581 formattedCount: post_view.counts.comments,
583 to={`/post/${post_view.post.id}?scrollToComments=true`}
585 <Icon icon="message-square" classes="mr-1" inline />
586 {i18n.t("number_of_comments", {
587 count: post_view.counts.comments,
588 formattedCount: numToSI(post_view.counts.comments),
597 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
602 className={`btn-animate btn py-0 px-1 ${
603 this.state.my_vote == 1 ? "text-info" : "text-muted"
606 onClick={linkEvent(this, this.handlePostLike)}
607 aria-label={i18n.t("upvote")}
609 <Icon icon="arrow-up1" classes="icon-inline small" />
611 <span class="ml-2">{numToSI(this.state.upvotes)}</span>
614 {this.props.enableDownvotes && (
616 className={`ml-2 btn-animate btn py-0 px-1 ${
617 this.state.my_vote == -1 ? "text-danger" : "text-muted"
619 onClick={linkEvent(this, this.handlePostDisLike)}
621 aria-label={i18n.t("downvote")}
623 <Icon icon="arrow-down1" classes="icon-inline small" />
626 class={classNames("ml-2", {
627 invisible: this.state.downvotes === 0,
630 {numToSI(this.state.downvotes)}
641 let saved = this.props.post_view.saved;
642 let label = saved ? i18n.t("unsave") : i18n.t("save");
645 class="btn btn-link btn-animate text-muted py-0"
646 onClick={linkEvent(this, this.handleSavePostClick)}
647 data-tippy-content={label}
652 classes={classNames({ "text-warning": saved })}
659 get crossPostButton() {
662 className="btn btn-link btn-animate text-muted py-0"
663 to={`/create_post${this.crossPostParams}`}
664 title={i18n.t("cross_post")}
666 <Icon icon="copy" inline />
674 class="btn btn-link btn-animate text-muted py-0"
675 onClick={linkEvent(this, this.handleShowReportDialog)}
676 data-tippy-content={i18n.t("show_report_dialog")}
677 aria-label={i18n.t("show_report_dialog")}
679 <Icon icon="flag" inline />
687 class="btn btn-link btn-animate text-muted py-0"
688 onClick={linkEvent(this, this.handleBlockUserClick)}
689 data-tippy-content={i18n.t("block_user")}
690 aria-label={i18n.t("block_user")}
692 <Icon icon="slash" inline />
700 class="btn btn-link btn-animate text-muted py-0"
701 onClick={linkEvent(this, this.handleEditClick)}
702 data-tippy-content={i18n.t("edit")}
703 aria-label={i18n.t("edit")}
705 <Icon icon="edit" inline />
711 let deleted = this.props.post_view.post.deleted;
712 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
715 class="btn btn-link btn-animate text-muted py-0"
716 onClick={linkEvent(this, this.handleDeleteClick)}
717 data-tippy-content={label}
722 classes={classNames({ "text-danger": deleted })}
729 get showMoreButton() {
732 class="btn btn-link btn-animate text-muted py-0"
733 onClick={linkEvent(this, this.handleShowAdvanced)}
734 data-tippy-content={i18n.t("more")}
735 aria-label={i18n.t("more")}
737 <Icon icon="more-vertical" inline />
742 get viewSourceButton() {
745 class="btn btn-link btn-animate text-muted py-0"
746 onClick={linkEvent(this, this.handleViewSource)}
747 data-tippy-content={i18n.t("view_source")}
748 aria-label={i18n.t("view_source")}
752 classes={classNames({ "text-success": this.state.viewSource })}
760 let locked = this.props.post_view.post.locked;
761 let label = locked ? i18n.t("unlock") : i18n.t("lock");
764 class="btn btn-link btn-animate text-muted py-0"
765 onClick={linkEvent(this, this.handleModLock)}
766 data-tippy-content={label}
771 classes={classNames({ "text-danger": locked })}
779 let stickied = this.props.post_view.post.stickied;
780 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
783 class="btn btn-link btn-animate text-muted py-0"
784 onClick={linkEvent(this, this.handleModSticky)}
785 data-tippy-content={label}
790 classes={classNames({ "text-success": stickied })}
797 get modRemoveButton() {
798 let removed = this.props.post_view.post.removed;
801 class="btn btn-link btn-animate text-muted py-0"
804 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
807 {/* TODO: Find an icon for this. */}
808 {!removed ? i18n.t("remove") : i18n.t("restore")}
814 * Mod/Admin actions to be taken against the author.
818 let post_view = this.props.post_view;
820 this.state.showAdvanced && (
824 {!this.creatorIsMod &&
825 (!post_view.creator_banned_from_community ? (
827 class="btn btn-link btn-animate text-muted py-0"
830 this.handleModBanFromCommunityShow
832 aria-label={i18n.t("ban")}
838 class="btn btn-link btn-animate text-muted py-0"
841 this.handleModBanFromCommunitySubmit
843 aria-label={i18n.t("unban")}
848 {!post_view.creator_banned_from_community && (
850 class="btn btn-link btn-animate text-muted py-0"
851 onClick={linkEvent(this, this.handleAddModToCommunity)}
854 ? i18n.t("remove_as_mod")
855 : i18n.t("appoint_as_mod")
859 ? i18n.t("remove_as_mod")
860 : i18n.t("appoint_as_mod")}
865 {/* Community creators and admins can transfer community to another mod */}
866 {(this.amCommunityCreator || this.canAdmin) &&
868 (!this.state.showConfirmTransferCommunity ? (
870 class="btn btn-link btn-animate text-muted py-0"
873 this.handleShowConfirmTransferCommunity
875 aria-label={i18n.t("transfer_community")}
877 {i18n.t("transfer_community")}
882 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
883 aria-label={i18n.t("are_you_sure")}
885 {i18n.t("are_you_sure")}
888 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
889 aria-label={i18n.t("yes")}
890 onClick={linkEvent(this, this.handleTransferCommunity)}
895 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
898 this.handleCancelShowConfirmTransferCommunity
900 aria-label={i18n.t("no")}
906 {/* Admins can ban from all, and appoint other admins */}
909 {!this.creatorIsAdmin &&
910 (!isBanned(post_view.creator) ? (
912 class="btn btn-link btn-animate text-muted py-0"
913 onClick={linkEvent(this, this.handleModBanShow)}
914 aria-label={i18n.t("ban_from_site")}
916 {i18n.t("ban_from_site")}
920 class="btn btn-link btn-animate text-muted py-0"
921 onClick={linkEvent(this, this.handleModBanSubmit)}
922 aria-label={i18n.t("unban_from_site")}
924 {i18n.t("unban_from_site")}
927 {!isBanned(post_view.creator) && post_view.creator.local && (
929 class="btn btn-link btn-animate text-muted py-0"
930 onClick={linkEvent(this, this.handleAddAdmin)}
933 ? i18n.t("remove_as_admin")
934 : i18n.t("appoint_as_admin")
938 ? i18n.t("remove_as_admin")
939 : i18n.t("appoint_as_admin")}
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 col-12">
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 <label class="col-form-label" htmlFor={`mod-ban-expires`}>
997 id={`mod-ban-expires`}
998 class="form-control mr-2"
999 placeholder={i18n.t("number_of_days")}
1000 value={this.state.banExpireDays}
1001 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1003 <div class="form-group">
1004 <div class="form-check">
1006 class="form-check-input"
1007 id="mod-ban-remove-data"
1009 checked={this.state.removeData}
1010 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1013 class="form-check-label"
1014 htmlFor="mod-ban-remove-data"
1015 title={i18n.t("remove_content_more")}
1017 {i18n.t("remove_content")}
1022 {/* TODO hold off on expires until later */}
1023 {/* <div class="form-group row"> */}
1024 {/* <label class="col-form-label">Expires</label> */}
1025 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1027 <div class="form-group row">
1030 class="btn btn-secondary"
1031 aria-label={i18n.t("ban")}
1033 {i18n.t("ban")} {post.creator.name}
1038 {this.state.showReportDialog && (
1041 onSubmit={linkEvent(this, this.handleReportSubmit)}
1043 <label class="sr-only" htmlFor="post-report-reason">
1048 id="post-report-reason"
1049 class="form-control mr-2"
1050 placeholder={i18n.t("reason")}
1052 value={this.state.reportReason}
1053 onInput={linkEvent(this, this.handleReportReasonChange)}
1057 class="btn btn-secondary"
1058 aria-label={i18n.t("create_report")}
1060 {i18n.t("create_report")}
1069 let post = this.props.post_view.post;
1070 return post.thumbnail_url || isImage(post.url) ? (
1072 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1073 {this.postTitleLine()}
1076 {/* Post body prev or thumbnail */}
1077 {!this.state.imageExpanded && this.thumbnail()}
1081 this.postTitleLine()
1085 showMobilePreview() {
1086 let post = this.props.post_view.post;
1091 className="md-div mb-1"
1092 dangerouslySetInnerHTML={{
1093 __html: md.render(previewLines(post.body)),
1103 {/* The mobile view*/}
1104 <div class="d-block d-sm-none">
1106 <div class="col-12">
1107 {this.createdLine()}
1109 {/* If it has a thumbnail, do a right aligned thumbnail */}
1110 {this.mobileThumbnail()}
1112 {/* Show a preview of the post body */}
1113 {this.showMobilePreview()}
1115 {this.commentsLine(true)}
1116 {this.userActionsLine()}
1117 {this.duplicatesLine()}
1118 {this.removeAndBanDialogs()}
1123 {/* The larger view*/}
1124 <div class="d-none d-sm-block">
1126 {!this.props.viewOnly && this.voteBar()}
1127 <div class="col-sm-2 pr-0">
1128 <div class="">{this.thumbnail()}</div>
1130 <div class="col-12 col-sm-9">
1132 <div className="col-12">
1133 {this.postTitleLine()}
1134 {this.createdLine()}
1135 {this.commentsLine()}
1136 {this.duplicatesLine()}
1137 {this.userActionsLine()}
1138 {this.removeAndBanDialogs()}
1148 private get myPost(): boolean {
1150 UserService.Instance.myUserInfo &&
1151 this.props.post_view.creator.id ==
1152 UserService.Instance.myUserInfo.local_user_view.person.id
1156 get creatorIsMod(): boolean {
1158 this.props.moderators &&
1160 this.props.moderators.map(m => m.moderator.id),
1161 this.props.post_view.creator.id
1166 get creatorIsAdmin(): boolean {
1168 this.props.admins &&
1170 this.props.admins.map(a => a.person.id),
1171 this.props.post_view.creator.id
1177 * If the current user is allowed to mod this post.
1178 * The creator of this post is not allowed even if they are a mod.
1180 get canMod(): boolean {
1181 if (this.props.admins && this.props.moderators) {
1182 let adminsThenMods = this.props.admins
1183 .map(a => a.person.id)
1184 .concat(this.props.moderators.map(m => m.moderator.id));
1187 UserService.Instance.myUserInfo,
1189 this.props.post_view.creator.id
1197 * If the current user is allowed to mod this post.
1198 * The creator of this post is allowed if they are a mod.
1200 get canModOnSelf(): boolean {
1201 if (this.props.admins && this.props.moderators) {
1202 let adminsThenMods = this.props.admins
1203 .map(a => a.person.id)
1204 .concat(this.props.moderators.map(m => m.moderator.id));
1207 UserService.Instance.myUserInfo,
1209 this.props.post_view.creator.id,
1217 get canAdmin(): boolean {
1219 this.props.admins &&
1221 UserService.Instance.myUserInfo,
1222 this.props.admins.map(a => a.person.id),
1223 this.props.post_view.creator.id
1228 get amCommunityCreator(): boolean {
1230 this.props.moderators &&
1231 UserService.Instance.myUserInfo &&
1232 this.props.post_view.creator.id !=
1233 UserService.Instance.myUserInfo.local_user_view.person.id &&
1234 UserService.Instance.myUserInfo.local_user_view.person.id ==
1235 this.props.moderators[0].moderator.id
1239 get amSiteCreator(): boolean {
1241 this.props.admins &&
1242 UserService.Instance.myUserInfo &&
1243 this.props.post_view.creator.id !=
1244 UserService.Instance.myUserInfo.local_user_view.person.id &&
1245 UserService.Instance.myUserInfo.local_user_view.person.id ==
1246 this.props.admins[0].person.id
1250 handlePostLike(i: PostListing, event: any) {
1251 event.preventDefault();
1252 if (!UserService.Instance.myUserInfo) {
1253 this.context.router.history.push(`/login`);
1256 let new_vote = i.state.my_vote == 1 ? 0 : 1;
1258 if (i.state.my_vote == 1) {
1261 } else if (i.state.my_vote == -1) {
1262 i.state.downvotes--;
1270 i.state.my_vote = new_vote;
1272 let form: CreatePostLike = {
1273 post_id: i.props.post_view.post.id,
1274 score: i.state.my_vote,
1278 WebSocketService.Instance.send(wsClient.likePost(form));
1279 i.setState(i.state);
1283 handlePostDisLike(i: PostListing, event: any) {
1284 event.preventDefault();
1285 if (!UserService.Instance.myUserInfo) {
1286 this.context.router.history.push(`/login`);
1289 let new_vote = i.state.my_vote == -1 ? 0 : -1;
1291 if (i.state.my_vote == 1) {
1294 i.state.downvotes++;
1295 } else if (i.state.my_vote == -1) {
1296 i.state.downvotes--;
1299 i.state.downvotes++;
1303 i.state.my_vote = new_vote;
1305 let form: CreatePostLike = {
1306 post_id: i.props.post_view.post.id,
1307 score: i.state.my_vote,
1311 WebSocketService.Instance.send(wsClient.likePost(form));
1312 i.setState(i.state);
1316 handleEditClick(i: PostListing) {
1317 i.state.showEdit = true;
1318 i.setState(i.state);
1321 handleEditCancel() {
1322 this.state.showEdit = false;
1323 this.setState(this.state);
1326 // The actual editing is done in the recieve for post
1328 this.state.showEdit = false;
1329 this.setState(this.state);
1332 handleShowReportDialog(i: PostListing) {
1333 i.state.showReportDialog = !i.state.showReportDialog;
1334 i.setState(this.state);
1337 handleReportReasonChange(i: PostListing, event: any) {
1338 i.state.reportReason = event.target.value;
1339 i.setState(i.state);
1342 handleReportSubmit(i: PostListing, event: any) {
1343 event.preventDefault();
1344 let form: CreatePostReport = {
1345 post_id: i.props.post_view.post.id,
1346 reason: i.state.reportReason,
1349 WebSocketService.Instance.send(wsClient.createPostReport(form));
1351 i.state.showReportDialog = false;
1352 i.setState(i.state);
1355 handleBlockUserClick(i: PostListing) {
1356 let blockUserForm: BlockPerson = {
1357 person_id: i.props.post_view.creator.id,
1361 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1364 handleDeleteClick(i: PostListing) {
1365 let deleteForm: DeletePost = {
1366 post_id: i.props.post_view.post.id,
1367 deleted: !i.props.post_view.post.deleted,
1370 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1373 handleSavePostClick(i: PostListing) {
1375 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1376 let form: SavePost = {
1377 post_id: i.props.post_view.post.id,
1382 WebSocketService.Instance.send(wsClient.savePost(form));
1385 get crossPostParams(): string {
1386 let post = this.props.post_view.post;
1387 let params = `?title=${encodeURIComponent(post.name)}`;
1390 params += `&url=${encodeURIComponent(post.url)}`;
1393 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1398 crossPostBody(): string {
1399 let post = this.props.post_view.post;
1400 let body = `${i18n.t("cross_posted_from")} ${
1402 }\n\n${post.body.replace(/^/gm, "> ")}`;
1406 get showBody(): boolean {
1407 return this.props.showBody || this.state.showBody;
1410 handleModRemoveShow(i: PostListing) {
1411 i.state.showRemoveDialog = !i.state.showRemoveDialog;
1412 i.state.showBanDialog = false;
1413 i.setState(i.state);
1416 handleModRemoveReasonChange(i: PostListing, event: any) {
1417 i.state.removeReason = event.target.value;
1418 i.setState(i.state);
1421 handleModRemoveDataChange(i: PostListing, event: any) {
1422 i.state.removeData = event.target.checked;
1423 i.setState(i.state);
1426 handleModRemoveSubmit(i: PostListing, event: any) {
1427 event.preventDefault();
1428 let form: RemovePost = {
1429 post_id: i.props.post_view.post.id,
1430 removed: !i.props.post_view.post.removed,
1431 reason: i.state.removeReason,
1434 WebSocketService.Instance.send(wsClient.removePost(form));
1436 i.state.showRemoveDialog = false;
1437 i.setState(i.state);
1440 handleModLock(i: PostListing) {
1441 let form: LockPost = {
1442 post_id: i.props.post_view.post.id,
1443 locked: !i.props.post_view.post.locked,
1446 WebSocketService.Instance.send(wsClient.lockPost(form));
1449 handleModSticky(i: PostListing) {
1450 let form: StickyPost = {
1451 post_id: i.props.post_view.post.id,
1452 stickied: !i.props.post_view.post.stickied,
1455 WebSocketService.Instance.send(wsClient.stickyPost(form));
1458 handleModBanFromCommunityShow(i: PostListing) {
1459 i.state.showBanDialog = true;
1460 i.state.banType = BanType.Community;
1461 i.state.showRemoveDialog = false;
1462 i.setState(i.state);
1465 handleModBanShow(i: PostListing) {
1466 i.state.showBanDialog = true;
1467 i.state.banType = BanType.Site;
1468 i.state.showRemoveDialog = false;
1469 i.setState(i.state);
1472 handleModBanReasonChange(i: PostListing, event: any) {
1473 i.state.banReason = event.target.value;
1474 i.setState(i.state);
1477 handleModBanExpireDaysChange(i: PostListing, event: any) {
1478 i.state.banExpireDays = event.target.value;
1479 i.setState(i.state);
1482 handleModBanFromCommunitySubmit(i: PostListing) {
1483 i.state.banType = BanType.Community;
1484 i.setState(i.state);
1485 i.handleModBanBothSubmit(i);
1488 handleModBanSubmit(i: PostListing) {
1489 i.state.banType = BanType.Site;
1490 i.setState(i.state);
1491 i.handleModBanBothSubmit(i);
1494 handleModBanBothSubmit(i: PostListing, event?: any) {
1495 if (event) event.preventDefault();
1497 if (i.state.banType == BanType.Community) {
1498 // If its an unban, restore all their data
1499 let ban = !i.props.post_view.creator_banned_from_community;
1501 i.state.removeData = false;
1503 let form: BanFromCommunity = {
1504 person_id: i.props.post_view.creator.id,
1505 community_id: i.props.post_view.community.id,
1507 remove_data: i.state.removeData,
1508 reason: i.state.banReason,
1509 expires: futureDaysToUnixTime(i.state.banExpireDays),
1512 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1514 // If its an unban, restore all their data
1515 let ban = !i.props.post_view.creator.banned;
1517 i.state.removeData = false;
1519 let form: BanPerson = {
1520 person_id: i.props.post_view.creator.id,
1522 remove_data: i.state.removeData,
1523 reason: i.state.banReason,
1524 expires: futureDaysToUnixTime(i.state.banExpireDays),
1527 WebSocketService.Instance.send(wsClient.banPerson(form));
1530 i.state.showBanDialog = false;
1531 i.setState(i.state);
1534 handleAddModToCommunity(i: PostListing) {
1535 let form: AddModToCommunity = {
1536 person_id: i.props.post_view.creator.id,
1537 community_id: i.props.post_view.community.id,
1538 added: !i.creatorIsMod,
1541 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1542 i.setState(i.state);
1545 handleAddAdmin(i: PostListing) {
1546 let form: AddAdmin = {
1547 person_id: i.props.post_view.creator.id,
1548 added: !i.creatorIsAdmin,
1551 WebSocketService.Instance.send(wsClient.addAdmin(form));
1552 i.setState(i.state);
1555 handleShowConfirmTransferCommunity(i: PostListing) {
1556 i.state.showConfirmTransferCommunity = true;
1557 i.setState(i.state);
1560 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1561 i.state.showConfirmTransferCommunity = false;
1562 i.setState(i.state);
1565 handleTransferCommunity(i: PostListing) {
1566 let form: TransferCommunity = {
1567 community_id: i.props.post_view.community.id,
1568 person_id: i.props.post_view.creator.id,
1571 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1572 i.state.showConfirmTransferCommunity = false;
1573 i.setState(i.state);
1576 handleShowConfirmTransferSite(i: PostListing) {
1577 i.state.showConfirmTransferSite = true;
1578 i.setState(i.state);
1581 handleCancelShowConfirmTransferSite(i: PostListing) {
1582 i.state.showConfirmTransferSite = false;
1583 i.setState(i.state);
1586 handleImageExpandClick(i: PostListing, event: any) {
1587 event.preventDefault();
1588 i.state.imageExpanded = !i.state.imageExpanded;
1589 i.setState(i.state);
1593 handleViewSource(i: PostListing) {
1594 i.state.viewSource = !i.state.viewSource;
1595 i.setState(i.state);
1598 handleShowAdvanced(i: PostListing) {
1599 i.state.showAdvanced = !i.state.showAdvanced;
1600 i.setState(i.state);
1604 handleShowMoreMobile(i: PostListing) {
1605 i.state.showMoreMobile = !i.state.showMoreMobile;
1606 i.state.showAdvanced = !i.state.showAdvanced;
1607 i.setState(i.state);
1611 handleShowBody(i: PostListing) {
1612 i.state.showBody = !i.state.showBody;
1613 i.setState(i.state);
1617 get pointsTippy(): string {
1618 let points = i18n.t("number_of_points", {
1619 count: this.state.score,
1620 formattedCount: this.state.score,
1623 let upvotes = i18n.t("number_of_upvotes", {
1624 count: this.state.upvotes,
1625 formattedCount: this.state.upvotes,
1628 let downvotes = i18n.t("number_of_downvotes", {
1629 count: this.state.downvotes,
1630 formattedCount: this.state.downvotes,
1633 return `${points} • ${upvotes} • ${downvotes}`;