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;
57 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,
95 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(post_view.post.body)}
358 data-tippy-allowHtml={true}
359 onClick={linkEvent(this, this.handleShowBody)}
361 <Icon icon="book-open" classes="icon-inline mr-1" />
372 <div className={`vote-bar col-1 pr-0 small text-center`}>
374 className={`btn-animate btn btn-link p-0 ${
375 this.state.my_vote == 1 ? "text-info" : "text-muted"
377 onClick={linkEvent(this, this.handlePostLike)}
378 data-tippy-content={i18n.t("upvote")}
379 aria-label={i18n.t("upvote")}
381 <Icon icon="arrow-up1" classes="upvote" />
385 class={`unselectable pointer font-weight-bold text-muted px-1`}
386 data-tippy-content={this.pointsTippy}
388 {numToSI(this.state.score)}
391 <div class="p-1"></div>
393 {this.props.enableDownvotes && (
395 className={`btn-animate btn btn-link p-0 ${
396 this.state.my_vote == -1 ? "text-danger" : "text-muted"
398 onClick={linkEvent(this, this.handlePostDisLike)}
399 data-tippy-content={i18n.t("downvote")}
400 aria-label={i18n.t("downvote")}
402 <Icon icon="arrow-down1" classes="downvote" />
410 let post = this.props.post_view.post;
412 <div className="post-title overflow-hidden">
414 {this.showBody && post.url ? (
416 className={!post.stickied ? "text-body" : "text-primary"}
425 className={!post.stickied ? "text-body" : "text-primary"}
426 to={`/post/${post.id}`}
427 title={i18n.t("comments")}
432 {(isImage(post.url) || post.thumbnail_url) && (
434 class="btn btn-link text-monospace text-muted small d-inline-block ml-2"
435 data-tippy-content={i18n.t("expand_here")}
436 onClick={linkEvent(this, this.handleImageExpandClick)}
440 !this.state.imageExpanded ? "plus-square" : "minus-square"
442 classes="icon-inline"
447 <small className="ml-2 text-muted font-italic">
453 className="unselectable pointer ml-2 text-muted font-italic"
454 data-tippy-content={i18n.t("deleted")}
456 <Icon icon="trash" classes="icon-inline text-danger" />
461 className="unselectable pointer ml-2 text-muted font-italic"
462 data-tippy-content={i18n.t("locked")}
464 <Icon icon="lock" classes="icon-inline text-danger" />
469 className="unselectable pointer ml-2 text-muted font-italic"
470 data-tippy-content={i18n.t("stickied")}
472 <Icon icon="pin" classes="icon-inline text-primary" />
476 <small className="ml-2 text-muted font-italic">
486 let dupes = this.props.duplicates;
489 dupes.length > 0 && (
490 <ul class="list-inline mb-1 small text-muted">
492 <li className="list-inline-item mr-2">
493 {i18n.t("cross_posted_to")}
496 <li className="list-inline-item mr-2">
497 <Link to={`/post/${pv.post.id}`}>
500 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
510 commentsLine(mobile = false) {
511 let post = this.props.post_view.post;
513 <div class="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
514 {this.commentsButton}
517 className="btn btn-link btn-animate text-muted py-0"
518 title={i18n.t("link")}
521 <Icon icon="fedilink" inline />
524 {mobile && !this.props.viewOnly && this.mobileVotes}
525 {UserService.Instance.myUserInfo &&
526 !this.props.viewOnly &&
527 this.postActions(mobile)}
532 postActions(mobile = false) {
533 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
534 // Possible enhancement: Make each button a component.
535 let post_view = this.props.post_view;
539 {this.crossPostButton}
540 {mobile && this.showMoreButton}
541 {(!mobile || this.state.showAdvanced) && (
549 {this.myPost && (this.showBody || this.state.showAdvanced) && (
557 {this.state.showAdvanced && (
559 {this.showBody && post_view.post.body && this.viewSourceButton}
560 {this.canModOnSelf && (
566 {(this.canMod || this.canAdmin || true) && (
567 <>{this.modRemoveButton}</>
571 {!mobile && this.showMoreButton}
576 get commentsButton() {
577 let post_view = this.props.post_view;
579 <button class="btn btn-link text-muted py-0 pl-0">
581 className="text-muted"
582 title={i18n.t("number_of_comments", {
583 count: post_view.counts.comments,
584 formattedCount: post_view.counts.comments,
586 to={`/post/${post_view.post.id}?scrollToComments=true`}
588 <Icon icon="message-square" classes="mr-1" inline />
589 {i18n.t("number_of_comments", {
590 count: post_view.counts.comments,
591 formattedCount: numToSI(post_view.counts.comments),
600 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
605 className={`btn-animate btn py-0 px-1 ${
606 this.state.my_vote == 1 ? "text-info" : "text-muted"
609 onClick={linkEvent(this, this.handlePostLike)}
610 aria-label={i18n.t("upvote")}
612 <Icon icon="arrow-up1" classes="icon-inline small" />
614 <span class="ml-2">{numToSI(this.state.upvotes)}</span>
617 {this.props.enableDownvotes && (
619 className={`ml-2 btn-animate btn py-0 px-1 ${
620 this.state.my_vote == -1 ? "text-danger" : "text-muted"
622 onClick={linkEvent(this, this.handlePostDisLike)}
624 aria-label={i18n.t("downvote")}
626 <Icon icon="arrow-down1" classes="icon-inline small" />
629 class={classNames("ml-2", {
630 invisible: this.state.downvotes === 0,
633 {numToSI(this.state.downvotes)}
644 let saved = this.props.post_view.saved;
645 let label = saved ? i18n.t("unsave") : i18n.t("save");
648 class="btn btn-link btn-animate text-muted py-0"
649 onClick={linkEvent(this, this.handleSavePostClick)}
650 data-tippy-content={label}
655 classes={classNames({ "text-warning": saved })}
662 get crossPostButton() {
665 className="btn btn-link btn-animate text-muted py-0"
666 to={`/create_post${this.crossPostParams}`}
667 title={i18n.t("cross_post")}
669 <Icon icon="copy" inline />
677 class="btn btn-link btn-animate text-muted py-0"
678 onClick={linkEvent(this, this.handleShowReportDialog)}
679 data-tippy-content={i18n.t("show_report_dialog")}
680 aria-label={i18n.t("show_report_dialog")}
682 <Icon icon="flag" inline />
690 class="btn btn-link btn-animate text-muted py-0"
691 onClick={linkEvent(this, this.handleBlockUserClick)}
692 data-tippy-content={i18n.t("block_user")}
693 aria-label={i18n.t("block_user")}
695 <Icon icon="slash" inline />
703 class="btn btn-link btn-animate text-muted py-0"
704 onClick={linkEvent(this, this.handleEditClick)}
705 data-tippy-content={i18n.t("edit")}
706 aria-label={i18n.t("edit")}
708 <Icon icon="edit" inline />
714 let deleted = this.props.post_view.post.deleted;
715 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
718 class="btn btn-link btn-animate text-muted py-0"
719 onClick={linkEvent(this, this.handleDeleteClick)}
720 data-tippy-content={label}
725 classes={classNames({ "text-danger": deleted })}
732 get showMoreButton() {
735 class="btn btn-link btn-animate text-muted py-0"
736 onClick={linkEvent(this, this.handleShowAdvanced)}
737 data-tippy-content={i18n.t("more")}
738 aria-label={i18n.t("more")}
740 <Icon icon="more-vertical" inline />
745 get viewSourceButton() {
748 class="btn btn-link btn-animate text-muted py-0"
749 onClick={linkEvent(this, this.handleViewSource)}
750 data-tippy-content={i18n.t("view_source")}
751 aria-label={i18n.t("view_source")}
755 classes={classNames({ "text-success": this.state.viewSource })}
763 let locked = this.props.post_view.post.locked;
764 let label = locked ? i18n.t("unlock") : i18n.t("lock");
767 class="btn btn-link btn-animate text-muted py-0"
768 onClick={linkEvent(this, this.handleModLock)}
769 data-tippy-content={label}
774 classes={classNames({ "text-danger": locked })}
782 let stickied = this.props.post_view.post.stickied;
783 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
786 class="btn btn-link btn-animate text-muted py-0"
787 onClick={linkEvent(this, this.handleModSticky)}
788 data-tippy-content={label}
793 classes={classNames({ "text-success": stickied })}
800 get modRemoveButton() {
801 let removed = this.props.post_view.post.removed;
804 class="btn btn-link btn-animate text-muted py-0"
807 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
810 {/* TODO: Find an icon for this. */}
811 {!removed ? i18n.t("remove") : i18n.t("restore")}
817 * Mod/Admin actions to be taken against the author.
821 let post_view = this.props.post_view;
823 this.state.showAdvanced && (
827 {!this.creatorIsMod &&
828 (!post_view.creator_banned_from_community ? (
830 class="btn btn-link btn-animate text-muted py-0"
833 this.handleModBanFromCommunityShow
835 aria-label={i18n.t("ban")}
841 class="btn btn-link btn-animate text-muted py-0"
844 this.handleModBanFromCommunitySubmit
846 aria-label={i18n.t("unban")}
851 {!post_view.creator_banned_from_community && (
853 class="btn btn-link btn-animate text-muted py-0"
854 onClick={linkEvent(this, this.handleAddModToCommunity)}
857 ? i18n.t("remove_as_mod")
858 : i18n.t("appoint_as_mod")
862 ? i18n.t("remove_as_mod")
863 : i18n.t("appoint_as_mod")}
868 {/* Community creators and admins can transfer community to another mod */}
869 {(this.amCommunityCreator || this.canAdmin) &&
871 (!this.state.showConfirmTransferCommunity ? (
873 class="btn btn-link btn-animate text-muted py-0"
876 this.handleShowConfirmTransferCommunity
878 aria-label={i18n.t("transfer_community")}
880 {i18n.t("transfer_community")}
885 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
886 aria-label={i18n.t("are_you_sure")}
888 {i18n.t("are_you_sure")}
891 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
892 aria-label={i18n.t("yes")}
893 onClick={linkEvent(this, this.handleTransferCommunity)}
898 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
901 this.handleCancelShowConfirmTransferCommunity
903 aria-label={i18n.t("no")}
909 {/* Admins can ban from all, and appoint other admins */}
912 {!this.creatorIsAdmin &&
913 (!isBanned(post_view.creator) ? (
915 class="btn btn-link btn-animate text-muted py-0"
916 onClick={linkEvent(this, this.handleModBanShow)}
917 aria-label={i18n.t("ban_from_site")}
919 {i18n.t("ban_from_site")}
923 class="btn btn-link btn-animate text-muted py-0"
924 onClick={linkEvent(this, this.handleModBanSubmit)}
925 aria-label={i18n.t("unban_from_site")}
927 {i18n.t("unban_from_site")}
930 {!isBanned(post_view.creator) && post_view.creator.local && (
932 class="btn btn-link btn-animate text-muted py-0"
933 onClick={linkEvent(this, this.handleAddAdmin)}
936 ? i18n.t("remove_as_admin")
937 : i18n.t("appoint_as_admin")
941 ? i18n.t("remove_as_admin")
942 : i18n.t("appoint_as_admin")}
952 removeAndBanDialogs() {
953 let post = this.props.post_view;
956 {this.state.showRemoveDialog && (
959 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
961 <label class="sr-only" htmlFor="post-listing-remove-reason">
966 id="post-listing-remove-reason"
967 class="form-control mr-2"
968 placeholder={i18n.t("reason")}
969 value={this.state.removeReason}
970 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
974 class="btn btn-secondary"
975 aria-label={i18n.t("remove_post")}
977 {i18n.t("remove_post")}
981 {this.state.showBanDialog && (
982 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
983 <div class="form-group row col-12">
984 <label class="col-form-label" htmlFor="post-listing-ban-reason">
989 id="post-listing-ban-reason"
990 class="form-control mr-2"
991 placeholder={i18n.t("reason")}
992 value={this.state.banReason}
993 onInput={linkEvent(this, this.handleModBanReasonChange)}
995 <label class="col-form-label" htmlFor={`mod-ban-expires`}>
1000 id={`mod-ban-expires`}
1001 class="form-control mr-2"
1002 placeholder={i18n.t("number_of_days")}
1003 value={this.state.banExpireDays}
1004 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1006 <div class="form-group">
1007 <div class="form-check">
1009 class="form-check-input"
1010 id="mod-ban-remove-data"
1012 checked={this.state.removeData}
1013 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1016 class="form-check-label"
1017 htmlFor="mod-ban-remove-data"
1018 title={i18n.t("remove_content_more")}
1020 {i18n.t("remove_content")}
1025 {/* TODO hold off on expires until later */}
1026 {/* <div class="form-group row"> */}
1027 {/* <label class="col-form-label">Expires</label> */}
1028 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1030 <div class="form-group row">
1033 class="btn btn-secondary"
1034 aria-label={i18n.t("ban")}
1036 {i18n.t("ban")} {post.creator.name}
1041 {this.state.showReportDialog && (
1044 onSubmit={linkEvent(this, this.handleReportSubmit)}
1046 <label class="sr-only" htmlFor="post-report-reason">
1051 id="post-report-reason"
1052 class="form-control mr-2"
1053 placeholder={i18n.t("reason")}
1055 value={this.state.reportReason}
1056 onInput={linkEvent(this, this.handleReportReasonChange)}
1060 class="btn btn-secondary"
1061 aria-label={i18n.t("create_report")}
1063 {i18n.t("create_report")}
1072 let post = this.props.post_view.post;
1073 return post.thumbnail_url || isImage(post.url) ? (
1075 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1076 {this.postTitleLine()}
1079 {/* Post body prev or thumbnail */}
1080 {!this.state.imageExpanded && this.thumbnail()}
1084 this.postTitleLine()
1088 showMobilePreview() {
1089 let post = this.props.post_view.post;
1093 <div className="md-div mb-1 preview-lines">{post.body}</div>
1101 {/* The mobile view*/}
1102 <div class="d-block d-sm-none">
1104 <div class="col-12">
1105 {this.createdLine()}
1107 {/* If it has a thumbnail, do a right aligned thumbnail */}
1108 {this.mobileThumbnail()}
1110 {/* Show a preview of the post body */}
1111 {this.showMobilePreview()}
1113 {this.commentsLine(true)}
1114 {this.userActionsLine()}
1115 {this.duplicatesLine()}
1116 {this.removeAndBanDialogs()}
1121 {/* The larger view*/}
1122 <div class="d-none d-sm-block">
1124 {!this.props.viewOnly && this.voteBar()}
1125 <div class="col-sm-2 pr-0">
1126 <div class="">{this.thumbnail()}</div>
1128 <div class="col-12 col-sm-9">
1130 <div className="col-12">
1131 {this.postTitleLine()}
1132 {this.createdLine()}
1133 {this.commentsLine()}
1134 {this.duplicatesLine()}
1135 {this.userActionsLine()}
1136 {this.removeAndBanDialogs()}
1146 private get myPost(): boolean {
1148 UserService.Instance.myUserInfo &&
1149 this.props.post_view.creator.id ==
1150 UserService.Instance.myUserInfo.local_user_view.person.id
1154 get creatorIsMod(): boolean {
1156 this.props.moderators &&
1158 this.props.moderators.map(m => m.moderator.id),
1159 this.props.post_view.creator.id
1164 get creatorIsAdmin(): boolean {
1166 this.props.admins &&
1168 this.props.admins.map(a => a.person.id),
1169 this.props.post_view.creator.id
1175 * If the current user is allowed to mod this post.
1176 * The creator of this post is not allowed even if they are a mod.
1178 get canMod(): boolean {
1179 if (this.props.admins && this.props.moderators) {
1180 let adminsThenMods = this.props.admins
1181 .map(a => a.person.id)
1182 .concat(this.props.moderators.map(m => m.moderator.id));
1185 UserService.Instance.myUserInfo,
1187 this.props.post_view.creator.id
1195 * If the current user is allowed to mod this post.
1196 * The creator of this post is allowed if they are a mod.
1198 get canModOnSelf(): boolean {
1199 if (this.props.admins && this.props.moderators) {
1200 let adminsThenMods = this.props.admins
1201 .map(a => a.person.id)
1202 .concat(this.props.moderators.map(m => m.moderator.id));
1205 UserService.Instance.myUserInfo,
1207 this.props.post_view.creator.id,
1215 get canAdmin(): boolean {
1217 this.props.admins &&
1219 UserService.Instance.myUserInfo,
1220 this.props.admins.map(a => a.person.id),
1221 this.props.post_view.creator.id
1226 get amCommunityCreator(): boolean {
1228 this.props.moderators &&
1229 UserService.Instance.myUserInfo &&
1230 this.props.post_view.creator.id !=
1231 UserService.Instance.myUserInfo.local_user_view.person.id &&
1232 UserService.Instance.myUserInfo.local_user_view.person.id ==
1233 this.props.moderators[0].moderator.id
1237 get amSiteCreator(): boolean {
1239 this.props.admins &&
1240 UserService.Instance.myUserInfo &&
1241 this.props.post_view.creator.id !=
1242 UserService.Instance.myUserInfo.local_user_view.person.id &&
1243 UserService.Instance.myUserInfo.local_user_view.person.id ==
1244 this.props.admins[0].person.id
1248 handlePostLike(i: PostListing, event: any) {
1249 event.preventDefault();
1250 if (!UserService.Instance.myUserInfo) {
1251 this.context.router.history.push(`/login`);
1254 let new_vote = i.state.my_vote == 1 ? 0 : 1;
1256 if (i.state.my_vote == 1) {
1259 } else if (i.state.my_vote == -1) {
1260 i.state.downvotes--;
1268 i.state.my_vote = new_vote;
1270 let form: CreatePostLike = {
1271 post_id: i.props.post_view.post.id,
1272 score: i.state.my_vote,
1276 WebSocketService.Instance.send(wsClient.likePost(form));
1277 i.setState(i.state);
1281 handlePostDisLike(i: PostListing, event: any) {
1282 event.preventDefault();
1283 if (!UserService.Instance.myUserInfo) {
1284 this.context.router.history.push(`/login`);
1287 let new_vote = i.state.my_vote == -1 ? 0 : -1;
1289 if (i.state.my_vote == 1) {
1292 i.state.downvotes++;
1293 } else if (i.state.my_vote == -1) {
1294 i.state.downvotes--;
1297 i.state.downvotes++;
1301 i.state.my_vote = new_vote;
1303 let form: CreatePostLike = {
1304 post_id: i.props.post_view.post.id,
1305 score: i.state.my_vote,
1309 WebSocketService.Instance.send(wsClient.likePost(form));
1310 i.setState(i.state);
1314 handleEditClick(i: PostListing) {
1315 i.state.showEdit = true;
1316 i.setState(i.state);
1319 handleEditCancel() {
1320 this.state.showEdit = false;
1321 this.setState(this.state);
1324 // The actual editing is done in the recieve for post
1326 this.state.showEdit = false;
1327 this.setState(this.state);
1330 handleShowReportDialog(i: PostListing) {
1331 i.state.showReportDialog = !i.state.showReportDialog;
1332 i.setState(this.state);
1335 handleReportReasonChange(i: PostListing, event: any) {
1336 i.state.reportReason = event.target.value;
1337 i.setState(i.state);
1340 handleReportSubmit(i: PostListing, event: any) {
1341 event.preventDefault();
1342 let form: CreatePostReport = {
1343 post_id: i.props.post_view.post.id,
1344 reason: i.state.reportReason,
1347 WebSocketService.Instance.send(wsClient.createPostReport(form));
1349 i.state.showReportDialog = false;
1350 i.setState(i.state);
1353 handleBlockUserClick(i: PostListing) {
1354 let blockUserForm: BlockPerson = {
1355 person_id: i.props.post_view.creator.id,
1359 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1362 handleDeleteClick(i: PostListing) {
1363 let deleteForm: DeletePost = {
1364 post_id: i.props.post_view.post.id,
1365 deleted: !i.props.post_view.post.deleted,
1368 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1371 handleSavePostClick(i: PostListing) {
1373 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1374 let form: SavePost = {
1375 post_id: i.props.post_view.post.id,
1380 WebSocketService.Instance.send(wsClient.savePost(form));
1383 get crossPostParams(): string {
1384 let post = this.props.post_view.post;
1385 let params = `?title=${encodeURIComponent(post.name)}`;
1388 params += `&url=${encodeURIComponent(post.url)}`;
1391 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1396 crossPostBody(): string {
1397 let post = this.props.post_view.post;
1398 let body = `${i18n.t("cross_posted_from")} ${
1400 }\n\n${post.body.replace(/^/gm, "> ")}`;
1404 get showBody(): boolean {
1405 return this.props.showBody || this.state.showBody;
1408 handleModRemoveShow(i: PostListing) {
1409 i.state.showRemoveDialog = !i.state.showRemoveDialog;
1410 i.state.showBanDialog = false;
1411 i.setState(i.state);
1414 handleModRemoveReasonChange(i: PostListing, event: any) {
1415 i.state.removeReason = event.target.value;
1416 i.setState(i.state);
1419 handleModRemoveDataChange(i: PostListing, event: any) {
1420 i.state.removeData = event.target.checked;
1421 i.setState(i.state);
1424 handleModRemoveSubmit(i: PostListing, event: any) {
1425 event.preventDefault();
1426 let form: RemovePost = {
1427 post_id: i.props.post_view.post.id,
1428 removed: !i.props.post_view.post.removed,
1429 reason: i.state.removeReason,
1432 WebSocketService.Instance.send(wsClient.removePost(form));
1434 i.state.showRemoveDialog = false;
1435 i.setState(i.state);
1438 handleModLock(i: PostListing) {
1439 let form: LockPost = {
1440 post_id: i.props.post_view.post.id,
1441 locked: !i.props.post_view.post.locked,
1444 WebSocketService.Instance.send(wsClient.lockPost(form));
1447 handleModSticky(i: PostListing) {
1448 let form: StickyPost = {
1449 post_id: i.props.post_view.post.id,
1450 stickied: !i.props.post_view.post.stickied,
1453 WebSocketService.Instance.send(wsClient.stickyPost(form));
1456 handleModBanFromCommunityShow(i: PostListing) {
1457 i.state.showBanDialog = true;
1458 i.state.banType = BanType.Community;
1459 i.state.showRemoveDialog = false;
1460 i.setState(i.state);
1463 handleModBanShow(i: PostListing) {
1464 i.state.showBanDialog = true;
1465 i.state.banType = BanType.Site;
1466 i.state.showRemoveDialog = false;
1467 i.setState(i.state);
1470 handleModBanReasonChange(i: PostListing, event: any) {
1471 i.state.banReason = event.target.value;
1472 i.setState(i.state);
1475 handleModBanExpireDaysChange(i: PostListing, event: any) {
1476 i.state.banExpireDays = event.target.value;
1477 i.setState(i.state);
1480 handleModBanFromCommunitySubmit(i: PostListing) {
1481 i.state.banType = BanType.Community;
1482 i.setState(i.state);
1483 i.handleModBanBothSubmit(i);
1486 handleModBanSubmit(i: PostListing) {
1487 i.state.banType = BanType.Site;
1488 i.setState(i.state);
1489 i.handleModBanBothSubmit(i);
1492 handleModBanBothSubmit(i: PostListing, event?: any) {
1493 if (event) event.preventDefault();
1495 if (i.state.banType == BanType.Community) {
1496 // If its an unban, restore all their data
1497 let ban = !i.props.post_view.creator_banned_from_community;
1499 i.state.removeData = false;
1501 let form: BanFromCommunity = {
1502 person_id: i.props.post_view.creator.id,
1503 community_id: i.props.post_view.community.id,
1505 remove_data: i.state.removeData,
1506 reason: i.state.banReason,
1507 expires: futureDaysToUnixTime(i.state.banExpireDays),
1510 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1512 // If its an unban, restore all their data
1513 let ban = !i.props.post_view.creator.banned;
1515 i.state.removeData = false;
1517 let form: BanPerson = {
1518 person_id: i.props.post_view.creator.id,
1520 remove_data: i.state.removeData,
1521 reason: i.state.banReason,
1522 expires: futureDaysToUnixTime(i.state.banExpireDays),
1525 WebSocketService.Instance.send(wsClient.banPerson(form));
1528 i.state.showBanDialog = false;
1529 i.setState(i.state);
1532 handleAddModToCommunity(i: PostListing) {
1533 let form: AddModToCommunity = {
1534 person_id: i.props.post_view.creator.id,
1535 community_id: i.props.post_view.community.id,
1536 added: !i.creatorIsMod,
1539 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1540 i.setState(i.state);
1543 handleAddAdmin(i: PostListing) {
1544 let form: AddAdmin = {
1545 person_id: i.props.post_view.creator.id,
1546 added: !i.creatorIsAdmin,
1549 WebSocketService.Instance.send(wsClient.addAdmin(form));
1550 i.setState(i.state);
1553 handleShowConfirmTransferCommunity(i: PostListing) {
1554 i.state.showConfirmTransferCommunity = true;
1555 i.setState(i.state);
1558 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1559 i.state.showConfirmTransferCommunity = false;
1560 i.setState(i.state);
1563 handleTransferCommunity(i: PostListing) {
1564 let form: TransferCommunity = {
1565 community_id: i.props.post_view.community.id,
1566 person_id: i.props.post_view.creator.id,
1569 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1570 i.state.showConfirmTransferCommunity = false;
1571 i.setState(i.state);
1574 handleShowConfirmTransferSite(i: PostListing) {
1575 i.state.showConfirmTransferSite = true;
1576 i.setState(i.state);
1579 handleCancelShowConfirmTransferSite(i: PostListing) {
1580 i.state.showConfirmTransferSite = false;
1581 i.setState(i.state);
1584 handleImageExpandClick(i: PostListing, event: any) {
1585 event.preventDefault();
1586 i.state.imageExpanded = !i.state.imageExpanded;
1587 i.setState(i.state);
1591 handleViewSource(i: PostListing) {
1592 i.state.viewSource = !i.state.viewSource;
1593 i.setState(i.state);
1596 handleShowAdvanced(i: PostListing) {
1597 i.state.showAdvanced = !i.state.showAdvanced;
1598 i.setState(i.state);
1602 handleShowMoreMobile(i: PostListing) {
1603 i.state.showMoreMobile = !i.state.showMoreMobile;
1604 i.state.showAdvanced = !i.state.showAdvanced;
1605 i.setState(i.state);
1609 handleShowBody(i: PostListing) {
1610 i.state.showBody = !i.state.showBody;
1611 i.setState(i.state);
1615 get pointsTippy(): string {
1616 let points = i18n.t("number_of_points", {
1617 count: this.state.score,
1618 formattedCount: this.state.score,
1621 let upvotes = i18n.t("number_of_upvotes", {
1622 count: this.state.upvotes,
1623 formattedCount: this.state.upvotes,
1626 let downvotes = i18n.t("number_of_downvotes", {
1627 count: this.state.downvotes,
1628 formattedCount: this.state.downvotes,
1631 return `${points} • ${upvotes} • ${downvotes}`;