1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
10 CommunityModeratorView,
22 } from "lemmy-js-client";
23 import { externalHost } from "../../env";
24 import { i18n } from "../../i18next";
25 import { BanType } from "../../interfaces";
26 import { UserService, WebSocketService } from "../../services";
44 import { Icon } from "../common/icon";
45 import { MomentTime } from "../common/moment-time";
46 import { PictrsImage } from "../common/pictrs-image";
47 import { CommunityLink } from "../community/community-link";
48 import { PersonListing } from "../person/person-listing";
49 import { MetadataCard } from "./metadata-card";
50 import { PostForm } from "./post-form";
52 interface PostListingState {
54 showRemoveDialog: boolean;
56 showBanDialog: boolean;
59 banExpireDays: number;
61 showConfirmTransferSite: boolean;
62 showConfirmTransferCommunity: boolean;
63 imageExpanded: boolean;
65 showAdvanced: boolean;
66 showMoreMobile: boolean;
68 showReportDialog: boolean;
76 interface PostListingProps {
78 duplicates?: PostView[];
79 showCommunity?: boolean;
81 moderators?: CommunityModeratorView[];
82 admins?: PersonViewSafe[];
83 enableDownvotes: boolean;
88 export class PostListing extends Component<PostListingProps, PostListingState> {
89 private emptyState: PostListingState = {
91 showRemoveDialog: false,
97 banType: BanType.Community,
98 showConfirmTransferSite: false,
99 showConfirmTransferCommunity: false,
100 imageExpanded: false,
103 showMoreMobile: false,
105 showReportDialog: false,
107 my_vote: this.props.post_view.my_vote,
108 score: this.props.post_view.counts.score,
109 upvotes: this.props.post_view.counts.upvotes,
110 downvotes: this.props.post_view.counts.downvotes,
113 constructor(props: any, context: any) {
114 super(props, context);
116 this.state = this.emptyState;
117 this.handlePostLike = this.handlePostLike.bind(this);
118 this.handlePostDisLike = this.handlePostDisLike.bind(this);
119 this.handleEditPost = this.handleEditPost.bind(this);
120 this.handleEditCancel = this.handleEditCancel.bind(this);
123 componentWillReceiveProps(nextProps: PostListingProps) {
124 this.state.my_vote = nextProps.post_view.my_vote;
125 this.state.upvotes = nextProps.post_view.counts.upvotes;
126 this.state.downvotes = nextProps.post_view.counts.downvotes;
127 this.state.score = nextProps.post_view.counts.score;
128 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
129 this.state.imageExpanded = false;
131 this.setState(this.state);
135 let post = this.props.post_view.post;
137 <div class="post-listing">
138 {!this.state.showEdit ? (
141 {this.state.imageExpanded && this.img}
142 {post.url && this.showBody && post.embed_title && (
143 <MetadataCard post={post} />
145 {this.showBody && post.body && this.body()}
150 post_view={this.props.post_view}
151 onEdit={this.handleEditPost}
152 onCancel={this.handleEditCancel}
153 enableNsfw={this.props.enableNsfw}
154 enableDownvotes={this.props.enableDownvotes}
163 let post = this.props.post_view.post;
165 <div class="col-12 card my-2 p-2">
166 {this.state.viewSource ? (
167 <pre>{post.body}</pre>
171 dangerouslySetInnerHTML={mdToHtml(post.body)}
181 <div class="offset-sm-3 my-2 d-none d-sm-block">
182 <a href={this.imageSrc} class="d-inline-block">
183 <PictrsImage src={this.imageSrc} />
186 <div className="my-2 d-block d-sm-none">
188 class="d-inline-block"
189 onClick={linkEvent(this, this.handleImageExpandClick)}
191 <PictrsImage src={this.imageSrc} />
198 imgThumb(src: string) {
199 let post_view = this.props.post_view;
205 nsfw={post_view.post.nsfw || post_view.community.nsfw}
210 get imageSrc(): string {
211 let post = this.props.post_view.post;
212 if (isImage(post.url)) {
213 if (post.url.includes("pictrs")) {
215 } else if (post.thumbnail_url) {
216 return post.thumbnail_url;
220 } else if (post.thumbnail_url) {
221 return post.thumbnail_url;
228 let post = this.props.post_view.post;
230 if (isImage(post.url)) {
234 class="text-body d-inline-block position-relative mb-2"
235 data-tippy-content={i18n.t("expand_here")}
236 onClick={linkEvent(this, this.handleImageExpandClick)}
237 aria-label={i18n.t("expand_here")}
239 {this.imgThumb(this.imageSrc)}
240 <Icon icon="image" classes="mini-overlay" />
243 } else if (post.thumbnail_url) {
246 class="text-body d-inline-block position-relative mb-2"
251 {this.imgThumb(this.imageSrc)}
252 <Icon icon="external-link" classes="mini-overlay" />
255 } else if (post.url) {
256 if (isVideo(post.url)) {
258 <div class="embed-responsive embed-responsive-16by9">
264 class="embed-responsive-item"
266 <source src={post.url} type="video/mp4" />
273 className="text-body"
278 <div class="thumbnail rounded bg-light d-flex justify-content-center">
279 <Icon icon="external-link" classes="d-flex align-items-center" />
287 className="text-body"
288 to={`/post/${post.id}`}
289 title={i18n.t("comments")}
291 <div class="thumbnail rounded bg-light d-flex justify-content-center">
292 <Icon icon="message-square" classes="d-flex align-items-center" />
300 let post_view = this.props.post_view;
302 <ul class="list-inline mb-1 text-muted small">
303 <li className="list-inline-item">
304 <PersonListing person={post_view.creator} />
306 {this.creatorIsMod && (
307 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
309 {this.creatorIsAdmin && (
310 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
312 {post_view.creator.bot_account && (
313 <span className="mx-1 badge badge-light">
314 {i18n.t("bot_account").toLowerCase()}
317 {(post_view.creator_banned_from_community ||
318 isBanned(post_view.creator)) && (
319 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
321 {post_view.creator_blocked && (
322 <span className="mx-1 badge badge-danger">{"blocked"}</span>
324 {this.props.showCommunity && (
326 <span class="mx-1"> {i18n.t("to")} </span>
327 <CommunityLink community={post_view.community} />
331 <li className="list-inline-item">•</li>
332 {post_view.post.url && !(hostname(post_view.post.url) == externalHost) && (
334 <li className="list-inline-item">
336 className="text-muted font-italic"
337 href={post_view.post.url}
338 title={post_view.post.url}
341 {hostname(post_view.post.url)}
344 <li className="list-inline-item">•</li>
347 <li className="list-inline-item">
349 <MomentTime data={post_view.post} />
352 {post_view.post.body && (
354 <li className="list-inline-item">•</li>
355 <li className="list-inline-item">
357 className="text-muted btn btn-sm btn-link p-0"
358 data-tippy-content={md.render(
359 previewLines(post_view.post.body)
361 data-tippy-allowHtml={true}
362 onClick={linkEvent(this, this.handleShowBody)}
364 <Icon icon="book-open" classes="icon-inline mr-1" />
375 <div className={`vote-bar col-1 pr-0 small text-center`}>
377 className={`btn-animate btn btn-link p-0 ${
378 this.state.my_vote == 1 ? "text-info" : "text-muted"
380 onClick={linkEvent(this, this.handlePostLike)}
381 data-tippy-content={i18n.t("upvote")}
382 aria-label={i18n.t("upvote")}
384 <Icon icon="arrow-up1" classes="upvote" />
388 class={`unselectable pointer font-weight-bold text-muted px-1`}
389 data-tippy-content={this.pointsTippy}
391 {numToSI(this.state.score)}
394 <div class="p-1"></div>
396 {this.props.enableDownvotes && (
398 className={`btn-animate btn btn-link p-0 ${
399 this.state.my_vote == -1 ? "text-danger" : "text-muted"
401 onClick={linkEvent(this, this.handlePostDisLike)}
402 data-tippy-content={i18n.t("downvote")}
403 aria-label={i18n.t("downvote")}
405 <Icon icon="arrow-down1" classes="downvote" />
413 let post = this.props.post_view.post;
415 <div className="post-title overflow-hidden">
417 {this.showBody && post.url ? (
419 className={!post.stickied ? "text-body" : "text-primary"}
428 className={!post.stickied ? "text-body" : "text-primary"}
429 to={`/post/${post.id}`}
430 title={i18n.t("comments")}
435 {(isImage(post.url) || post.thumbnail_url) && (
437 class="btn btn-link text-monospace text-muted small d-inline-block ml-2"
438 data-tippy-content={i18n.t("expand_here")}
439 onClick={linkEvent(this, this.handleImageExpandClick)}
443 !this.state.imageExpanded ? "plus-square" : "minus-square"
445 classes="icon-inline"
450 <small className="ml-2 text-muted font-italic">
456 className="unselectable pointer ml-2 text-muted font-italic"
457 data-tippy-content={i18n.t("deleted")}
459 <Icon icon="trash" classes="icon-inline text-danger" />
464 className="unselectable pointer ml-2 text-muted font-italic"
465 data-tippy-content={i18n.t("locked")}
467 <Icon icon="lock" classes="icon-inline text-danger" />
472 className="unselectable pointer ml-2 text-muted font-italic"
473 data-tippy-content={i18n.t("stickied")}
475 <Icon icon="pin" classes="icon-inline text-primary" />
479 <small className="ml-2 text-muted font-italic">
489 let dupes = this.props.duplicates;
492 dupes.length > 0 && (
493 <ul class="list-inline mb-1 small text-muted">
495 <li className="list-inline-item mr-2">
496 {i18n.t("cross_posted_to")}
499 <li className="list-inline-item mr-2">
500 <Link to={`/post/${pv.post.id}`}>
503 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
513 commentsLine(mobile = false) {
515 <div class="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
516 {this.commentsButton}
517 {mobile && !this.props.viewOnly && this.mobileVotes}
518 {UserService.Instance.myUserInfo &&
519 !this.props.viewOnly &&
520 this.postActions(mobile)}
525 postActions(mobile = false) {
526 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
527 // Possible enhancement: Make each button a component.
528 let post_view = this.props.post_view;
532 {this.crossPostButton}
533 {mobile && this.showMoreButton}
534 {(!mobile || this.state.showAdvanced) && (
542 {this.myPost && (this.showBody || this.state.showAdvanced) && (
550 {this.state.showAdvanced && (
552 {this.showBody && post_view.post.body && this.viewSourceButton}
553 {this.canModOnSelf && (
559 {(this.canMod || this.canAdmin || true) && (
560 <>{this.modRemoveButton}</>
564 {!mobile && this.showMoreButton}
569 get commentsButton() {
570 let post_view = this.props.post_view;
572 <button class="btn btn-link text-muted py-0 pl-0">
574 className="text-muted"
575 title={i18n.t("number_of_comments", {
576 count: post_view.counts.comments,
577 formattedCount: post_view.counts.comments,
579 to={`/post/${post_view.post.id}?scrollToComments=true`}
581 <Icon icon="message-square" classes="mr-1" inline />
582 {i18n.t("number_of_comments", {
583 count: post_view.counts.comments,
584 formattedCount: numToSI(post_view.counts.comments),
593 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
598 className={`btn-animate btn py-0 px-1 ${
599 this.state.my_vote == 1 ? "text-info" : "text-muted"
602 onClick={linkEvent(this, this.handlePostLike)}
603 aria-label={i18n.t("upvote")}
605 <Icon icon="arrow-up1" classes="icon-inline small" />
607 <span class="ml-2">{numToSI(this.state.upvotes)}</span>
610 {this.props.enableDownvotes && (
612 className={`ml-2 btn-animate btn py-0 px-1 ${
613 this.state.my_vote == -1 ? "text-danger" : "text-muted"
615 onClick={linkEvent(this, this.handlePostDisLike)}
617 aria-label={i18n.t("downvote")}
619 <Icon icon="arrow-down1" classes="icon-inline small" />
622 class={classNames("ml-2", {
623 invisible: this.state.downvotes === 0,
626 {numToSI(this.state.downvotes)}
637 let saved = this.props.post_view.saved;
638 let label = saved ? i18n.t("unsave") : i18n.t("save");
641 class="btn btn-link btn-animate text-muted py-0"
642 onClick={linkEvent(this, this.handleSavePostClick)}
643 data-tippy-content={label}
648 classes={classNames({ "text-warning": saved })}
655 get crossPostButton() {
658 className="btn btn-link btn-animate text-muted py-0"
659 to={`/create_post${this.crossPostParams}`}
660 title={i18n.t("cross_post")}
662 <Icon icon="copy" inline />
670 class="btn btn-link btn-animate text-muted py-0"
671 onClick={linkEvent(this, this.handleShowReportDialog)}
672 data-tippy-content={i18n.t("show_report_dialog")}
673 aria-label={i18n.t("show_report_dialog")}
675 <Icon icon="flag" inline />
683 class="btn btn-link btn-animate text-muted py-0"
684 onClick={linkEvent(this, this.handleBlockUserClick)}
685 data-tippy-content={i18n.t("block_user")}
686 aria-label={i18n.t("block_user")}
688 <Icon icon="slash" inline />
696 class="btn btn-link btn-animate text-muted py-0"
697 onClick={linkEvent(this, this.handleEditClick)}
698 data-tippy-content={i18n.t("edit")}
699 aria-label={i18n.t("edit")}
701 <Icon icon="edit" inline />
707 let deleted = this.props.post_view.post.deleted;
708 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
711 class="btn btn-link btn-animate text-muted py-0"
712 onClick={linkEvent(this, this.handleDeleteClick)}
713 data-tippy-content={label}
718 classes={classNames({ "text-danger": deleted })}
725 get showMoreButton() {
728 class="btn btn-link btn-animate text-muted py-0"
729 onClick={linkEvent(this, this.handleShowAdvanced)}
730 data-tippy-content={i18n.t("more")}
731 aria-label={i18n.t("more")}
733 <Icon icon="more-vertical" inline />
738 get viewSourceButton() {
741 class="btn btn-link btn-animate text-muted py-0"
742 onClick={linkEvent(this, this.handleViewSource)}
743 data-tippy-content={i18n.t("view_source")}
744 aria-label={i18n.t("view_source")}
748 classes={classNames({ "text-success": this.state.viewSource })}
756 let locked = this.props.post_view.post.locked;
757 let label = locked ? i18n.t("unlock") : i18n.t("lock");
760 class="btn btn-link btn-animate text-muted py-0"
761 onClick={linkEvent(this, this.handleModLock)}
762 data-tippy-content={label}
767 classes={classNames({ "text-danger": locked })}
775 let stickied = this.props.post_view.post.stickied;
776 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
779 class="btn btn-link btn-animate text-muted py-0"
780 onClick={linkEvent(this, this.handleModSticky)}
781 data-tippy-content={label}
786 classes={classNames({ "text-success": stickied })}
793 get modRemoveButton() {
794 let removed = this.props.post_view.post.removed;
797 class="btn btn-link btn-animate text-muted py-0"
800 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
803 {/* TODO: Find an icon for this. */}
804 {!removed ? i18n.t("remove") : i18n.t("restore")}
810 * Mod/Admin actions to be taken against the author.
814 let post_view = this.props.post_view;
816 this.state.showAdvanced && (
820 {!this.creatorIsMod &&
821 (!post_view.creator_banned_from_community ? (
823 class="btn btn-link btn-animate text-muted py-0"
826 this.handleModBanFromCommunityShow
828 aria-label={i18n.t("ban")}
834 class="btn btn-link btn-animate text-muted py-0"
837 this.handleModBanFromCommunitySubmit
839 aria-label={i18n.t("unban")}
844 {!post_view.creator_banned_from_community && (
846 class="btn btn-link btn-animate text-muted py-0"
847 onClick={linkEvent(this, this.handleAddModToCommunity)}
850 ? i18n.t("remove_as_mod")
851 : i18n.t("appoint_as_mod")
855 ? i18n.t("remove_as_mod")
856 : i18n.t("appoint_as_mod")}
861 {/* Community creators and admins can transfer community to another mod */}
862 {(this.amCommunityCreator || this.canAdmin) &&
864 (!this.state.showConfirmTransferCommunity ? (
866 class="btn btn-link btn-animate text-muted py-0"
869 this.handleShowConfirmTransferCommunity
871 aria-label={i18n.t("transfer_community")}
873 {i18n.t("transfer_community")}
878 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
879 aria-label={i18n.t("are_you_sure")}
881 {i18n.t("are_you_sure")}
884 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
885 aria-label={i18n.t("yes")}
886 onClick={linkEvent(this, this.handleTransferCommunity)}
891 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
894 this.handleCancelShowConfirmTransferCommunity
896 aria-label={i18n.t("no")}
902 {/* Admins can ban from all, and appoint other admins */}
905 {!this.creatorIsAdmin &&
906 (!isBanned(post_view.creator) ? (
908 class="btn btn-link btn-animate text-muted py-0"
909 onClick={linkEvent(this, this.handleModBanShow)}
910 aria-label={i18n.t("ban_from_site")}
912 {i18n.t("ban_from_site")}
916 class="btn btn-link btn-animate text-muted py-0"
917 onClick={linkEvent(this, this.handleModBanSubmit)}
918 aria-label={i18n.t("unban_from_site")}
920 {i18n.t("unban_from_site")}
923 {!isBanned(post_view.creator) && post_view.creator.local && (
925 class="btn btn-link btn-animate text-muted py-0"
926 onClick={linkEvent(this, this.handleAddAdmin)}
929 ? i18n.t("remove_as_admin")
930 : i18n.t("appoint_as_admin")
934 ? i18n.t("remove_as_admin")
935 : i18n.t("appoint_as_admin")}
940 {/* Site Creator can transfer to another admin */}
941 {this.amSiteCreator &&
942 this.creatorIsAdmin &&
943 (!this.state.showConfirmTransferSite ? (
945 class="btn btn-link btn-animate text-muted py-0"
946 onClick={linkEvent(this, this.handleShowConfirmTransferSite)}
947 aria-label={i18n.t("transfer_site")}
949 {i18n.t("transfer_site")}
954 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
955 aria-label={i18n.t("are_you_sure")}
957 {i18n.t("are_you_sure")}
960 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
961 onClick={linkEvent(this, this.handleTransferSite)}
962 aria-label={i18n.t("yes")}
967 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
970 this.handleCancelShowConfirmTransferSite
972 aria-label={i18n.t("no")}
983 removeAndBanDialogs() {
984 let post = this.props.post_view;
987 {this.state.showRemoveDialog && (
990 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
992 <label class="sr-only" htmlFor="post-listing-remove-reason">
997 id="post-listing-remove-reason"
998 class="form-control mr-2"
999 placeholder={i18n.t("reason")}
1000 value={this.state.removeReason}
1001 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1005 class="btn btn-secondary"
1006 aria-label={i18n.t("remove_post")}
1008 {i18n.t("remove_post")}
1012 {this.state.showBanDialog && (
1013 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1014 <div class="form-group row col-12">
1015 <label class="col-form-label" htmlFor="post-listing-ban-reason">
1020 id="post-listing-ban-reason"
1021 class="form-control mr-2"
1022 placeholder={i18n.t("reason")}
1023 value={this.state.banReason}
1024 onInput={linkEvent(this, this.handleModBanReasonChange)}
1026 <label class="col-form-label" htmlFor={`mod-ban-expires`}>
1031 id={`mod-ban-expires`}
1032 class="form-control mr-2"
1033 placeholder={i18n.t("number_of_days")}
1034 value={this.state.banExpireDays}
1035 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1037 <div class="form-group">
1038 <div class="form-check">
1040 class="form-check-input"
1041 id="mod-ban-remove-data"
1043 checked={this.state.removeData}
1044 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1047 class="form-check-label"
1048 htmlFor="mod-ban-remove-data"
1049 title={i18n.t("remove_content_more")}
1051 {i18n.t("remove_content")}
1056 {/* TODO hold off on expires until later */}
1057 {/* <div class="form-group row"> */}
1058 {/* <label class="col-form-label">Expires</label> */}
1059 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1061 <div class="form-group row">
1064 class="btn btn-secondary"
1065 aria-label={i18n.t("ban")}
1067 {i18n.t("ban")} {post.creator.name}
1072 {this.state.showReportDialog && (
1075 onSubmit={linkEvent(this, this.handleReportSubmit)}
1077 <label class="sr-only" htmlFor="post-report-reason">
1082 id="post-report-reason"
1083 class="form-control mr-2"
1084 placeholder={i18n.t("reason")}
1086 value={this.state.reportReason}
1087 onInput={linkEvent(this, this.handleReportReasonChange)}
1091 class="btn btn-secondary"
1092 aria-label={i18n.t("create_report")}
1094 {i18n.t("create_report")}
1103 let post = this.props.post_view.post;
1104 return post.thumbnail_url || isImage(post.url) ? (
1106 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1107 {this.postTitleLine()}
1110 {/* Post body prev or thumbnail */}
1111 {!this.state.imageExpanded && this.thumbnail()}
1115 this.postTitleLine()
1119 showMobilePreview() {
1120 let post = this.props.post_view.post;
1125 className="md-div mb-1"
1126 dangerouslySetInnerHTML={{
1127 __html: md.render(previewLines(post.body)),
1137 {/* The mobile view*/}
1138 <div class="d-block d-sm-none">
1140 <div class="col-12">
1141 {this.createdLine()}
1143 {/* If it has a thumbnail, do a right aligned thumbnail */}
1144 {this.mobileThumbnail()}
1146 {/* Show a preview of the post body */}
1147 {this.showMobilePreview()}
1149 {this.commentsLine(true)}
1150 {this.userActionsLine()}
1151 {this.duplicatesLine()}
1152 {this.removeAndBanDialogs()}
1157 {/* The larger view*/}
1158 <div class="d-none d-sm-block">
1160 {!this.props.viewOnly && this.voteBar()}
1161 <div class="col-sm-2 pr-0">
1162 <div class="">{this.thumbnail()}</div>
1164 <div class="col-12 col-sm-9">
1166 <div className="col-12">
1167 {this.postTitleLine()}
1168 {this.createdLine()}
1169 {this.commentsLine()}
1170 {this.duplicatesLine()}
1171 {this.userActionsLine()}
1172 {this.removeAndBanDialogs()}
1182 private get myPost(): boolean {
1184 UserService.Instance.myUserInfo &&
1185 this.props.post_view.creator.id ==
1186 UserService.Instance.myUserInfo.local_user_view.person.id
1190 get creatorIsMod(): boolean {
1192 this.props.moderators &&
1194 this.props.moderators.map(m => m.moderator.id),
1195 this.props.post_view.creator.id
1200 get creatorIsAdmin(): boolean {
1202 this.props.admins &&
1204 this.props.admins.map(a => a.person.id),
1205 this.props.post_view.creator.id
1211 * If the current user is allowed to mod this post.
1212 * The creator of this post is not allowed even if they are a mod.
1214 get canMod(): boolean {
1215 if (this.props.admins && this.props.moderators) {
1216 let adminsThenMods = this.props.admins
1217 .map(a => a.person.id)
1218 .concat(this.props.moderators.map(m => m.moderator.id));
1221 UserService.Instance.myUserInfo,
1223 this.props.post_view.creator.id
1231 * If the current user is allowed to mod this post.
1232 * The creator of this post is allowed if they are a mod.
1234 get canModOnSelf(): boolean {
1235 if (this.props.admins && this.props.moderators) {
1236 let adminsThenMods = this.props.admins
1237 .map(a => a.person.id)
1238 .concat(this.props.moderators.map(m => m.moderator.id));
1241 UserService.Instance.myUserInfo,
1243 this.props.post_view.creator.id,
1251 get canAdmin(): boolean {
1253 this.props.admins &&
1255 UserService.Instance.myUserInfo,
1256 this.props.admins.map(a => a.person.id),
1257 this.props.post_view.creator.id
1262 get amCommunityCreator(): boolean {
1264 this.props.moderators &&
1265 UserService.Instance.myUserInfo &&
1266 this.props.post_view.creator.id !=
1267 UserService.Instance.myUserInfo.local_user_view.person.id &&
1268 UserService.Instance.myUserInfo.local_user_view.person.id ==
1269 this.props.moderators[0].moderator.id
1273 get amSiteCreator(): boolean {
1275 this.props.admins &&
1276 UserService.Instance.myUserInfo &&
1277 this.props.post_view.creator.id !=
1278 UserService.Instance.myUserInfo.local_user_view.person.id &&
1279 UserService.Instance.myUserInfo.local_user_view.person.id ==
1280 this.props.admins[0].person.id
1284 handlePostLike(i: PostListing, event: any) {
1285 event.preventDefault();
1286 if (!UserService.Instance.myUserInfo) {
1287 this.context.router.history.push(`/login`);
1290 let new_vote = i.state.my_vote == 1 ? 0 : 1;
1292 if (i.state.my_vote == 1) {
1295 } else if (i.state.my_vote == -1) {
1296 i.state.downvotes--;
1304 i.state.my_vote = new_vote;
1306 let form: CreatePostLike = {
1307 post_id: i.props.post_view.post.id,
1308 score: i.state.my_vote,
1312 WebSocketService.Instance.send(wsClient.likePost(form));
1313 i.setState(i.state);
1317 handlePostDisLike(i: PostListing, event: any) {
1318 event.preventDefault();
1319 if (!UserService.Instance.myUserInfo) {
1320 this.context.router.history.push(`/login`);
1323 let new_vote = i.state.my_vote == -1 ? 0 : -1;
1325 if (i.state.my_vote == 1) {
1328 i.state.downvotes++;
1329 } else if (i.state.my_vote == -1) {
1330 i.state.downvotes--;
1333 i.state.downvotes++;
1337 i.state.my_vote = new_vote;
1339 let form: CreatePostLike = {
1340 post_id: i.props.post_view.post.id,
1341 score: i.state.my_vote,
1345 WebSocketService.Instance.send(wsClient.likePost(form));
1346 i.setState(i.state);
1350 handleEditClick(i: PostListing) {
1351 i.state.showEdit = true;
1352 i.setState(i.state);
1355 handleEditCancel() {
1356 this.state.showEdit = false;
1357 this.setState(this.state);
1360 // The actual editing is done in the recieve for post
1362 this.state.showEdit = false;
1363 this.setState(this.state);
1366 handleShowReportDialog(i: PostListing) {
1367 i.state.showReportDialog = !i.state.showReportDialog;
1368 i.setState(this.state);
1371 handleReportReasonChange(i: PostListing, event: any) {
1372 i.state.reportReason = event.target.value;
1373 i.setState(i.state);
1376 handleReportSubmit(i: PostListing, event: any) {
1377 event.preventDefault();
1378 let form: CreatePostReport = {
1379 post_id: i.props.post_view.post.id,
1380 reason: i.state.reportReason,
1383 WebSocketService.Instance.send(wsClient.createPostReport(form));
1385 i.state.showReportDialog = false;
1386 i.setState(i.state);
1389 handleBlockUserClick(i: PostListing) {
1390 let blockUserForm: BlockPerson = {
1391 person_id: i.props.post_view.creator.id,
1395 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1398 handleDeleteClick(i: PostListing) {
1399 let deleteForm: DeletePost = {
1400 post_id: i.props.post_view.post.id,
1401 deleted: !i.props.post_view.post.deleted,
1404 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1407 handleSavePostClick(i: PostListing) {
1409 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1410 let form: SavePost = {
1411 post_id: i.props.post_view.post.id,
1416 WebSocketService.Instance.send(wsClient.savePost(form));
1419 get crossPostParams(): string {
1420 let post = this.props.post_view.post;
1421 let params = `?title=${encodeURIComponent(post.name)}`;
1424 params += `&url=${encodeURIComponent(post.url)}`;
1427 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1432 crossPostBody(): string {
1433 let post = this.props.post_view.post;
1434 let body = `${i18n.t("cross_posted_from")} ${
1436 }\n\n${post.body.replace(/^/gm, "> ")}`;
1440 get showBody(): boolean {
1441 return this.props.showBody || this.state.showBody;
1444 handleModRemoveShow(i: PostListing) {
1445 i.state.showRemoveDialog = !i.state.showRemoveDialog;
1446 i.state.showBanDialog = false;
1447 i.setState(i.state);
1450 handleModRemoveReasonChange(i: PostListing, event: any) {
1451 i.state.removeReason = event.target.value;
1452 i.setState(i.state);
1455 handleModRemoveDataChange(i: PostListing, event: any) {
1456 i.state.removeData = event.target.checked;
1457 i.setState(i.state);
1460 handleModRemoveSubmit(i: PostListing, event: any) {
1461 event.preventDefault();
1462 let form: RemovePost = {
1463 post_id: i.props.post_view.post.id,
1464 removed: !i.props.post_view.post.removed,
1465 reason: i.state.removeReason,
1468 WebSocketService.Instance.send(wsClient.removePost(form));
1470 i.state.showRemoveDialog = false;
1471 i.setState(i.state);
1474 handleModLock(i: PostListing) {
1475 let form: LockPost = {
1476 post_id: i.props.post_view.post.id,
1477 locked: !i.props.post_view.post.locked,
1480 WebSocketService.Instance.send(wsClient.lockPost(form));
1483 handleModSticky(i: PostListing) {
1484 let form: StickyPost = {
1485 post_id: i.props.post_view.post.id,
1486 stickied: !i.props.post_view.post.stickied,
1489 WebSocketService.Instance.send(wsClient.stickyPost(form));
1492 handleModBanFromCommunityShow(i: PostListing) {
1493 i.state.showBanDialog = true;
1494 i.state.banType = BanType.Community;
1495 i.state.showRemoveDialog = false;
1496 i.setState(i.state);
1499 handleModBanShow(i: PostListing) {
1500 i.state.showBanDialog = true;
1501 i.state.banType = BanType.Site;
1502 i.state.showRemoveDialog = false;
1503 i.setState(i.state);
1506 handleModBanReasonChange(i: PostListing, event: any) {
1507 i.state.banReason = event.target.value;
1508 i.setState(i.state);
1511 handleModBanExpireDaysChange(i: PostListing, event: any) {
1512 i.state.banExpireDays = event.target.value;
1513 i.setState(i.state);
1516 handleModBanFromCommunitySubmit(i: PostListing) {
1517 i.state.banType = BanType.Community;
1518 i.setState(i.state);
1519 i.handleModBanBothSubmit(i);
1522 handleModBanSubmit(i: PostListing) {
1523 i.state.banType = BanType.Site;
1524 i.setState(i.state);
1525 i.handleModBanBothSubmit(i);
1528 handleModBanBothSubmit(i: PostListing, event?: any) {
1529 if (event) event.preventDefault();
1531 if (i.state.banType == BanType.Community) {
1532 // If its an unban, restore all their data
1533 let ban = !i.props.post_view.creator_banned_from_community;
1535 i.state.removeData = false;
1537 let form: BanFromCommunity = {
1538 person_id: i.props.post_view.creator.id,
1539 community_id: i.props.post_view.community.id,
1541 remove_data: i.state.removeData,
1542 reason: i.state.banReason,
1543 expires: futureDaysToUnixTime(i.state.banExpireDays),
1546 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1548 // If its an unban, restore all their data
1549 let ban = !i.props.post_view.creator.banned;
1551 i.state.removeData = false;
1553 let form: BanPerson = {
1554 person_id: i.props.post_view.creator.id,
1556 remove_data: i.state.removeData,
1557 reason: i.state.banReason,
1558 expires: futureDaysToUnixTime(i.state.banExpireDays),
1561 WebSocketService.Instance.send(wsClient.banPerson(form));
1564 i.state.showBanDialog = false;
1565 i.setState(i.state);
1568 handleAddModToCommunity(i: PostListing) {
1569 let form: AddModToCommunity = {
1570 person_id: i.props.post_view.creator.id,
1571 community_id: i.props.post_view.community.id,
1572 added: !i.creatorIsMod,
1575 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1576 i.setState(i.state);
1579 handleAddAdmin(i: PostListing) {
1580 let form: AddAdmin = {
1581 person_id: i.props.post_view.creator.id,
1582 added: !i.creatorIsAdmin,
1585 WebSocketService.Instance.send(wsClient.addAdmin(form));
1586 i.setState(i.state);
1589 handleShowConfirmTransferCommunity(i: PostListing) {
1590 i.state.showConfirmTransferCommunity = true;
1591 i.setState(i.state);
1594 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1595 i.state.showConfirmTransferCommunity = false;
1596 i.setState(i.state);
1599 handleTransferCommunity(i: PostListing) {
1600 let form: TransferCommunity = {
1601 community_id: i.props.post_view.community.id,
1602 person_id: i.props.post_view.creator.id,
1605 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1606 i.state.showConfirmTransferCommunity = false;
1607 i.setState(i.state);
1610 handleShowConfirmTransferSite(i: PostListing) {
1611 i.state.showConfirmTransferSite = true;
1612 i.setState(i.state);
1615 handleCancelShowConfirmTransferSite(i: PostListing) {
1616 i.state.showConfirmTransferSite = false;
1617 i.setState(i.state);
1620 handleTransferSite(i: PostListing) {
1621 let form: TransferSite = {
1622 person_id: i.props.post_view.creator.id,
1625 WebSocketService.Instance.send(wsClient.transferSite(form));
1626 i.state.showConfirmTransferSite = false;
1627 i.setState(i.state);
1630 handleImageExpandClick(i: PostListing, event: any) {
1631 event.preventDefault();
1632 i.state.imageExpanded = !i.state.imageExpanded;
1633 i.setState(i.state);
1637 handleViewSource(i: PostListing) {
1638 i.state.viewSource = !i.state.viewSource;
1639 i.setState(i.state);
1642 handleShowAdvanced(i: PostListing) {
1643 i.state.showAdvanced = !i.state.showAdvanced;
1644 i.setState(i.state);
1648 handleShowMoreMobile(i: PostListing) {
1649 i.state.showMoreMobile = !i.state.showMoreMobile;
1650 i.state.showAdvanced = !i.state.showAdvanced;
1651 i.setState(i.state);
1655 handleShowBody(i: PostListing) {
1656 i.state.showBody = !i.state.showBody;
1657 i.setState(i.state);
1661 get pointsTippy(): string {
1662 let points = i18n.t("number_of_points", {
1663 count: this.state.score,
1664 formattedCount: this.state.score,
1667 let upvotes = i18n.t("number_of_upvotes", {
1668 count: this.state.upvotes,
1669 formattedCount: this.state.upvotes,
1672 let downvotes = i18n.t("number_of_downvotes", {
1673 count: this.state.downvotes,
1674 formattedCount: this.state.downvotes,
1677 return `${points} • ${upvotes} • ${downvotes}`;