1 import { None, Option, Some } from "@sniptt/monads";
2 import classNames from "classnames";
3 import { Component, linkEvent } from "inferno";
4 import { Link } from "inferno-router";
11 CommunityModeratorView,
25 } from "lemmy-js-client";
26 import { externalHost } from "../../env";
27 import { i18n } from "../../i18next";
28 import { BanType, PurgeType } from "../../interfaces";
29 import { UserService, WebSocketService } from "../../services";
50 import { Icon, PurgeWarning, Spinner } from "../common/icon";
51 import { MomentTime } from "../common/moment-time";
52 import { PictrsImage } from "../common/pictrs-image";
53 import { CommunityLink } from "../community/community-link";
54 import { PersonListing } from "../person/person-listing";
55 import { MetadataCard } from "./metadata-card";
56 import { PostForm } from "./post-form";
58 interface PostListingState {
60 showRemoveDialog: boolean;
61 showPurgeDialog: boolean;
62 purgeReason: Option<string>;
64 purgeLoading: boolean;
65 removeReason: Option<string>;
66 showBanDialog: boolean;
67 banReason: Option<string>;
68 banExpireDays: Option<number>;
71 showConfirmTransferSite: boolean;
72 showConfirmTransferCommunity: boolean;
73 imageExpanded: boolean;
75 showAdvanced: boolean;
76 showMoreMobile: boolean;
78 showReportDialog: boolean;
79 reportReason: Option<string>;
80 my_vote: Option<number>;
86 interface PostListingProps {
88 duplicates: Option<PostView[]>;
89 moderators: Option<CommunityModeratorView[]>;
90 admins: Option<PersonViewSafe[]>;
91 showCommunity?: boolean;
93 enableDownvotes?: boolean;
98 export class PostListing extends Component<PostListingProps, PostListingState> {
99 private emptyState: PostListingState = {
101 showRemoveDialog: false,
102 showPurgeDialog: false,
104 purgeType: PurgeType.Person,
107 showBanDialog: false,
110 banType: BanType.Community,
112 showConfirmTransferSite: false,
113 showConfirmTransferCommunity: false,
114 imageExpanded: false,
117 showMoreMobile: false,
119 showReportDialog: false,
121 my_vote: this.props.post_view.my_vote,
122 score: this.props.post_view.counts.score,
123 upvotes: this.props.post_view.counts.upvotes,
124 downvotes: this.props.post_view.counts.downvotes,
127 constructor(props: any, context: any) {
128 super(props, context);
130 this.state = this.emptyState;
131 this.handlePostLike = this.handlePostLike.bind(this);
132 this.handlePostDisLike = this.handlePostDisLike.bind(this);
133 this.handleEditPost = this.handleEditPost.bind(this);
134 this.handleEditCancel = this.handleEditCancel.bind(this);
137 componentWillReceiveProps(nextProps: PostListingProps) {
139 my_vote: nextProps.post_view.my_vote,
140 upvotes: nextProps.post_view.counts.upvotes,
141 downvotes: nextProps.post_view.counts.downvotes,
142 score: nextProps.post_view.counts.score,
144 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
145 this.setState({ imageExpanded: false });
150 let post = this.props.post_view.post;
152 <div className="post-listing">
153 {!this.state.showEdit ? (
156 {this.state.imageExpanded && this.img}
157 {post.url.isSome() &&
159 post.embed_title.isSome() && <MetadataCard post={post} />}
160 {this.showBody && this.body()}
163 <div className="col-12">
165 post_view={Some(this.props.post_view)}
168 onEdit={this.handleEditPost}
169 onCancel={this.handleEditCancel}
170 enableNsfw={this.props.enableNsfw}
171 enableDownvotes={this.props.enableDownvotes}
180 return this.props.post_view.post.body.match({
182 <div className="col-12 card my-2 p-2">
183 {this.state.viewSource ? (
186 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
195 return this.imageSrc.match({
198 <div className="offset-sm-3 my-2 d-none d-sm-block">
199 <a href={src} className="d-inline-block">
200 <PictrsImage src={src} />
203 <div className="my-2 d-block d-sm-none">
205 className="d-inline-block"
206 onClick={linkEvent(this, this.handleImageExpandClick)}
208 <PictrsImage src={src} />
217 imgThumb(src: string) {
218 let post_view = this.props.post_view;
224 nsfw={post_view.post.nsfw || post_view.community.nsfw}
229 get imageSrc(): Option<string> {
230 let post = this.props.post_view.post;
232 let thumbnail = post.thumbnail_url;
234 if (url.isSome() && isImage(url.unwrap())) {
235 if (url.unwrap().includes("pictrs")) {
237 } else if (thumbnail.isSome()) {
242 } else if (thumbnail.isSome()) {
250 let post = this.props.post_view.post;
252 let thumbnail = post.thumbnail_url;
254 if (url.isSome() && isImage(url.unwrap())) {
257 href={this.imageSrc.unwrap()}
258 className="text-body d-inline-block position-relative mb-2"
259 data-tippy-content={i18n.t("expand_here")}
260 onClick={linkEvent(this, this.handleImageExpandClick)}
261 aria-label={i18n.t("expand_here")}
263 {this.imgThumb(this.imageSrc.unwrap())}
264 <Icon icon="image" classes="mini-overlay" />
267 } else if (url.isSome() && thumbnail.isSome()) {
270 className="text-body d-inline-block position-relative mb-2"
275 {this.imgThumb(this.imageSrc.unwrap())}
276 <Icon icon="external-link" classes="mini-overlay" />
279 } else if (url.isSome()) {
280 if (isVideo(url.unwrap())) {
282 <div className="embed-responsive embed-responsive-16by9">
288 className="embed-responsive-item"
290 <source src={url.unwrap()} type="video/mp4" />
297 className="text-body"
302 <div className="thumbnail rounded bg-light d-flex justify-content-center">
303 <Icon icon="external-link" classes="d-flex align-items-center" />
311 className="text-body"
312 to={`/post/${post.id}`}
313 title={i18n.t("comments")}
315 <div className="thumbnail rounded bg-light d-flex justify-content-center">
316 <Icon icon="message-square" classes="d-flex align-items-center" />
324 let post_view = this.props.post_view;
326 <ul className="list-inline mb-1 text-muted small">
327 <li className="list-inline-item">
328 <PersonListing person={post_view.creator} />
330 {this.creatorIsMod_ && (
331 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
333 {this.creatorIsAdmin_ && (
334 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
336 {post_view.creator.bot_account && (
337 <span className="mx-1 badge badge-light">
338 {i18n.t("bot_account").toLowerCase()}
341 {(post_view.creator_banned_from_community ||
342 isBanned(post_view.creator)) && (
343 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
345 {post_view.creator_blocked && (
346 <span className="mx-1 badge badge-danger">{"blocked"}</span>
348 {this.props.showCommunity && (
350 <span className="mx-1"> {i18n.t("to")} </span>
351 <CommunityLink community={post_view.community} />
355 <li className="list-inline-item">•</li>
356 {post_view.post.url.match({
358 !(hostname(url) == externalHost) && (
360 <li className="list-inline-item">
362 className="text-muted font-italic"
370 <li className="list-inline-item">•</li>
375 <li className="list-inline-item">
378 published={post_view.post.published}
379 updated={post_view.post.updated}
383 {post_view.post.body.match({
386 <li className="list-inline-item">•</li>
387 <li className="list-inline-item">
389 className="text-muted btn btn-sm btn-link p-0"
390 data-tippy-content={md.render(body)}
391 data-tippy-allowHtml={true}
392 onClick={linkEvent(this, this.handleShowBody)}
394 <Icon icon="book-open" classes="icon-inline mr-1" />
407 <div className={`vote-bar col-1 pr-0 small text-center`}>
409 className={`btn-animate btn btn-link p-0 ${
410 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
412 onClick={this.handlePostLike}
413 data-tippy-content={i18n.t("upvote")}
414 aria-label={i18n.t("upvote")}
416 <Icon icon="arrow-up1" classes="upvote" />
420 className={`unselectable pointer font-weight-bold text-muted px-1`}
421 data-tippy-content={this.pointsTippy}
423 {numToSI(this.state.score)}
426 <div className="p-1"></div>
428 {this.props.enableDownvotes && (
430 className={`btn-animate btn btn-link p-0 ${
431 this.state.my_vote.unwrapOr(0) == -1
435 onClick={this.handlePostDisLike}
436 data-tippy-content={i18n.t("downvote")}
437 aria-label={i18n.t("downvote")}
439 <Icon icon="arrow-down1" classes="downvote" />
447 let post = this.props.post_view.post;
449 <div className="post-title overflow-hidden">
454 className={!post.stickied ? "text-body" : "text-primary"}
464 className={!post.stickied ? "text-body" : "text-primary"}
465 to={`/post/${post.id}`}
466 title={i18n.t("comments")}
472 {post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
474 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
475 data-tippy-content={i18n.t("expand_here")}
476 onClick={linkEvent(this, this.handleImageExpandClick)}
480 !this.state.imageExpanded ? "plus-square" : "minus-square"
482 classes="icon-inline"
487 <small className="ml-2 text-muted font-italic">
493 className="unselectable pointer ml-2 text-muted font-italic"
494 data-tippy-content={i18n.t("deleted")}
496 <Icon icon="trash" classes="icon-inline text-danger" />
501 className="unselectable pointer ml-2 text-muted font-italic"
502 data-tippy-content={i18n.t("locked")}
504 <Icon icon="lock" classes="icon-inline text-danger" />
509 className="unselectable pointer ml-2 text-muted font-italic"
510 data-tippy-content={i18n.t("stickied")}
512 <Icon icon="pin" classes="icon-inline text-primary" />
516 <small className="ml-2 text-muted font-italic">
526 return this.props.duplicates.match({
528 dupes.length > 0 && (
529 <ul className="list-inline mb-1 small text-muted">
531 <li className="list-inline-item mr-2">
532 {i18n.t("cross_posted_to")}
535 <li key={pv.post.id} className="list-inline-item mr-2">
536 <Link to={`/post/${pv.post.id}`}>
539 : `${pv.community.name}@${hostname(
540 pv.community.actor_id
552 commentsLine(mobile = false) {
553 let post = this.props.post_view.post;
555 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
556 {this.commentsButton}
559 className="btn btn-link btn-animate text-muted py-0"
560 title={i18n.t("link")}
563 <Icon icon="fedilink" inline />
566 {mobile && !this.props.viewOnly && this.mobileVotes}
567 {UserService.Instance.myUserInfo.isSome() &&
568 !this.props.viewOnly &&
569 this.postActions(mobile)}
574 postActions(mobile = false) {
575 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
576 // Possible enhancement: Make each button a component.
577 let post_view = this.props.post_view;
581 {this.crossPostButton}
582 {mobile && this.showMoreButton}
583 {(!mobile || this.state.showAdvanced) && (
591 {this.myPost && (this.showBody || this.state.showAdvanced) && (
599 {this.state.showAdvanced && (
602 post_view.post.body.isSome() &&
603 this.viewSourceButton}
604 {this.canModOnSelf_ && (
610 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
613 {!mobile && this.showMoreButton}
618 get commentsButton() {
619 let post_view = this.props.post_view;
621 <button className="btn btn-link text-muted py-0 pl-0">
623 className="text-muted"
624 title={i18n.t("number_of_comments", {
625 count: post_view.counts.comments,
626 formattedCount: post_view.counts.comments,
628 to={`/post/${post_view.post.id}?scrollToComments=true`}
630 <Icon icon="message-square" classes="mr-1" inline />
631 {i18n.t("number_of_comments", {
632 count: post_view.counts.comments,
633 formattedCount: numToSI(post_view.counts.comments),
642 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
647 className={`btn-animate btn py-0 px-1 ${
648 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
651 onClick={this.handlePostLike}
652 aria-label={i18n.t("upvote")}
654 <Icon icon="arrow-up1" classes="icon-inline small" />
656 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
659 {this.props.enableDownvotes && (
661 className={`ml-2 btn-animate btn py-0 px-1 ${
662 this.state.my_vote.unwrapOr(0) == -1
666 onClick={this.handlePostDisLike}
668 aria-label={i18n.t("downvote")}
670 <Icon icon="arrow-down1" classes="icon-inline small" />
673 className={classNames("ml-2", {
674 invisible: this.state.downvotes === 0,
677 {numToSI(this.state.downvotes)}
688 let saved = this.props.post_view.saved;
689 let label = saved ? i18n.t("unsave") : i18n.t("save");
692 className="btn btn-link btn-animate text-muted py-0"
693 onClick={linkEvent(this, this.handleSavePostClick)}
694 data-tippy-content={label}
699 classes={classNames({ "text-warning": saved })}
706 get crossPostButton() {
709 className="btn btn-link btn-animate text-muted py-0"
710 to={`/create_post${this.crossPostParams}`}
711 title={i18n.t("cross_post")}
713 <Icon icon="copy" inline />
721 className="btn btn-link btn-animate text-muted py-0"
722 onClick={linkEvent(this, this.handleShowReportDialog)}
723 data-tippy-content={i18n.t("show_report_dialog")}
724 aria-label={i18n.t("show_report_dialog")}
726 <Icon icon="flag" inline />
734 className="btn btn-link btn-animate text-muted py-0"
735 onClick={linkEvent(this, this.handleBlockUserClick)}
736 data-tippy-content={i18n.t("block_user")}
737 aria-label={i18n.t("block_user")}
739 <Icon icon="slash" inline />
747 className="btn btn-link btn-animate text-muted py-0"
748 onClick={linkEvent(this, this.handleEditClick)}
749 data-tippy-content={i18n.t("edit")}
750 aria-label={i18n.t("edit")}
752 <Icon icon="edit" inline />
758 let deleted = this.props.post_view.post.deleted;
759 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
762 className="btn btn-link btn-animate text-muted py-0"
763 onClick={linkEvent(this, this.handleDeleteClick)}
764 data-tippy-content={label}
769 classes={classNames({ "text-danger": deleted })}
776 get showMoreButton() {
779 className="btn btn-link btn-animate text-muted py-0"
780 onClick={linkEvent(this, this.handleShowAdvanced)}
781 data-tippy-content={i18n.t("more")}
782 aria-label={i18n.t("more")}
784 <Icon icon="more-vertical" inline />
789 get viewSourceButton() {
792 className="btn btn-link btn-animate text-muted py-0"
793 onClick={linkEvent(this, this.handleViewSource)}
794 data-tippy-content={i18n.t("view_source")}
795 aria-label={i18n.t("view_source")}
799 classes={classNames({ "text-success": this.state.viewSource })}
807 let locked = this.props.post_view.post.locked;
808 let label = locked ? i18n.t("unlock") : i18n.t("lock");
811 className="btn btn-link btn-animate text-muted py-0"
812 onClick={linkEvent(this, this.handleModLock)}
813 data-tippy-content={label}
818 classes={classNames({ "text-danger": locked })}
826 let stickied = this.props.post_view.post.stickied;
827 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
830 className="btn btn-link btn-animate text-muted py-0"
831 onClick={linkEvent(this, this.handleModSticky)}
832 data-tippy-content={label}
837 classes={classNames({ "text-success": stickied })}
844 get modRemoveButton() {
845 let removed = this.props.post_view.post.removed;
848 className="btn btn-link btn-animate text-muted py-0"
851 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
854 {/* TODO: Find an icon for this. */}
855 {!removed ? i18n.t("remove") : i18n.t("restore")}
861 * Mod/Admin actions to be taken against the author.
865 let post_view = this.props.post_view;
867 this.state.showAdvanced && (
871 {!this.creatorIsMod_ &&
872 (!post_view.creator_banned_from_community ? (
874 className="btn btn-link btn-animate text-muted py-0"
877 this.handleModBanFromCommunityShow
879 aria-label={i18n.t("ban")}
885 className="btn btn-link btn-animate text-muted py-0"
888 this.handleModBanFromCommunitySubmit
890 aria-label={i18n.t("unban")}
895 {!post_view.creator_banned_from_community && (
897 className="btn btn-link btn-animate text-muted py-0"
898 onClick={linkEvent(this, this.handleAddModToCommunity)}
901 ? i18n.t("remove_as_mod")
902 : i18n.t("appoint_as_mod")
906 ? i18n.t("remove_as_mod")
907 : i18n.t("appoint_as_mod")}
912 {/* Community creators and admins can transfer community to another mod */}
913 {(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
915 this.creatorIsMod_ &&
916 (!this.state.showConfirmTransferCommunity ? (
918 className="btn btn-link btn-animate text-muted py-0"
921 this.handleShowConfirmTransferCommunity
923 aria-label={i18n.t("transfer_community")}
925 {i18n.t("transfer_community")}
930 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
931 aria-label={i18n.t("are_you_sure")}
933 {i18n.t("are_you_sure")}
936 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
937 aria-label={i18n.t("yes")}
938 onClick={linkEvent(this, this.handleTransferCommunity)}
943 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
946 this.handleCancelShowConfirmTransferCommunity
948 aria-label={i18n.t("no")}
954 {/* Admins can ban from all, and appoint other admins */}
957 {!this.creatorIsAdmin_ && (
959 {!isBanned(post_view.creator) ? (
961 className="btn btn-link btn-animate text-muted py-0"
962 onClick={linkEvent(this, this.handleModBanShow)}
963 aria-label={i18n.t("ban_from_site")}
965 {i18n.t("ban_from_site")}
969 className="btn btn-link btn-animate text-muted py-0"
970 onClick={linkEvent(this, this.handleModBanSubmit)}
971 aria-label={i18n.t("unban_from_site")}
973 {i18n.t("unban_from_site")}
977 className="btn btn-link btn-animate text-muted py-0"
978 onClick={linkEvent(this, this.handlePurgePersonShow)}
979 aria-label={i18n.t("purge_user")}
981 {i18n.t("purge_user")}
984 className="btn btn-link btn-animate text-muted py-0"
985 onClick={linkEvent(this, this.handlePurgePostShow)}
986 aria-label={i18n.t("purge_post")}
988 {i18n.t("purge_post")}
992 {!isBanned(post_view.creator) && post_view.creator.local && (
994 className="btn btn-link btn-animate text-muted py-0"
995 onClick={linkEvent(this, this.handleAddAdmin)}
998 ? i18n.t("remove_as_admin")
999 : i18n.t("appoint_as_admin")
1002 {this.creatorIsAdmin_
1003 ? i18n.t("remove_as_admin")
1004 : i18n.t("appoint_as_admin")}
1014 removeAndBanDialogs() {
1015 let post = this.props.post_view;
1016 let purgeTypeText: string;
1017 if (this.state.purgeType == PurgeType.Post) {
1018 purgeTypeText = i18n.t("purge_post");
1019 } else if (this.state.purgeType == PurgeType.Person) {
1020 purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
1024 {this.state.showRemoveDialog && (
1026 className="form-inline"
1027 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1029 <label className="sr-only" htmlFor="post-listing-remove-reason">
1034 id="post-listing-remove-reason"
1035 className="form-control mr-2"
1036 placeholder={i18n.t("reason")}
1037 value={toUndefined(this.state.removeReason)}
1038 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1042 className="btn btn-secondary"
1043 aria-label={i18n.t("remove_post")}
1045 {i18n.t("remove_post")}
1049 {this.state.showBanDialog && (
1050 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1051 <div className="form-group row col-12">
1053 className="col-form-label"
1054 htmlFor="post-listing-ban-reason"
1060 id="post-listing-ban-reason"
1061 className="form-control mr-2"
1062 placeholder={i18n.t("reason")}
1063 value={toUndefined(this.state.banReason)}
1064 onInput={linkEvent(this, this.handleModBanReasonChange)}
1066 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1071 id={`mod-ban-expires`}
1072 className="form-control mr-2"
1073 placeholder={i18n.t("number_of_days")}
1074 value={toUndefined(this.state.banExpireDays)}
1075 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1077 <div className="form-group">
1078 <div className="form-check">
1080 className="form-check-input"
1081 id="mod-ban-remove-data"
1083 checked={this.state.removeData}
1084 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1087 className="form-check-label"
1088 htmlFor="mod-ban-remove-data"
1089 title={i18n.t("remove_content_more")}
1091 {i18n.t("remove_content")}
1096 {/* TODO hold off on expires until later */}
1097 {/* <div class="form-group row"> */}
1098 {/* <label class="col-form-label">Expires</label> */}
1099 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1101 <div className="form-group row">
1104 className="btn btn-secondary"
1105 aria-label={i18n.t("ban")}
1107 {i18n.t("ban")} {post.creator.name}
1112 {this.state.showReportDialog && (
1114 className="form-inline"
1115 onSubmit={linkEvent(this, this.handleReportSubmit)}
1117 <label className="sr-only" htmlFor="post-report-reason">
1122 id="post-report-reason"
1123 className="form-control mr-2"
1124 placeholder={i18n.t("reason")}
1126 value={toUndefined(this.state.reportReason)}
1127 onInput={linkEvent(this, this.handleReportReasonChange)}
1131 className="btn btn-secondary"
1132 aria-label={i18n.t("create_report")}
1134 {i18n.t("create_report")}
1138 {this.state.showPurgeDialog && (
1140 className="form-inline"
1141 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1144 <label className="sr-only" htmlFor="purge-reason">
1150 className="form-control mr-2"
1151 placeholder={i18n.t("reason")}
1152 value={toUndefined(this.state.purgeReason)}
1153 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1155 {this.state.purgeLoading ? (
1160 className="btn btn-secondary"
1161 aria-label={purgeTypeText}
1173 let post = this.props.post_view.post;
1174 return post.thumbnail_url.isSome() ||
1175 post.url.map(isImage).unwrapOr(false) ? (
1176 <div className="row">
1177 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1178 {this.postTitleLine()}
1180 <div className="col-4">
1181 {/* Post body prev or thumbnail */}
1182 {!this.state.imageExpanded && this.thumbnail()}
1186 this.postTitleLine()
1190 showMobilePreview() {
1191 let post = this.props.post_view.post;
1195 some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
1204 {/* The mobile view*/}
1205 <div className="d-block d-sm-none">
1206 <div className="row">
1207 <div className="col-12">
1208 {this.createdLine()}
1210 {/* If it has a thumbnail, do a right aligned thumbnail */}
1211 {this.mobileThumbnail()}
1213 {/* Show a preview of the post body */}
1214 {this.showMobilePreview()}
1216 {this.commentsLine(true)}
1217 {this.userActionsLine()}
1218 {this.duplicatesLine()}
1219 {this.removeAndBanDialogs()}
1224 {/* The larger view*/}
1225 <div className="d-none d-sm-block">
1226 <div className="row">
1227 {!this.props.viewOnly && this.voteBar()}
1228 <div className="col-sm-2 pr-0">
1229 <div className="">{this.thumbnail()}</div>
1231 <div className="col-12 col-sm-9">
1232 <div className="row">
1233 <div className="col-12">
1234 {this.postTitleLine()}
1235 {this.createdLine()}
1236 {this.commentsLine()}
1237 {this.duplicatesLine()}
1238 {this.userActionsLine()}
1239 {this.removeAndBanDialogs()}
1249 private get myPost(): boolean {
1250 return UserService.Instance.myUserInfo.match({
1252 this.props.post_view.creator.id == mui.local_user_view.person.id,
1257 handlePostLike(event: any) {
1258 event.preventDefault();
1259 if (UserService.Instance.myUserInfo.isNone()) {
1260 this.context.router.history.push(`/login`);
1263 let myVote = this.state.my_vote.unwrapOr(0);
1264 let newVote = myVote == 1 ? 0 : 1;
1268 score: this.state.score - 1,
1269 upvotes: this.state.upvotes - 1,
1271 } else if (myVote == -1) {
1273 score: this.state.score + 2,
1274 upvotes: this.state.upvotes + 1,
1275 downvotes: this.state.downvotes - 1,
1279 score: this.state.score + 1,
1280 upvotes: this.state.upvotes + 1,
1284 this.setState({ my_vote: Some(newVote) });
1286 let form = new CreatePostLike({
1287 post_id: this.props.post_view.post.id,
1289 auth: auth().unwrap(),
1292 WebSocketService.Instance.send(wsClient.likePost(form));
1293 this.setState(this.state);
1297 handlePostDisLike(event: any) {
1298 event.preventDefault();
1299 if (UserService.Instance.myUserInfo.isNone()) {
1300 this.context.router.history.push(`/login`);
1303 let myVote = this.state.my_vote.unwrapOr(0);
1304 let newVote = myVote == -1 ? 0 : -1;
1308 score: this.state.score - 2,
1309 upvotes: this.state.upvotes - 1,
1310 downvotes: this.state.downvotes + 1,
1312 } else if (myVote == -1) {
1314 score: this.state.score + 1,
1315 downvotes: this.state.downvotes - 1,
1319 score: this.state.score - 1,
1320 downvotes: this.state.downvotes + 1,
1324 this.setState({ my_vote: Some(newVote) });
1326 let form = new CreatePostLike({
1327 post_id: this.props.post_view.post.id,
1329 auth: auth().unwrap(),
1332 WebSocketService.Instance.send(wsClient.likePost(form));
1333 this.setState(this.state);
1337 handleEditClick(i: PostListing) {
1338 i.setState({ showEdit: true });
1341 handleEditCancel() {
1342 this.setState({ showEdit: false });
1345 // The actual editing is done in the recieve for post
1347 this.setState({ showEdit: false });
1350 handleShowReportDialog(i: PostListing) {
1351 i.setState({ showReportDialog: !i.state.showReportDialog });
1354 handleReportReasonChange(i: PostListing, event: any) {
1355 i.setState({ reportReason: Some(event.target.value) });
1358 handleReportSubmit(i: PostListing, event: any) {
1359 event.preventDefault();
1360 let form = new CreatePostReport({
1361 post_id: i.props.post_view.post.id,
1362 reason: toUndefined(i.state.reportReason),
1363 auth: auth().unwrap(),
1365 WebSocketService.Instance.send(wsClient.createPostReport(form));
1367 i.setState({ showReportDialog: false });
1370 handleBlockUserClick(i: PostListing) {
1371 let blockUserForm = new BlockPerson({
1372 person_id: i.props.post_view.creator.id,
1374 auth: auth().unwrap(),
1376 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1379 handleDeleteClick(i: PostListing) {
1380 let deleteForm = new DeletePost({
1381 post_id: i.props.post_view.post.id,
1382 deleted: !i.props.post_view.post.deleted,
1383 auth: auth().unwrap(),
1385 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1388 handleSavePostClick(i: PostListing) {
1390 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1391 let form = new SavePost({
1392 post_id: i.props.post_view.post.id,
1394 auth: auth().unwrap(),
1397 WebSocketService.Instance.send(wsClient.savePost(form));
1400 get crossPostParams(): string {
1401 let post = this.props.post_view.post;
1402 let params = `?title=${encodeURIComponent(post.name)}`;
1404 if (post.url.isSome()) {
1405 params += `&url=${encodeURIComponent(post.url.unwrap())}`;
1407 if (post.body.isSome()) {
1408 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1413 crossPostBody(): string {
1414 let post = this.props.post_view.post;
1415 let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
1417 .replace(/^/gm, "> ")}`;
1421 get showBody(): boolean {
1422 return this.props.showBody || this.state.showBody;
1425 handleModRemoveShow(i: PostListing) {
1427 showRemoveDialog: !i.state.showRemoveDialog,
1428 showBanDialog: false,
1432 handleModRemoveReasonChange(i: PostListing, event: any) {
1433 i.setState({ removeReason: Some(event.target.value) });
1436 handleModRemoveDataChange(i: PostListing, event: any) {
1437 i.setState({ removeData: event.target.checked });
1440 handleModRemoveSubmit(i: PostListing, event: any) {
1441 event.preventDefault();
1442 let form = new RemovePost({
1443 post_id: i.props.post_view.post.id,
1444 removed: !i.props.post_view.post.removed,
1445 reason: i.state.removeReason,
1446 auth: auth().unwrap(),
1448 WebSocketService.Instance.send(wsClient.removePost(form));
1450 i.setState({ showRemoveDialog: false });
1453 handleModLock(i: PostListing) {
1454 let form = new LockPost({
1455 post_id: i.props.post_view.post.id,
1456 locked: !i.props.post_view.post.locked,
1457 auth: auth().unwrap(),
1459 WebSocketService.Instance.send(wsClient.lockPost(form));
1462 handleModSticky(i: PostListing) {
1463 let form = new StickyPost({
1464 post_id: i.props.post_view.post.id,
1465 stickied: !i.props.post_view.post.stickied,
1466 auth: auth().unwrap(),
1468 WebSocketService.Instance.send(wsClient.stickyPost(form));
1471 handleModBanFromCommunityShow(i: PostListing) {
1473 showBanDialog: true,
1474 banType: BanType.Community,
1475 showRemoveDialog: false,
1479 handleModBanShow(i: PostListing) {
1481 showBanDialog: true,
1482 banType: BanType.Site,
1483 showRemoveDialog: false,
1487 handlePurgePersonShow(i: PostListing) {
1489 showPurgeDialog: true,
1490 purgeType: PurgeType.Person,
1491 showRemoveDialog: false,
1495 handlePurgePostShow(i: PostListing) {
1497 showPurgeDialog: true,
1498 purgeType: PurgeType.Post,
1499 showRemoveDialog: false,
1503 handlePurgeReasonChange(i: PostListing, event: any) {
1504 i.setState({ purgeReason: Some(event.target.value) });
1507 handlePurgeSubmit(i: PostListing, event: any) {
1508 event.preventDefault();
1510 if (i.state.purgeType == PurgeType.Person) {
1511 let form = new PurgePerson({
1512 person_id: i.props.post_view.creator.id,
1513 reason: i.state.purgeReason,
1514 auth: auth().unwrap(),
1516 WebSocketService.Instance.send(wsClient.purgePerson(form));
1517 } else if (i.state.purgeType == PurgeType.Post) {
1518 let form = new PurgePost({
1519 post_id: i.props.post_view.post.id,
1520 reason: i.state.purgeReason,
1521 auth: auth().unwrap(),
1523 WebSocketService.Instance.send(wsClient.purgePost(form));
1526 i.setState({ purgeLoading: true });
1529 handleModBanReasonChange(i: PostListing, event: any) {
1530 i.setState({ banReason: Some(event.target.value) });
1533 handleModBanExpireDaysChange(i: PostListing, event: any) {
1534 i.setState({ banExpireDays: Some(event.target.value) });
1537 handleModBanFromCommunitySubmit(i: PostListing) {
1538 i.setState({ banType: BanType.Community });
1539 i.handleModBanBothSubmit(i);
1542 handleModBanSubmit(i: PostListing) {
1543 i.setState({ banType: BanType.Site });
1544 i.handleModBanBothSubmit(i);
1547 handleModBanBothSubmit(i: PostListing, event?: any) {
1548 if (event) event.preventDefault();
1550 if (i.state.banType == BanType.Community) {
1551 // If its an unban, restore all their data
1552 let ban = !i.props.post_view.creator_banned_from_community;
1554 i.setState({ removeData: false });
1556 let form = new BanFromCommunity({
1557 person_id: i.props.post_view.creator.id,
1558 community_id: i.props.post_view.community.id,
1560 remove_data: Some(i.state.removeData),
1561 reason: i.state.banReason,
1562 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1563 auth: auth().unwrap(),
1565 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1567 // If its an unban, restore all their data
1568 let ban = !i.props.post_view.creator.banned;
1570 i.setState({ removeData: false });
1572 let form = new BanPerson({
1573 person_id: i.props.post_view.creator.id,
1575 remove_data: Some(i.state.removeData),
1576 reason: i.state.banReason,
1577 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1578 auth: auth().unwrap(),
1580 WebSocketService.Instance.send(wsClient.banPerson(form));
1583 i.setState({ showBanDialog: false });
1586 handleAddModToCommunity(i: PostListing) {
1587 let form = new AddModToCommunity({
1588 person_id: i.props.post_view.creator.id,
1589 community_id: i.props.post_view.community.id,
1590 added: !i.creatorIsMod_,
1591 auth: auth().unwrap(),
1593 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1594 i.setState(i.state);
1597 handleAddAdmin(i: PostListing) {
1598 let form = new AddAdmin({
1599 person_id: i.props.post_view.creator.id,
1600 added: !i.creatorIsAdmin_,
1601 auth: auth().unwrap(),
1603 WebSocketService.Instance.send(wsClient.addAdmin(form));
1604 i.setState(i.state);
1607 handleShowConfirmTransferCommunity(i: PostListing) {
1608 i.setState({ showConfirmTransferCommunity: true });
1611 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1612 i.setState({ showConfirmTransferCommunity: false });
1615 handleTransferCommunity(i: PostListing) {
1616 let form = new TransferCommunity({
1617 community_id: i.props.post_view.community.id,
1618 person_id: i.props.post_view.creator.id,
1619 auth: auth().unwrap(),
1621 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1622 i.setState({ showConfirmTransferCommunity: false });
1625 handleShowConfirmTransferSite(i: PostListing) {
1626 i.setState({ showConfirmTransferSite: true });
1629 handleCancelShowConfirmTransferSite(i: PostListing) {
1630 i.setState({ showConfirmTransferSite: false });
1633 handleImageExpandClick(i: PostListing, event: any) {
1634 event.preventDefault();
1635 i.setState({ imageExpanded: !i.state.imageExpanded });
1639 handleViewSource(i: PostListing) {
1640 i.setState({ viewSource: !i.state.viewSource });
1643 handleShowAdvanced(i: PostListing) {
1644 i.setState({ showAdvanced: !i.state.showAdvanced });
1648 handleShowMoreMobile(i: PostListing) {
1650 showMoreMobile: !i.state.showMoreMobile,
1651 showAdvanced: !i.state.showAdvanced,
1656 handleShowBody(i: PostListing) {
1657 i.setState({ showBody: !i.state.showBody });
1661 get pointsTippy(): string {
1662 let points = i18n.t("number_of_points", {
1663 count: this.state.score,
1664 formattedCount: this.state.score,
1667 let upvotes = i18n.t("number_of_upvotes", {
1668 count: this.state.upvotes,
1669 formattedCount: this.state.upvotes,
1672 let downvotes = i18n.t("number_of_downvotes", {
1673 count: this.state.downvotes,
1674 formattedCount: this.state.downvotes,
1677 return `${points} • ${upvotes} • ${downvotes}`;
1680 get canModOnSelf_(): boolean {
1682 this.props.moderators,
1684 this.props.post_view.creator.id,
1690 get canMod_(): boolean {
1692 this.props.moderators,
1694 this.props.post_view.creator.id
1698 get canAdmin_(): boolean {
1699 return canAdmin(this.props.admins, this.props.post_view.creator.id);
1702 get creatorIsMod_(): boolean {
1703 return isMod(this.props.moderators, this.props.post_view.creator.id);
1706 get creatorIsAdmin_(): boolean {
1707 return isAdmin(this.props.admins, this.props.post_view.creator.id);