1 import { Component, linkEvent } from "inferno";
2 import { Link } from "inferno-router";
9 CommunityModeratorView,
21 } from "lemmy-js-client";
22 import { externalHost } from "../../env";
23 import { i18n } from "../../i18next";
24 import { BanType } from "../../interfaces";
25 import { UserService, WebSocketService } from "../../services";
43 import { Icon } from "../common/icon";
44 import { MomentTime } from "../common/moment-time";
45 import { PictrsImage } from "../common/pictrs-image";
46 import { CommunityLink } from "../community/community-link";
47 import { PersonListing } from "../person/person-listing";
48 import { MetadataCard } from "./metadata-card";
49 import { PostForm } from "./post-form";
51 interface PostListingState {
53 showRemoveDialog: boolean;
55 showBanDialog: boolean;
58 banExpireDays: number;
60 showConfirmTransferSite: boolean;
61 showConfirmTransferCommunity: boolean;
62 imageExpanded: boolean;
64 showAdvanced: boolean;
65 showMoreMobile: boolean;
67 showReportDialog: boolean;
75 interface PostListingProps {
77 duplicates?: PostView[];
78 showCommunity?: boolean;
80 moderators?: CommunityModeratorView[];
81 admins?: PersonViewSafe[];
82 enableDownvotes: boolean;
86 export class PostListing extends Component<PostListingProps, PostListingState> {
87 private emptyState: PostListingState = {
89 showRemoveDialog: false,
95 banType: BanType.Community,
96 showConfirmTransferSite: false,
97 showConfirmTransferCommunity: false,
101 showMoreMobile: false,
103 showReportDialog: false,
105 my_vote: this.props.post_view.my_vote,
106 score: this.props.post_view.counts.score,
107 upvotes: this.props.post_view.counts.upvotes,
108 downvotes: this.props.post_view.counts.downvotes,
111 constructor(props: any, context: any) {
112 super(props, context);
114 this.state = this.emptyState;
115 this.handlePostLike = this.handlePostLike.bind(this);
116 this.handlePostDisLike = this.handlePostDisLike.bind(this);
117 this.handleEditPost = this.handleEditPost.bind(this);
118 this.handleEditCancel = this.handleEditCancel.bind(this);
121 componentWillReceiveProps(nextProps: PostListingProps) {
122 this.state.my_vote = nextProps.post_view.my_vote;
123 this.state.upvotes = nextProps.post_view.counts.upvotes;
124 this.state.downvotes = nextProps.post_view.counts.downvotes;
125 this.state.score = nextProps.post_view.counts.score;
126 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
127 this.state.imageExpanded = false;
129 this.setState(this.state);
135 {!this.state.showEdit ? (
143 post_view={this.props.post_view}
144 onEdit={this.handleEditPost}
145 onCancel={this.handleEditCancel}
146 enableNsfw={this.props.enableNsfw}
147 enableDownvotes={this.props.enableDownvotes}
156 let post = this.props.post_view.post;
160 {post.url && this.showBody && post.embed_title && (
161 <MetadataCard post={post} />
165 (this.state.viewSource ? (
166 <pre>{post.body}</pre>
170 dangerouslySetInnerHTML={mdToHtml(post.body)}
178 imgThumb(src: string) {
179 let post_view = this.props.post_view;
185 nsfw={post_view.post.nsfw || post_view.community.nsfw}
190 getImageSrc(): string {
191 let post = this.props.post_view.post;
192 if (isImage(post.url)) {
193 if (post.url.includes("pictrs")) {
195 } else if (post.thumbnail_url) {
196 return post.thumbnail_url;
200 } else if (post.thumbnail_url) {
201 return post.thumbnail_url;
208 let post = this.props.post_view.post;
210 if (isImage(post.url)) {
213 href={this.getImageSrc()}
214 class="float-right text-body d-inline-block position-relative mb-2"
215 data-tippy-content={i18n.t("expand_here")}
216 onClick={linkEvent(this, this.handleImageExpandClick)}
217 aria-label={i18n.t("expand_here")}
219 {this.imgThumb(this.getImageSrc())}
220 <Icon icon="image" classes="mini-overlay" />
223 } else if (post.thumbnail_url) {
226 class="float-right text-body d-inline-block position-relative mb-2"
231 {this.imgThumb(this.getImageSrc())}
232 <Icon icon="external-link" classes="mini-overlay" />
235 } else if (post.url) {
236 if (isVideo(post.url)) {
238 <div class="embed-responsive embed-responsive-16by9">
244 class="embed-responsive-item"
246 <source src={post.url} type="video/mp4" />
253 className="text-body"
258 <div class="thumbnail rounded bg-light d-flex justify-content-center">
259 <Icon icon="external-link" classes="d-flex align-items-center" />
267 className="text-body"
268 to={`/post/${post.id}`}
269 title={i18n.t("comments")}
271 <div class="thumbnail rounded bg-light d-flex justify-content-center">
272 <Icon icon="message-square" classes="d-flex align-items-center" />
280 let post_view = this.props.post_view;
282 <ul class="list-inline mb-1 text-muted small">
283 <li className="list-inline-item">
284 <PersonListing person={post_view.creator} />
287 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
290 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
292 {post_view.creator.bot_account && (
293 <span className="mx-1 badge badge-light">
294 {i18n.t("bot_account").toLowerCase()}
297 {(post_view.creator_banned_from_community ||
298 isBanned(post_view.creator)) && (
299 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
301 {post_view.creator_blocked && (
302 <span className="mx-1 badge badge-danger">{"blocked"}</span>
304 {this.props.showCommunity && (
306 <span class="mx-1"> {i18n.t("to")} </span>
307 <CommunityLink community={post_view.community} />
311 <li className="list-inline-item">•</li>
312 {post_view.post.url && !(hostname(post_view.post.url) == externalHost) && (
314 <li className="list-inline-item">
316 className="text-muted font-italic"
317 href={post_view.post.url}
318 title={post_view.post.url}
321 {hostname(post_view.post.url)}
324 <li className="list-inline-item">•</li>
327 <li className="list-inline-item">
329 <MomentTime data={post_view.post} />
332 {post_view.post.body && (
334 <li className="list-inline-item">•</li>
335 <li className="list-inline-item">
337 className="text-muted btn btn-sm btn-link p-0"
338 data-tippy-content={md.render(
339 previewLines(post_view.post.body)
341 data-tippy-allowHtml={true}
342 onClick={linkEvent(this, this.handleShowBody)}
344 <Icon icon="book-open" classes="icon-inline mr-1" />
355 <div className={`vote-bar col-1 pr-0 small text-center`}>
357 className={`btn-animate btn btn-link p-0 ${
358 this.state.my_vote == 1 ? "text-info" : "text-muted"
360 onClick={linkEvent(this, this.handlePostLike)}
361 data-tippy-content={i18n.t("upvote")}
362 aria-label={i18n.t("upvote")}
364 <Icon icon="arrow-up1" classes="upvote" />
368 class={`unselectable pointer font-weight-bold text-muted px-1`}
369 data-tippy-content={this.pointsTippy}
371 {numToSI(this.state.score)}
374 <div class="p-1"></div>
376 {this.props.enableDownvotes && (
378 className={`btn-animate btn btn-link p-0 ${
379 this.state.my_vote == -1 ? "text-danger" : "text-muted"
381 onClick={linkEvent(this, this.handlePostDisLike)}
382 data-tippy-content={i18n.t("downvote")}
383 aria-label={i18n.t("downvote")}
385 <Icon icon="arrow-down1" classes="downvote" />
393 let post = this.props.post_view.post;
395 <div className="post-title overflow-hidden">
397 {this.showBody && post.url ? (
399 className={!post.stickied ? "text-body" : "text-primary"}
408 className={!post.stickied ? "text-body" : "text-primary"}
409 to={`/post/${post.id}`}
410 title={i18n.t("comments")}
415 {(isImage(post.url) || post.thumbnail_url) &&
416 (!this.state.imageExpanded ? (
418 class="btn btn-link text-monospace text-muted small d-inline-block ml-2"
419 data-tippy-content={i18n.t("expand_here")}
420 onClick={linkEvent(this, this.handleImageExpandClick)}
422 <Icon icon="plus-square" classes="icon-inline" />
427 class="btn btn-link text-monospace text-muted small d-inline-block ml-2"
428 onClick={linkEvent(this, this.handleImageExpandClick)}
430 <Icon icon="minus-square" classes="icon-inline" />
434 href={this.getImageSrc()}
435 class="btn btn-link d-inline-block"
436 onClick={linkEvent(this, this.handleImageExpandClick)}
438 <PictrsImage src={this.getImageSrc()} />
444 <small className="ml-2 text-muted font-italic">
450 className="unselectable pointer ml-2 text-muted font-italic"
451 data-tippy-content={i18n.t("deleted")}
453 <Icon icon="trash" classes="icon-inline text-danger" />
458 className="unselectable pointer ml-2 text-muted font-italic"
459 data-tippy-content={i18n.t("locked")}
461 <Icon icon="lock" classes="icon-inline text-danger" />
466 className="unselectable pointer ml-2 text-muted font-italic"
467 data-tippy-content={i18n.t("stickied")}
469 <Icon icon="pin" classes="icon-inline text-primary" />
473 <small className="ml-2 text-muted font-italic">
482 commentsLine(mobile = false) {
483 let post_view = this.props.post_view;
485 <div class="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold mb-1">
486 <button class="btn btn-link text-muted p-0">
488 className="text-muted small"
489 title={i18n.t("number_of_comments", {
490 count: post_view.counts.comments,
491 formattedCount: post_view.counts.comments,
493 to={`/post/${post_view.post.id}?scrollToComments=true`}
495 <Icon icon="message-square" classes="icon-inline mr-1" />
496 {i18n.t("number_of_comments", {
497 count: post_view.counts.comments,
498 formattedCount: numToSI(post_view.counts.comments),
504 {this.state.downvotes !== 0 && showScores() && (
506 class="btn text-muted py-0 pr-0"
507 data-tippy-content={this.pointsTippy}
508 aria-label={i18n.t("downvote")}
511 <Icon icon="arrow-down1" classes="icon-inline mr-1" />
512 <span>{numToSI(this.state.downvotes)}</span>
518 class="btn btn-link btn-animate text-muted py-0"
519 onClick={linkEvent(this, this.handleSavePostClick)}
521 post_view.saved ? i18n.t("unsave") : i18n.t("save")
523 aria-label={post_view.saved ? i18n.t("unsave") : i18n.t("save")}
528 classes={`icon-inline ${post_view.saved && "text-warning"}`}
535 {/* This is an expanding spacer for mobile */}
536 <div className="flex-grow-1"></div>
542 className={`btn-animate btn py-0 px-1 ${
543 this.state.my_vote == 1 ? "text-info" : "text-muted"
545 data-tippy-content={this.pointsTippy}
546 onClick={linkEvent(this, this.handlePostLike)}
547 aria-label={i18n.t("upvote")}
549 <Icon icon="arrow-up1" classes="icon-inline small mr-2" />
550 {numToSI(this.state.upvotes)}
554 className={`btn-animate btn py-0 px-1 ${
555 this.state.my_vote == 1 ? "text-info" : "text-muted"
557 onClick={linkEvent(this, this.handlePostLike)}
558 aria-label={i18n.t("upvote")}
560 <Icon icon="arrow-up1" classes="icon-inline small" />
563 {this.props.enableDownvotes &&
566 className={`ml-2 btn-animate btn py-0 pl-1 ${
567 this.state.my_vote == -1 ? "text-danger" : "text-muted"
569 onClick={linkEvent(this, this.handlePostDisLike)}
570 data-tippy-content={this.pointsTippy}
571 aria-label={i18n.t("downvote")}
573 <Icon icon="arrow-down1" classes="icon-inline small mr-2" />
574 {this.state.downvotes !== 0 && (
575 <span>{numToSI(this.state.downvotes)}</span>
580 className={`ml-2 btn-animate btn py-0 pl-1 ${
581 this.state.my_vote == -1 ? "text-danger" : "text-muted"
583 onClick={linkEvent(this, this.handlePostDisLike)}
584 aria-label={i18n.t("downvote")}
586 <Icon icon="arrow-down1" classes="icon-inline small" />
591 class="btn btn-link btn-animate text-muted py-0 pl-1 pr-0"
592 onClick={linkEvent(this, this.handleSavePostClick)}
593 aria-label={post_view.saved ? i18n.t("unsave") : i18n.t("save")}
595 post_view.saved ? i18n.t("unsave") : i18n.t("save")
600 classes={`icon-inline ${post_view.saved && "text-warning"}`}
604 {!this.state.showMoreMobile && this.showBody && (
606 class="btn btn-link btn-animate text-muted py-0"
607 onClick={linkEvent(this, this.handleShowMoreMobile)}
608 aria-label={i18n.t("more")}
609 data-tippy-content={i18n.t("more")}
611 <Icon icon="more-vertical" classes="icon-inline" />
614 {this.state.showMoreMobile && this.postActions(mobile)}
622 let dupes = this.props.duplicates;
625 dupes.length > 0 && (
626 <ul class="list-inline mb-1 small text-muted">
628 <li className="list-inline-item mr-2">
629 {i18n.t("cross_posted_to")}
632 <li className="list-inline-item mr-2">
633 <Link to={`/post/${pv.post.id}`}>
636 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
646 postActions(mobile = false) {
647 let post_view = this.props.post_view;
649 UserService.Instance.myUserInfo && (
655 class="btn btn-link btn-animate text-muted py-0 pl-0"
656 onClick={linkEvent(this, this.handleSavePostClick)}
658 post_view.saved ? i18n.t("unsave") : i18n.t("save")
661 post_view.saved ? i18n.t("unsave") : i18n.t("save")
666 classes={`icon-inline ${post_view.saved && "text-warning"}`}
671 className="btn btn-link btn-animate text-muted py-0"
672 to={`/create_post${this.crossPostParams}`}
673 title={i18n.t("cross_post")}
675 <Icon icon="copy" classes="icon-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" classes="icon-inline" />
688 class="btn btn-link btn-animate text-muted py-0"
689 onClick={linkEvent(this, this.handleBlockUserClick)}
690 data-tippy-content={i18n.t("block_user")}
691 aria-label={i18n.t("block_user")}
693 <Icon icon="slash" classes="icon-inline" />
699 {this.myPost && this.showBody && (
702 class="btn btn-link btn-animate text-muted py-0"
703 onClick={linkEvent(this, this.handleEditClick)}
704 data-tippy-content={i18n.t("edit")}
705 aria-label={i18n.t("edit")}
707 <Icon icon="edit" classes="icon-inline" />
710 class="btn btn-link btn-animate text-muted py-0"
711 onClick={linkEvent(this, this.handleDeleteClick)}
713 !post_view.post.deleted ? i18n.t("delete") : i18n.t("restore")
716 !post_view.post.deleted ? i18n.t("delete") : i18n.t("restore")
721 classes={`icon-inline ${
722 post_view.post.deleted && "text-danger"
729 {!this.state.showAdvanced && this.showBody ? (
731 class="btn btn-link btn-animate text-muted py-0"
732 onClick={linkEvent(this, this.handleShowAdvanced)}
733 data-tippy-content={i18n.t("more")}
734 aria-label={i18n.t("more")}
736 <Icon icon="more-vertical" classes="icon-inline" />
740 {this.showBody && post_view.post.body && (
742 class="btn btn-link btn-animate text-muted py-0"
743 onClick={linkEvent(this, this.handleViewSource)}
744 data-tippy-content={i18n.t("view_source")}
745 aria-label={i18n.t("view_source")}
749 classes={`icon-inline ${
750 this.state.viewSource && "text-success"
755 {this.canModOnSelf && (
758 class="btn btn-link btn-animate text-muted py-0"
759 onClick={linkEvent(this, this.handleModLock)}
761 post_view.post.locked ? i18n.t("unlock") : i18n.t("lock")
764 post_view.post.locked ? i18n.t("unlock") : i18n.t("lock")
769 classes={`icon-inline ${
770 post_view.post.locked && "text-danger"
775 class="btn btn-link btn-animate text-muted py-0"
776 onClick={linkEvent(this, this.handleModSticky)}
778 post_view.post.stickied
783 post_view.post.stickied
790 classes={`icon-inline ${
791 post_view.post.stickied && "text-success"
797 {/* Mods can ban from community, and appoint as mods to community */}
798 {(this.canMod || this.canAdmin) &&
799 (!post_view.post.removed ? (
801 class="btn btn-link btn-animate text-muted py-0"
802 onClick={linkEvent(this, this.handleModRemoveShow)}
803 aria-label={i18n.t("remove")}
809 class="btn btn-link btn-animate text-muted py-0"
810 onClick={linkEvent(this, this.handleModRemoveSubmit)}
811 aria-label={i18n.t("restore")}
819 (!post_view.creator_banned_from_community ? (
821 class="btn btn-link btn-animate text-muted py-0"
824 this.handleModBanFromCommunityShow
826 aria-label={i18n.t("ban")}
832 class="btn btn-link btn-animate text-muted py-0"
835 this.handleModBanFromCommunitySubmit
837 aria-label={i18n.t("unban")}
842 {!post_view.creator_banned_from_community && (
844 class="btn btn-link btn-animate text-muted py-0"
845 onClick={linkEvent(this, this.handleAddModToCommunity)}
848 ? i18n.t("remove_as_mod")
849 : i18n.t("appoint_as_mod")
853 ? i18n.t("remove_as_mod")
854 : i18n.t("appoint_as_mod")}
859 {/* Community creators and admins can transfer community to another mod */}
860 {(this.amCommunityCreator || this.canAdmin) &&
862 (!this.state.showConfirmTransferCommunity ? (
864 class="btn btn-link btn-animate text-muted py-0"
867 this.handleShowConfirmTransferCommunity
869 aria-label={i18n.t("transfer_community")}
871 {i18n.t("transfer_community")}
876 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
877 aria-label={i18n.t("are_you_sure")}
879 {i18n.t("are_you_sure")}
882 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
883 aria-label={i18n.t("yes")}
884 onClick={linkEvent(this, this.handleTransferCommunity)}
889 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
892 this.handleCancelShowConfirmTransferCommunity
894 aria-label={i18n.t("no")}
900 {/* Admins can ban from all, and appoint other admins */}
904 (!isBanned(post_view.creator) ? (
906 class="btn btn-link btn-animate text-muted py-0"
907 onClick={linkEvent(this, this.handleModBanShow)}
908 aria-label={i18n.t("ban_from_site")}
910 {i18n.t("ban_from_site")}
914 class="btn btn-link btn-animate text-muted py-0"
915 onClick={linkEvent(this, this.handleModBanSubmit)}
916 aria-label={i18n.t("unban_from_site")}
918 {i18n.t("unban_from_site")}
921 {!isBanned(post_view.creator) && post_view.creator.local && (
923 class="btn btn-link btn-animate text-muted py-0"
924 onClick={linkEvent(this, this.handleAddAdmin)}
927 ? i18n.t("remove_as_admin")
928 : i18n.t("appoint_as_admin")
932 ? i18n.t("remove_as_admin")
933 : i18n.t("appoint_as_admin")}
938 {/* Site Creator can transfer to another admin */}
939 {this.amSiteCreator &&
941 (!this.state.showConfirmTransferSite ? (
943 class="btn btn-link btn-animate text-muted py-0"
946 this.handleShowConfirmTransferSite
948 aria-label={i18n.t("transfer_site")}
950 {i18n.t("transfer_site")}
955 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
956 aria-label={i18n.t("are_you_sure")}
958 {i18n.t("are_you_sure")}
961 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
962 onClick={linkEvent(this, this.handleTransferSite)}
963 aria-label={i18n.t("yes")}
968 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
971 this.handleCancelShowConfirmTransferSite
973 aria-label={i18n.t("no")}
986 removeAndBanDialogs() {
987 let post = this.props.post_view;
990 {this.state.showRemoveDialog && (
993 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
995 <label class="sr-only" htmlFor="post-listing-remove-reason">
1000 id="post-listing-remove-reason"
1001 class="form-control mr-2"
1002 placeholder={i18n.t("reason")}
1003 value={this.state.removeReason}
1004 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1008 class="btn btn-secondary"
1009 aria-label={i18n.t("remove_post")}
1011 {i18n.t("remove_post")}
1015 {this.state.showBanDialog && (
1016 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1017 <div class="form-group row col-12">
1018 <label class="col-form-label" htmlFor="post-listing-ban-reason">
1023 id="post-listing-ban-reason"
1024 class="form-control mr-2"
1025 placeholder={i18n.t("reason")}
1026 value={this.state.banReason}
1027 onInput={linkEvent(this, this.handleModBanReasonChange)}
1029 <label class="col-form-label" htmlFor={`mod-ban-expires`}>
1034 id={`mod-ban-expires`}
1035 class="form-control mr-2"
1036 placeholder={i18n.t("number_of_days")}
1037 value={this.state.banExpireDays}
1038 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1040 <div class="form-group">
1041 <div class="form-check">
1043 class="form-check-input"
1044 id="mod-ban-remove-data"
1046 checked={this.state.removeData}
1047 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1050 class="form-check-label"
1051 htmlFor="mod-ban-remove-data"
1052 title={i18n.t("remove_content_more")}
1054 {i18n.t("remove_content")}
1059 {/* TODO hold off on expires until later */}
1060 {/* <div class="form-group row"> */}
1061 {/* <label class="col-form-label">Expires</label> */}
1062 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1064 <div class="form-group row">
1067 class="btn btn-secondary"
1068 aria-label={i18n.t("ban")}
1070 {i18n.t("ban")} {post.creator.name}
1075 {this.state.showReportDialog && (
1078 onSubmit={linkEvent(this, this.handleReportSubmit)}
1080 <label class="sr-only" htmlFor="post-report-reason">
1085 id="post-report-reason"
1086 class="form-control mr-2"
1087 placeholder={i18n.t("reason")}
1089 value={this.state.reportReason}
1090 onInput={linkEvent(this, this.handleReportReasonChange)}
1094 class="btn btn-secondary"
1095 aria-label={i18n.t("create_report")}
1097 {i18n.t("create_report")}
1106 let post = this.props.post_view.post;
1107 return post.thumbnail_url || isImage(post.url) ? (
1109 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1110 {this.postTitleLine()}
1113 {/* Post body prev or thumbnail */}
1114 {!this.state.imageExpanded && this.thumbnail()}
1118 this.postTitleLine()
1122 showMobilePreview() {
1123 let post = this.props.post_view.post;
1128 className="md-div mb-1"
1129 dangerouslySetInnerHTML={{
1130 __html: md.render(previewLines(post.body)),
1140 {/* The mobile view*/}
1141 <div class="d-block d-sm-none">
1143 <div class="col-12">
1144 {this.createdLine()}
1146 {/* If it has a thumbnail, do a right aligned thumbnail */}
1147 {this.mobileThumbnail()}
1149 {/* Show a preview of the post body */}
1150 {this.showMobilePreview()}
1152 {this.commentsLine(true)}
1153 {this.duplicatesLine()}
1154 {this.removeAndBanDialogs()}
1159 {/* The larger view*/}
1160 <div class="d-none d-sm-block">
1163 {!this.state.imageExpanded && (
1164 <div class="col-sm-2 pr-0">
1165 <div class="">{this.thumbnail()}</div>
1170 this.state.imageExpanded ? "col-12" : "col-12 col-sm-9"
1174 <div className="col-12">
1175 {this.postTitleLine()}
1176 {this.createdLine()}
1177 {this.commentsLine()}
1178 {this.duplicatesLine()}
1179 {this.postActions()}
1180 {this.removeAndBanDialogs()}
1190 private get myPost(): boolean {
1192 UserService.Instance.myUserInfo &&
1193 this.props.post_view.creator.id ==
1194 UserService.Instance.myUserInfo.local_user_view.person.id
1198 get isMod(): boolean {
1200 this.props.moderators &&
1202 this.props.moderators.map(m => m.moderator.id),
1203 this.props.post_view.creator.id
1208 get isAdmin(): boolean {
1210 this.props.admins &&
1212 this.props.admins.map(a => a.person.id),
1213 this.props.post_view.creator.id
1218 get canMod(): boolean {
1219 if (this.props.admins && this.props.moderators) {
1220 let adminsThenMods = this.props.admins
1221 .map(a => a.person.id)
1222 .concat(this.props.moderators.map(m => m.moderator.id));
1225 UserService.Instance.myUserInfo,
1227 this.props.post_view.creator.id
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,
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,
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);
1636 handleViewSource(i: PostListing) {
1637 i.state.viewSource = !i.state.viewSource;
1638 i.setState(i.state);
1641 handleShowAdvanced(i: PostListing) {
1642 i.state.showAdvanced = !i.state.showAdvanced;
1643 i.setState(i.state);
1647 handleShowMoreMobile(i: PostListing) {
1648 i.state.showMoreMobile = !i.state.showMoreMobile;
1649 i.state.showAdvanced = !i.state.showAdvanced;
1650 i.setState(i.state);
1654 handleShowBody(i: PostListing) {
1655 i.state.showBody = !i.state.showBody;
1656 i.setState(i.state);
1660 get pointsTippy(): string {
1661 let points = i18n.t("number_of_points", {
1662 count: this.state.score,
1663 formattedCount: this.state.score,
1666 let upvotes = i18n.t("number_of_upvotes", {
1667 count: this.state.upvotes,
1668 formattedCount: this.state.upvotes,
1671 let downvotes = i18n.t("number_of_downvotes", {
1672 count: this.state.downvotes,
1673 formattedCount: this.state.downvotes,
1676 return `${points} • ${upvotes} • ${downvotes}`;