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";
51 import { Icon, PurgeWarning, Spinner } from "../common/icon";
52 import { MomentTime } from "../common/moment-time";
53 import { PictrsImage } from "../common/pictrs-image";
54 import { CommunityLink } from "../community/community-link";
55 import { PersonListing } from "../person/person-listing";
56 import { MetadataCard } from "./metadata-card";
57 import { PostForm } from "./post-form";
59 interface PostListingState {
61 showRemoveDialog: boolean;
62 showPurgeDialog: boolean;
63 purgeReason: Option<string>;
65 purgeLoading: boolean;
66 removeReason: Option<string>;
67 showBanDialog: boolean;
68 banReason: Option<string>;
69 banExpireDays: Option<number>;
72 showConfirmTransferSite: boolean;
73 showConfirmTransferCommunity: boolean;
74 imageExpanded: boolean;
76 showAdvanced: boolean;
77 showMoreMobile: boolean;
79 showReportDialog: boolean;
80 reportReason: Option<string>;
81 my_vote: Option<number>;
87 interface PostListingProps {
89 duplicates: Option<PostView[]>;
90 moderators: Option<CommunityModeratorView[]>;
91 admins: Option<PersonViewSafe[]>;
92 allLanguages: Language[];
93 showCommunity?: boolean;
95 enableDownvotes?: boolean;
100 export class PostListing extends Component<PostListingProps, PostListingState> {
101 private emptyState: PostListingState = {
103 showRemoveDialog: false,
104 showPurgeDialog: false,
106 purgeType: PurgeType.Person,
109 showBanDialog: false,
112 banType: BanType.Community,
114 showConfirmTransferSite: false,
115 showConfirmTransferCommunity: false,
116 imageExpanded: false,
119 showMoreMobile: false,
121 showReportDialog: false,
123 my_vote: this.props.post_view.my_vote,
124 score: this.props.post_view.counts.score,
125 upvotes: this.props.post_view.counts.upvotes,
126 downvotes: this.props.post_view.counts.downvotes,
129 constructor(props: any, context: any) {
130 super(props, context);
132 this.state = this.emptyState;
133 this.handlePostLike = this.handlePostLike.bind(this);
134 this.handlePostDisLike = this.handlePostDisLike.bind(this);
135 this.handleEditPost = this.handleEditPost.bind(this);
136 this.handleEditCancel = this.handleEditCancel.bind(this);
139 componentWillReceiveProps(nextProps: PostListingProps) {
141 my_vote: nextProps.post_view.my_vote,
142 upvotes: nextProps.post_view.counts.upvotes,
143 downvotes: nextProps.post_view.counts.downvotes,
144 score: nextProps.post_view.counts.score,
146 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
147 this.setState({ imageExpanded: false });
152 let post = this.props.post_view.post;
154 <div className="post-listing">
155 {!this.state.showEdit ? (
158 {this.state.imageExpanded && this.img}
159 {post.url.isSome() &&
161 post.embed_title.isSome() && <MetadataCard post={post} />}
162 {this.showBody && this.body()}
165 <div className="col-12">
167 post_view={Some(this.props.post_view)}
170 onEdit={this.handleEditPost}
171 onCancel={this.handleEditCancel}
172 enableNsfw={this.props.enableNsfw}
173 enableDownvotes={this.props.enableDownvotes}
174 allLanguages={this.props.allLanguages}
183 return this.props.post_view.post.body.match({
185 <div className="col-12 card my-2 p-2">
186 {this.state.viewSource ? (
189 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
198 return this.imageSrc.match({
201 <div className="offset-sm-3 my-2 d-none d-sm-block">
202 <a href={src} className="d-inline-block">
203 <PictrsImage src={src} />
206 <div className="my-2 d-block d-sm-none">
208 className="d-inline-block"
209 onClick={linkEvent(this, this.handleImageExpandClick)}
211 <PictrsImage src={src} />
220 imgThumb(src: string) {
221 let post_view = this.props.post_view;
227 nsfw={post_view.post.nsfw || post_view.community.nsfw}
232 get imageSrc(): Option<string> {
233 let post = this.props.post_view.post;
235 let thumbnail = post.thumbnail_url;
237 if (url.isSome() && isImage(url.unwrap())) {
238 if (url.unwrap().includes("pictrs")) {
240 } else if (thumbnail.isSome()) {
245 } else if (thumbnail.isSome()) {
253 let post = this.props.post_view.post;
255 let thumbnail = post.thumbnail_url;
257 if (url.isSome() && isImage(url.unwrap())) {
260 href={this.imageSrc.unwrap()}
261 className="text-body d-inline-block position-relative mb-2"
262 data-tippy-content={i18n.t("expand_here")}
263 onClick={linkEvent(this, this.handleImageExpandClick)}
264 aria-label={i18n.t("expand_here")}
266 {this.imgThumb(this.imageSrc.unwrap())}
267 <Icon icon="image" classes="mini-overlay" />
270 } else if (url.isSome() && thumbnail.isSome()) {
273 className="text-body d-inline-block position-relative mb-2"
278 {this.imgThumb(this.imageSrc.unwrap())}
279 <Icon icon="external-link" classes="mini-overlay" />
282 } else if (url.isSome()) {
283 if (isVideo(url.unwrap())) {
285 <div className="embed-responsive embed-responsive-16by9">
291 className="embed-responsive-item"
293 <source src={url.unwrap()} type="video/mp4" />
300 className="text-body"
305 <div className="thumbnail rounded bg-light d-flex justify-content-center">
306 <Icon icon="external-link" classes="d-flex align-items-center" />
314 className="text-body"
315 to={`/post/${post.id}`}
316 title={i18n.t("comments")}
318 <div className="thumbnail rounded bg-light d-flex justify-content-center">
319 <Icon icon="message-square" classes="d-flex align-items-center" />
327 let post_view = this.props.post_view;
329 <ul className="list-inline mb-1 text-muted small">
330 <li className="list-inline-item">
331 <PersonListing person={post_view.creator} />
333 {this.creatorIsMod_ && (
334 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
336 {this.creatorIsAdmin_ && (
337 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
339 {post_view.creator.bot_account && (
340 <span className="mx-1 badge badge-light">
341 {i18n.t("bot_account").toLowerCase()}
344 {(post_view.creator_banned_from_community ||
345 isBanned(post_view.creator)) && (
346 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
348 {post_view.creator_blocked && (
349 <span className="mx-1 badge badge-danger">{"blocked"}</span>
351 {this.props.showCommunity && (
353 <span className="mx-1"> {i18n.t("to")} </span>
354 <CommunityLink community={post_view.community} />
358 <li className="list-inline-item">•</li>
359 {post_view.post.url.match({
361 !(hostname(url) == externalHost) && (
363 <li className="list-inline-item">
365 className="text-muted font-italic"
373 <li className="list-inline-item">•</li>
378 <li className="list-inline-item">
381 published={post_view.post.published}
382 updated={post_view.post.updated}
386 {post_view.post.body.match({
389 <li className="list-inline-item">•</li>
390 <li className="list-inline-item">
392 className="text-muted btn btn-sm btn-link p-0"
393 data-tippy-content={md.render(body)}
394 data-tippy-allowHtml={true}
395 onClick={linkEvent(this, this.handleShowBody)}
397 <Icon icon="book-open" classes="icon-inline mr-1" />
410 <div className={`vote-bar col-1 pr-0 small text-center`}>
412 className={`btn-animate btn btn-link p-0 ${
413 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
415 onClick={this.handlePostLike}
416 data-tippy-content={i18n.t("upvote")}
417 aria-label={i18n.t("upvote")}
419 <Icon icon="arrow-up1" classes="upvote" />
423 className={`unselectable pointer font-weight-bold text-muted px-1`}
424 data-tippy-content={this.pointsTippy}
426 {numToSI(this.state.score)}
429 <div className="p-1"></div>
431 {this.props.enableDownvotes && (
433 className={`btn-animate btn btn-link p-0 ${
434 this.state.my_vote.unwrapOr(0) == -1
438 onClick={this.handlePostDisLike}
439 data-tippy-content={i18n.t("downvote")}
440 aria-label={i18n.t("downvote")}
442 <Icon icon="arrow-down1" classes="downvote" />
450 let post = this.props.post_view.post;
452 <div className="post-title overflow-hidden">
457 className={!post.stickied ? "text-body" : "text-primary"}
467 className={!post.stickied ? "text-body" : "text-primary"}
468 to={`/post/${post.id}`}
469 title={i18n.t("comments")}
475 {post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
477 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
478 data-tippy-content={i18n.t("expand_here")}
479 onClick={linkEvent(this, this.handleImageExpandClick)}
483 !this.state.imageExpanded ? "plus-square" : "minus-square"
485 classes="icon-inline"
490 <small className="ml-2 text-muted font-italic">
496 className="unselectable pointer ml-2 text-muted font-italic"
497 data-tippy-content={i18n.t("deleted")}
499 <Icon icon="trash" classes="icon-inline text-danger" />
504 className="unselectable pointer ml-2 text-muted font-italic"
505 data-tippy-content={i18n.t("locked")}
507 <Icon icon="lock" classes="icon-inline text-danger" />
512 className="unselectable pointer ml-2 text-muted font-italic"
513 data-tippy-content={i18n.t("stickied")}
515 <Icon icon="pin" classes="icon-inline text-primary" />
519 <small className="ml-2 text-muted font-italic">
529 return this.props.duplicates.match({
531 dupes.length > 0 && (
532 <ul className="list-inline mb-1 small text-muted">
534 <li className="list-inline-item mr-2">
535 {i18n.t("cross_posted_to")}
538 <li key={pv.post.id} className="list-inline-item mr-2">
539 <Link to={`/post/${pv.post.id}`}>
542 : `${pv.community.name}@${hostname(
543 pv.community.actor_id
555 commentsLine(mobile = false) {
556 let post = this.props.post_view.post;
558 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
559 {this.commentsButton}
562 className="btn btn-link btn-animate text-muted py-0"
563 title={i18n.t("link")}
566 <Icon icon="fedilink" inline />
569 {mobile && !this.props.viewOnly && this.mobileVotes}
570 {UserService.Instance.myUserInfo.isSome() &&
571 !this.props.viewOnly &&
572 this.postActions(mobile)}
577 postActions(mobile = false) {
578 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
579 // Possible enhancement: Make each button a component.
580 let post_view = this.props.post_view;
584 {this.crossPostButton}
585 {mobile && this.showMoreButton}
586 {(!mobile || this.state.showAdvanced) && (
594 {this.myPost && (this.showBody || this.state.showAdvanced) && (
602 {this.state.showAdvanced && (
605 post_view.post.body.isSome() &&
606 this.viewSourceButton}
607 {this.canModOnSelf_ && (
613 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
616 {!mobile && this.showMoreButton}
621 get commentsButton() {
622 let post_view = this.props.post_view;
624 <button className="btn btn-link text-muted py-0 pl-0">
626 className="text-muted"
627 title={i18n.t("number_of_comments", {
628 count: post_view.counts.comments,
629 formattedCount: post_view.counts.comments,
631 to={`/post/${post_view.post.id}?scrollToComments=true`}
633 <Icon icon="message-square" classes="mr-1" inline />
634 <span className="mr-2">
635 {i18n.t("number_of_comments", {
636 count: post_view.counts.comments,
637 formattedCount: numToSI(post_view.counts.comments),
640 {this.unreadCount.match({
641 some: unreadCount => (
642 <span className="small text-warning">
643 ({unreadCount} {i18n.t("new")})
653 get unreadCount(): Option<number> {
654 let pv = this.props.post_view;
655 if (pv.unread_comments == pv.counts.comments || pv.unread_comments == 0) {
658 return Some(pv.unread_comments);
664 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
669 className={`btn-animate btn py-0 px-1 ${
670 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
673 onClick={this.handlePostLike}
674 aria-label={i18n.t("upvote")}
676 <Icon icon="arrow-up1" classes="icon-inline small" />
678 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
681 {this.props.enableDownvotes && (
683 className={`ml-2 btn-animate btn py-0 px-1 ${
684 this.state.my_vote.unwrapOr(0) == -1
688 onClick={this.handlePostDisLike}
690 aria-label={i18n.t("downvote")}
692 <Icon icon="arrow-down1" classes="icon-inline small" />
695 className={classNames("ml-2", {
696 invisible: this.state.downvotes === 0,
699 {numToSI(this.state.downvotes)}
710 let saved = this.props.post_view.saved;
711 let label = saved ? i18n.t("unsave") : i18n.t("save");
714 className="btn btn-link btn-animate text-muted py-0"
715 onClick={linkEvent(this, this.handleSavePostClick)}
716 data-tippy-content={label}
721 classes={classNames({ "text-warning": saved })}
728 get crossPostButton() {
731 className="btn btn-link btn-animate text-muted py-0"
732 to={`/create_post${this.crossPostParams}`}
733 title={i18n.t("cross_post")}
735 <Icon icon="copy" inline />
743 className="btn btn-link btn-animate text-muted py-0"
744 onClick={linkEvent(this, this.handleShowReportDialog)}
745 data-tippy-content={i18n.t("show_report_dialog")}
746 aria-label={i18n.t("show_report_dialog")}
748 <Icon icon="flag" inline />
756 className="btn btn-link btn-animate text-muted py-0"
757 onClick={linkEvent(this, this.handleBlockUserClick)}
758 data-tippy-content={i18n.t("block_user")}
759 aria-label={i18n.t("block_user")}
761 <Icon icon="slash" inline />
769 className="btn btn-link btn-animate text-muted py-0"
770 onClick={linkEvent(this, this.handleEditClick)}
771 data-tippy-content={i18n.t("edit")}
772 aria-label={i18n.t("edit")}
774 <Icon icon="edit" inline />
780 let deleted = this.props.post_view.post.deleted;
781 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
784 className="btn btn-link btn-animate text-muted py-0"
785 onClick={linkEvent(this, this.handleDeleteClick)}
786 data-tippy-content={label}
791 classes={classNames({ "text-danger": deleted })}
798 get showMoreButton() {
801 className="btn btn-link btn-animate text-muted py-0"
802 onClick={linkEvent(this, this.handleShowAdvanced)}
803 data-tippy-content={i18n.t("more")}
804 aria-label={i18n.t("more")}
806 <Icon icon="more-vertical" inline />
811 get viewSourceButton() {
814 className="btn btn-link btn-animate text-muted py-0"
815 onClick={linkEvent(this, this.handleViewSource)}
816 data-tippy-content={i18n.t("view_source")}
817 aria-label={i18n.t("view_source")}
821 classes={classNames({ "text-success": this.state.viewSource })}
829 let locked = this.props.post_view.post.locked;
830 let label = locked ? i18n.t("unlock") : i18n.t("lock");
833 className="btn btn-link btn-animate text-muted py-0"
834 onClick={linkEvent(this, this.handleModLock)}
835 data-tippy-content={label}
840 classes={classNames({ "text-danger": locked })}
848 let stickied = this.props.post_view.post.stickied;
849 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
852 className="btn btn-link btn-animate text-muted py-0"
853 onClick={linkEvent(this, this.handleModSticky)}
854 data-tippy-content={label}
859 classes={classNames({ "text-success": stickied })}
866 get modRemoveButton() {
867 let removed = this.props.post_view.post.removed;
870 className="btn btn-link btn-animate text-muted py-0"
873 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
876 {/* TODO: Find an icon for this. */}
877 {!removed ? i18n.t("remove") : i18n.t("restore")}
883 * Mod/Admin actions to be taken against the author.
887 let post_view = this.props.post_view;
889 this.state.showAdvanced && (
893 {!this.creatorIsMod_ &&
894 (!post_view.creator_banned_from_community ? (
896 className="btn btn-link btn-animate text-muted py-0"
899 this.handleModBanFromCommunityShow
901 aria-label={i18n.t("ban")}
907 className="btn btn-link btn-animate text-muted py-0"
910 this.handleModBanFromCommunitySubmit
912 aria-label={i18n.t("unban")}
917 {!post_view.creator_banned_from_community && (
919 className="btn btn-link btn-animate text-muted py-0"
920 onClick={linkEvent(this, this.handleAddModToCommunity)}
923 ? i18n.t("remove_as_mod")
924 : i18n.t("appoint_as_mod")
928 ? i18n.t("remove_as_mod")
929 : i18n.t("appoint_as_mod")}
934 {/* Community creators and admins can transfer community to another mod */}
935 {(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
937 this.creatorIsMod_ &&
938 (!this.state.showConfirmTransferCommunity ? (
940 className="btn btn-link btn-animate text-muted py-0"
943 this.handleShowConfirmTransferCommunity
945 aria-label={i18n.t("transfer_community")}
947 {i18n.t("transfer_community")}
952 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
953 aria-label={i18n.t("are_you_sure")}
955 {i18n.t("are_you_sure")}
958 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
959 aria-label={i18n.t("yes")}
960 onClick={linkEvent(this, this.handleTransferCommunity)}
965 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
968 this.handleCancelShowConfirmTransferCommunity
970 aria-label={i18n.t("no")}
976 {/* Admins can ban from all, and appoint other admins */}
979 {!this.creatorIsAdmin_ && (
981 {!isBanned(post_view.creator) ? (
983 className="btn btn-link btn-animate text-muted py-0"
984 onClick={linkEvent(this, this.handleModBanShow)}
985 aria-label={i18n.t("ban_from_site")}
987 {i18n.t("ban_from_site")}
991 className="btn btn-link btn-animate text-muted py-0"
992 onClick={linkEvent(this, this.handleModBanSubmit)}
993 aria-label={i18n.t("unban_from_site")}
995 {i18n.t("unban_from_site")}
999 className="btn btn-link btn-animate text-muted py-0"
1000 onClick={linkEvent(this, this.handlePurgePersonShow)}
1001 aria-label={i18n.t("purge_user")}
1003 {i18n.t("purge_user")}
1006 className="btn btn-link btn-animate text-muted py-0"
1007 onClick={linkEvent(this, this.handlePurgePostShow)}
1008 aria-label={i18n.t("purge_post")}
1010 {i18n.t("purge_post")}
1014 {!isBanned(post_view.creator) && post_view.creator.local && (
1016 className="btn btn-link btn-animate text-muted py-0"
1017 onClick={linkEvent(this, this.handleAddAdmin)}
1019 this.creatorIsAdmin_
1020 ? i18n.t("remove_as_admin")
1021 : i18n.t("appoint_as_admin")
1024 {this.creatorIsAdmin_
1025 ? i18n.t("remove_as_admin")
1026 : i18n.t("appoint_as_admin")}
1036 removeAndBanDialogs() {
1037 let post = this.props.post_view;
1038 let purgeTypeText: string;
1039 if (this.state.purgeType == PurgeType.Post) {
1040 purgeTypeText = i18n.t("purge_post");
1041 } else if (this.state.purgeType == PurgeType.Person) {
1042 purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
1046 {this.state.showRemoveDialog && (
1048 className="form-inline"
1049 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1051 <label className="sr-only" htmlFor="post-listing-remove-reason">
1056 id="post-listing-remove-reason"
1057 className="form-control mr-2"
1058 placeholder={i18n.t("reason")}
1059 value={toUndefined(this.state.removeReason)}
1060 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1064 className="btn btn-secondary"
1065 aria-label={i18n.t("remove_post")}
1067 {i18n.t("remove_post")}
1071 {this.state.showBanDialog && (
1072 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1073 <div className="form-group row col-12">
1075 className="col-form-label"
1076 htmlFor="post-listing-ban-reason"
1082 id="post-listing-ban-reason"
1083 className="form-control mr-2"
1084 placeholder={i18n.t("reason")}
1085 value={toUndefined(this.state.banReason)}
1086 onInput={linkEvent(this, this.handleModBanReasonChange)}
1088 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1093 id={`mod-ban-expires`}
1094 className="form-control mr-2"
1095 placeholder={i18n.t("number_of_days")}
1096 value={toUndefined(this.state.banExpireDays)}
1097 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1099 <div className="form-group">
1100 <div className="form-check">
1102 className="form-check-input"
1103 id="mod-ban-remove-data"
1105 checked={this.state.removeData}
1106 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1109 className="form-check-label"
1110 htmlFor="mod-ban-remove-data"
1111 title={i18n.t("remove_content_more")}
1113 {i18n.t("remove_content")}
1118 {/* TODO hold off on expires until later */}
1119 {/* <div class="form-group row"> */}
1120 {/* <label class="col-form-label">Expires</label> */}
1121 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1123 <div className="form-group row">
1126 className="btn btn-secondary"
1127 aria-label={i18n.t("ban")}
1129 {i18n.t("ban")} {post.creator.name}
1134 {this.state.showReportDialog && (
1136 className="form-inline"
1137 onSubmit={linkEvent(this, this.handleReportSubmit)}
1139 <label className="sr-only" htmlFor="post-report-reason">
1144 id="post-report-reason"
1145 className="form-control mr-2"
1146 placeholder={i18n.t("reason")}
1148 value={toUndefined(this.state.reportReason)}
1149 onInput={linkEvent(this, this.handleReportReasonChange)}
1153 className="btn btn-secondary"
1154 aria-label={i18n.t("create_report")}
1156 {i18n.t("create_report")}
1160 {this.state.showPurgeDialog && (
1162 className="form-inline"
1163 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1166 <label className="sr-only" htmlFor="purge-reason">
1172 className="form-control mr-2"
1173 placeholder={i18n.t("reason")}
1174 value={toUndefined(this.state.purgeReason)}
1175 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1177 {this.state.purgeLoading ? (
1182 className="btn btn-secondary"
1183 aria-label={purgeTypeText}
1195 let post = this.props.post_view.post;
1196 return post.thumbnail_url.isSome() ||
1197 post.url.map(isImage).unwrapOr(false) ? (
1198 <div className="row">
1199 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1200 {this.postTitleLine()}
1202 <div className="col-4">
1203 {/* Post body prev or thumbnail */}
1204 {!this.state.imageExpanded && this.thumbnail()}
1208 this.postTitleLine()
1212 showMobilePreview() {
1213 let post = this.props.post_view.post;
1217 some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
1226 {/* The mobile view*/}
1227 <div className="d-block d-sm-none">
1228 <div className="row">
1229 <div className="col-12">
1230 {this.createdLine()}
1232 {/* If it has a thumbnail, do a right aligned thumbnail */}
1233 {this.mobileThumbnail()}
1235 {/* Show a preview of the post body */}
1236 {this.showMobilePreview()}
1238 {this.commentsLine(true)}
1239 {this.userActionsLine()}
1240 {this.duplicatesLine()}
1241 {this.removeAndBanDialogs()}
1246 {/* The larger view*/}
1247 <div className="d-none d-sm-block">
1248 <div className="row">
1249 {!this.props.viewOnly && this.voteBar()}
1250 <div className="col-sm-2 pr-0">
1251 <div className="">{this.thumbnail()}</div>
1253 <div className="col-12 col-sm-9">
1254 <div className="row">
1255 <div className="col-12">
1256 {this.postTitleLine()}
1257 {this.createdLine()}
1258 {this.commentsLine()}
1259 {this.duplicatesLine()}
1260 {this.userActionsLine()}
1261 {this.removeAndBanDialogs()}
1271 private get myPost(): boolean {
1272 return UserService.Instance.myUserInfo.match({
1274 this.props.post_view.creator.id == mui.local_user_view.person.id,
1279 handlePostLike(event: any) {
1280 event.preventDefault();
1281 if (UserService.Instance.myUserInfo.isNone()) {
1282 this.context.router.history.push(`/login`);
1285 let myVote = this.state.my_vote.unwrapOr(0);
1286 let newVote = myVote == 1 ? 0 : 1;
1290 score: this.state.score - 1,
1291 upvotes: this.state.upvotes - 1,
1293 } else if (myVote == -1) {
1295 score: this.state.score + 2,
1296 upvotes: this.state.upvotes + 1,
1297 downvotes: this.state.downvotes - 1,
1301 score: this.state.score + 1,
1302 upvotes: this.state.upvotes + 1,
1306 this.setState({ my_vote: Some(newVote) });
1308 let form = new CreatePostLike({
1309 post_id: this.props.post_view.post.id,
1311 auth: auth().unwrap(),
1314 WebSocketService.Instance.send(wsClient.likePost(form));
1315 this.setState(this.state);
1319 handlePostDisLike(event: any) {
1320 event.preventDefault();
1321 if (UserService.Instance.myUserInfo.isNone()) {
1322 this.context.router.history.push(`/login`);
1325 let myVote = this.state.my_vote.unwrapOr(0);
1326 let newVote = myVote == -1 ? 0 : -1;
1330 score: this.state.score - 2,
1331 upvotes: this.state.upvotes - 1,
1332 downvotes: this.state.downvotes + 1,
1334 } else if (myVote == -1) {
1336 score: this.state.score + 1,
1337 downvotes: this.state.downvotes - 1,
1341 score: this.state.score - 1,
1342 downvotes: this.state.downvotes + 1,
1346 this.setState({ my_vote: Some(newVote) });
1348 let form = new CreatePostLike({
1349 post_id: this.props.post_view.post.id,
1351 auth: auth().unwrap(),
1354 WebSocketService.Instance.send(wsClient.likePost(form));
1355 this.setState(this.state);
1359 handleEditClick(i: PostListing) {
1360 i.setState({ showEdit: true });
1363 handleEditCancel() {
1364 this.setState({ showEdit: false });
1367 // The actual editing is done in the recieve for post
1369 this.setState({ showEdit: false });
1372 handleShowReportDialog(i: PostListing) {
1373 i.setState({ showReportDialog: !i.state.showReportDialog });
1376 handleReportReasonChange(i: PostListing, event: any) {
1377 i.setState({ reportReason: Some(event.target.value) });
1380 handleReportSubmit(i: PostListing, event: any) {
1381 event.preventDefault();
1382 let form = new CreatePostReport({
1383 post_id: i.props.post_view.post.id,
1384 reason: toUndefined(i.state.reportReason),
1385 auth: auth().unwrap(),
1387 WebSocketService.Instance.send(wsClient.createPostReport(form));
1389 i.setState({ showReportDialog: false });
1392 handleBlockUserClick(i: PostListing) {
1393 let blockUserForm = new BlockPerson({
1394 person_id: i.props.post_view.creator.id,
1396 auth: auth().unwrap(),
1398 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1401 handleDeleteClick(i: PostListing) {
1402 let deleteForm = new DeletePost({
1403 post_id: i.props.post_view.post.id,
1404 deleted: !i.props.post_view.post.deleted,
1405 auth: auth().unwrap(),
1407 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1410 handleSavePostClick(i: PostListing) {
1412 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1413 let form = new SavePost({
1414 post_id: i.props.post_view.post.id,
1416 auth: auth().unwrap(),
1419 WebSocketService.Instance.send(wsClient.savePost(form));
1422 get crossPostParams(): string {
1423 let post = this.props.post_view.post;
1424 let params = `?title=${encodeURIComponent(post.name)}`;
1426 if (post.url.isSome()) {
1427 params += `&url=${encodeURIComponent(post.url.unwrap())}`;
1429 if (post.body.isSome()) {
1430 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1435 crossPostBody(): string {
1436 let post = this.props.post_view.post;
1437 let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
1439 .replace(/^/gm, "> ")}`;
1443 get showBody(): boolean {
1444 return this.props.showBody || this.state.showBody;
1447 handleModRemoveShow(i: PostListing) {
1449 showRemoveDialog: !i.state.showRemoveDialog,
1450 showBanDialog: false,
1454 handleModRemoveReasonChange(i: PostListing, event: any) {
1455 i.setState({ removeReason: Some(event.target.value) });
1458 handleModRemoveDataChange(i: PostListing, event: any) {
1459 i.setState({ removeData: event.target.checked });
1462 handleModRemoveSubmit(i: PostListing, event: any) {
1463 event.preventDefault();
1464 let form = new RemovePost({
1465 post_id: i.props.post_view.post.id,
1466 removed: !i.props.post_view.post.removed,
1467 reason: i.state.removeReason,
1468 auth: auth().unwrap(),
1470 WebSocketService.Instance.send(wsClient.removePost(form));
1472 i.setState({ showRemoveDialog: false });
1475 handleModLock(i: PostListing) {
1476 let form = new LockPost({
1477 post_id: i.props.post_view.post.id,
1478 locked: !i.props.post_view.post.locked,
1479 auth: auth().unwrap(),
1481 WebSocketService.Instance.send(wsClient.lockPost(form));
1484 handleModSticky(i: PostListing) {
1485 let form = new StickyPost({
1486 post_id: i.props.post_view.post.id,
1487 stickied: !i.props.post_view.post.stickied,
1488 auth: auth().unwrap(),
1490 WebSocketService.Instance.send(wsClient.stickyPost(form));
1493 handleModBanFromCommunityShow(i: PostListing) {
1495 showBanDialog: true,
1496 banType: BanType.Community,
1497 showRemoveDialog: false,
1501 handleModBanShow(i: PostListing) {
1503 showBanDialog: true,
1504 banType: BanType.Site,
1505 showRemoveDialog: false,
1509 handlePurgePersonShow(i: PostListing) {
1511 showPurgeDialog: true,
1512 purgeType: PurgeType.Person,
1513 showRemoveDialog: false,
1517 handlePurgePostShow(i: PostListing) {
1519 showPurgeDialog: true,
1520 purgeType: PurgeType.Post,
1521 showRemoveDialog: false,
1525 handlePurgeReasonChange(i: PostListing, event: any) {
1526 i.setState({ purgeReason: Some(event.target.value) });
1529 handlePurgeSubmit(i: PostListing, event: any) {
1530 event.preventDefault();
1532 if (i.state.purgeType == PurgeType.Person) {
1533 let form = new PurgePerson({
1534 person_id: i.props.post_view.creator.id,
1535 reason: i.state.purgeReason,
1536 auth: auth().unwrap(),
1538 WebSocketService.Instance.send(wsClient.purgePerson(form));
1539 } else if (i.state.purgeType == PurgeType.Post) {
1540 let form = new PurgePost({
1541 post_id: i.props.post_view.post.id,
1542 reason: i.state.purgeReason,
1543 auth: auth().unwrap(),
1545 WebSocketService.Instance.send(wsClient.purgePost(form));
1548 i.setState({ purgeLoading: true });
1551 handleModBanReasonChange(i: PostListing, event: any) {
1552 i.setState({ banReason: Some(event.target.value) });
1555 handleModBanExpireDaysChange(i: PostListing, event: any) {
1556 i.setState({ banExpireDays: Some(event.target.value) });
1559 handleModBanFromCommunitySubmit(i: PostListing) {
1560 i.setState({ banType: BanType.Community });
1561 i.handleModBanBothSubmit(i);
1564 handleModBanSubmit(i: PostListing) {
1565 i.setState({ banType: BanType.Site });
1566 i.handleModBanBothSubmit(i);
1569 handleModBanBothSubmit(i: PostListing, event?: any) {
1570 if (event) event.preventDefault();
1572 if (i.state.banType == BanType.Community) {
1573 // If its an unban, restore all their data
1574 let ban = !i.props.post_view.creator_banned_from_community;
1576 i.setState({ removeData: false });
1578 let form = new BanFromCommunity({
1579 person_id: i.props.post_view.creator.id,
1580 community_id: i.props.post_view.community.id,
1582 remove_data: Some(i.state.removeData),
1583 reason: i.state.banReason,
1584 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1585 auth: auth().unwrap(),
1587 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1589 // If its an unban, restore all their data
1590 let ban = !i.props.post_view.creator.banned;
1592 i.setState({ removeData: false });
1594 let form = new BanPerson({
1595 person_id: i.props.post_view.creator.id,
1597 remove_data: Some(i.state.removeData),
1598 reason: i.state.banReason,
1599 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1600 auth: auth().unwrap(),
1602 WebSocketService.Instance.send(wsClient.banPerson(form));
1605 i.setState({ showBanDialog: false });
1608 handleAddModToCommunity(i: PostListing) {
1609 let form = new AddModToCommunity({
1610 person_id: i.props.post_view.creator.id,
1611 community_id: i.props.post_view.community.id,
1612 added: !i.creatorIsMod_,
1613 auth: auth().unwrap(),
1615 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1616 i.setState(i.state);
1619 handleAddAdmin(i: PostListing) {
1620 let form = new AddAdmin({
1621 person_id: i.props.post_view.creator.id,
1622 added: !i.creatorIsAdmin_,
1623 auth: auth().unwrap(),
1625 WebSocketService.Instance.send(wsClient.addAdmin(form));
1626 i.setState(i.state);
1629 handleShowConfirmTransferCommunity(i: PostListing) {
1630 i.setState({ showConfirmTransferCommunity: true });
1633 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1634 i.setState({ showConfirmTransferCommunity: false });
1637 handleTransferCommunity(i: PostListing) {
1638 let form = new TransferCommunity({
1639 community_id: i.props.post_view.community.id,
1640 person_id: i.props.post_view.creator.id,
1641 auth: auth().unwrap(),
1643 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1644 i.setState({ showConfirmTransferCommunity: false });
1647 handleShowConfirmTransferSite(i: PostListing) {
1648 i.setState({ showConfirmTransferSite: true });
1651 handleCancelShowConfirmTransferSite(i: PostListing) {
1652 i.setState({ showConfirmTransferSite: false });
1655 handleImageExpandClick(i: PostListing, event: any) {
1656 event.preventDefault();
1657 i.setState({ imageExpanded: !i.state.imageExpanded });
1661 handleViewSource(i: PostListing) {
1662 i.setState({ viewSource: !i.state.viewSource });
1665 handleShowAdvanced(i: PostListing) {
1666 i.setState({ showAdvanced: !i.state.showAdvanced });
1670 handleShowMoreMobile(i: PostListing) {
1672 showMoreMobile: !i.state.showMoreMobile,
1673 showAdvanced: !i.state.showAdvanced,
1678 handleShowBody(i: PostListing) {
1679 i.setState({ showBody: !i.state.showBody });
1683 get pointsTippy(): string {
1684 let points = i18n.t("number_of_points", {
1685 count: this.state.score,
1686 formattedCount: this.state.score,
1689 let upvotes = i18n.t("number_of_upvotes", {
1690 count: this.state.upvotes,
1691 formattedCount: this.state.upvotes,
1694 let downvotes = i18n.t("number_of_downvotes", {
1695 count: this.state.downvotes,
1696 formattedCount: this.state.downvotes,
1699 return `${points} • ${upvotes} • ${downvotes}`;
1702 get canModOnSelf_(): boolean {
1704 this.props.moderators,
1706 this.props.post_view.creator.id,
1712 get canMod_(): boolean {
1714 this.props.moderators,
1716 this.props.post_view.creator.id
1720 get canAdmin_(): boolean {
1721 return canAdmin(this.props.admins, this.props.post_view.creator.id);
1724 get creatorIsMod_(): boolean {
1725 return isMod(this.props.moderators, this.props.post_view.creator.id);
1728 get creatorIsAdmin_(): boolean {
1729 return isAdmin(this.props.admins, this.props.post_view.creator.id);