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,
27 } from "lemmy-js-client";
28 import { externalHost } from "../../env";
29 import { i18n } from "../../i18next";
30 import { BanType, PurgeType } from "../../interfaces";
31 import { UserService, WebSocketService } from "../../services";
54 import { Icon, PurgeWarning, Spinner } from "../common/icon";
55 import { MomentTime } from "../common/moment-time";
56 import { PictrsImage } from "../common/pictrs-image";
57 import { CommunityLink } from "../community/community-link";
58 import { PersonListing } from "../person/person-listing";
59 import { MetadataCard } from "./metadata-card";
60 import { PostForm } from "./post-form";
62 interface PostListingState {
64 showRemoveDialog: boolean;
65 showPurgeDialog: boolean;
66 purgeReason: Option<string>;
68 purgeLoading: boolean;
69 removeReason: Option<string>;
70 showBanDialog: boolean;
71 banReason: Option<string>;
72 banExpireDays: Option<number>;
75 showConfirmTransferSite: boolean;
76 showConfirmTransferCommunity: boolean;
77 imageExpanded: boolean;
79 showAdvanced: boolean;
80 showMoreMobile: boolean;
82 showReportDialog: boolean;
83 reportReason: Option<string>;
84 my_vote: Option<number>;
90 interface PostListingProps {
92 duplicates: Option<PostView[]>;
93 moderators: Option<CommunityModeratorView[]>;
94 admins: Option<PersonViewSafe[]>;
95 allLanguages: Language[];
96 siteLanguages: number[];
97 showCommunity?: boolean;
100 enableDownvotes?: boolean;
101 enableNsfw?: boolean;
105 export class PostListing extends Component<PostListingProps, PostListingState> {
106 private emptyState: PostListingState = {
108 showRemoveDialog: false,
109 showPurgeDialog: false,
111 purgeType: PurgeType.Person,
114 showBanDialog: false,
117 banType: BanType.Community,
119 showConfirmTransferSite: false,
120 showConfirmTransferCommunity: false,
121 imageExpanded: false,
124 showMoreMobile: false,
126 showReportDialog: false,
128 my_vote: this.props.post_view.my_vote,
129 score: this.props.post_view.counts.score,
130 upvotes: this.props.post_view.counts.upvotes,
131 downvotes: this.props.post_view.counts.downvotes,
134 constructor(props: any, context: any) {
135 super(props, context);
137 this.state = this.emptyState;
138 this.handlePostLike = this.handlePostLike.bind(this);
139 this.handlePostDisLike = this.handlePostDisLike.bind(this);
140 this.handleEditPost = this.handleEditPost.bind(this);
141 this.handleEditCancel = this.handleEditCancel.bind(this);
144 componentWillReceiveProps(nextProps: PostListingProps) {
146 my_vote: nextProps.post_view.my_vote,
147 upvotes: nextProps.post_view.counts.upvotes,
148 downvotes: nextProps.post_view.counts.downvotes,
149 score: nextProps.post_view.counts.score,
151 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
152 this.setState({ imageExpanded: false });
157 let post = this.props.post_view.post;
159 <div className="post-listing">
160 {!this.state.showEdit ? (
163 {this.state.imageExpanded && !this.props.hideImage && this.img}
164 {post.url.isSome() &&
166 post.embed_title.isSome() && <MetadataCard post={post} />}
167 {this.showBody && this.body()}
170 <div className="col-12">
172 post_view={Some(this.props.post_view)}
175 onEdit={this.handleEditPost}
176 onCancel={this.handleEditCancel}
177 enableNsfw={this.props.enableNsfw}
178 enableDownvotes={this.props.enableDownvotes}
179 allLanguages={this.props.allLanguages}
180 siteLanguages={this.props.siteLanguages}
189 return this.props.post_view.post.body.match({
191 <div className="col-12 card my-2 p-2">
192 {this.state.viewSource ? (
195 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
204 return this.imageSrc.match({
207 <div className="offset-sm-3 my-2 d-none d-sm-block">
208 <a href={src} className="d-inline-block">
209 <PictrsImage src={src} />
212 <div className="my-2 d-block d-sm-none">
214 className="d-inline-block"
215 onClick={linkEvent(this, this.handleImageExpandClick)}
217 <PictrsImage src={src} />
226 imgThumb(src: string) {
227 let post_view = this.props.post_view;
233 nsfw={post_view.post.nsfw || post_view.community.nsfw}
238 get imageSrc(): Option<string> {
239 let post = this.props.post_view.post;
241 let thumbnail = post.thumbnail_url;
243 if (url.isSome() && isImage(url.unwrap())) {
244 if (url.unwrap().includes("pictrs")) {
246 } else if (thumbnail.isSome()) {
251 } else if (thumbnail.isSome()) {
259 let post = this.props.post_view.post;
261 let thumbnail = post.thumbnail_url;
263 if (!this.props.hideImage && url.isSome() && isImage(url.unwrap())) {
266 href={this.imageSrc.unwrap()}
267 className="text-body d-inline-block position-relative mb-2"
268 data-tippy-content={i18n.t("expand_here")}
269 onClick={linkEvent(this, this.handleImageExpandClick)}
270 aria-label={i18n.t("expand_here")}
272 {this.imgThumb(this.imageSrc.unwrap())}
273 <Icon icon="image" classes="mini-overlay" />
276 } else if (!this.props.hideImage && url.isSome() && thumbnail.isSome()) {
279 className="text-body d-inline-block position-relative mb-2"
284 {this.imgThumb(this.imageSrc.unwrap())}
285 <Icon icon="external-link" classes="mini-overlay" />
288 } else if (url.isSome()) {
289 if (!this.props.hideImage && isVideo(url.unwrap())) {
291 <div className="embed-responsive embed-responsive-16by9">
297 className="embed-responsive-item"
299 <source src={url.unwrap()} type="video/mp4" />
306 className="text-body"
311 <div className="thumbnail rounded bg-light d-flex justify-content-center">
312 <Icon icon="external-link" classes="d-flex align-items-center" />
320 className="text-body"
321 to={`/post/${post.id}`}
322 title={i18n.t("comments")}
324 <div className="thumbnail rounded bg-light d-flex justify-content-center">
325 <Icon icon="message-square" classes="d-flex align-items-center" />
333 let post_view = this.props.post_view;
335 <ul className="list-inline mb-1 text-muted small">
336 <li className="list-inline-item">
337 <PersonListing person={post_view.creator} />
339 {this.creatorIsMod_ && (
340 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
342 {this.creatorIsAdmin_ && (
343 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
345 {post_view.creator.bot_account && (
346 <span className="mx-1 badge badge-light">
347 {i18n.t("bot_account").toLowerCase()}
350 {(post_view.creator_banned_from_community ||
351 isBanned(post_view.creator)) && (
352 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
354 {post_view.creator_blocked && (
355 <span className="mx-1 badge badge-danger">{"blocked"}</span>
357 {this.props.showCommunity && (
359 <span className="mx-1"> {i18n.t("to")} </span>
360 <CommunityLink community={post_view.community} />
364 <li className="list-inline-item">•</li>
365 {post_view.post.url.match({
367 !(hostname(url) == externalHost) && (
369 <li className="list-inline-item">
371 className="text-muted font-italic"
379 <li className="list-inline-item">•</li>
384 <li className="list-inline-item">
387 published={post_view.post.published}
388 updated={post_view.post.updated}
392 {post_view.post.body.match({
395 <li className="list-inline-item">•</li>
396 <li className="list-inline-item">
398 className="text-muted btn btn-sm btn-link p-0"
399 data-tippy-content={mdNoImages.render(body)}
400 data-tippy-allowHtml={true}
401 onClick={linkEvent(this, this.handleShowBody)}
403 <Icon icon="book-open" classes="icon-inline mr-1" />
416 <div className={`vote-bar col-1 pr-0 small text-center`}>
418 className={`btn-animate btn btn-link p-0 ${
419 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
421 onClick={this.handlePostLike}
422 data-tippy-content={i18n.t("upvote")}
423 aria-label={i18n.t("upvote")}
425 <Icon icon="arrow-up1" classes="upvote" />
429 className={`unselectable pointer font-weight-bold text-muted px-1`}
430 data-tippy-content={this.pointsTippy}
432 {numToSI(this.state.score)}
435 <div className="p-1"></div>
437 {this.props.enableDownvotes && (
439 className={`btn-animate btn btn-link p-0 ${
440 this.state.my_vote.unwrapOr(0) == -1
444 onClick={this.handlePostDisLike}
445 data-tippy-content={i18n.t("downvote")}
446 aria-label={i18n.t("downvote")}
448 <Icon icon="arrow-down1" classes="downvote" />
456 let post = this.props.post_view.post;
460 !post.featured_community && !post.featured_local
464 to={`/post/${post.id}`}
465 title={i18n.t("comments")}
467 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
473 let post = this.props.post_view.post;
475 <div className="post-title overflow-hidden">
479 this.props.showBody ? (
482 !post.featured_community && !post.featured_local
490 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
497 {post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
499 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
500 data-tippy-content={i18n.t("expand_here")}
501 onClick={linkEvent(this, this.handleImageExpandClick)}
505 !this.state.imageExpanded ? "plus-square" : "minus-square"
507 classes="icon-inline"
512 <small className="ml-2 text-muted font-italic">
518 className="unselectable pointer ml-2 text-muted font-italic"
519 data-tippy-content={i18n.t("deleted")}
521 <Icon icon="trash" classes="icon-inline text-danger" />
526 className="unselectable pointer ml-2 text-muted font-italic"
527 data-tippy-content={i18n.t("locked")}
529 <Icon icon="lock" classes="icon-inline text-danger" />
532 {post.featured_community && (
534 className="unselectable pointer ml-2 text-muted font-italic"
535 data-tippy-content={i18n.t("featured")}
537 <Icon icon="pin" classes="icon-inline text-primary" />
540 {post.featured_local && (
542 className="unselectable pointer ml-2 text-muted font-italic"
543 data-tippy-content={i18n.t("featured")}
545 <Icon icon="pin" classes="icon-inline text-secondary" />
549 <small className="ml-2 text-muted font-italic">
559 return this.props.duplicates.match({
561 dupes.length > 0 && (
562 <ul className="list-inline mb-1 small text-muted">
564 <li className="list-inline-item mr-2">
565 {i18n.t("cross_posted_to")}
568 <li key={pv.post.id} className="list-inline-item mr-2">
569 <Link to={`/post/${pv.post.id}`}>
572 : `${pv.community.name}@${hostname(
573 pv.community.actor_id
585 commentsLine(mobile = false) {
586 let post = this.props.post_view.post;
588 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
589 {this.commentsButton}
592 className="btn btn-link btn-animate text-muted py-0"
593 title={i18n.t("link")}
596 <Icon icon="fedilink" inline />
599 {mobile && !this.props.viewOnly && this.mobileVotes}
600 {UserService.Instance.myUserInfo.isSome() &&
601 !this.props.viewOnly &&
602 this.postActions(mobile)}
607 postActions(mobile = false) {
608 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
609 // Possible enhancement: Make each button a component.
610 let post_view = this.props.post_view;
614 {this.crossPostButton}
615 {mobile && this.showMoreButton}
616 {(!mobile || this.state.showAdvanced) && (
624 {this.myPost && (this.showBody || this.state.showAdvanced) && (
632 {this.state.showAdvanced && (
635 post_view.post.body.isSome() &&
636 this.viewSourceButton}
637 {this.canModOnSelf_ && (
643 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
646 {!mobile && this.showMoreButton}
651 get commentsButton() {
652 let post_view = this.props.post_view;
654 <button className="btn btn-link text-muted py-0 pl-0">
656 className="text-muted"
657 title={i18n.t("number_of_comments", {
658 count: post_view.counts.comments,
659 formattedCount: post_view.counts.comments,
661 to={`/post/${post_view.post.id}?scrollToComments=true`}
663 <Icon icon="message-square" classes="mr-1" inline />
664 <span className="mr-2">
665 {i18n.t("number_of_comments", {
666 count: post_view.counts.comments,
667 formattedCount: numToSI(post_view.counts.comments),
670 {this.unreadCount.match({
671 some: unreadCount => (
672 <span className="small text-warning">
673 ({unreadCount} {i18n.t("new")})
683 get unreadCount(): Option<number> {
684 let pv = this.props.post_view;
685 if (pv.unread_comments == pv.counts.comments || pv.unread_comments == 0) {
688 return Some(pv.unread_comments);
694 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
699 className={`btn-animate btn py-0 px-1 ${
700 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
703 onClick={this.handlePostLike}
704 aria-label={i18n.t("upvote")}
706 <Icon icon="arrow-up1" classes="icon-inline small" />
708 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
711 {this.props.enableDownvotes && (
713 className={`ml-2 btn-animate btn py-0 px-1 ${
714 this.state.my_vote.unwrapOr(0) == -1
718 onClick={this.handlePostDisLike}
720 aria-label={i18n.t("downvote")}
722 <Icon icon="arrow-down1" classes="icon-inline small" />
725 className={classNames("ml-2", {
726 invisible: this.state.downvotes === 0,
729 {numToSI(this.state.downvotes)}
740 let saved = this.props.post_view.saved;
741 let label = saved ? i18n.t("unsave") : i18n.t("save");
744 className="btn btn-link btn-animate text-muted py-0"
745 onClick={linkEvent(this, this.handleSavePostClick)}
746 data-tippy-content={label}
751 classes={classNames({ "text-warning": saved })}
758 get crossPostButton() {
761 className="btn btn-link btn-animate text-muted py-0"
762 to={`/create_post${this.crossPostParams}`}
763 title={i18n.t("cross_post")}
765 <Icon icon="copy" inline />
773 className="btn btn-link btn-animate text-muted py-0"
774 onClick={linkEvent(this, this.handleShowReportDialog)}
775 data-tippy-content={i18n.t("show_report_dialog")}
776 aria-label={i18n.t("show_report_dialog")}
778 <Icon icon="flag" inline />
786 className="btn btn-link btn-animate text-muted py-0"
787 onClick={linkEvent(this, this.handleBlockUserClick)}
788 data-tippy-content={i18n.t("block_user")}
789 aria-label={i18n.t("block_user")}
791 <Icon icon="slash" inline />
799 className="btn btn-link btn-animate text-muted py-0"
800 onClick={linkEvent(this, this.handleEditClick)}
801 data-tippy-content={i18n.t("edit")}
802 aria-label={i18n.t("edit")}
804 <Icon icon="edit" inline />
810 let deleted = this.props.post_view.post.deleted;
811 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
814 className="btn btn-link btn-animate text-muted py-0"
815 onClick={linkEvent(this, this.handleDeleteClick)}
816 data-tippy-content={label}
821 classes={classNames({ "text-danger": deleted })}
828 get showMoreButton() {
831 className="btn btn-link btn-animate text-muted py-0"
832 onClick={linkEvent(this, this.handleShowAdvanced)}
833 data-tippy-content={i18n.t("more")}
834 aria-label={i18n.t("more")}
836 <Icon icon="more-vertical" inline />
841 get viewSourceButton() {
844 className="btn btn-link btn-animate text-muted py-0"
845 onClick={linkEvent(this, this.handleViewSource)}
846 data-tippy-content={i18n.t("view_source")}
847 aria-label={i18n.t("view_source")}
851 classes={classNames({ "text-success": this.state.viewSource })}
859 let locked = this.props.post_view.post.locked;
860 let label = locked ? i18n.t("unlock") : i18n.t("lock");
863 className="btn btn-link btn-animate text-muted py-0"
864 onClick={linkEvent(this, this.handleModLock)}
865 data-tippy-content={label}
870 classes={classNames({ "text-danger": locked })}
877 get featureButton() {
878 const featured_community = this.props.post_view.post.featured_community;
879 const label_community = featured_community
880 ? i18n.t("unfeature_from_community")
881 : i18n.t("feature_in_community");
883 const is_admin = amAdmin();
884 const featured_local = this.props.post_view.post.featured_local;
885 const label_local = featured_local
886 ? i18n.t("unfeature_from_local")
887 : i18n.t("feature_in_local");
891 className="btn btn-link btn-animate text-muted py-0 pl-0"
892 onClick={() => this.handleModFeaturePost(this, true)}
893 data-tippy-content={label_community}
894 aria-label={label_community}
898 classes={classNames({ "text-success": featured_community })}
905 className="btn btn-link btn-animate text-muted py-0"
906 onClick={() => this.handleModFeaturePost(this, false)}
907 data-tippy-content={label_local}
908 aria-label={label_local}
912 classes={classNames({ "text-success": featured_local })}
922 get modRemoveButton() {
923 let removed = this.props.post_view.post.removed;
926 className="btn btn-link btn-animate text-muted py-0"
929 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
932 {/* TODO: Find an icon for this. */}
933 {!removed ? i18n.t("remove") : i18n.t("restore")}
939 * Mod/Admin actions to be taken against the author.
943 let post_view = this.props.post_view;
945 this.state.showAdvanced && (
949 {!this.creatorIsMod_ &&
950 (!post_view.creator_banned_from_community ? (
952 className="btn btn-link btn-animate text-muted py-0"
955 this.handleModBanFromCommunityShow
957 aria-label={i18n.t("ban")}
963 className="btn btn-link btn-animate text-muted py-0"
966 this.handleModBanFromCommunitySubmit
968 aria-label={i18n.t("unban")}
973 {!post_view.creator_banned_from_community && (
975 className="btn btn-link btn-animate text-muted py-0"
976 onClick={linkEvent(this, this.handleAddModToCommunity)}
979 ? i18n.t("remove_as_mod")
980 : i18n.t("appoint_as_mod")
984 ? i18n.t("remove_as_mod")
985 : i18n.t("appoint_as_mod")}
990 {/* Community creators and admins can transfer community to another mod */}
991 {(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
993 this.creatorIsMod_ &&
994 (!this.state.showConfirmTransferCommunity ? (
996 className="btn btn-link btn-animate text-muted py-0"
999 this.handleShowConfirmTransferCommunity
1001 aria-label={i18n.t("transfer_community")}
1003 {i18n.t("transfer_community")}
1008 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1009 aria-label={i18n.t("are_you_sure")}
1011 {i18n.t("are_you_sure")}
1014 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1015 aria-label={i18n.t("yes")}
1016 onClick={linkEvent(this, this.handleTransferCommunity)}
1021 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1024 this.handleCancelShowConfirmTransferCommunity
1026 aria-label={i18n.t("no")}
1032 {/* Admins can ban from all, and appoint other admins */}
1033 {this.canAdmin_ && (
1035 {!this.creatorIsAdmin_ && (
1037 {!isBanned(post_view.creator) ? (
1039 className="btn btn-link btn-animate text-muted py-0"
1040 onClick={linkEvent(this, this.handleModBanShow)}
1041 aria-label={i18n.t("ban_from_site")}
1043 {i18n.t("ban_from_site")}
1047 className="btn btn-link btn-animate text-muted py-0"
1048 onClick={linkEvent(this, this.handleModBanSubmit)}
1049 aria-label={i18n.t("unban_from_site")}
1051 {i18n.t("unban_from_site")}
1055 className="btn btn-link btn-animate text-muted py-0"
1056 onClick={linkEvent(this, this.handlePurgePersonShow)}
1057 aria-label={i18n.t("purge_user")}
1059 {i18n.t("purge_user")}
1062 className="btn btn-link btn-animate text-muted py-0"
1063 onClick={linkEvent(this, this.handlePurgePostShow)}
1064 aria-label={i18n.t("purge_post")}
1066 {i18n.t("purge_post")}
1070 {!isBanned(post_view.creator) && post_view.creator.local && (
1072 className="btn btn-link btn-animate text-muted py-0"
1073 onClick={linkEvent(this, this.handleAddAdmin)}
1075 this.creatorIsAdmin_
1076 ? i18n.t("remove_as_admin")
1077 : i18n.t("appoint_as_admin")
1080 {this.creatorIsAdmin_
1081 ? i18n.t("remove_as_admin")
1082 : i18n.t("appoint_as_admin")}
1092 removeAndBanDialogs() {
1093 let post = this.props.post_view;
1094 let purgeTypeText: string;
1095 if (this.state.purgeType == PurgeType.Post) {
1096 purgeTypeText = i18n.t("purge_post");
1097 } else if (this.state.purgeType == PurgeType.Person) {
1098 purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
1102 {this.state.showRemoveDialog && (
1104 className="form-inline"
1105 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1107 <label className="sr-only" htmlFor="post-listing-remove-reason">
1112 id="post-listing-remove-reason"
1113 className="form-control mr-2"
1114 placeholder={i18n.t("reason")}
1115 value={toUndefined(this.state.removeReason)}
1116 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1120 className="btn btn-secondary"
1121 aria-label={i18n.t("remove_post")}
1123 {i18n.t("remove_post")}
1127 {this.state.showBanDialog && (
1128 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1129 <div className="form-group row col-12">
1131 className="col-form-label"
1132 htmlFor="post-listing-ban-reason"
1138 id="post-listing-ban-reason"
1139 className="form-control mr-2"
1140 placeholder={i18n.t("reason")}
1141 value={toUndefined(this.state.banReason)}
1142 onInput={linkEvent(this, this.handleModBanReasonChange)}
1144 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1149 id={`mod-ban-expires`}
1150 className="form-control mr-2"
1151 placeholder={i18n.t("number_of_days")}
1152 value={toUndefined(this.state.banExpireDays)}
1153 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1155 <div className="form-group">
1156 <div className="form-check">
1158 className="form-check-input"
1159 id="mod-ban-remove-data"
1161 checked={this.state.removeData}
1162 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1165 className="form-check-label"
1166 htmlFor="mod-ban-remove-data"
1167 title={i18n.t("remove_content_more")}
1169 {i18n.t("remove_content")}
1174 {/* TODO hold off on expires until later */}
1175 {/* <div class="form-group row"> */}
1176 {/* <label class="col-form-label">Expires</label> */}
1177 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1179 <div className="form-group row">
1182 className="btn btn-secondary"
1183 aria-label={i18n.t("ban")}
1185 {i18n.t("ban")} {post.creator.name}
1190 {this.state.showReportDialog && (
1192 className="form-inline"
1193 onSubmit={linkEvent(this, this.handleReportSubmit)}
1195 <label className="sr-only" htmlFor="post-report-reason">
1200 id="post-report-reason"
1201 className="form-control mr-2"
1202 placeholder={i18n.t("reason")}
1204 value={toUndefined(this.state.reportReason)}
1205 onInput={linkEvent(this, this.handleReportReasonChange)}
1209 className="btn btn-secondary"
1210 aria-label={i18n.t("create_report")}
1212 {i18n.t("create_report")}
1216 {this.state.showPurgeDialog && (
1218 className="form-inline"
1219 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1222 <label className="sr-only" htmlFor="purge-reason">
1228 className="form-control mr-2"
1229 placeholder={i18n.t("reason")}
1230 value={toUndefined(this.state.purgeReason)}
1231 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1233 {this.state.purgeLoading ? (
1238 className="btn btn-secondary"
1239 aria-label={purgeTypeText}
1251 let post = this.props.post_view.post;
1252 return post.thumbnail_url.isSome() ||
1253 post.url.map(isImage).unwrapOr(false) ? (
1254 <div className="row">
1255 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1256 {this.postTitleLine()}
1258 <div className="col-4">
1259 {/* Post body prev or thumbnail */}
1260 {!this.state.imageExpanded && this.thumbnail()}
1264 this.postTitleLine()
1268 showMobilePreview() {
1269 let post = this.props.post_view.post;
1273 some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
1282 {/* The mobile view*/}
1283 <div className="d-block d-sm-none">
1284 <div className="row">
1285 <div className="col-12">
1286 {this.createdLine()}
1288 {/* If it has a thumbnail, do a right aligned thumbnail */}
1289 {this.mobileThumbnail()}
1291 {/* Show a preview of the post body */}
1292 {this.showMobilePreview()}
1294 {this.commentsLine(true)}
1295 {this.userActionsLine()}
1296 {this.duplicatesLine()}
1297 {this.removeAndBanDialogs()}
1302 {/* The larger view*/}
1303 <div className="d-none d-sm-block">
1304 <div className="row">
1305 {!this.props.viewOnly && this.voteBar()}
1306 <div className="col-sm-2 pr-0">
1307 <div className="">{this.thumbnail()}</div>
1309 <div className="col-12 col-sm-9">
1310 <div className="row">
1311 <div className="col-12">
1312 {this.postTitleLine()}
1313 {this.createdLine()}
1314 {this.commentsLine()}
1315 {this.duplicatesLine()}
1316 {this.userActionsLine()}
1317 {this.removeAndBanDialogs()}
1327 private get myPost(): boolean {
1328 return UserService.Instance.myUserInfo.match({
1330 this.props.post_view.creator.id == mui.local_user_view.person.id,
1335 handlePostLike(event: any) {
1336 event.preventDefault();
1337 if (UserService.Instance.myUserInfo.isNone()) {
1338 this.context.router.history.push(`/login`);
1341 let myVote = this.state.my_vote.unwrapOr(0);
1342 let newVote = myVote == 1 ? 0 : 1;
1346 score: this.state.score - 1,
1347 upvotes: this.state.upvotes - 1,
1349 } else if (myVote == -1) {
1351 score: this.state.score + 2,
1352 upvotes: this.state.upvotes + 1,
1353 downvotes: this.state.downvotes - 1,
1357 score: this.state.score + 1,
1358 upvotes: this.state.upvotes + 1,
1362 this.setState({ my_vote: Some(newVote) });
1364 let form = new CreatePostLike({
1365 post_id: this.props.post_view.post.id,
1367 auth: auth().unwrap(),
1370 WebSocketService.Instance.send(wsClient.likePost(form));
1371 this.setState(this.state);
1375 handlePostDisLike(event: any) {
1376 event.preventDefault();
1377 if (UserService.Instance.myUserInfo.isNone()) {
1378 this.context.router.history.push(`/login`);
1381 let myVote = this.state.my_vote.unwrapOr(0);
1382 let newVote = myVote == -1 ? 0 : -1;
1386 score: this.state.score - 2,
1387 upvotes: this.state.upvotes - 1,
1388 downvotes: this.state.downvotes + 1,
1390 } else if (myVote == -1) {
1392 score: this.state.score + 1,
1393 downvotes: this.state.downvotes - 1,
1397 score: this.state.score - 1,
1398 downvotes: this.state.downvotes + 1,
1402 this.setState({ my_vote: Some(newVote) });
1404 let form = new CreatePostLike({
1405 post_id: this.props.post_view.post.id,
1407 auth: auth().unwrap(),
1410 WebSocketService.Instance.send(wsClient.likePost(form));
1411 this.setState(this.state);
1415 handleEditClick(i: PostListing) {
1416 i.setState({ showEdit: true });
1419 handleEditCancel() {
1420 this.setState({ showEdit: false });
1423 // The actual editing is done in the recieve for post
1425 this.setState({ showEdit: false });
1428 handleShowReportDialog(i: PostListing) {
1429 i.setState({ showReportDialog: !i.state.showReportDialog });
1432 handleReportReasonChange(i: PostListing, event: any) {
1433 i.setState({ reportReason: Some(event.target.value) });
1436 handleReportSubmit(i: PostListing, event: any) {
1437 event.preventDefault();
1438 let form = new CreatePostReport({
1439 post_id: i.props.post_view.post.id,
1440 reason: toUndefined(i.state.reportReason),
1441 auth: auth().unwrap(),
1443 WebSocketService.Instance.send(wsClient.createPostReport(form));
1445 i.setState({ showReportDialog: false });
1448 handleBlockUserClick(i: PostListing) {
1449 let blockUserForm = new BlockPerson({
1450 person_id: i.props.post_view.creator.id,
1452 auth: auth().unwrap(),
1454 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1457 handleDeleteClick(i: PostListing) {
1458 let deleteForm = new DeletePost({
1459 post_id: i.props.post_view.post.id,
1460 deleted: !i.props.post_view.post.deleted,
1461 auth: auth().unwrap(),
1463 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1466 handleSavePostClick(i: PostListing) {
1468 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1469 let form = new SavePost({
1470 post_id: i.props.post_view.post.id,
1472 auth: auth().unwrap(),
1475 WebSocketService.Instance.send(wsClient.savePost(form));
1478 get crossPostParams(): string {
1479 let post = this.props.post_view.post;
1480 let params = `?title=${encodeURIComponent(post.name)}`;
1482 if (post.url.isSome()) {
1483 params += `&url=${encodeURIComponent(post.url.unwrap())}`;
1485 if (post.body.isSome()) {
1486 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1491 crossPostBody(): string {
1492 let post = this.props.post_view.post;
1493 let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
1495 .replace(/^/gm, "> ")}`;
1499 get showBody(): boolean {
1500 return this.props.showBody || this.state.showBody;
1503 handleModRemoveShow(i: PostListing) {
1505 showRemoveDialog: !i.state.showRemoveDialog,
1506 showBanDialog: false,
1510 handleModRemoveReasonChange(i: PostListing, event: any) {
1511 i.setState({ removeReason: Some(event.target.value) });
1514 handleModRemoveDataChange(i: PostListing, event: any) {
1515 i.setState({ removeData: event.target.checked });
1518 handleModRemoveSubmit(i: PostListing, event: any) {
1519 event.preventDefault();
1520 let form = new RemovePost({
1521 post_id: i.props.post_view.post.id,
1522 removed: !i.props.post_view.post.removed,
1523 reason: i.state.removeReason,
1524 auth: auth().unwrap(),
1526 WebSocketService.Instance.send(wsClient.removePost(form));
1528 i.setState({ showRemoveDialog: false });
1531 handleModLock(i: PostListing) {
1532 let form = new LockPost({
1533 post_id: i.props.post_view.post.id,
1534 locked: !i.props.post_view.post.locked,
1535 auth: auth().unwrap(),
1537 WebSocketService.Instance.send(wsClient.lockPost(form));
1540 handleModFeaturePost(i: PostListing, is_community: boolean) {
1541 let form = new FeaturePost({
1542 post_id: i.props.post_view.post.id,
1543 featured: is_community
1544 ? !i.props.post_view.post.featured_community
1545 : !i.props.post_view.post.featured_local,
1546 feature_type: is_community
1547 ? PostFeatureType.Community
1548 : PostFeatureType.Local,
1549 auth: auth().unwrap(),
1551 WebSocketService.Instance.send(wsClient.featurePost(form));
1554 handleModBanFromCommunityShow(i: PostListing) {
1556 showBanDialog: true,
1557 banType: BanType.Community,
1558 showRemoveDialog: false,
1562 handleModBanShow(i: PostListing) {
1564 showBanDialog: true,
1565 banType: BanType.Site,
1566 showRemoveDialog: false,
1570 handlePurgePersonShow(i: PostListing) {
1572 showPurgeDialog: true,
1573 purgeType: PurgeType.Person,
1574 showRemoveDialog: false,
1578 handlePurgePostShow(i: PostListing) {
1580 showPurgeDialog: true,
1581 purgeType: PurgeType.Post,
1582 showRemoveDialog: false,
1586 handlePurgeReasonChange(i: PostListing, event: any) {
1587 i.setState({ purgeReason: Some(event.target.value) });
1590 handlePurgeSubmit(i: PostListing, event: any) {
1591 event.preventDefault();
1593 if (i.state.purgeType == PurgeType.Person) {
1594 let form = new PurgePerson({
1595 person_id: i.props.post_view.creator.id,
1596 reason: i.state.purgeReason,
1597 auth: auth().unwrap(),
1599 WebSocketService.Instance.send(wsClient.purgePerson(form));
1600 } else if (i.state.purgeType == PurgeType.Post) {
1601 let form = new PurgePost({
1602 post_id: i.props.post_view.post.id,
1603 reason: i.state.purgeReason,
1604 auth: auth().unwrap(),
1606 WebSocketService.Instance.send(wsClient.purgePost(form));
1609 i.setState({ purgeLoading: true });
1612 handleModBanReasonChange(i: PostListing, event: any) {
1613 i.setState({ banReason: Some(event.target.value) });
1616 handleModBanExpireDaysChange(i: PostListing, event: any) {
1617 i.setState({ banExpireDays: Some(event.target.value) });
1620 handleModBanFromCommunitySubmit(i: PostListing) {
1621 i.setState({ banType: BanType.Community });
1622 i.handleModBanBothSubmit(i);
1625 handleModBanSubmit(i: PostListing) {
1626 i.setState({ banType: BanType.Site });
1627 i.handleModBanBothSubmit(i);
1630 handleModBanBothSubmit(i: PostListing, event?: any) {
1631 if (event) event.preventDefault();
1633 if (i.state.banType == BanType.Community) {
1634 // If its an unban, restore all their data
1635 let ban = !i.props.post_view.creator_banned_from_community;
1637 i.setState({ removeData: false });
1639 let form = new BanFromCommunity({
1640 person_id: i.props.post_view.creator.id,
1641 community_id: i.props.post_view.community.id,
1643 remove_data: Some(i.state.removeData),
1644 reason: i.state.banReason,
1645 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1646 auth: auth().unwrap(),
1648 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1650 // If its an unban, restore all their data
1651 let ban = !i.props.post_view.creator.banned;
1653 i.setState({ removeData: false });
1655 let form = new BanPerson({
1656 person_id: i.props.post_view.creator.id,
1658 remove_data: Some(i.state.removeData),
1659 reason: i.state.banReason,
1660 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1661 auth: auth().unwrap(),
1663 WebSocketService.Instance.send(wsClient.banPerson(form));
1666 i.setState({ showBanDialog: false });
1669 handleAddModToCommunity(i: PostListing) {
1670 let form = new AddModToCommunity({
1671 person_id: i.props.post_view.creator.id,
1672 community_id: i.props.post_view.community.id,
1673 added: !i.creatorIsMod_,
1674 auth: auth().unwrap(),
1676 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1677 i.setState(i.state);
1680 handleAddAdmin(i: PostListing) {
1681 let form = new AddAdmin({
1682 person_id: i.props.post_view.creator.id,
1683 added: !i.creatorIsAdmin_,
1684 auth: auth().unwrap(),
1686 WebSocketService.Instance.send(wsClient.addAdmin(form));
1687 i.setState(i.state);
1690 handleShowConfirmTransferCommunity(i: PostListing) {
1691 i.setState({ showConfirmTransferCommunity: true });
1694 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1695 i.setState({ showConfirmTransferCommunity: false });
1698 handleTransferCommunity(i: PostListing) {
1699 let form = new TransferCommunity({
1700 community_id: i.props.post_view.community.id,
1701 person_id: i.props.post_view.creator.id,
1702 auth: auth().unwrap(),
1704 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1705 i.setState({ showConfirmTransferCommunity: false });
1708 handleShowConfirmTransferSite(i: PostListing) {
1709 i.setState({ showConfirmTransferSite: true });
1712 handleCancelShowConfirmTransferSite(i: PostListing) {
1713 i.setState({ showConfirmTransferSite: false });
1716 handleImageExpandClick(i: PostListing, event: any) {
1717 event.preventDefault();
1718 i.setState({ imageExpanded: !i.state.imageExpanded });
1722 handleViewSource(i: PostListing) {
1723 i.setState({ viewSource: !i.state.viewSource });
1726 handleShowAdvanced(i: PostListing) {
1727 i.setState({ showAdvanced: !i.state.showAdvanced });
1731 handleShowMoreMobile(i: PostListing) {
1733 showMoreMobile: !i.state.showMoreMobile,
1734 showAdvanced: !i.state.showAdvanced,
1739 handleShowBody(i: PostListing) {
1740 i.setState({ showBody: !i.state.showBody });
1744 get pointsTippy(): string {
1745 let points = i18n.t("number_of_points", {
1746 count: this.state.score,
1747 formattedCount: this.state.score,
1750 let upvotes = i18n.t("number_of_upvotes", {
1751 count: this.state.upvotes,
1752 formattedCount: this.state.upvotes,
1755 let downvotes = i18n.t("number_of_downvotes", {
1756 count: this.state.downvotes,
1757 formattedCount: this.state.downvotes,
1760 return `${points} • ${upvotes} • ${downvotes}`;
1763 get canModOnSelf_(): boolean {
1765 this.props.moderators,
1767 this.props.post_view.creator.id,
1773 get canMod_(): boolean {
1775 this.props.moderators,
1777 this.props.post_view.creator.id
1781 get canAdmin_(): boolean {
1782 return canAdmin(this.props.admins, this.props.post_view.creator.id);
1785 get creatorIsMod_(): boolean {
1786 return isMod(this.props.moderators, this.props.post_view.creator.id);
1789 get creatorIsAdmin_(): boolean {
1790 return isAdmin(this.props.admins, this.props.post_view.creator.id);