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";
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;
58 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,
96 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) {
514 let post = this.props.post_view.post;
516 <div class="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
517 {this.commentsButton}
520 className="btn btn-link btn-animate text-muted py-0"
521 title={i18n.t("link")}
524 <Icon icon="fedilink" inline />
527 {mobile && !this.props.viewOnly && this.mobileVotes}
528 {UserService.Instance.myUserInfo &&
529 !this.props.viewOnly &&
530 this.postActions(mobile)}
535 postActions(mobile = false) {
536 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
537 // Possible enhancement: Make each button a component.
538 let post_view = this.props.post_view;
542 {this.crossPostButton}
543 {mobile && this.showMoreButton}
544 {(!mobile || this.state.showAdvanced) && (
552 {this.myPost && (this.showBody || this.state.showAdvanced) && (
560 {this.state.showAdvanced && (
562 {this.showBody && post_view.post.body && this.viewSourceButton}
563 {this.canModOnSelf && (
569 {(this.canMod || this.canAdmin || true) && (
570 <>{this.modRemoveButton}</>
574 {!mobile && this.showMoreButton}
579 get commentsButton() {
580 let post_view = this.props.post_view;
582 <button class="btn btn-link text-muted py-0 pl-0">
584 className="text-muted"
585 title={i18n.t("number_of_comments", {
586 count: post_view.counts.comments,
587 formattedCount: post_view.counts.comments,
589 to={`/post/${post_view.post.id}?scrollToComments=true`}
591 <Icon icon="message-square" classes="mr-1" inline />
592 {i18n.t("number_of_comments", {
593 count: post_view.counts.comments,
594 formattedCount: numToSI(post_view.counts.comments),
603 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
608 className={`btn-animate btn py-0 px-1 ${
609 this.state.my_vote == 1 ? "text-info" : "text-muted"
612 onClick={linkEvent(this, this.handlePostLike)}
613 aria-label={i18n.t("upvote")}
615 <Icon icon="arrow-up1" classes="icon-inline small" />
617 <span class="ml-2">{numToSI(this.state.upvotes)}</span>
620 {this.props.enableDownvotes && (
622 className={`ml-2 btn-animate btn py-0 px-1 ${
623 this.state.my_vote == -1 ? "text-danger" : "text-muted"
625 onClick={linkEvent(this, this.handlePostDisLike)}
627 aria-label={i18n.t("downvote")}
629 <Icon icon="arrow-down1" classes="icon-inline small" />
632 class={classNames("ml-2", {
633 invisible: this.state.downvotes === 0,
636 {numToSI(this.state.downvotes)}
647 let saved = this.props.post_view.saved;
648 let label = saved ? i18n.t("unsave") : i18n.t("save");
651 class="btn btn-link btn-animate text-muted py-0"
652 onClick={linkEvent(this, this.handleSavePostClick)}
653 data-tippy-content={label}
658 classes={classNames({ "text-warning": saved })}
665 get crossPostButton() {
668 className="btn btn-link btn-animate text-muted py-0"
669 to={`/create_post${this.crossPostParams}`}
670 title={i18n.t("cross_post")}
672 <Icon icon="copy" inline />
680 class="btn btn-link btn-animate text-muted py-0"
681 onClick={linkEvent(this, this.handleShowReportDialog)}
682 data-tippy-content={i18n.t("show_report_dialog")}
683 aria-label={i18n.t("show_report_dialog")}
685 <Icon icon="flag" inline />
693 class="btn btn-link btn-animate text-muted py-0"
694 onClick={linkEvent(this, this.handleBlockUserClick)}
695 data-tippy-content={i18n.t("block_user")}
696 aria-label={i18n.t("block_user")}
698 <Icon icon="slash" inline />
706 class="btn btn-link btn-animate text-muted py-0"
707 onClick={linkEvent(this, this.handleEditClick)}
708 data-tippy-content={i18n.t("edit")}
709 aria-label={i18n.t("edit")}
711 <Icon icon="edit" inline />
717 let deleted = this.props.post_view.post.deleted;
718 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
721 class="btn btn-link btn-animate text-muted py-0"
722 onClick={linkEvent(this, this.handleDeleteClick)}
723 data-tippy-content={label}
728 classes={classNames({ "text-danger": deleted })}
735 get showMoreButton() {
738 class="btn btn-link btn-animate text-muted py-0"
739 onClick={linkEvent(this, this.handleShowAdvanced)}
740 data-tippy-content={i18n.t("more")}
741 aria-label={i18n.t("more")}
743 <Icon icon="more-vertical" inline />
748 get viewSourceButton() {
751 class="btn btn-link btn-animate text-muted py-0"
752 onClick={linkEvent(this, this.handleViewSource)}
753 data-tippy-content={i18n.t("view_source")}
754 aria-label={i18n.t("view_source")}
758 classes={classNames({ "text-success": this.state.viewSource })}
766 let locked = this.props.post_view.post.locked;
767 let label = locked ? i18n.t("unlock") : i18n.t("lock");
770 class="btn btn-link btn-animate text-muted py-0"
771 onClick={linkEvent(this, this.handleModLock)}
772 data-tippy-content={label}
777 classes={classNames({ "text-danger": locked })}
785 let stickied = this.props.post_view.post.stickied;
786 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
789 class="btn btn-link btn-animate text-muted py-0"
790 onClick={linkEvent(this, this.handleModSticky)}
791 data-tippy-content={label}
796 classes={classNames({ "text-success": stickied })}
803 get modRemoveButton() {
804 let removed = this.props.post_view.post.removed;
807 class="btn btn-link btn-animate text-muted py-0"
810 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
813 {/* TODO: Find an icon for this. */}
814 {!removed ? i18n.t("remove") : i18n.t("restore")}
820 * Mod/Admin actions to be taken against the author.
824 let post_view = this.props.post_view;
826 this.state.showAdvanced && (
830 {!this.creatorIsMod &&
831 (!post_view.creator_banned_from_community ? (
833 class="btn btn-link btn-animate text-muted py-0"
836 this.handleModBanFromCommunityShow
838 aria-label={i18n.t("ban")}
844 class="btn btn-link btn-animate text-muted py-0"
847 this.handleModBanFromCommunitySubmit
849 aria-label={i18n.t("unban")}
854 {!post_view.creator_banned_from_community && (
856 class="btn btn-link btn-animate text-muted py-0"
857 onClick={linkEvent(this, this.handleAddModToCommunity)}
860 ? i18n.t("remove_as_mod")
861 : i18n.t("appoint_as_mod")
865 ? i18n.t("remove_as_mod")
866 : i18n.t("appoint_as_mod")}
871 {/* Community creators and admins can transfer community to another mod */}
872 {(this.amCommunityCreator || this.canAdmin) &&
874 (!this.state.showConfirmTransferCommunity ? (
876 class="btn btn-link btn-animate text-muted py-0"
879 this.handleShowConfirmTransferCommunity
881 aria-label={i18n.t("transfer_community")}
883 {i18n.t("transfer_community")}
888 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
889 aria-label={i18n.t("are_you_sure")}
891 {i18n.t("are_you_sure")}
894 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
895 aria-label={i18n.t("yes")}
896 onClick={linkEvent(this, this.handleTransferCommunity)}
901 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
904 this.handleCancelShowConfirmTransferCommunity
906 aria-label={i18n.t("no")}
912 {/* Admins can ban from all, and appoint other admins */}
915 {!this.creatorIsAdmin &&
916 (!isBanned(post_view.creator) ? (
918 class="btn btn-link btn-animate text-muted py-0"
919 onClick={linkEvent(this, this.handleModBanShow)}
920 aria-label={i18n.t("ban_from_site")}
922 {i18n.t("ban_from_site")}
926 class="btn btn-link btn-animate text-muted py-0"
927 onClick={linkEvent(this, this.handleModBanSubmit)}
928 aria-label={i18n.t("unban_from_site")}
930 {i18n.t("unban_from_site")}
933 {!isBanned(post_view.creator) && post_view.creator.local && (
935 class="btn btn-link btn-animate text-muted py-0"
936 onClick={linkEvent(this, this.handleAddAdmin)}
939 ? i18n.t("remove_as_admin")
940 : i18n.t("appoint_as_admin")
944 ? i18n.t("remove_as_admin")
945 : i18n.t("appoint_as_admin")}
955 removeAndBanDialogs() {
956 let post = this.props.post_view;
959 {this.state.showRemoveDialog && (
962 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
964 <label class="sr-only" htmlFor="post-listing-remove-reason">
969 id="post-listing-remove-reason"
970 class="form-control mr-2"
971 placeholder={i18n.t("reason")}
972 value={this.state.removeReason}
973 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
977 class="btn btn-secondary"
978 aria-label={i18n.t("remove_post")}
980 {i18n.t("remove_post")}
984 {this.state.showBanDialog && (
985 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
986 <div class="form-group row col-12">
987 <label class="col-form-label" htmlFor="post-listing-ban-reason">
992 id="post-listing-ban-reason"
993 class="form-control mr-2"
994 placeholder={i18n.t("reason")}
995 value={this.state.banReason}
996 onInput={linkEvent(this, this.handleModBanReasonChange)}
998 <label class="col-form-label" htmlFor={`mod-ban-expires`}>
1003 id={`mod-ban-expires`}
1004 class="form-control mr-2"
1005 placeholder={i18n.t("number_of_days")}
1006 value={this.state.banExpireDays}
1007 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1009 <div class="form-group">
1010 <div class="form-check">
1012 class="form-check-input"
1013 id="mod-ban-remove-data"
1015 checked={this.state.removeData}
1016 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1019 class="form-check-label"
1020 htmlFor="mod-ban-remove-data"
1021 title={i18n.t("remove_content_more")}
1023 {i18n.t("remove_content")}
1028 {/* TODO hold off on expires until later */}
1029 {/* <div class="form-group row"> */}
1030 {/* <label class="col-form-label">Expires</label> */}
1031 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1033 <div class="form-group row">
1036 class="btn btn-secondary"
1037 aria-label={i18n.t("ban")}
1039 {i18n.t("ban")} {post.creator.name}
1044 {this.state.showReportDialog && (
1047 onSubmit={linkEvent(this, this.handleReportSubmit)}
1049 <label class="sr-only" htmlFor="post-report-reason">
1054 id="post-report-reason"
1055 class="form-control mr-2"
1056 placeholder={i18n.t("reason")}
1058 value={this.state.reportReason}
1059 onInput={linkEvent(this, this.handleReportReasonChange)}
1063 class="btn btn-secondary"
1064 aria-label={i18n.t("create_report")}
1066 {i18n.t("create_report")}
1075 let post = this.props.post_view.post;
1076 return post.thumbnail_url || isImage(post.url) ? (
1078 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1079 {this.postTitleLine()}
1082 {/* Post body prev or thumbnail */}
1083 {!this.state.imageExpanded && this.thumbnail()}
1087 this.postTitleLine()
1091 showMobilePreview() {
1092 let post = this.props.post_view.post;
1097 className="md-div mb-1"
1098 dangerouslySetInnerHTML={{
1099 __html: md.render(previewLines(post.body)),
1109 {/* The mobile view*/}
1110 <div class="d-block d-sm-none">
1112 <div class="col-12">
1113 {this.createdLine()}
1115 {/* If it has a thumbnail, do a right aligned thumbnail */}
1116 {this.mobileThumbnail()}
1118 {/* Show a preview of the post body */}
1119 {this.showMobilePreview()}
1121 {this.commentsLine(true)}
1122 {this.userActionsLine()}
1123 {this.duplicatesLine()}
1124 {this.removeAndBanDialogs()}
1129 {/* The larger view*/}
1130 <div class="d-none d-sm-block">
1132 {!this.props.viewOnly && this.voteBar()}
1133 <div class="col-sm-2 pr-0">
1134 <div class="">{this.thumbnail()}</div>
1136 <div class="col-12 col-sm-9">
1138 <div className="col-12">
1139 {this.postTitleLine()}
1140 {this.createdLine()}
1141 {this.commentsLine()}
1142 {this.duplicatesLine()}
1143 {this.userActionsLine()}
1144 {this.removeAndBanDialogs()}
1154 private get myPost(): boolean {
1156 UserService.Instance.myUserInfo &&
1157 this.props.post_view.creator.id ==
1158 UserService.Instance.myUserInfo.local_user_view.person.id
1162 get creatorIsMod(): boolean {
1164 this.props.moderators &&
1166 this.props.moderators.map(m => m.moderator.id),
1167 this.props.post_view.creator.id
1172 get creatorIsAdmin(): boolean {
1174 this.props.admins &&
1176 this.props.admins.map(a => a.person.id),
1177 this.props.post_view.creator.id
1183 * If the current user is allowed to mod this post.
1184 * The creator of this post is not allowed even if they are a mod.
1186 get canMod(): boolean {
1187 if (this.props.admins && this.props.moderators) {
1188 let adminsThenMods = this.props.admins
1189 .map(a => a.person.id)
1190 .concat(this.props.moderators.map(m => m.moderator.id));
1193 UserService.Instance.myUserInfo,
1195 this.props.post_view.creator.id
1203 * If the current user is allowed to mod this post.
1204 * The creator of this post is allowed if they are a mod.
1206 get canModOnSelf(): boolean {
1207 if (this.props.admins && this.props.moderators) {
1208 let adminsThenMods = this.props.admins
1209 .map(a => a.person.id)
1210 .concat(this.props.moderators.map(m => m.moderator.id));
1213 UserService.Instance.myUserInfo,
1215 this.props.post_view.creator.id,
1223 get canAdmin(): boolean {
1225 this.props.admins &&
1227 UserService.Instance.myUserInfo,
1228 this.props.admins.map(a => a.person.id),
1229 this.props.post_view.creator.id
1234 get amCommunityCreator(): boolean {
1236 this.props.moderators &&
1237 UserService.Instance.myUserInfo &&
1238 this.props.post_view.creator.id !=
1239 UserService.Instance.myUserInfo.local_user_view.person.id &&
1240 UserService.Instance.myUserInfo.local_user_view.person.id ==
1241 this.props.moderators[0].moderator.id
1245 get amSiteCreator(): boolean {
1247 this.props.admins &&
1248 UserService.Instance.myUserInfo &&
1249 this.props.post_view.creator.id !=
1250 UserService.Instance.myUserInfo.local_user_view.person.id &&
1251 UserService.Instance.myUserInfo.local_user_view.person.id ==
1252 this.props.admins[0].person.id
1256 handlePostLike(i: PostListing, event: any) {
1257 event.preventDefault();
1258 if (!UserService.Instance.myUserInfo) {
1259 this.context.router.history.push(`/login`);
1262 let new_vote = i.state.my_vote == 1 ? 0 : 1;
1264 if (i.state.my_vote == 1) {
1267 } else if (i.state.my_vote == -1) {
1268 i.state.downvotes--;
1276 i.state.my_vote = new_vote;
1278 let form: CreatePostLike = {
1279 post_id: i.props.post_view.post.id,
1280 score: i.state.my_vote,
1284 WebSocketService.Instance.send(wsClient.likePost(form));
1285 i.setState(i.state);
1289 handlePostDisLike(i: PostListing, event: any) {
1290 event.preventDefault();
1291 if (!UserService.Instance.myUserInfo) {
1292 this.context.router.history.push(`/login`);
1295 let new_vote = i.state.my_vote == -1 ? 0 : -1;
1297 if (i.state.my_vote == 1) {
1300 i.state.downvotes++;
1301 } else if (i.state.my_vote == -1) {
1302 i.state.downvotes--;
1305 i.state.downvotes++;
1309 i.state.my_vote = new_vote;
1311 let form: CreatePostLike = {
1312 post_id: i.props.post_view.post.id,
1313 score: i.state.my_vote,
1317 WebSocketService.Instance.send(wsClient.likePost(form));
1318 i.setState(i.state);
1322 handleEditClick(i: PostListing) {
1323 i.state.showEdit = true;
1324 i.setState(i.state);
1327 handleEditCancel() {
1328 this.state.showEdit = false;
1329 this.setState(this.state);
1332 // The actual editing is done in the recieve for post
1334 this.state.showEdit = false;
1335 this.setState(this.state);
1338 handleShowReportDialog(i: PostListing) {
1339 i.state.showReportDialog = !i.state.showReportDialog;
1340 i.setState(this.state);
1343 handleReportReasonChange(i: PostListing, event: any) {
1344 i.state.reportReason = event.target.value;
1345 i.setState(i.state);
1348 handleReportSubmit(i: PostListing, event: any) {
1349 event.preventDefault();
1350 let form: CreatePostReport = {
1351 post_id: i.props.post_view.post.id,
1352 reason: i.state.reportReason,
1355 WebSocketService.Instance.send(wsClient.createPostReport(form));
1357 i.state.showReportDialog = false;
1358 i.setState(i.state);
1361 handleBlockUserClick(i: PostListing) {
1362 let blockUserForm: BlockPerson = {
1363 person_id: i.props.post_view.creator.id,
1367 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1370 handleDeleteClick(i: PostListing) {
1371 let deleteForm: DeletePost = {
1372 post_id: i.props.post_view.post.id,
1373 deleted: !i.props.post_view.post.deleted,
1376 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1379 handleSavePostClick(i: PostListing) {
1381 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1382 let form: SavePost = {
1383 post_id: i.props.post_view.post.id,
1388 WebSocketService.Instance.send(wsClient.savePost(form));
1391 get crossPostParams(): string {
1392 let post = this.props.post_view.post;
1393 let params = `?title=${encodeURIComponent(post.name)}`;
1396 params += `&url=${encodeURIComponent(post.url)}`;
1399 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1404 crossPostBody(): string {
1405 let post = this.props.post_view.post;
1406 let body = `${i18n.t("cross_posted_from")} ${
1408 }\n\n${post.body.replace(/^/gm, "> ")}`;
1412 get showBody(): boolean {
1413 return this.props.showBody || this.state.showBody;
1416 handleModRemoveShow(i: PostListing) {
1417 i.state.showRemoveDialog = !i.state.showRemoveDialog;
1418 i.state.showBanDialog = false;
1419 i.setState(i.state);
1422 handleModRemoveReasonChange(i: PostListing, event: any) {
1423 i.state.removeReason = event.target.value;
1424 i.setState(i.state);
1427 handleModRemoveDataChange(i: PostListing, event: any) {
1428 i.state.removeData = event.target.checked;
1429 i.setState(i.state);
1432 handleModRemoveSubmit(i: PostListing, event: any) {
1433 event.preventDefault();
1434 let form: RemovePost = {
1435 post_id: i.props.post_view.post.id,
1436 removed: !i.props.post_view.post.removed,
1437 reason: i.state.removeReason,
1440 WebSocketService.Instance.send(wsClient.removePost(form));
1442 i.state.showRemoveDialog = false;
1443 i.setState(i.state);
1446 handleModLock(i: PostListing) {
1447 let form: LockPost = {
1448 post_id: i.props.post_view.post.id,
1449 locked: !i.props.post_view.post.locked,
1452 WebSocketService.Instance.send(wsClient.lockPost(form));
1455 handleModSticky(i: PostListing) {
1456 let form: StickyPost = {
1457 post_id: i.props.post_view.post.id,
1458 stickied: !i.props.post_view.post.stickied,
1461 WebSocketService.Instance.send(wsClient.stickyPost(form));
1464 handleModBanFromCommunityShow(i: PostListing) {
1465 i.state.showBanDialog = true;
1466 i.state.banType = BanType.Community;
1467 i.state.showRemoveDialog = false;
1468 i.setState(i.state);
1471 handleModBanShow(i: PostListing) {
1472 i.state.showBanDialog = true;
1473 i.state.banType = BanType.Site;
1474 i.state.showRemoveDialog = false;
1475 i.setState(i.state);
1478 handleModBanReasonChange(i: PostListing, event: any) {
1479 i.state.banReason = event.target.value;
1480 i.setState(i.state);
1483 handleModBanExpireDaysChange(i: PostListing, event: any) {
1484 i.state.banExpireDays = event.target.value;
1485 i.setState(i.state);
1488 handleModBanFromCommunitySubmit(i: PostListing) {
1489 i.state.banType = BanType.Community;
1490 i.setState(i.state);
1491 i.handleModBanBothSubmit(i);
1494 handleModBanSubmit(i: PostListing) {
1495 i.state.banType = BanType.Site;
1496 i.setState(i.state);
1497 i.handleModBanBothSubmit(i);
1500 handleModBanBothSubmit(i: PostListing, event?: any) {
1501 if (event) event.preventDefault();
1503 if (i.state.banType == BanType.Community) {
1504 // If its an unban, restore all their data
1505 let ban = !i.props.post_view.creator_banned_from_community;
1507 i.state.removeData = false;
1509 let form: BanFromCommunity = {
1510 person_id: i.props.post_view.creator.id,
1511 community_id: i.props.post_view.community.id,
1513 remove_data: i.state.removeData,
1514 reason: i.state.banReason,
1515 expires: futureDaysToUnixTime(i.state.banExpireDays),
1518 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1520 // If its an unban, restore all their data
1521 let ban = !i.props.post_view.creator.banned;
1523 i.state.removeData = false;
1525 let form: BanPerson = {
1526 person_id: i.props.post_view.creator.id,
1528 remove_data: i.state.removeData,
1529 reason: i.state.banReason,
1530 expires: futureDaysToUnixTime(i.state.banExpireDays),
1533 WebSocketService.Instance.send(wsClient.banPerson(form));
1536 i.state.showBanDialog = false;
1537 i.setState(i.state);
1540 handleAddModToCommunity(i: PostListing) {
1541 let form: AddModToCommunity = {
1542 person_id: i.props.post_view.creator.id,
1543 community_id: i.props.post_view.community.id,
1544 added: !i.creatorIsMod,
1547 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1548 i.setState(i.state);
1551 handleAddAdmin(i: PostListing) {
1552 let form: AddAdmin = {
1553 person_id: i.props.post_view.creator.id,
1554 added: !i.creatorIsAdmin,
1557 WebSocketService.Instance.send(wsClient.addAdmin(form));
1558 i.setState(i.state);
1561 handleShowConfirmTransferCommunity(i: PostListing) {
1562 i.state.showConfirmTransferCommunity = true;
1563 i.setState(i.state);
1566 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1567 i.state.showConfirmTransferCommunity = false;
1568 i.setState(i.state);
1571 handleTransferCommunity(i: PostListing) {
1572 let form: TransferCommunity = {
1573 community_id: i.props.post_view.community.id,
1574 person_id: i.props.post_view.creator.id,
1577 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1578 i.state.showConfirmTransferCommunity = false;
1579 i.setState(i.state);
1582 handleShowConfirmTransferSite(i: PostListing) {
1583 i.state.showConfirmTransferSite = true;
1584 i.setState(i.state);
1587 handleCancelShowConfirmTransferSite(i: PostListing) {
1588 i.state.showConfirmTransferSite = false;
1589 i.setState(i.state);
1592 handleImageExpandClick(i: PostListing, event: any) {
1593 event.preventDefault();
1594 i.state.imageExpanded = !i.state.imageExpanded;
1595 i.setState(i.state);
1599 handleViewSource(i: PostListing) {
1600 i.state.viewSource = !i.state.viewSource;
1601 i.setState(i.state);
1604 handleShowAdvanced(i: PostListing) {
1605 i.state.showAdvanced = !i.state.showAdvanced;
1606 i.setState(i.state);
1610 handleShowMoreMobile(i: PostListing) {
1611 i.state.showMoreMobile = !i.state.showMoreMobile;
1612 i.state.showAdvanced = !i.state.showAdvanced;
1613 i.setState(i.state);
1617 handleShowBody(i: PostListing) {
1618 i.state.showBody = !i.state.showBody;
1619 i.setState(i.state);
1623 get pointsTippy(): string {
1624 let points = i18n.t("number_of_points", {
1625 count: this.state.score,
1626 formattedCount: this.state.score,
1629 let upvotes = i18n.t("number_of_upvotes", {
1630 count: this.state.upvotes,
1631 formattedCount: this.state.upvotes,
1634 let downvotes = i18n.t("number_of_downvotes", {
1635 count: this.state.downvotes,
1636 formattedCount: this.state.downvotes,
1639 return `${points} • ${upvotes} • ${downvotes}`;