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;
96 enableDownvotes?: boolean;
101 export class PostListing extends Component<PostListingProps, PostListingState> {
102 private emptyState: PostListingState = {
104 showRemoveDialog: false,
105 showPurgeDialog: false,
107 purgeType: PurgeType.Person,
110 showBanDialog: false,
113 banType: BanType.Community,
115 showConfirmTransferSite: false,
116 showConfirmTransferCommunity: false,
117 imageExpanded: false,
120 showMoreMobile: false,
122 showReportDialog: false,
124 my_vote: this.props.post_view.my_vote,
125 score: this.props.post_view.counts.score,
126 upvotes: this.props.post_view.counts.upvotes,
127 downvotes: this.props.post_view.counts.downvotes,
130 constructor(props: any, context: any) {
131 super(props, context);
133 this.state = this.emptyState;
134 this.handlePostLike = this.handlePostLike.bind(this);
135 this.handlePostDisLike = this.handlePostDisLike.bind(this);
136 this.handleEditPost = this.handleEditPost.bind(this);
137 this.handleEditCancel = this.handleEditCancel.bind(this);
140 componentWillReceiveProps(nextProps: PostListingProps) {
142 my_vote: nextProps.post_view.my_vote,
143 upvotes: nextProps.post_view.counts.upvotes,
144 downvotes: nextProps.post_view.counts.downvotes,
145 score: nextProps.post_view.counts.score,
147 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
148 this.setState({ imageExpanded: false });
153 let post = this.props.post_view.post;
155 <div className="post-listing">
156 {!this.state.showEdit ? (
159 {this.state.imageExpanded && this.img}
160 {post.url.isSome() &&
162 post.embed_title.isSome() && <MetadataCard post={post} />}
163 {this.showBody && this.body()}
166 <div className="col-12">
168 post_view={Some(this.props.post_view)}
171 onEdit={this.handleEditPost}
172 onCancel={this.handleEditCancel}
173 enableNsfw={this.props.enableNsfw}
174 enableDownvotes={this.props.enableDownvotes}
175 allLanguages={this.props.allLanguages}
184 return this.props.post_view.post.body.match({
186 <div className="col-12 card my-2 p-2">
187 {this.state.viewSource ? (
190 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
199 return this.imageSrc.match({
202 <div className="offset-sm-3 my-2 d-none d-sm-block">
203 <a href={src} className="d-inline-block">
204 <PictrsImage src={src} />
207 <div className="my-2 d-block d-sm-none">
209 className="d-inline-block"
210 onClick={linkEvent(this, this.handleImageExpandClick)}
212 <PictrsImage src={src} />
221 imgThumb(src: string) {
222 let post_view = this.props.post_view;
228 nsfw={post_view.post.nsfw || post_view.community.nsfw}
233 get imageSrc(): Option<string> {
234 let post = this.props.post_view.post;
236 let thumbnail = post.thumbnail_url;
238 if (url.isSome() && isImage(url.unwrap())) {
239 if (url.unwrap().includes("pictrs")) {
241 } else if (thumbnail.isSome()) {
246 } else if (thumbnail.isSome()) {
254 let post = this.props.post_view.post;
256 let thumbnail = post.thumbnail_url;
258 if (url.isSome() && isImage(url.unwrap())) {
261 href={this.imageSrc.unwrap()}
262 className="text-body d-inline-block position-relative mb-2"
263 data-tippy-content={i18n.t("expand_here")}
264 onClick={linkEvent(this, this.handleImageExpandClick)}
265 aria-label={i18n.t("expand_here")}
267 {this.imgThumb(this.imageSrc.unwrap())}
268 <Icon icon="image" classes="mini-overlay" />
271 } else if (url.isSome() && thumbnail.isSome()) {
274 className="text-body d-inline-block position-relative mb-2"
279 {this.imgThumb(this.imageSrc.unwrap())}
280 <Icon icon="external-link" classes="mini-overlay" />
283 } else if (url.isSome()) {
284 if (isVideo(url.unwrap())) {
286 <div className="embed-responsive embed-responsive-16by9">
292 className="embed-responsive-item"
294 <source src={url.unwrap()} type="video/mp4" />
301 className="text-body"
306 <div className="thumbnail rounded bg-light d-flex justify-content-center">
307 <Icon icon="external-link" classes="d-flex align-items-center" />
315 className="text-body"
316 to={`/post/${post.id}`}
317 title={i18n.t("comments")}
319 <div className="thumbnail rounded bg-light d-flex justify-content-center">
320 <Icon icon="message-square" classes="d-flex align-items-center" />
328 let post_view = this.props.post_view;
330 <ul className="list-inline mb-1 text-muted small">
331 <li className="list-inline-item">
332 <PersonListing person={post_view.creator} />
334 {this.creatorIsMod_ && (
335 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
337 {this.creatorIsAdmin_ && (
338 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
340 {post_view.creator.bot_account && (
341 <span className="mx-1 badge badge-light">
342 {i18n.t("bot_account").toLowerCase()}
345 {(post_view.creator_banned_from_community ||
346 isBanned(post_view.creator)) && (
347 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
349 {post_view.creator_blocked && (
350 <span className="mx-1 badge badge-danger">{"blocked"}</span>
352 {this.props.showCommunity && (
354 <span className="mx-1"> {i18n.t("to")} </span>
355 <CommunityLink community={post_view.community} />
359 <li className="list-inline-item">•</li>
360 {post_view.post.url.match({
362 !(hostname(url) == externalHost) && (
364 <li className="list-inline-item">
366 className="text-muted font-italic"
374 <li className="list-inline-item">•</li>
379 <li className="list-inline-item">
382 published={post_view.post.published}
383 updated={post_view.post.updated}
387 {post_view.post.body.match({
390 <li className="list-inline-item">•</li>
391 <li className="list-inline-item">
393 className="text-muted btn btn-sm btn-link p-0"
394 data-tippy-content={md.render(body)}
395 data-tippy-allowHtml={true}
396 onClick={linkEvent(this, this.handleShowBody)}
398 <Icon icon="book-open" classes="icon-inline mr-1" />
411 <div className={`vote-bar col-1 pr-0 small text-center`}>
413 className={`btn-animate btn btn-link p-0 ${
414 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
416 onClick={this.handlePostLike}
417 data-tippy-content={i18n.t("upvote")}
418 aria-label={i18n.t("upvote")}
420 <Icon icon="arrow-up1" classes="upvote" />
424 className={`unselectable pointer font-weight-bold text-muted px-1`}
425 data-tippy-content={this.pointsTippy}
427 {numToSI(this.state.score)}
430 <div className="p-1"></div>
432 {this.props.enableDownvotes && (
434 className={`btn-animate btn btn-link p-0 ${
435 this.state.my_vote.unwrapOr(0) == -1
439 onClick={this.handlePostDisLike}
440 data-tippy-content={i18n.t("downvote")}
441 aria-label={i18n.t("downvote")}
443 <Icon icon="arrow-down1" classes="downvote" />
451 let post = this.props.post_view.post;
453 <div className="post-title overflow-hidden">
458 className={!post.stickied ? "text-body" : "text-primary"}
463 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
468 className={!post.stickied ? "text-body" : "text-primary"}
469 to={`/post/${post.id}`}
470 title={i18n.t("comments")}
472 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
476 {post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
478 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
479 data-tippy-content={i18n.t("expand_here")}
480 onClick={linkEvent(this, this.handleImageExpandClick)}
484 !this.state.imageExpanded ? "plus-square" : "minus-square"
486 classes="icon-inline"
491 <small className="ml-2 text-muted font-italic">
497 className="unselectable pointer ml-2 text-muted font-italic"
498 data-tippy-content={i18n.t("deleted")}
500 <Icon icon="trash" classes="icon-inline text-danger" />
505 className="unselectable pointer ml-2 text-muted font-italic"
506 data-tippy-content={i18n.t("locked")}
508 <Icon icon="lock" classes="icon-inline text-danger" />
513 className="unselectable pointer ml-2 text-muted font-italic"
514 data-tippy-content={i18n.t("stickied")}
516 <Icon icon="pin" classes="icon-inline text-primary" />
520 <small className="ml-2 text-muted font-italic">
530 return this.props.duplicates.match({
532 dupes.length > 0 && (
533 <ul className="list-inline mb-1 small text-muted">
535 <li className="list-inline-item mr-2">
536 {i18n.t("cross_posted_to")}
539 <li key={pv.post.id} className="list-inline-item mr-2">
540 <Link to={`/post/${pv.post.id}`}>
543 : `${pv.community.name}@${hostname(
544 pv.community.actor_id
556 commentsLine(mobile = false) {
557 let post = this.props.post_view.post;
559 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
560 {this.commentsButton}
563 className="btn btn-link btn-animate text-muted py-0"
564 title={i18n.t("link")}
567 <Icon icon="fedilink" inline />
570 {mobile && !this.props.viewOnly && this.mobileVotes}
571 {UserService.Instance.myUserInfo.isSome() &&
572 !this.props.viewOnly &&
573 this.postActions(mobile)}
578 postActions(mobile = false) {
579 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
580 // Possible enhancement: Make each button a component.
581 let post_view = this.props.post_view;
585 {this.crossPostButton}
586 {mobile && this.showMoreButton}
587 {(!mobile || this.state.showAdvanced) && (
595 {this.myPost && (this.showBody || this.state.showAdvanced) && (
603 {this.state.showAdvanced && (
606 post_view.post.body.isSome() &&
607 this.viewSourceButton}
608 {this.canModOnSelf_ && (
614 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
617 {!mobile && this.showMoreButton}
622 get commentsButton() {
623 let post_view = this.props.post_view;
625 <button className="btn btn-link text-muted py-0 pl-0">
627 className="text-muted"
628 title={i18n.t("number_of_comments", {
629 count: post_view.counts.comments,
630 formattedCount: post_view.counts.comments,
632 to={`/post/${post_view.post.id}?scrollToComments=true`}
634 <Icon icon="message-square" classes="mr-1" inline />
635 <span className="mr-2">
636 {i18n.t("number_of_comments", {
637 count: post_view.counts.comments,
638 formattedCount: numToSI(post_view.counts.comments),
641 {this.unreadCount.match({
642 some: unreadCount => (
643 <span className="small text-warning">
644 ({unreadCount} {i18n.t("new")})
654 get unreadCount(): Option<number> {
655 let pv = this.props.post_view;
656 if (pv.unread_comments == pv.counts.comments || pv.unread_comments == 0) {
659 return Some(pv.unread_comments);
665 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
670 className={`btn-animate btn py-0 px-1 ${
671 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
674 onClick={this.handlePostLike}
675 aria-label={i18n.t("upvote")}
677 <Icon icon="arrow-up1" classes="icon-inline small" />
679 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
682 {this.props.enableDownvotes && (
684 className={`ml-2 btn-animate btn py-0 px-1 ${
685 this.state.my_vote.unwrapOr(0) == -1
689 onClick={this.handlePostDisLike}
691 aria-label={i18n.t("downvote")}
693 <Icon icon="arrow-down1" classes="icon-inline small" />
696 className={classNames("ml-2", {
697 invisible: this.state.downvotes === 0,
700 {numToSI(this.state.downvotes)}
711 let saved = this.props.post_view.saved;
712 let label = saved ? i18n.t("unsave") : i18n.t("save");
715 className="btn btn-link btn-animate text-muted py-0"
716 onClick={linkEvent(this, this.handleSavePostClick)}
717 data-tippy-content={label}
722 classes={classNames({ "text-warning": saved })}
729 get crossPostButton() {
732 className="btn btn-link btn-animate text-muted py-0"
733 to={`/create_post${this.crossPostParams}`}
734 title={i18n.t("cross_post")}
736 <Icon icon="copy" inline />
744 className="btn btn-link btn-animate text-muted py-0"
745 onClick={linkEvent(this, this.handleShowReportDialog)}
746 data-tippy-content={i18n.t("show_report_dialog")}
747 aria-label={i18n.t("show_report_dialog")}
749 <Icon icon="flag" inline />
757 className="btn btn-link btn-animate text-muted py-0"
758 onClick={linkEvent(this, this.handleBlockUserClick)}
759 data-tippy-content={i18n.t("block_user")}
760 aria-label={i18n.t("block_user")}
762 <Icon icon="slash" inline />
770 className="btn btn-link btn-animate text-muted py-0"
771 onClick={linkEvent(this, this.handleEditClick)}
772 data-tippy-content={i18n.t("edit")}
773 aria-label={i18n.t("edit")}
775 <Icon icon="edit" inline />
781 let deleted = this.props.post_view.post.deleted;
782 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
785 className="btn btn-link btn-animate text-muted py-0"
786 onClick={linkEvent(this, this.handleDeleteClick)}
787 data-tippy-content={label}
792 classes={classNames({ "text-danger": deleted })}
799 get showMoreButton() {
802 className="btn btn-link btn-animate text-muted py-0"
803 onClick={linkEvent(this, this.handleShowAdvanced)}
804 data-tippy-content={i18n.t("more")}
805 aria-label={i18n.t("more")}
807 <Icon icon="more-vertical" inline />
812 get viewSourceButton() {
815 className="btn btn-link btn-animate text-muted py-0"
816 onClick={linkEvent(this, this.handleViewSource)}
817 data-tippy-content={i18n.t("view_source")}
818 aria-label={i18n.t("view_source")}
822 classes={classNames({ "text-success": this.state.viewSource })}
830 let locked = this.props.post_view.post.locked;
831 let label = locked ? i18n.t("unlock") : i18n.t("lock");
834 className="btn btn-link btn-animate text-muted py-0"
835 onClick={linkEvent(this, this.handleModLock)}
836 data-tippy-content={label}
841 classes={classNames({ "text-danger": locked })}
849 let stickied = this.props.post_view.post.stickied;
850 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
853 className="btn btn-link btn-animate text-muted py-0"
854 onClick={linkEvent(this, this.handleModSticky)}
855 data-tippy-content={label}
860 classes={classNames({ "text-success": stickied })}
867 get modRemoveButton() {
868 let removed = this.props.post_view.post.removed;
871 className="btn btn-link btn-animate text-muted py-0"
874 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
877 {/* TODO: Find an icon for this. */}
878 {!removed ? i18n.t("remove") : i18n.t("restore")}
884 * Mod/Admin actions to be taken against the author.
888 let post_view = this.props.post_view;
890 this.state.showAdvanced && (
894 {!this.creatorIsMod_ &&
895 (!post_view.creator_banned_from_community ? (
897 className="btn btn-link btn-animate text-muted py-0"
900 this.handleModBanFromCommunityShow
902 aria-label={i18n.t("ban")}
908 className="btn btn-link btn-animate text-muted py-0"
911 this.handleModBanFromCommunitySubmit
913 aria-label={i18n.t("unban")}
918 {!post_view.creator_banned_from_community && (
920 className="btn btn-link btn-animate text-muted py-0"
921 onClick={linkEvent(this, this.handleAddModToCommunity)}
924 ? i18n.t("remove_as_mod")
925 : i18n.t("appoint_as_mod")
929 ? i18n.t("remove_as_mod")
930 : i18n.t("appoint_as_mod")}
935 {/* Community creators and admins can transfer community to another mod */}
936 {(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
938 this.creatorIsMod_ &&
939 (!this.state.showConfirmTransferCommunity ? (
941 className="btn btn-link btn-animate text-muted py-0"
944 this.handleShowConfirmTransferCommunity
946 aria-label={i18n.t("transfer_community")}
948 {i18n.t("transfer_community")}
953 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
954 aria-label={i18n.t("are_you_sure")}
956 {i18n.t("are_you_sure")}
959 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
960 aria-label={i18n.t("yes")}
961 onClick={linkEvent(this, this.handleTransferCommunity)}
966 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
969 this.handleCancelShowConfirmTransferCommunity
971 aria-label={i18n.t("no")}
977 {/* Admins can ban from all, and appoint other admins */}
980 {!this.creatorIsAdmin_ && (
982 {!isBanned(post_view.creator) ? (
984 className="btn btn-link btn-animate text-muted py-0"
985 onClick={linkEvent(this, this.handleModBanShow)}
986 aria-label={i18n.t("ban_from_site")}
988 {i18n.t("ban_from_site")}
992 className="btn btn-link btn-animate text-muted py-0"
993 onClick={linkEvent(this, this.handleModBanSubmit)}
994 aria-label={i18n.t("unban_from_site")}
996 {i18n.t("unban_from_site")}
1000 className="btn btn-link btn-animate text-muted py-0"
1001 onClick={linkEvent(this, this.handlePurgePersonShow)}
1002 aria-label={i18n.t("purge_user")}
1004 {i18n.t("purge_user")}
1007 className="btn btn-link btn-animate text-muted py-0"
1008 onClick={linkEvent(this, this.handlePurgePostShow)}
1009 aria-label={i18n.t("purge_post")}
1011 {i18n.t("purge_post")}
1015 {!isBanned(post_view.creator) && post_view.creator.local && (
1017 className="btn btn-link btn-animate text-muted py-0"
1018 onClick={linkEvent(this, this.handleAddAdmin)}
1020 this.creatorIsAdmin_
1021 ? i18n.t("remove_as_admin")
1022 : i18n.t("appoint_as_admin")
1025 {this.creatorIsAdmin_
1026 ? i18n.t("remove_as_admin")
1027 : i18n.t("appoint_as_admin")}
1037 removeAndBanDialogs() {
1038 let post = this.props.post_view;
1039 let purgeTypeText: string;
1040 if (this.state.purgeType == PurgeType.Post) {
1041 purgeTypeText = i18n.t("purge_post");
1042 } else if (this.state.purgeType == PurgeType.Person) {
1043 purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
1047 {this.state.showRemoveDialog && (
1049 className="form-inline"
1050 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1052 <label className="sr-only" htmlFor="post-listing-remove-reason">
1057 id="post-listing-remove-reason"
1058 className="form-control mr-2"
1059 placeholder={i18n.t("reason")}
1060 value={toUndefined(this.state.removeReason)}
1061 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1065 className="btn btn-secondary"
1066 aria-label={i18n.t("remove_post")}
1068 {i18n.t("remove_post")}
1072 {this.state.showBanDialog && (
1073 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1074 <div className="form-group row col-12">
1076 className="col-form-label"
1077 htmlFor="post-listing-ban-reason"
1083 id="post-listing-ban-reason"
1084 className="form-control mr-2"
1085 placeholder={i18n.t("reason")}
1086 value={toUndefined(this.state.banReason)}
1087 onInput={linkEvent(this, this.handleModBanReasonChange)}
1089 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1094 id={`mod-ban-expires`}
1095 className="form-control mr-2"
1096 placeholder={i18n.t("number_of_days")}
1097 value={toUndefined(this.state.banExpireDays)}
1098 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1100 <div className="form-group">
1101 <div className="form-check">
1103 className="form-check-input"
1104 id="mod-ban-remove-data"
1106 checked={this.state.removeData}
1107 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1110 className="form-check-label"
1111 htmlFor="mod-ban-remove-data"
1112 title={i18n.t("remove_content_more")}
1114 {i18n.t("remove_content")}
1119 {/* TODO hold off on expires until later */}
1120 {/* <div class="form-group row"> */}
1121 {/* <label class="col-form-label">Expires</label> */}
1122 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1124 <div className="form-group row">
1127 className="btn btn-secondary"
1128 aria-label={i18n.t("ban")}
1130 {i18n.t("ban")} {post.creator.name}
1135 {this.state.showReportDialog && (
1137 className="form-inline"
1138 onSubmit={linkEvent(this, this.handleReportSubmit)}
1140 <label className="sr-only" htmlFor="post-report-reason">
1145 id="post-report-reason"
1146 className="form-control mr-2"
1147 placeholder={i18n.t("reason")}
1149 value={toUndefined(this.state.reportReason)}
1150 onInput={linkEvent(this, this.handleReportReasonChange)}
1154 className="btn btn-secondary"
1155 aria-label={i18n.t("create_report")}
1157 {i18n.t("create_report")}
1161 {this.state.showPurgeDialog && (
1163 className="form-inline"
1164 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1167 <label className="sr-only" htmlFor="purge-reason">
1173 className="form-control mr-2"
1174 placeholder={i18n.t("reason")}
1175 value={toUndefined(this.state.purgeReason)}
1176 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1178 {this.state.purgeLoading ? (
1183 className="btn btn-secondary"
1184 aria-label={purgeTypeText}
1196 let post = this.props.post_view.post;
1197 return post.thumbnail_url.isSome() ||
1198 post.url.map(isImage).unwrapOr(false) ? (
1199 <div className="row">
1200 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1201 {this.postTitleLine()}
1203 <div className="col-4">
1204 {/* Post body prev or thumbnail */}
1205 {!this.state.imageExpanded && this.thumbnail()}
1209 this.postTitleLine()
1213 showMobilePreview() {
1214 let post = this.props.post_view.post;
1218 some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
1227 {/* The mobile view*/}
1228 <div className="d-block d-sm-none">
1229 <div className="row">
1230 <div className="col-12">
1231 {this.createdLine()}
1233 {/* If it has a thumbnail, do a right aligned thumbnail */}
1234 {this.mobileThumbnail()}
1236 {/* Show a preview of the post body */}
1237 {this.showMobilePreview()}
1239 {this.commentsLine(true)}
1240 {this.userActionsLine()}
1241 {this.duplicatesLine()}
1242 {this.removeAndBanDialogs()}
1247 {/* The larger view*/}
1248 <div className="d-none d-sm-block">
1249 <div className="row">
1250 {!this.props.viewOnly && this.voteBar()}
1251 <div className="col-sm-2 pr-0">
1252 <div className="">{this.thumbnail()}</div>
1254 <div className="col-12 col-sm-9">
1255 <div className="row">
1256 <div className="col-12">
1257 {this.postTitleLine()}
1258 {this.createdLine()}
1259 {this.commentsLine()}
1260 {this.duplicatesLine()}
1261 {this.userActionsLine()}
1262 {this.removeAndBanDialogs()}
1272 private get myPost(): boolean {
1273 return UserService.Instance.myUserInfo.match({
1275 this.props.post_view.creator.id == mui.local_user_view.person.id,
1280 handlePostLike(event: any) {
1281 event.preventDefault();
1282 if (UserService.Instance.myUserInfo.isNone()) {
1283 this.context.router.history.push(`/login`);
1286 let myVote = this.state.my_vote.unwrapOr(0);
1287 let newVote = myVote == 1 ? 0 : 1;
1291 score: this.state.score - 1,
1292 upvotes: this.state.upvotes - 1,
1294 } else if (myVote == -1) {
1296 score: this.state.score + 2,
1297 upvotes: this.state.upvotes + 1,
1298 downvotes: this.state.downvotes - 1,
1302 score: this.state.score + 1,
1303 upvotes: this.state.upvotes + 1,
1307 this.setState({ my_vote: Some(newVote) });
1309 let form = new CreatePostLike({
1310 post_id: this.props.post_view.post.id,
1312 auth: auth().unwrap(),
1315 WebSocketService.Instance.send(wsClient.likePost(form));
1316 this.setState(this.state);
1320 handlePostDisLike(event: any) {
1321 event.preventDefault();
1322 if (UserService.Instance.myUserInfo.isNone()) {
1323 this.context.router.history.push(`/login`);
1326 let myVote = this.state.my_vote.unwrapOr(0);
1327 let newVote = myVote == -1 ? 0 : -1;
1331 score: this.state.score - 2,
1332 upvotes: this.state.upvotes - 1,
1333 downvotes: this.state.downvotes + 1,
1335 } else if (myVote == -1) {
1337 score: this.state.score + 1,
1338 downvotes: this.state.downvotes - 1,
1342 score: this.state.score - 1,
1343 downvotes: this.state.downvotes + 1,
1347 this.setState({ my_vote: Some(newVote) });
1349 let form = new CreatePostLike({
1350 post_id: this.props.post_view.post.id,
1352 auth: auth().unwrap(),
1355 WebSocketService.Instance.send(wsClient.likePost(form));
1356 this.setState(this.state);
1360 handleEditClick(i: PostListing) {
1361 i.setState({ showEdit: true });
1364 handleEditCancel() {
1365 this.setState({ showEdit: false });
1368 // The actual editing is done in the recieve for post
1370 this.setState({ showEdit: false });
1373 handleShowReportDialog(i: PostListing) {
1374 i.setState({ showReportDialog: !i.state.showReportDialog });
1377 handleReportReasonChange(i: PostListing, event: any) {
1378 i.setState({ reportReason: Some(event.target.value) });
1381 handleReportSubmit(i: PostListing, event: any) {
1382 event.preventDefault();
1383 let form = new CreatePostReport({
1384 post_id: i.props.post_view.post.id,
1385 reason: toUndefined(i.state.reportReason),
1386 auth: auth().unwrap(),
1388 WebSocketService.Instance.send(wsClient.createPostReport(form));
1390 i.setState({ showReportDialog: false });
1393 handleBlockUserClick(i: PostListing) {
1394 let blockUserForm = new BlockPerson({
1395 person_id: i.props.post_view.creator.id,
1397 auth: auth().unwrap(),
1399 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1402 handleDeleteClick(i: PostListing) {
1403 let deleteForm = new DeletePost({
1404 post_id: i.props.post_view.post.id,
1405 deleted: !i.props.post_view.post.deleted,
1406 auth: auth().unwrap(),
1408 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1411 handleSavePostClick(i: PostListing) {
1413 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1414 let form = new SavePost({
1415 post_id: i.props.post_view.post.id,
1417 auth: auth().unwrap(),
1420 WebSocketService.Instance.send(wsClient.savePost(form));
1423 get crossPostParams(): string {
1424 let post = this.props.post_view.post;
1425 let params = `?title=${encodeURIComponent(post.name)}`;
1427 if (post.url.isSome()) {
1428 params += `&url=${encodeURIComponent(post.url.unwrap())}`;
1430 if (post.body.isSome()) {
1431 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1436 crossPostBody(): string {
1437 let post = this.props.post_view.post;
1438 let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
1440 .replace(/^/gm, "> ")}`;
1444 get showBody(): boolean {
1445 return this.props.showBody || this.state.showBody;
1448 handleModRemoveShow(i: PostListing) {
1450 showRemoveDialog: !i.state.showRemoveDialog,
1451 showBanDialog: false,
1455 handleModRemoveReasonChange(i: PostListing, event: any) {
1456 i.setState({ removeReason: Some(event.target.value) });
1459 handleModRemoveDataChange(i: PostListing, event: any) {
1460 i.setState({ removeData: event.target.checked });
1463 handleModRemoveSubmit(i: PostListing, event: any) {
1464 event.preventDefault();
1465 let form = new RemovePost({
1466 post_id: i.props.post_view.post.id,
1467 removed: !i.props.post_view.post.removed,
1468 reason: i.state.removeReason,
1469 auth: auth().unwrap(),
1471 WebSocketService.Instance.send(wsClient.removePost(form));
1473 i.setState({ showRemoveDialog: false });
1476 handleModLock(i: PostListing) {
1477 let form = new LockPost({
1478 post_id: i.props.post_view.post.id,
1479 locked: !i.props.post_view.post.locked,
1480 auth: auth().unwrap(),
1482 WebSocketService.Instance.send(wsClient.lockPost(form));
1485 handleModSticky(i: PostListing) {
1486 let form = new StickyPost({
1487 post_id: i.props.post_view.post.id,
1488 stickied: !i.props.post_view.post.stickied,
1489 auth: auth().unwrap(),
1491 WebSocketService.Instance.send(wsClient.stickyPost(form));
1494 handleModBanFromCommunityShow(i: PostListing) {
1496 showBanDialog: true,
1497 banType: BanType.Community,
1498 showRemoveDialog: false,
1502 handleModBanShow(i: PostListing) {
1504 showBanDialog: true,
1505 banType: BanType.Site,
1506 showRemoveDialog: false,
1510 handlePurgePersonShow(i: PostListing) {
1512 showPurgeDialog: true,
1513 purgeType: PurgeType.Person,
1514 showRemoveDialog: false,
1518 handlePurgePostShow(i: PostListing) {
1520 showPurgeDialog: true,
1521 purgeType: PurgeType.Post,
1522 showRemoveDialog: false,
1526 handlePurgeReasonChange(i: PostListing, event: any) {
1527 i.setState({ purgeReason: Some(event.target.value) });
1530 handlePurgeSubmit(i: PostListing, event: any) {
1531 event.preventDefault();
1533 if (i.state.purgeType == PurgeType.Person) {
1534 let form = new PurgePerson({
1535 person_id: i.props.post_view.creator.id,
1536 reason: i.state.purgeReason,
1537 auth: auth().unwrap(),
1539 WebSocketService.Instance.send(wsClient.purgePerson(form));
1540 } else if (i.state.purgeType == PurgeType.Post) {
1541 let form = new PurgePost({
1542 post_id: i.props.post_view.post.id,
1543 reason: i.state.purgeReason,
1544 auth: auth().unwrap(),
1546 WebSocketService.Instance.send(wsClient.purgePost(form));
1549 i.setState({ purgeLoading: true });
1552 handleModBanReasonChange(i: PostListing, event: any) {
1553 i.setState({ banReason: Some(event.target.value) });
1556 handleModBanExpireDaysChange(i: PostListing, event: any) {
1557 i.setState({ banExpireDays: Some(event.target.value) });
1560 handleModBanFromCommunitySubmit(i: PostListing) {
1561 i.setState({ banType: BanType.Community });
1562 i.handleModBanBothSubmit(i);
1565 handleModBanSubmit(i: PostListing) {
1566 i.setState({ banType: BanType.Site });
1567 i.handleModBanBothSubmit(i);
1570 handleModBanBothSubmit(i: PostListing, event?: any) {
1571 if (event) event.preventDefault();
1573 if (i.state.banType == BanType.Community) {
1574 // If its an unban, restore all their data
1575 let ban = !i.props.post_view.creator_banned_from_community;
1577 i.setState({ removeData: false });
1579 let form = new BanFromCommunity({
1580 person_id: i.props.post_view.creator.id,
1581 community_id: i.props.post_view.community.id,
1583 remove_data: Some(i.state.removeData),
1584 reason: i.state.banReason,
1585 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1586 auth: auth().unwrap(),
1588 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1590 // If its an unban, restore all their data
1591 let ban = !i.props.post_view.creator.banned;
1593 i.setState({ removeData: false });
1595 let form = new BanPerson({
1596 person_id: i.props.post_view.creator.id,
1598 remove_data: Some(i.state.removeData),
1599 reason: i.state.banReason,
1600 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1601 auth: auth().unwrap(),
1603 WebSocketService.Instance.send(wsClient.banPerson(form));
1606 i.setState({ showBanDialog: false });
1609 handleAddModToCommunity(i: PostListing) {
1610 let form = new AddModToCommunity({
1611 person_id: i.props.post_view.creator.id,
1612 community_id: i.props.post_view.community.id,
1613 added: !i.creatorIsMod_,
1614 auth: auth().unwrap(),
1616 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1617 i.setState(i.state);
1620 handleAddAdmin(i: PostListing) {
1621 let form = new AddAdmin({
1622 person_id: i.props.post_view.creator.id,
1623 added: !i.creatorIsAdmin_,
1624 auth: auth().unwrap(),
1626 WebSocketService.Instance.send(wsClient.addAdmin(form));
1627 i.setState(i.state);
1630 handleShowConfirmTransferCommunity(i: PostListing) {
1631 i.setState({ showConfirmTransferCommunity: true });
1634 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1635 i.setState({ showConfirmTransferCommunity: false });
1638 handleTransferCommunity(i: PostListing) {
1639 let form = new TransferCommunity({
1640 community_id: i.props.post_view.community.id,
1641 person_id: i.props.post_view.creator.id,
1642 auth: auth().unwrap(),
1644 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1645 i.setState({ showConfirmTransferCommunity: false });
1648 handleShowConfirmTransferSite(i: PostListing) {
1649 i.setState({ showConfirmTransferSite: true });
1652 handleCancelShowConfirmTransferSite(i: PostListing) {
1653 i.setState({ showConfirmTransferSite: false });
1656 handleImageExpandClick(i: PostListing, event: any) {
1657 event.preventDefault();
1658 i.setState({ imageExpanded: !i.state.imageExpanded });
1662 handleViewSource(i: PostListing) {
1663 i.setState({ viewSource: !i.state.viewSource });
1666 handleShowAdvanced(i: PostListing) {
1667 i.setState({ showAdvanced: !i.state.showAdvanced });
1671 handleShowMoreMobile(i: PostListing) {
1673 showMoreMobile: !i.state.showMoreMobile,
1674 showAdvanced: !i.state.showAdvanced,
1679 handleShowBody(i: PostListing) {
1680 i.setState({ showBody: !i.state.showBody });
1684 get pointsTippy(): string {
1685 let points = i18n.t("number_of_points", {
1686 count: this.state.score,
1687 formattedCount: this.state.score,
1690 let upvotes = i18n.t("number_of_upvotes", {
1691 count: this.state.upvotes,
1692 formattedCount: this.state.upvotes,
1695 let downvotes = i18n.t("number_of_downvotes", {
1696 count: this.state.downvotes,
1697 formattedCount: this.state.downvotes,
1700 return `${points} • ${upvotes} • ${downvotes}`;
1703 get canModOnSelf_(): boolean {
1705 this.props.moderators,
1707 this.props.post_view.creator.id,
1713 get canMod_(): boolean {
1715 this.props.moderators,
1717 this.props.post_view.creator.id
1721 get canAdmin_(): boolean {
1722 return canAdmin(this.props.admins, this.props.post_view.creator.id);
1725 get creatorIsMod_(): boolean {
1726 return isMod(this.props.moderators, this.props.post_view.creator.id);
1729 get creatorIsAdmin_(): boolean {
1730 return isAdmin(this.props.admins, this.props.post_view.creator.id);