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,
26 } from "lemmy-js-client";
27 import { externalHost } from "../../env";
28 import { i18n } from "../../i18next";
29 import { BanType, PurgeType } from "../../interfaces";
30 import { UserService, WebSocketService } from "../../services";
52 import { Icon, PurgeWarning, Spinner } from "../common/icon";
53 import { MomentTime } from "../common/moment-time";
54 import { PictrsImage } from "../common/pictrs-image";
55 import { CommunityLink } from "../community/community-link";
56 import { PersonListing } from "../person/person-listing";
57 import { MetadataCard } from "./metadata-card";
58 import { PostForm } from "./post-form";
60 interface PostListingState {
62 showRemoveDialog: boolean;
63 showPurgeDialog: boolean;
64 purgeReason: Option<string>;
66 purgeLoading: boolean;
67 removeReason: Option<string>;
68 showBanDialog: boolean;
69 banReason: Option<string>;
70 banExpireDays: Option<number>;
73 showConfirmTransferSite: boolean;
74 showConfirmTransferCommunity: boolean;
75 imageExpanded: boolean;
77 showAdvanced: boolean;
78 showMoreMobile: boolean;
80 showReportDialog: boolean;
81 reportReason: Option<string>;
82 my_vote: Option<number>;
88 interface PostListingProps {
90 duplicates: Option<PostView[]>;
91 moderators: Option<CommunityModeratorView[]>;
92 admins: Option<PersonViewSafe[]>;
93 allLanguages: Language[];
94 showCommunity?: boolean;
97 enableDownvotes?: boolean;
102 export class PostListing extends Component<PostListingProps, PostListingState> {
103 private emptyState: PostListingState = {
105 showRemoveDialog: false,
106 showPurgeDialog: false,
108 purgeType: PurgeType.Person,
111 showBanDialog: false,
114 banType: BanType.Community,
116 showConfirmTransferSite: false,
117 showConfirmTransferCommunity: false,
118 imageExpanded: false,
121 showMoreMobile: false,
123 showReportDialog: false,
125 my_vote: this.props.post_view.my_vote,
126 score: this.props.post_view.counts.score,
127 upvotes: this.props.post_view.counts.upvotes,
128 downvotes: this.props.post_view.counts.downvotes,
131 constructor(props: any, context: any) {
132 super(props, context);
134 this.state = this.emptyState;
135 this.handlePostLike = this.handlePostLike.bind(this);
136 this.handlePostDisLike = this.handlePostDisLike.bind(this);
137 this.handleEditPost = this.handleEditPost.bind(this);
138 this.handleEditCancel = this.handleEditCancel.bind(this);
141 componentWillReceiveProps(nextProps: PostListingProps) {
143 my_vote: nextProps.post_view.my_vote,
144 upvotes: nextProps.post_view.counts.upvotes,
145 downvotes: nextProps.post_view.counts.downvotes,
146 score: nextProps.post_view.counts.score,
148 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
149 this.setState({ imageExpanded: false });
154 let post = this.props.post_view.post;
156 <div className="post-listing">
157 {!this.state.showEdit ? (
160 {this.state.imageExpanded && !this.props.hideImage && this.img}
161 {post.url.isSome() &&
163 post.embed_title.isSome() && <MetadataCard post={post} />}
164 {this.showBody && this.body()}
167 <div className="col-12">
169 post_view={Some(this.props.post_view)}
172 onEdit={this.handleEditPost}
173 onCancel={this.handleEditCancel}
174 enableNsfw={this.props.enableNsfw}
175 enableDownvotes={this.props.enableDownvotes}
176 allLanguages={this.props.allLanguages}
185 return this.props.post_view.post.body.match({
187 <div className="col-12 card my-2 p-2">
188 {this.state.viewSource ? (
191 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
200 return this.imageSrc.match({
203 <div className="offset-sm-3 my-2 d-none d-sm-block">
204 <a href={src} className="d-inline-block">
205 <PictrsImage src={src} />
208 <div className="my-2 d-block d-sm-none">
210 className="d-inline-block"
211 onClick={linkEvent(this, this.handleImageExpandClick)}
213 <PictrsImage src={src} />
222 imgThumb(src: string) {
223 let post_view = this.props.post_view;
229 nsfw={post_view.post.nsfw || post_view.community.nsfw}
234 get imageSrc(): Option<string> {
235 let post = this.props.post_view.post;
237 let thumbnail = post.thumbnail_url;
239 if (url.isSome() && isImage(url.unwrap())) {
240 if (url.unwrap().includes("pictrs")) {
242 } else if (thumbnail.isSome()) {
247 } else if (thumbnail.isSome()) {
255 let post = this.props.post_view.post;
257 let thumbnail = post.thumbnail_url;
259 if (!this.props.hideImage && url.isSome() && isImage(url.unwrap())) {
262 href={this.imageSrc.unwrap()}
263 className="text-body d-inline-block position-relative mb-2"
264 data-tippy-content={i18n.t("expand_here")}
265 onClick={linkEvent(this, this.handleImageExpandClick)}
266 aria-label={i18n.t("expand_here")}
268 {this.imgThumb(this.imageSrc.unwrap())}
269 <Icon icon="image" classes="mini-overlay" />
272 } else if (!this.props.hideImage && url.isSome() && thumbnail.isSome()) {
275 className="text-body d-inline-block position-relative mb-2"
280 {this.imgThumb(this.imageSrc.unwrap())}
281 <Icon icon="external-link" classes="mini-overlay" />
284 } else if (url.isSome()) {
285 if (!this.props.hideImage && isVideo(url.unwrap())) {
287 <div className="embed-responsive embed-responsive-16by9">
293 className="embed-responsive-item"
295 <source src={url.unwrap()} type="video/mp4" />
302 className="text-body"
307 <div className="thumbnail rounded bg-light d-flex justify-content-center">
308 <Icon icon="external-link" classes="d-flex align-items-center" />
316 className="text-body"
317 to={`/post/${post.id}`}
318 title={i18n.t("comments")}
320 <div className="thumbnail rounded bg-light d-flex justify-content-center">
321 <Icon icon="message-square" classes="d-flex align-items-center" />
329 let post_view = this.props.post_view;
331 <ul className="list-inline mb-1 text-muted small">
332 <li className="list-inline-item">
333 <PersonListing person={post_view.creator} />
335 {this.creatorIsMod_ && (
336 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
338 {this.creatorIsAdmin_ && (
339 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
341 {post_view.creator.bot_account && (
342 <span className="mx-1 badge badge-light">
343 {i18n.t("bot_account").toLowerCase()}
346 {(post_view.creator_banned_from_community ||
347 isBanned(post_view.creator)) && (
348 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
350 {post_view.creator_blocked && (
351 <span className="mx-1 badge badge-danger">{"blocked"}</span>
353 {this.props.showCommunity && (
355 <span className="mx-1"> {i18n.t("to")} </span>
356 <CommunityLink community={post_view.community} />
360 <li className="list-inline-item">•</li>
361 {post_view.post.url.match({
363 !(hostname(url) == externalHost) && (
365 <li className="list-inline-item">
367 className="text-muted font-italic"
375 <li className="list-inline-item">•</li>
380 <li className="list-inline-item">
383 published={post_view.post.published}
384 updated={post_view.post.updated}
388 {post_view.post.body.match({
391 <li className="list-inline-item">•</li>
392 <li className="list-inline-item">
394 className="text-muted btn btn-sm btn-link p-0"
395 data-tippy-content={mdNoImages.render(body)}
396 data-tippy-allowHtml={true}
397 onClick={linkEvent(this, this.handleShowBody)}
399 <Icon icon="book-open" classes="icon-inline mr-1" />
412 <div className={`vote-bar col-1 pr-0 small text-center`}>
414 className={`btn-animate btn btn-link p-0 ${
415 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
417 onClick={this.handlePostLike}
418 data-tippy-content={i18n.t("upvote")}
419 aria-label={i18n.t("upvote")}
421 <Icon icon="arrow-up1" classes="upvote" />
425 className={`unselectable pointer font-weight-bold text-muted px-1`}
426 data-tippy-content={this.pointsTippy}
428 {numToSI(this.state.score)}
431 <div className="p-1"></div>
433 {this.props.enableDownvotes && (
435 className={`btn-animate btn btn-link p-0 ${
436 this.state.my_vote.unwrapOr(0) == -1
440 onClick={this.handlePostDisLike}
441 data-tippy-content={i18n.t("downvote")}
442 aria-label={i18n.t("downvote")}
444 <Icon icon="arrow-down1" classes="downvote" />
452 let post = this.props.post_view.post;
455 className={!post.stickied ? "text-body" : "text-primary"}
456 to={`/post/${post.id}`}
457 title={i18n.t("comments")}
459 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
465 let post = this.props.post_view.post;
467 <div className="post-title overflow-hidden">
471 this.props.showBody ? (
473 className={!post.stickied ? "text-body" : "text-primary"}
478 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
485 {post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
487 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
488 data-tippy-content={i18n.t("expand_here")}
489 onClick={linkEvent(this, this.handleImageExpandClick)}
493 !this.state.imageExpanded ? "plus-square" : "minus-square"
495 classes="icon-inline"
500 <small className="ml-2 text-muted font-italic">
506 className="unselectable pointer ml-2 text-muted font-italic"
507 data-tippy-content={i18n.t("deleted")}
509 <Icon icon="trash" classes="icon-inline text-danger" />
514 className="unselectable pointer ml-2 text-muted font-italic"
515 data-tippy-content={i18n.t("locked")}
517 <Icon icon="lock" classes="icon-inline text-danger" />
522 className="unselectable pointer ml-2 text-muted font-italic"
523 data-tippy-content={i18n.t("stickied")}
525 <Icon icon="pin" classes="icon-inline text-primary" />
529 <small className="ml-2 text-muted font-italic">
539 return this.props.duplicates.match({
541 dupes.length > 0 && (
542 <ul className="list-inline mb-1 small text-muted">
544 <li className="list-inline-item mr-2">
545 {i18n.t("cross_posted_to")}
548 <li key={pv.post.id} className="list-inline-item mr-2">
549 <Link to={`/post/${pv.post.id}`}>
552 : `${pv.community.name}@${hostname(
553 pv.community.actor_id
565 commentsLine(mobile = false) {
566 let post = this.props.post_view.post;
568 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
569 {this.commentsButton}
572 className="btn btn-link btn-animate text-muted py-0"
573 title={i18n.t("link")}
576 <Icon icon="fedilink" inline />
579 {mobile && !this.props.viewOnly && this.mobileVotes}
580 {UserService.Instance.myUserInfo.isSome() &&
581 !this.props.viewOnly &&
582 this.postActions(mobile)}
587 postActions(mobile = false) {
588 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
589 // Possible enhancement: Make each button a component.
590 let post_view = this.props.post_view;
594 {this.crossPostButton}
595 {mobile && this.showMoreButton}
596 {(!mobile || this.state.showAdvanced) && (
604 {this.myPost && (this.showBody || this.state.showAdvanced) && (
612 {this.state.showAdvanced && (
615 post_view.post.body.isSome() &&
616 this.viewSourceButton}
617 {this.canModOnSelf_ && (
623 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
626 {!mobile && this.showMoreButton}
631 get commentsButton() {
632 let post_view = this.props.post_view;
634 <button className="btn btn-link text-muted py-0 pl-0">
636 className="text-muted"
637 title={i18n.t("number_of_comments", {
638 count: post_view.counts.comments,
639 formattedCount: post_view.counts.comments,
641 to={`/post/${post_view.post.id}?scrollToComments=true`}
643 <Icon icon="message-square" classes="mr-1" inline />
644 <span className="mr-2">
645 {i18n.t("number_of_comments", {
646 count: post_view.counts.comments,
647 formattedCount: numToSI(post_view.counts.comments),
650 {this.unreadCount.match({
651 some: unreadCount => (
652 <span className="small text-warning">
653 ({unreadCount} {i18n.t("new")})
663 get unreadCount(): Option<number> {
664 let pv = this.props.post_view;
665 if (pv.unread_comments == pv.counts.comments || pv.unread_comments == 0) {
668 return Some(pv.unread_comments);
674 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
679 className={`btn-animate btn py-0 px-1 ${
680 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
683 onClick={this.handlePostLike}
684 aria-label={i18n.t("upvote")}
686 <Icon icon="arrow-up1" classes="icon-inline small" />
688 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
691 {this.props.enableDownvotes && (
693 className={`ml-2 btn-animate btn py-0 px-1 ${
694 this.state.my_vote.unwrapOr(0) == -1
698 onClick={this.handlePostDisLike}
700 aria-label={i18n.t("downvote")}
702 <Icon icon="arrow-down1" classes="icon-inline small" />
705 className={classNames("ml-2", {
706 invisible: this.state.downvotes === 0,
709 {numToSI(this.state.downvotes)}
720 let saved = this.props.post_view.saved;
721 let label = saved ? i18n.t("unsave") : i18n.t("save");
724 className="btn btn-link btn-animate text-muted py-0"
725 onClick={linkEvent(this, this.handleSavePostClick)}
726 data-tippy-content={label}
731 classes={classNames({ "text-warning": saved })}
738 get crossPostButton() {
741 className="btn btn-link btn-animate text-muted py-0"
742 to={`/create_post${this.crossPostParams}`}
743 title={i18n.t("cross_post")}
745 <Icon icon="copy" inline />
753 className="btn btn-link btn-animate text-muted py-0"
754 onClick={linkEvent(this, this.handleShowReportDialog)}
755 data-tippy-content={i18n.t("show_report_dialog")}
756 aria-label={i18n.t("show_report_dialog")}
758 <Icon icon="flag" inline />
766 className="btn btn-link btn-animate text-muted py-0"
767 onClick={linkEvent(this, this.handleBlockUserClick)}
768 data-tippy-content={i18n.t("block_user")}
769 aria-label={i18n.t("block_user")}
771 <Icon icon="slash" inline />
779 className="btn btn-link btn-animate text-muted py-0"
780 onClick={linkEvent(this, this.handleEditClick)}
781 data-tippy-content={i18n.t("edit")}
782 aria-label={i18n.t("edit")}
784 <Icon icon="edit" inline />
790 let deleted = this.props.post_view.post.deleted;
791 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
794 className="btn btn-link btn-animate text-muted py-0"
795 onClick={linkEvent(this, this.handleDeleteClick)}
796 data-tippy-content={label}
801 classes={classNames({ "text-danger": deleted })}
808 get showMoreButton() {
811 className="btn btn-link btn-animate text-muted py-0"
812 onClick={linkEvent(this, this.handleShowAdvanced)}
813 data-tippy-content={i18n.t("more")}
814 aria-label={i18n.t("more")}
816 <Icon icon="more-vertical" inline />
821 get viewSourceButton() {
824 className="btn btn-link btn-animate text-muted py-0"
825 onClick={linkEvent(this, this.handleViewSource)}
826 data-tippy-content={i18n.t("view_source")}
827 aria-label={i18n.t("view_source")}
831 classes={classNames({ "text-success": this.state.viewSource })}
839 let locked = this.props.post_view.post.locked;
840 let label = locked ? i18n.t("unlock") : i18n.t("lock");
843 className="btn btn-link btn-animate text-muted py-0"
844 onClick={linkEvent(this, this.handleModLock)}
845 data-tippy-content={label}
850 classes={classNames({ "text-danger": locked })}
858 let stickied = this.props.post_view.post.stickied;
859 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
862 className="btn btn-link btn-animate text-muted py-0"
863 onClick={linkEvent(this, this.handleModSticky)}
864 data-tippy-content={label}
869 classes={classNames({ "text-success": stickied })}
876 get modRemoveButton() {
877 let removed = this.props.post_view.post.removed;
880 className="btn btn-link btn-animate text-muted py-0"
883 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
886 {/* TODO: Find an icon for this. */}
887 {!removed ? i18n.t("remove") : i18n.t("restore")}
893 * Mod/Admin actions to be taken against the author.
897 let post_view = this.props.post_view;
899 this.state.showAdvanced && (
903 {!this.creatorIsMod_ &&
904 (!post_view.creator_banned_from_community ? (
906 className="btn btn-link btn-animate text-muted py-0"
909 this.handleModBanFromCommunityShow
911 aria-label={i18n.t("ban")}
917 className="btn btn-link btn-animate text-muted py-0"
920 this.handleModBanFromCommunitySubmit
922 aria-label={i18n.t("unban")}
927 {!post_view.creator_banned_from_community && (
929 className="btn btn-link btn-animate text-muted py-0"
930 onClick={linkEvent(this, this.handleAddModToCommunity)}
933 ? i18n.t("remove_as_mod")
934 : i18n.t("appoint_as_mod")
938 ? i18n.t("remove_as_mod")
939 : i18n.t("appoint_as_mod")}
944 {/* Community creators and admins can transfer community to another mod */}
945 {(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
947 this.creatorIsMod_ &&
948 (!this.state.showConfirmTransferCommunity ? (
950 className="btn btn-link btn-animate text-muted py-0"
953 this.handleShowConfirmTransferCommunity
955 aria-label={i18n.t("transfer_community")}
957 {i18n.t("transfer_community")}
962 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
963 aria-label={i18n.t("are_you_sure")}
965 {i18n.t("are_you_sure")}
968 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
969 aria-label={i18n.t("yes")}
970 onClick={linkEvent(this, this.handleTransferCommunity)}
975 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
978 this.handleCancelShowConfirmTransferCommunity
980 aria-label={i18n.t("no")}
986 {/* Admins can ban from all, and appoint other admins */}
989 {!this.creatorIsAdmin_ && (
991 {!isBanned(post_view.creator) ? (
993 className="btn btn-link btn-animate text-muted py-0"
994 onClick={linkEvent(this, this.handleModBanShow)}
995 aria-label={i18n.t("ban_from_site")}
997 {i18n.t("ban_from_site")}
1001 className="btn btn-link btn-animate text-muted py-0"
1002 onClick={linkEvent(this, this.handleModBanSubmit)}
1003 aria-label={i18n.t("unban_from_site")}
1005 {i18n.t("unban_from_site")}
1009 className="btn btn-link btn-animate text-muted py-0"
1010 onClick={linkEvent(this, this.handlePurgePersonShow)}
1011 aria-label={i18n.t("purge_user")}
1013 {i18n.t("purge_user")}
1016 className="btn btn-link btn-animate text-muted py-0"
1017 onClick={linkEvent(this, this.handlePurgePostShow)}
1018 aria-label={i18n.t("purge_post")}
1020 {i18n.t("purge_post")}
1024 {!isBanned(post_view.creator) && post_view.creator.local && (
1026 className="btn btn-link btn-animate text-muted py-0"
1027 onClick={linkEvent(this, this.handleAddAdmin)}
1029 this.creatorIsAdmin_
1030 ? i18n.t("remove_as_admin")
1031 : i18n.t("appoint_as_admin")
1034 {this.creatorIsAdmin_
1035 ? i18n.t("remove_as_admin")
1036 : i18n.t("appoint_as_admin")}
1046 removeAndBanDialogs() {
1047 let post = this.props.post_view;
1048 let purgeTypeText: string;
1049 if (this.state.purgeType == PurgeType.Post) {
1050 purgeTypeText = i18n.t("purge_post");
1051 } else if (this.state.purgeType == PurgeType.Person) {
1052 purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
1056 {this.state.showRemoveDialog && (
1058 className="form-inline"
1059 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1061 <label className="sr-only" htmlFor="post-listing-remove-reason">
1066 id="post-listing-remove-reason"
1067 className="form-control mr-2"
1068 placeholder={i18n.t("reason")}
1069 value={toUndefined(this.state.removeReason)}
1070 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1074 className="btn btn-secondary"
1075 aria-label={i18n.t("remove_post")}
1077 {i18n.t("remove_post")}
1081 {this.state.showBanDialog && (
1082 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1083 <div className="form-group row col-12">
1085 className="col-form-label"
1086 htmlFor="post-listing-ban-reason"
1092 id="post-listing-ban-reason"
1093 className="form-control mr-2"
1094 placeholder={i18n.t("reason")}
1095 value={toUndefined(this.state.banReason)}
1096 onInput={linkEvent(this, this.handleModBanReasonChange)}
1098 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1103 id={`mod-ban-expires`}
1104 className="form-control mr-2"
1105 placeholder={i18n.t("number_of_days")}
1106 value={toUndefined(this.state.banExpireDays)}
1107 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1109 <div className="form-group">
1110 <div className="form-check">
1112 className="form-check-input"
1113 id="mod-ban-remove-data"
1115 checked={this.state.removeData}
1116 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1119 className="form-check-label"
1120 htmlFor="mod-ban-remove-data"
1121 title={i18n.t("remove_content_more")}
1123 {i18n.t("remove_content")}
1128 {/* TODO hold off on expires until later */}
1129 {/* <div class="form-group row"> */}
1130 {/* <label class="col-form-label">Expires</label> */}
1131 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1133 <div className="form-group row">
1136 className="btn btn-secondary"
1137 aria-label={i18n.t("ban")}
1139 {i18n.t("ban")} {post.creator.name}
1144 {this.state.showReportDialog && (
1146 className="form-inline"
1147 onSubmit={linkEvent(this, this.handleReportSubmit)}
1149 <label className="sr-only" htmlFor="post-report-reason">
1154 id="post-report-reason"
1155 className="form-control mr-2"
1156 placeholder={i18n.t("reason")}
1158 value={toUndefined(this.state.reportReason)}
1159 onInput={linkEvent(this, this.handleReportReasonChange)}
1163 className="btn btn-secondary"
1164 aria-label={i18n.t("create_report")}
1166 {i18n.t("create_report")}
1170 {this.state.showPurgeDialog && (
1172 className="form-inline"
1173 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1176 <label className="sr-only" htmlFor="purge-reason">
1182 className="form-control mr-2"
1183 placeholder={i18n.t("reason")}
1184 value={toUndefined(this.state.purgeReason)}
1185 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1187 {this.state.purgeLoading ? (
1192 className="btn btn-secondary"
1193 aria-label={purgeTypeText}
1205 let post = this.props.post_view.post;
1206 return post.thumbnail_url.isSome() ||
1207 post.url.map(isImage).unwrapOr(false) ? (
1208 <div className="row">
1209 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1210 {this.postTitleLine()}
1212 <div className="col-4">
1213 {/* Post body prev or thumbnail */}
1214 {!this.state.imageExpanded && this.thumbnail()}
1218 this.postTitleLine()
1222 showMobilePreview() {
1223 let post = this.props.post_view.post;
1227 some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
1236 {/* The mobile view*/}
1237 <div className="d-block d-sm-none">
1238 <div className="row">
1239 <div className="col-12">
1240 {this.createdLine()}
1242 {/* If it has a thumbnail, do a right aligned thumbnail */}
1243 {this.mobileThumbnail()}
1245 {/* Show a preview of the post body */}
1246 {this.showMobilePreview()}
1248 {this.commentsLine(true)}
1249 {this.userActionsLine()}
1250 {this.duplicatesLine()}
1251 {this.removeAndBanDialogs()}
1256 {/* The larger view*/}
1257 <div className="d-none d-sm-block">
1258 <div className="row">
1259 {!this.props.viewOnly && this.voteBar()}
1260 <div className="col-sm-2 pr-0">
1261 <div className="">{this.thumbnail()}</div>
1263 <div className="col-12 col-sm-9">
1264 <div className="row">
1265 <div className="col-12">
1266 {this.postTitleLine()}
1267 {this.createdLine()}
1268 {this.commentsLine()}
1269 {this.duplicatesLine()}
1270 {this.userActionsLine()}
1271 {this.removeAndBanDialogs()}
1281 private get myPost(): boolean {
1282 return UserService.Instance.myUserInfo.match({
1284 this.props.post_view.creator.id == mui.local_user_view.person.id,
1289 handlePostLike(event: any) {
1290 event.preventDefault();
1291 if (UserService.Instance.myUserInfo.isNone()) {
1292 this.context.router.history.push(`/login`);
1295 let myVote = this.state.my_vote.unwrapOr(0);
1296 let newVote = myVote == 1 ? 0 : 1;
1300 score: this.state.score - 1,
1301 upvotes: this.state.upvotes - 1,
1303 } else if (myVote == -1) {
1305 score: this.state.score + 2,
1306 upvotes: this.state.upvotes + 1,
1307 downvotes: this.state.downvotes - 1,
1311 score: this.state.score + 1,
1312 upvotes: this.state.upvotes + 1,
1316 this.setState({ my_vote: Some(newVote) });
1318 let form = new CreatePostLike({
1319 post_id: this.props.post_view.post.id,
1321 auth: auth().unwrap(),
1324 WebSocketService.Instance.send(wsClient.likePost(form));
1325 this.setState(this.state);
1329 handlePostDisLike(event: any) {
1330 event.preventDefault();
1331 if (UserService.Instance.myUserInfo.isNone()) {
1332 this.context.router.history.push(`/login`);
1335 let myVote = this.state.my_vote.unwrapOr(0);
1336 let newVote = myVote == -1 ? 0 : -1;
1340 score: this.state.score - 2,
1341 upvotes: this.state.upvotes - 1,
1342 downvotes: this.state.downvotes + 1,
1344 } else if (myVote == -1) {
1346 score: this.state.score + 1,
1347 downvotes: this.state.downvotes - 1,
1351 score: this.state.score - 1,
1352 downvotes: this.state.downvotes + 1,
1356 this.setState({ my_vote: Some(newVote) });
1358 let form = new CreatePostLike({
1359 post_id: this.props.post_view.post.id,
1361 auth: auth().unwrap(),
1364 WebSocketService.Instance.send(wsClient.likePost(form));
1365 this.setState(this.state);
1369 handleEditClick(i: PostListing) {
1370 i.setState({ showEdit: true });
1373 handleEditCancel() {
1374 this.setState({ showEdit: false });
1377 // The actual editing is done in the recieve for post
1379 this.setState({ showEdit: false });
1382 handleShowReportDialog(i: PostListing) {
1383 i.setState({ showReportDialog: !i.state.showReportDialog });
1386 handleReportReasonChange(i: PostListing, event: any) {
1387 i.setState({ reportReason: Some(event.target.value) });
1390 handleReportSubmit(i: PostListing, event: any) {
1391 event.preventDefault();
1392 let form = new CreatePostReport({
1393 post_id: i.props.post_view.post.id,
1394 reason: toUndefined(i.state.reportReason),
1395 auth: auth().unwrap(),
1397 WebSocketService.Instance.send(wsClient.createPostReport(form));
1399 i.setState({ showReportDialog: false });
1402 handleBlockUserClick(i: PostListing) {
1403 let blockUserForm = new BlockPerson({
1404 person_id: i.props.post_view.creator.id,
1406 auth: auth().unwrap(),
1408 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1411 handleDeleteClick(i: PostListing) {
1412 let deleteForm = new DeletePost({
1413 post_id: i.props.post_view.post.id,
1414 deleted: !i.props.post_view.post.deleted,
1415 auth: auth().unwrap(),
1417 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1420 handleSavePostClick(i: PostListing) {
1422 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1423 let form = new SavePost({
1424 post_id: i.props.post_view.post.id,
1426 auth: auth().unwrap(),
1429 WebSocketService.Instance.send(wsClient.savePost(form));
1432 get crossPostParams(): string {
1433 let post = this.props.post_view.post;
1434 let params = `?title=${encodeURIComponent(post.name)}`;
1436 if (post.url.isSome()) {
1437 params += `&url=${encodeURIComponent(post.url.unwrap())}`;
1439 if (post.body.isSome()) {
1440 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1445 crossPostBody(): string {
1446 let post = this.props.post_view.post;
1447 let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
1449 .replace(/^/gm, "> ")}`;
1453 get showBody(): boolean {
1454 return this.props.showBody || this.state.showBody;
1457 handleModRemoveShow(i: PostListing) {
1459 showRemoveDialog: !i.state.showRemoveDialog,
1460 showBanDialog: false,
1464 handleModRemoveReasonChange(i: PostListing, event: any) {
1465 i.setState({ removeReason: Some(event.target.value) });
1468 handleModRemoveDataChange(i: PostListing, event: any) {
1469 i.setState({ removeData: event.target.checked });
1472 handleModRemoveSubmit(i: PostListing, event: any) {
1473 event.preventDefault();
1474 let form = new RemovePost({
1475 post_id: i.props.post_view.post.id,
1476 removed: !i.props.post_view.post.removed,
1477 reason: i.state.removeReason,
1478 auth: auth().unwrap(),
1480 WebSocketService.Instance.send(wsClient.removePost(form));
1482 i.setState({ showRemoveDialog: false });
1485 handleModLock(i: PostListing) {
1486 let form = new LockPost({
1487 post_id: i.props.post_view.post.id,
1488 locked: !i.props.post_view.post.locked,
1489 auth: auth().unwrap(),
1491 WebSocketService.Instance.send(wsClient.lockPost(form));
1494 handleModSticky(i: PostListing) {
1495 let form = new StickyPost({
1496 post_id: i.props.post_view.post.id,
1497 stickied: !i.props.post_view.post.stickied,
1498 auth: auth().unwrap(),
1500 WebSocketService.Instance.send(wsClient.stickyPost(form));
1503 handleModBanFromCommunityShow(i: PostListing) {
1505 showBanDialog: true,
1506 banType: BanType.Community,
1507 showRemoveDialog: false,
1511 handleModBanShow(i: PostListing) {
1513 showBanDialog: true,
1514 banType: BanType.Site,
1515 showRemoveDialog: false,
1519 handlePurgePersonShow(i: PostListing) {
1521 showPurgeDialog: true,
1522 purgeType: PurgeType.Person,
1523 showRemoveDialog: false,
1527 handlePurgePostShow(i: PostListing) {
1529 showPurgeDialog: true,
1530 purgeType: PurgeType.Post,
1531 showRemoveDialog: false,
1535 handlePurgeReasonChange(i: PostListing, event: any) {
1536 i.setState({ purgeReason: Some(event.target.value) });
1539 handlePurgeSubmit(i: PostListing, event: any) {
1540 event.preventDefault();
1542 if (i.state.purgeType == PurgeType.Person) {
1543 let form = new PurgePerson({
1544 person_id: i.props.post_view.creator.id,
1545 reason: i.state.purgeReason,
1546 auth: auth().unwrap(),
1548 WebSocketService.Instance.send(wsClient.purgePerson(form));
1549 } else if (i.state.purgeType == PurgeType.Post) {
1550 let form = new PurgePost({
1551 post_id: i.props.post_view.post.id,
1552 reason: i.state.purgeReason,
1553 auth: auth().unwrap(),
1555 WebSocketService.Instance.send(wsClient.purgePost(form));
1558 i.setState({ purgeLoading: true });
1561 handleModBanReasonChange(i: PostListing, event: any) {
1562 i.setState({ banReason: Some(event.target.value) });
1565 handleModBanExpireDaysChange(i: PostListing, event: any) {
1566 i.setState({ banExpireDays: Some(event.target.value) });
1569 handleModBanFromCommunitySubmit(i: PostListing) {
1570 i.setState({ banType: BanType.Community });
1571 i.handleModBanBothSubmit(i);
1574 handleModBanSubmit(i: PostListing) {
1575 i.setState({ banType: BanType.Site });
1576 i.handleModBanBothSubmit(i);
1579 handleModBanBothSubmit(i: PostListing, event?: any) {
1580 if (event) event.preventDefault();
1582 if (i.state.banType == BanType.Community) {
1583 // If its an unban, restore all their data
1584 let ban = !i.props.post_view.creator_banned_from_community;
1586 i.setState({ removeData: false });
1588 let form = new BanFromCommunity({
1589 person_id: i.props.post_view.creator.id,
1590 community_id: i.props.post_view.community.id,
1592 remove_data: Some(i.state.removeData),
1593 reason: i.state.banReason,
1594 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1595 auth: auth().unwrap(),
1597 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1599 // If its an unban, restore all their data
1600 let ban = !i.props.post_view.creator.banned;
1602 i.setState({ removeData: false });
1604 let form = new BanPerson({
1605 person_id: i.props.post_view.creator.id,
1607 remove_data: Some(i.state.removeData),
1608 reason: i.state.banReason,
1609 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1610 auth: auth().unwrap(),
1612 WebSocketService.Instance.send(wsClient.banPerson(form));
1615 i.setState({ showBanDialog: false });
1618 handleAddModToCommunity(i: PostListing) {
1619 let form = new AddModToCommunity({
1620 person_id: i.props.post_view.creator.id,
1621 community_id: i.props.post_view.community.id,
1622 added: !i.creatorIsMod_,
1623 auth: auth().unwrap(),
1625 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1626 i.setState(i.state);
1629 handleAddAdmin(i: PostListing) {
1630 let form = new AddAdmin({
1631 person_id: i.props.post_view.creator.id,
1632 added: !i.creatorIsAdmin_,
1633 auth: auth().unwrap(),
1635 WebSocketService.Instance.send(wsClient.addAdmin(form));
1636 i.setState(i.state);
1639 handleShowConfirmTransferCommunity(i: PostListing) {
1640 i.setState({ showConfirmTransferCommunity: true });
1643 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1644 i.setState({ showConfirmTransferCommunity: false });
1647 handleTransferCommunity(i: PostListing) {
1648 let form = new TransferCommunity({
1649 community_id: i.props.post_view.community.id,
1650 person_id: i.props.post_view.creator.id,
1651 auth: auth().unwrap(),
1653 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1654 i.setState({ showConfirmTransferCommunity: false });
1657 handleShowConfirmTransferSite(i: PostListing) {
1658 i.setState({ showConfirmTransferSite: true });
1661 handleCancelShowConfirmTransferSite(i: PostListing) {
1662 i.setState({ showConfirmTransferSite: false });
1665 handleImageExpandClick(i: PostListing, event: any) {
1666 event.preventDefault();
1667 i.setState({ imageExpanded: !i.state.imageExpanded });
1671 handleViewSource(i: PostListing) {
1672 i.setState({ viewSource: !i.state.viewSource });
1675 handleShowAdvanced(i: PostListing) {
1676 i.setState({ showAdvanced: !i.state.showAdvanced });
1680 handleShowMoreMobile(i: PostListing) {
1682 showMoreMobile: !i.state.showMoreMobile,
1683 showAdvanced: !i.state.showAdvanced,
1688 handleShowBody(i: PostListing) {
1689 i.setState({ showBody: !i.state.showBody });
1693 get pointsTippy(): string {
1694 let points = i18n.t("number_of_points", {
1695 count: this.state.score,
1696 formattedCount: this.state.score,
1699 let upvotes = i18n.t("number_of_upvotes", {
1700 count: this.state.upvotes,
1701 formattedCount: this.state.upvotes,
1704 let downvotes = i18n.t("number_of_downvotes", {
1705 count: this.state.downvotes,
1706 formattedCount: this.state.downvotes,
1709 return `${points} • ${upvotes} • ${downvotes}`;
1712 get canModOnSelf_(): boolean {
1714 this.props.moderators,
1716 this.props.post_view.creator.id,
1722 get canMod_(): boolean {
1724 this.props.moderators,
1726 this.props.post_view.creator.id
1730 get canAdmin_(): boolean {
1731 return canAdmin(this.props.admins, this.props.post_view.creator.id);
1734 get creatorIsMod_(): boolean {
1735 return isMod(this.props.moderators, this.props.post_view.creator.id);
1738 get creatorIsAdmin_(): boolean {
1739 return isAdmin(this.props.admins, this.props.post_view.creator.id);