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={md.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;
454 <div className="post-title overflow-hidden">
459 className={!post.stickied ? "text-body" : "text-primary"}
464 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
469 className={!post.stickied ? "text-body" : "text-primary"}
470 to={`/post/${post.id}`}
471 title={i18n.t("comments")}
473 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
477 {post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
479 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
480 data-tippy-content={i18n.t("expand_here")}
481 onClick={linkEvent(this, this.handleImageExpandClick)}
485 !this.state.imageExpanded ? "plus-square" : "minus-square"
487 classes="icon-inline"
492 <small className="ml-2 text-muted font-italic">
498 className="unselectable pointer ml-2 text-muted font-italic"
499 data-tippy-content={i18n.t("deleted")}
501 <Icon icon="trash" classes="icon-inline text-danger" />
506 className="unselectable pointer ml-2 text-muted font-italic"
507 data-tippy-content={i18n.t("locked")}
509 <Icon icon="lock" classes="icon-inline text-danger" />
514 className="unselectable pointer ml-2 text-muted font-italic"
515 data-tippy-content={i18n.t("stickied")}
517 <Icon icon="pin" classes="icon-inline text-primary" />
521 <small className="ml-2 text-muted font-italic">
531 return this.props.duplicates.match({
533 dupes.length > 0 && (
534 <ul className="list-inline mb-1 small text-muted">
536 <li className="list-inline-item mr-2">
537 {i18n.t("cross_posted_to")}
540 <li key={pv.post.id} className="list-inline-item mr-2">
541 <Link to={`/post/${pv.post.id}`}>
544 : `${pv.community.name}@${hostname(
545 pv.community.actor_id
557 commentsLine(mobile = false) {
558 let post = this.props.post_view.post;
560 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
561 {this.commentsButton}
564 className="btn btn-link btn-animate text-muted py-0"
565 title={i18n.t("link")}
568 <Icon icon="fedilink" inline />
571 {mobile && !this.props.viewOnly && this.mobileVotes}
572 {UserService.Instance.myUserInfo.isSome() &&
573 !this.props.viewOnly &&
574 this.postActions(mobile)}
579 postActions(mobile = false) {
580 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
581 // Possible enhancement: Make each button a component.
582 let post_view = this.props.post_view;
586 {this.crossPostButton}
587 {mobile && this.showMoreButton}
588 {(!mobile || this.state.showAdvanced) && (
596 {this.myPost && (this.showBody || this.state.showAdvanced) && (
604 {this.state.showAdvanced && (
607 post_view.post.body.isSome() &&
608 this.viewSourceButton}
609 {this.canModOnSelf_ && (
615 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
618 {!mobile && this.showMoreButton}
623 get commentsButton() {
624 let post_view = this.props.post_view;
626 <button className="btn btn-link text-muted py-0 pl-0">
628 className="text-muted"
629 title={i18n.t("number_of_comments", {
630 count: post_view.counts.comments,
631 formattedCount: post_view.counts.comments,
633 to={`/post/${post_view.post.id}?scrollToComments=true`}
635 <Icon icon="message-square" classes="mr-1" inline />
636 <span className="mr-2">
637 {i18n.t("number_of_comments", {
638 count: post_view.counts.comments,
639 formattedCount: numToSI(post_view.counts.comments),
642 {this.unreadCount.match({
643 some: unreadCount => (
644 <span className="small text-warning">
645 ({unreadCount} {i18n.t("new")})
655 get unreadCount(): Option<number> {
656 let pv = this.props.post_view;
657 if (pv.unread_comments == pv.counts.comments || pv.unread_comments == 0) {
660 return Some(pv.unread_comments);
666 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
671 className={`btn-animate btn py-0 px-1 ${
672 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
675 onClick={this.handlePostLike}
676 aria-label={i18n.t("upvote")}
678 <Icon icon="arrow-up1" classes="icon-inline small" />
680 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
683 {this.props.enableDownvotes && (
685 className={`ml-2 btn-animate btn py-0 px-1 ${
686 this.state.my_vote.unwrapOr(0) == -1
690 onClick={this.handlePostDisLike}
692 aria-label={i18n.t("downvote")}
694 <Icon icon="arrow-down1" classes="icon-inline small" />
697 className={classNames("ml-2", {
698 invisible: this.state.downvotes === 0,
701 {numToSI(this.state.downvotes)}
712 let saved = this.props.post_view.saved;
713 let label = saved ? i18n.t("unsave") : i18n.t("save");
716 className="btn btn-link btn-animate text-muted py-0"
717 onClick={linkEvent(this, this.handleSavePostClick)}
718 data-tippy-content={label}
723 classes={classNames({ "text-warning": saved })}
730 get crossPostButton() {
733 className="btn btn-link btn-animate text-muted py-0"
734 to={`/create_post${this.crossPostParams}`}
735 title={i18n.t("cross_post")}
737 <Icon icon="copy" inline />
745 className="btn btn-link btn-animate text-muted py-0"
746 onClick={linkEvent(this, this.handleShowReportDialog)}
747 data-tippy-content={i18n.t("show_report_dialog")}
748 aria-label={i18n.t("show_report_dialog")}
750 <Icon icon="flag" inline />
758 className="btn btn-link btn-animate text-muted py-0"
759 onClick={linkEvent(this, this.handleBlockUserClick)}
760 data-tippy-content={i18n.t("block_user")}
761 aria-label={i18n.t("block_user")}
763 <Icon icon="slash" inline />
771 className="btn btn-link btn-animate text-muted py-0"
772 onClick={linkEvent(this, this.handleEditClick)}
773 data-tippy-content={i18n.t("edit")}
774 aria-label={i18n.t("edit")}
776 <Icon icon="edit" inline />
782 let deleted = this.props.post_view.post.deleted;
783 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
786 className="btn btn-link btn-animate text-muted py-0"
787 onClick={linkEvent(this, this.handleDeleteClick)}
788 data-tippy-content={label}
793 classes={classNames({ "text-danger": deleted })}
800 get showMoreButton() {
803 className="btn btn-link btn-animate text-muted py-0"
804 onClick={linkEvent(this, this.handleShowAdvanced)}
805 data-tippy-content={i18n.t("more")}
806 aria-label={i18n.t("more")}
808 <Icon icon="more-vertical" inline />
813 get viewSourceButton() {
816 className="btn btn-link btn-animate text-muted py-0"
817 onClick={linkEvent(this, this.handleViewSource)}
818 data-tippy-content={i18n.t("view_source")}
819 aria-label={i18n.t("view_source")}
823 classes={classNames({ "text-success": this.state.viewSource })}
831 let locked = this.props.post_view.post.locked;
832 let label = locked ? i18n.t("unlock") : i18n.t("lock");
835 className="btn btn-link btn-animate text-muted py-0"
836 onClick={linkEvent(this, this.handleModLock)}
837 data-tippy-content={label}
842 classes={classNames({ "text-danger": locked })}
850 let stickied = this.props.post_view.post.stickied;
851 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
854 className="btn btn-link btn-animate text-muted py-0"
855 onClick={linkEvent(this, this.handleModSticky)}
856 data-tippy-content={label}
861 classes={classNames({ "text-success": stickied })}
868 get modRemoveButton() {
869 let removed = this.props.post_view.post.removed;
872 className="btn btn-link btn-animate text-muted py-0"
875 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
878 {/* TODO: Find an icon for this. */}
879 {!removed ? i18n.t("remove") : i18n.t("restore")}
885 * Mod/Admin actions to be taken against the author.
889 let post_view = this.props.post_view;
891 this.state.showAdvanced && (
895 {!this.creatorIsMod_ &&
896 (!post_view.creator_banned_from_community ? (
898 className="btn btn-link btn-animate text-muted py-0"
901 this.handleModBanFromCommunityShow
903 aria-label={i18n.t("ban")}
909 className="btn btn-link btn-animate text-muted py-0"
912 this.handleModBanFromCommunitySubmit
914 aria-label={i18n.t("unban")}
919 {!post_view.creator_banned_from_community && (
921 className="btn btn-link btn-animate text-muted py-0"
922 onClick={linkEvent(this, this.handleAddModToCommunity)}
925 ? i18n.t("remove_as_mod")
926 : i18n.t("appoint_as_mod")
930 ? i18n.t("remove_as_mod")
931 : i18n.t("appoint_as_mod")}
936 {/* Community creators and admins can transfer community to another mod */}
937 {(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
939 this.creatorIsMod_ &&
940 (!this.state.showConfirmTransferCommunity ? (
942 className="btn btn-link btn-animate text-muted py-0"
945 this.handleShowConfirmTransferCommunity
947 aria-label={i18n.t("transfer_community")}
949 {i18n.t("transfer_community")}
954 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
955 aria-label={i18n.t("are_you_sure")}
957 {i18n.t("are_you_sure")}
960 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
961 aria-label={i18n.t("yes")}
962 onClick={linkEvent(this, this.handleTransferCommunity)}
967 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
970 this.handleCancelShowConfirmTransferCommunity
972 aria-label={i18n.t("no")}
978 {/* Admins can ban from all, and appoint other admins */}
981 {!this.creatorIsAdmin_ && (
983 {!isBanned(post_view.creator) ? (
985 className="btn btn-link btn-animate text-muted py-0"
986 onClick={linkEvent(this, this.handleModBanShow)}
987 aria-label={i18n.t("ban_from_site")}
989 {i18n.t("ban_from_site")}
993 className="btn btn-link btn-animate text-muted py-0"
994 onClick={linkEvent(this, this.handleModBanSubmit)}
995 aria-label={i18n.t("unban_from_site")}
997 {i18n.t("unban_from_site")}
1001 className="btn btn-link btn-animate text-muted py-0"
1002 onClick={linkEvent(this, this.handlePurgePersonShow)}
1003 aria-label={i18n.t("purge_user")}
1005 {i18n.t("purge_user")}
1008 className="btn btn-link btn-animate text-muted py-0"
1009 onClick={linkEvent(this, this.handlePurgePostShow)}
1010 aria-label={i18n.t("purge_post")}
1012 {i18n.t("purge_post")}
1016 {!isBanned(post_view.creator) && post_view.creator.local && (
1018 className="btn btn-link btn-animate text-muted py-0"
1019 onClick={linkEvent(this, this.handleAddAdmin)}
1021 this.creatorIsAdmin_
1022 ? i18n.t("remove_as_admin")
1023 : i18n.t("appoint_as_admin")
1026 {this.creatorIsAdmin_
1027 ? i18n.t("remove_as_admin")
1028 : i18n.t("appoint_as_admin")}
1038 removeAndBanDialogs() {
1039 let post = this.props.post_view;
1040 let purgeTypeText: string;
1041 if (this.state.purgeType == PurgeType.Post) {
1042 purgeTypeText = i18n.t("purge_post");
1043 } else if (this.state.purgeType == PurgeType.Person) {
1044 purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
1048 {this.state.showRemoveDialog && (
1050 className="form-inline"
1051 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1053 <label className="sr-only" htmlFor="post-listing-remove-reason">
1058 id="post-listing-remove-reason"
1059 className="form-control mr-2"
1060 placeholder={i18n.t("reason")}
1061 value={toUndefined(this.state.removeReason)}
1062 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1066 className="btn btn-secondary"
1067 aria-label={i18n.t("remove_post")}
1069 {i18n.t("remove_post")}
1073 {this.state.showBanDialog && (
1074 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1075 <div className="form-group row col-12">
1077 className="col-form-label"
1078 htmlFor="post-listing-ban-reason"
1084 id="post-listing-ban-reason"
1085 className="form-control mr-2"
1086 placeholder={i18n.t("reason")}
1087 value={toUndefined(this.state.banReason)}
1088 onInput={linkEvent(this, this.handleModBanReasonChange)}
1090 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1095 id={`mod-ban-expires`}
1096 className="form-control mr-2"
1097 placeholder={i18n.t("number_of_days")}
1098 value={toUndefined(this.state.banExpireDays)}
1099 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1101 <div className="form-group">
1102 <div className="form-check">
1104 className="form-check-input"
1105 id="mod-ban-remove-data"
1107 checked={this.state.removeData}
1108 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1111 className="form-check-label"
1112 htmlFor="mod-ban-remove-data"
1113 title={i18n.t("remove_content_more")}
1115 {i18n.t("remove_content")}
1120 {/* TODO hold off on expires until later */}
1121 {/* <div class="form-group row"> */}
1122 {/* <label class="col-form-label">Expires</label> */}
1123 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1125 <div className="form-group row">
1128 className="btn btn-secondary"
1129 aria-label={i18n.t("ban")}
1131 {i18n.t("ban")} {post.creator.name}
1136 {this.state.showReportDialog && (
1138 className="form-inline"
1139 onSubmit={linkEvent(this, this.handleReportSubmit)}
1141 <label className="sr-only" htmlFor="post-report-reason">
1146 id="post-report-reason"
1147 className="form-control mr-2"
1148 placeholder={i18n.t("reason")}
1150 value={toUndefined(this.state.reportReason)}
1151 onInput={linkEvent(this, this.handleReportReasonChange)}
1155 className="btn btn-secondary"
1156 aria-label={i18n.t("create_report")}
1158 {i18n.t("create_report")}
1162 {this.state.showPurgeDialog && (
1164 className="form-inline"
1165 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1168 <label className="sr-only" htmlFor="purge-reason">
1174 className="form-control mr-2"
1175 placeholder={i18n.t("reason")}
1176 value={toUndefined(this.state.purgeReason)}
1177 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1179 {this.state.purgeLoading ? (
1184 className="btn btn-secondary"
1185 aria-label={purgeTypeText}
1197 let post = this.props.post_view.post;
1198 return post.thumbnail_url.isSome() ||
1199 post.url.map(isImage).unwrapOr(false) ? (
1200 <div className="row">
1201 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1202 {this.postTitleLine()}
1204 <div className="col-4">
1205 {/* Post body prev or thumbnail */}
1206 {!this.state.imageExpanded && this.thumbnail()}
1210 this.postTitleLine()
1214 showMobilePreview() {
1215 let post = this.props.post_view.post;
1219 some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
1228 {/* The mobile view*/}
1229 <div className="d-block d-sm-none">
1230 <div className="row">
1231 <div className="col-12">
1232 {this.createdLine()}
1234 {/* If it has a thumbnail, do a right aligned thumbnail */}
1235 {this.mobileThumbnail()}
1237 {/* Show a preview of the post body */}
1238 {this.showMobilePreview()}
1240 {this.commentsLine(true)}
1241 {this.userActionsLine()}
1242 {this.duplicatesLine()}
1243 {this.removeAndBanDialogs()}
1248 {/* The larger view*/}
1249 <div className="d-none d-sm-block">
1250 <div className="row">
1251 {!this.props.viewOnly && this.voteBar()}
1252 <div className="col-sm-2 pr-0">
1253 <div className="">{this.thumbnail()}</div>
1255 <div className="col-12 col-sm-9">
1256 <div className="row">
1257 <div className="col-12">
1258 {this.postTitleLine()}
1259 {this.createdLine()}
1260 {this.commentsLine()}
1261 {this.duplicatesLine()}
1262 {this.userActionsLine()}
1263 {this.removeAndBanDialogs()}
1273 private get myPost(): boolean {
1274 return UserService.Instance.myUserInfo.match({
1276 this.props.post_view.creator.id == mui.local_user_view.person.id,
1281 handlePostLike(event: any) {
1282 event.preventDefault();
1283 if (UserService.Instance.myUserInfo.isNone()) {
1284 this.context.router.history.push(`/login`);
1287 let myVote = this.state.my_vote.unwrapOr(0);
1288 let newVote = myVote == 1 ? 0 : 1;
1292 score: this.state.score - 1,
1293 upvotes: this.state.upvotes - 1,
1295 } else if (myVote == -1) {
1297 score: this.state.score + 2,
1298 upvotes: this.state.upvotes + 1,
1299 downvotes: this.state.downvotes - 1,
1303 score: this.state.score + 1,
1304 upvotes: this.state.upvotes + 1,
1308 this.setState({ my_vote: Some(newVote) });
1310 let form = new CreatePostLike({
1311 post_id: this.props.post_view.post.id,
1313 auth: auth().unwrap(),
1316 WebSocketService.Instance.send(wsClient.likePost(form));
1317 this.setState(this.state);
1321 handlePostDisLike(event: any) {
1322 event.preventDefault();
1323 if (UserService.Instance.myUserInfo.isNone()) {
1324 this.context.router.history.push(`/login`);
1327 let myVote = this.state.my_vote.unwrapOr(0);
1328 let newVote = myVote == -1 ? 0 : -1;
1332 score: this.state.score - 2,
1333 upvotes: this.state.upvotes - 1,
1334 downvotes: this.state.downvotes + 1,
1336 } else if (myVote == -1) {
1338 score: this.state.score + 1,
1339 downvotes: this.state.downvotes - 1,
1343 score: this.state.score - 1,
1344 downvotes: this.state.downvotes + 1,
1348 this.setState({ my_vote: Some(newVote) });
1350 let form = new CreatePostLike({
1351 post_id: this.props.post_view.post.id,
1353 auth: auth().unwrap(),
1356 WebSocketService.Instance.send(wsClient.likePost(form));
1357 this.setState(this.state);
1361 handleEditClick(i: PostListing) {
1362 i.setState({ showEdit: true });
1365 handleEditCancel() {
1366 this.setState({ showEdit: false });
1369 // The actual editing is done in the recieve for post
1371 this.setState({ showEdit: false });
1374 handleShowReportDialog(i: PostListing) {
1375 i.setState({ showReportDialog: !i.state.showReportDialog });
1378 handleReportReasonChange(i: PostListing, event: any) {
1379 i.setState({ reportReason: Some(event.target.value) });
1382 handleReportSubmit(i: PostListing, event: any) {
1383 event.preventDefault();
1384 let form = new CreatePostReport({
1385 post_id: i.props.post_view.post.id,
1386 reason: toUndefined(i.state.reportReason),
1387 auth: auth().unwrap(),
1389 WebSocketService.Instance.send(wsClient.createPostReport(form));
1391 i.setState({ showReportDialog: false });
1394 handleBlockUserClick(i: PostListing) {
1395 let blockUserForm = new BlockPerson({
1396 person_id: i.props.post_view.creator.id,
1398 auth: auth().unwrap(),
1400 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1403 handleDeleteClick(i: PostListing) {
1404 let deleteForm = new DeletePost({
1405 post_id: i.props.post_view.post.id,
1406 deleted: !i.props.post_view.post.deleted,
1407 auth: auth().unwrap(),
1409 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1412 handleSavePostClick(i: PostListing) {
1414 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1415 let form = new SavePost({
1416 post_id: i.props.post_view.post.id,
1418 auth: auth().unwrap(),
1421 WebSocketService.Instance.send(wsClient.savePost(form));
1424 get crossPostParams(): string {
1425 let post = this.props.post_view.post;
1426 let params = `?title=${encodeURIComponent(post.name)}`;
1428 if (post.url.isSome()) {
1429 params += `&url=${encodeURIComponent(post.url.unwrap())}`;
1431 if (post.body.isSome()) {
1432 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1437 crossPostBody(): string {
1438 let post = this.props.post_view.post;
1439 let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
1441 .replace(/^/gm, "> ")}`;
1445 get showBody(): boolean {
1446 return this.props.showBody || this.state.showBody;
1449 handleModRemoveShow(i: PostListing) {
1451 showRemoveDialog: !i.state.showRemoveDialog,
1452 showBanDialog: false,
1456 handleModRemoveReasonChange(i: PostListing, event: any) {
1457 i.setState({ removeReason: Some(event.target.value) });
1460 handleModRemoveDataChange(i: PostListing, event: any) {
1461 i.setState({ removeData: event.target.checked });
1464 handleModRemoveSubmit(i: PostListing, event: any) {
1465 event.preventDefault();
1466 let form = new RemovePost({
1467 post_id: i.props.post_view.post.id,
1468 removed: !i.props.post_view.post.removed,
1469 reason: i.state.removeReason,
1470 auth: auth().unwrap(),
1472 WebSocketService.Instance.send(wsClient.removePost(form));
1474 i.setState({ showRemoveDialog: false });
1477 handleModLock(i: PostListing) {
1478 let form = new LockPost({
1479 post_id: i.props.post_view.post.id,
1480 locked: !i.props.post_view.post.locked,
1481 auth: auth().unwrap(),
1483 WebSocketService.Instance.send(wsClient.lockPost(form));
1486 handleModSticky(i: PostListing) {
1487 let form = new StickyPost({
1488 post_id: i.props.post_view.post.id,
1489 stickied: !i.props.post_view.post.stickied,
1490 auth: auth().unwrap(),
1492 WebSocketService.Instance.send(wsClient.stickyPost(form));
1495 handleModBanFromCommunityShow(i: PostListing) {
1497 showBanDialog: true,
1498 banType: BanType.Community,
1499 showRemoveDialog: false,
1503 handleModBanShow(i: PostListing) {
1505 showBanDialog: true,
1506 banType: BanType.Site,
1507 showRemoveDialog: false,
1511 handlePurgePersonShow(i: PostListing) {
1513 showPurgeDialog: true,
1514 purgeType: PurgeType.Person,
1515 showRemoveDialog: false,
1519 handlePurgePostShow(i: PostListing) {
1521 showPurgeDialog: true,
1522 purgeType: PurgeType.Post,
1523 showRemoveDialog: false,
1527 handlePurgeReasonChange(i: PostListing, event: any) {
1528 i.setState({ purgeReason: Some(event.target.value) });
1531 handlePurgeSubmit(i: PostListing, event: any) {
1532 event.preventDefault();
1534 if (i.state.purgeType == PurgeType.Person) {
1535 let form = new PurgePerson({
1536 person_id: i.props.post_view.creator.id,
1537 reason: i.state.purgeReason,
1538 auth: auth().unwrap(),
1540 WebSocketService.Instance.send(wsClient.purgePerson(form));
1541 } else if (i.state.purgeType == PurgeType.Post) {
1542 let form = new PurgePost({
1543 post_id: i.props.post_view.post.id,
1544 reason: i.state.purgeReason,
1545 auth: auth().unwrap(),
1547 WebSocketService.Instance.send(wsClient.purgePost(form));
1550 i.setState({ purgeLoading: true });
1553 handleModBanReasonChange(i: PostListing, event: any) {
1554 i.setState({ banReason: Some(event.target.value) });
1557 handleModBanExpireDaysChange(i: PostListing, event: any) {
1558 i.setState({ banExpireDays: Some(event.target.value) });
1561 handleModBanFromCommunitySubmit(i: PostListing) {
1562 i.setState({ banType: BanType.Community });
1563 i.handleModBanBothSubmit(i);
1566 handleModBanSubmit(i: PostListing) {
1567 i.setState({ banType: BanType.Site });
1568 i.handleModBanBothSubmit(i);
1571 handleModBanBothSubmit(i: PostListing, event?: any) {
1572 if (event) event.preventDefault();
1574 if (i.state.banType == BanType.Community) {
1575 // If its an unban, restore all their data
1576 let ban = !i.props.post_view.creator_banned_from_community;
1578 i.setState({ removeData: false });
1580 let form = new BanFromCommunity({
1581 person_id: i.props.post_view.creator.id,
1582 community_id: i.props.post_view.community.id,
1584 remove_data: Some(i.state.removeData),
1585 reason: i.state.banReason,
1586 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1587 auth: auth().unwrap(),
1589 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1591 // If its an unban, restore all their data
1592 let ban = !i.props.post_view.creator.banned;
1594 i.setState({ removeData: false });
1596 let form = new BanPerson({
1597 person_id: i.props.post_view.creator.id,
1599 remove_data: Some(i.state.removeData),
1600 reason: i.state.banReason,
1601 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1602 auth: auth().unwrap(),
1604 WebSocketService.Instance.send(wsClient.banPerson(form));
1607 i.setState({ showBanDialog: false });
1610 handleAddModToCommunity(i: PostListing) {
1611 let form = new AddModToCommunity({
1612 person_id: i.props.post_view.creator.id,
1613 community_id: i.props.post_view.community.id,
1614 added: !i.creatorIsMod_,
1615 auth: auth().unwrap(),
1617 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1618 i.setState(i.state);
1621 handleAddAdmin(i: PostListing) {
1622 let form = new AddAdmin({
1623 person_id: i.props.post_view.creator.id,
1624 added: !i.creatorIsAdmin_,
1625 auth: auth().unwrap(),
1627 WebSocketService.Instance.send(wsClient.addAdmin(form));
1628 i.setState(i.state);
1631 handleShowConfirmTransferCommunity(i: PostListing) {
1632 i.setState({ showConfirmTransferCommunity: true });
1635 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1636 i.setState({ showConfirmTransferCommunity: false });
1639 handleTransferCommunity(i: PostListing) {
1640 let form = new TransferCommunity({
1641 community_id: i.props.post_view.community.id,
1642 person_id: i.props.post_view.creator.id,
1643 auth: auth().unwrap(),
1645 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1646 i.setState({ showConfirmTransferCommunity: false });
1649 handleShowConfirmTransferSite(i: PostListing) {
1650 i.setState({ showConfirmTransferSite: true });
1653 handleCancelShowConfirmTransferSite(i: PostListing) {
1654 i.setState({ showConfirmTransferSite: false });
1657 handleImageExpandClick(i: PostListing, event: any) {
1658 event.preventDefault();
1659 i.setState({ imageExpanded: !i.state.imageExpanded });
1663 handleViewSource(i: PostListing) {
1664 i.setState({ viewSource: !i.state.viewSource });
1667 handleShowAdvanced(i: PostListing) {
1668 i.setState({ showAdvanced: !i.state.showAdvanced });
1672 handleShowMoreMobile(i: PostListing) {
1674 showMoreMobile: !i.state.showMoreMobile,
1675 showAdvanced: !i.state.showAdvanced,
1680 handleShowBody(i: PostListing) {
1681 i.setState({ showBody: !i.state.showBody });
1685 get pointsTippy(): string {
1686 let points = i18n.t("number_of_points", {
1687 count: this.state.score,
1688 formattedCount: this.state.score,
1691 let upvotes = i18n.t("number_of_upvotes", {
1692 count: this.state.upvotes,
1693 formattedCount: this.state.upvotes,
1696 let downvotes = i18n.t("number_of_downvotes", {
1697 count: this.state.downvotes,
1698 formattedCount: this.state.downvotes,
1701 return `${points} • ${upvotes} • ${downvotes}`;
1704 get canModOnSelf_(): boolean {
1706 this.props.moderators,
1708 this.props.post_view.creator.id,
1714 get canMod_(): boolean {
1716 this.props.moderators,
1718 this.props.post_view.creator.id
1722 get canAdmin_(): boolean {
1723 return canAdmin(this.props.admins, this.props.post_view.creator.id);
1726 get creatorIsMod_(): boolean {
1727 return isMod(this.props.moderators, this.props.post_view.creator.id);
1730 get creatorIsAdmin_(): boolean {
1731 return isAdmin(this.props.admins, this.props.post_view.creator.id);