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 showCommunity?: boolean;
99 enableDownvotes?: boolean;
100 enableNsfw?: boolean;
104 export class PostListing extends Component<PostListingProps, PostListingState> {
105 private emptyState: PostListingState = {
107 showRemoveDialog: false,
108 showPurgeDialog: false,
110 purgeType: PurgeType.Person,
113 showBanDialog: false,
116 banType: BanType.Community,
118 showConfirmTransferSite: false,
119 showConfirmTransferCommunity: false,
120 imageExpanded: false,
123 showMoreMobile: false,
125 showReportDialog: false,
127 my_vote: this.props.post_view.my_vote,
128 score: this.props.post_view.counts.score,
129 upvotes: this.props.post_view.counts.upvotes,
130 downvotes: this.props.post_view.counts.downvotes,
133 constructor(props: any, context: any) {
134 super(props, context);
136 this.state = this.emptyState;
137 this.handlePostLike = this.handlePostLike.bind(this);
138 this.handlePostDisLike = this.handlePostDisLike.bind(this);
139 this.handleEditPost = this.handleEditPost.bind(this);
140 this.handleEditCancel = this.handleEditCancel.bind(this);
143 componentWillReceiveProps(nextProps: PostListingProps) {
145 my_vote: nextProps.post_view.my_vote,
146 upvotes: nextProps.post_view.counts.upvotes,
147 downvotes: nextProps.post_view.counts.downvotes,
148 score: nextProps.post_view.counts.score,
150 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
151 this.setState({ imageExpanded: false });
156 let post = this.props.post_view.post;
158 <div className="post-listing">
159 {!this.state.showEdit ? (
162 {this.state.imageExpanded && !this.props.hideImage && this.img}
163 {post.url.isSome() &&
165 post.embed_title.isSome() && <MetadataCard post={post} />}
166 {this.showBody && this.body()}
169 <div className="col-12">
171 post_view={Some(this.props.post_view)}
174 onEdit={this.handleEditPost}
175 onCancel={this.handleEditCancel}
176 enableNsfw={this.props.enableNsfw}
177 enableDownvotes={this.props.enableDownvotes}
178 allLanguages={this.props.allLanguages}
187 return this.props.post_view.post.body.match({
189 <div className="col-12 card my-2 p-2">
190 {this.state.viewSource ? (
193 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
202 return this.imageSrc.match({
205 <div className="offset-sm-3 my-2 d-none d-sm-block">
206 <a href={src} className="d-inline-block">
207 <PictrsImage src={src} />
210 <div className="my-2 d-block d-sm-none">
212 className="d-inline-block"
213 onClick={linkEvent(this, this.handleImageExpandClick)}
215 <PictrsImage src={src} />
224 imgThumb(src: string) {
225 let post_view = this.props.post_view;
231 nsfw={post_view.post.nsfw || post_view.community.nsfw}
236 get imageSrc(): Option<string> {
237 let post = this.props.post_view.post;
239 let thumbnail = post.thumbnail_url;
241 if (url.isSome() && isImage(url.unwrap())) {
242 if (url.unwrap().includes("pictrs")) {
244 } else if (thumbnail.isSome()) {
249 } else if (thumbnail.isSome()) {
257 let post = this.props.post_view.post;
259 let thumbnail = post.thumbnail_url;
261 if (!this.props.hideImage && url.isSome() && isImage(url.unwrap())) {
264 href={this.imageSrc.unwrap()}
265 className="text-body d-inline-block position-relative mb-2"
266 data-tippy-content={i18n.t("expand_here")}
267 onClick={linkEvent(this, this.handleImageExpandClick)}
268 aria-label={i18n.t("expand_here")}
270 {this.imgThumb(this.imageSrc.unwrap())}
271 <Icon icon="image" classes="mini-overlay" />
274 } else if (!this.props.hideImage && url.isSome() && thumbnail.isSome()) {
277 className="text-body d-inline-block position-relative mb-2"
282 {this.imgThumb(this.imageSrc.unwrap())}
283 <Icon icon="external-link" classes="mini-overlay" />
286 } else if (url.isSome()) {
287 if (!this.props.hideImage && isVideo(url.unwrap())) {
289 <div className="embed-responsive embed-responsive-16by9">
295 className="embed-responsive-item"
297 <source src={url.unwrap()} type="video/mp4" />
304 className="text-body"
309 <div className="thumbnail rounded bg-light d-flex justify-content-center">
310 <Icon icon="external-link" classes="d-flex align-items-center" />
318 className="text-body"
319 to={`/post/${post.id}`}
320 title={i18n.t("comments")}
322 <div className="thumbnail rounded bg-light d-flex justify-content-center">
323 <Icon icon="message-square" classes="d-flex align-items-center" />
331 let post_view = this.props.post_view;
333 <ul className="list-inline mb-1 text-muted small">
334 <li className="list-inline-item">
335 <PersonListing person={post_view.creator} />
337 {this.creatorIsMod_ && (
338 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
340 {this.creatorIsAdmin_ && (
341 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
343 {post_view.creator.bot_account && (
344 <span className="mx-1 badge badge-light">
345 {i18n.t("bot_account").toLowerCase()}
348 {(post_view.creator_banned_from_community ||
349 isBanned(post_view.creator)) && (
350 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
352 {post_view.creator_blocked && (
353 <span className="mx-1 badge badge-danger">{"blocked"}</span>
355 {this.props.showCommunity && (
357 <span className="mx-1"> {i18n.t("to")} </span>
358 <CommunityLink community={post_view.community} />
362 <li className="list-inline-item">•</li>
363 {post_view.post.url.match({
365 !(hostname(url) == externalHost) && (
367 <li className="list-inline-item">
369 className="text-muted font-italic"
377 <li className="list-inline-item">•</li>
382 <li className="list-inline-item">
385 published={post_view.post.published}
386 updated={post_view.post.updated}
390 {post_view.post.body.match({
393 <li className="list-inline-item">•</li>
394 <li className="list-inline-item">
396 className="text-muted btn btn-sm btn-link p-0"
397 data-tippy-content={mdNoImages.render(body)}
398 data-tippy-allowHtml={true}
399 onClick={linkEvent(this, this.handleShowBody)}
401 <Icon icon="book-open" classes="icon-inline mr-1" />
414 <div className={`vote-bar col-1 pr-0 small text-center`}>
416 className={`btn-animate btn btn-link p-0 ${
417 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
419 onClick={this.handlePostLike}
420 data-tippy-content={i18n.t("upvote")}
421 aria-label={i18n.t("upvote")}
423 <Icon icon="arrow-up1" classes="upvote" />
427 className={`unselectable pointer font-weight-bold text-muted px-1`}
428 data-tippy-content={this.pointsTippy}
430 {numToSI(this.state.score)}
433 <div className="p-1"></div>
435 {this.props.enableDownvotes && (
437 className={`btn-animate btn btn-link p-0 ${
438 this.state.my_vote.unwrapOr(0) == -1
442 onClick={this.handlePostDisLike}
443 data-tippy-content={i18n.t("downvote")}
444 aria-label={i18n.t("downvote")}
446 <Icon icon="arrow-down1" classes="downvote" />
454 let post = this.props.post_view.post;
458 !post.featured_community && !post.featured_local
462 to={`/post/${post.id}`}
463 title={i18n.t("comments")}
465 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
471 let post = this.props.post_view.post;
473 <div className="post-title overflow-hidden">
477 this.props.showBody ? (
480 !post.featured_community && !post.featured_local
488 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
495 {post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
497 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
498 data-tippy-content={i18n.t("expand_here")}
499 onClick={linkEvent(this, this.handleImageExpandClick)}
503 !this.state.imageExpanded ? "plus-square" : "minus-square"
505 classes="icon-inline"
510 <small className="ml-2 text-muted font-italic">
516 className="unselectable pointer ml-2 text-muted font-italic"
517 data-tippy-content={i18n.t("deleted")}
519 <Icon icon="trash" classes="icon-inline text-danger" />
524 className="unselectable pointer ml-2 text-muted font-italic"
525 data-tippy-content={i18n.t("locked")}
527 <Icon icon="lock" classes="icon-inline text-danger" />
530 {post.featured_community && (
532 className="unselectable pointer ml-2 text-muted font-italic"
533 data-tippy-content={i18n.t("featured")}
535 <Icon icon="pin" classes="icon-inline text-primary" />
538 {post.featured_local && (
540 className="unselectable pointer ml-2 text-muted font-italic"
541 data-tippy-content={i18n.t("featured")}
543 <Icon icon="pin" classes="icon-inline text-secondary" />
547 <small className="ml-2 text-muted font-italic">
557 return this.props.duplicates.match({
559 dupes.length > 0 && (
560 <ul className="list-inline mb-1 small text-muted">
562 <li className="list-inline-item mr-2">
563 {i18n.t("cross_posted_to")}
566 <li key={pv.post.id} className="list-inline-item mr-2">
567 <Link to={`/post/${pv.post.id}`}>
570 : `${pv.community.name}@${hostname(
571 pv.community.actor_id
583 commentsLine(mobile = false) {
584 let post = this.props.post_view.post;
586 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
587 {this.commentsButton}
590 className="btn btn-link btn-animate text-muted py-0"
591 title={i18n.t("link")}
594 <Icon icon="fedilink" inline />
597 {mobile && !this.props.viewOnly && this.mobileVotes}
598 {UserService.Instance.myUserInfo.isSome() &&
599 !this.props.viewOnly &&
600 this.postActions(mobile)}
605 postActions(mobile = false) {
606 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
607 // Possible enhancement: Make each button a component.
608 let post_view = this.props.post_view;
612 {this.crossPostButton}
613 {mobile && this.showMoreButton}
614 {(!mobile || this.state.showAdvanced) && (
622 {this.myPost && (this.showBody || this.state.showAdvanced) && (
630 {this.state.showAdvanced && (
633 post_view.post.body.isSome() &&
634 this.viewSourceButton}
635 {this.canModOnSelf_ && (
641 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
644 {!mobile && this.showMoreButton}
649 get commentsButton() {
650 let post_view = this.props.post_view;
652 <button className="btn btn-link text-muted py-0 pl-0">
654 className="text-muted"
655 title={i18n.t("number_of_comments", {
656 count: post_view.counts.comments,
657 formattedCount: post_view.counts.comments,
659 to={`/post/${post_view.post.id}?scrollToComments=true`}
661 <Icon icon="message-square" classes="mr-1" inline />
662 <span className="mr-2">
663 {i18n.t("number_of_comments", {
664 count: post_view.counts.comments,
665 formattedCount: numToSI(post_view.counts.comments),
668 {this.unreadCount.match({
669 some: unreadCount => (
670 <span className="small text-warning">
671 ({unreadCount} {i18n.t("new")})
681 get unreadCount(): Option<number> {
682 let pv = this.props.post_view;
683 if (pv.unread_comments == pv.counts.comments || pv.unread_comments == 0) {
686 return Some(pv.unread_comments);
692 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
697 className={`btn-animate btn py-0 px-1 ${
698 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
701 onClick={this.handlePostLike}
702 aria-label={i18n.t("upvote")}
704 <Icon icon="arrow-up1" classes="icon-inline small" />
706 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
709 {this.props.enableDownvotes && (
711 className={`ml-2 btn-animate btn py-0 px-1 ${
712 this.state.my_vote.unwrapOr(0) == -1
716 onClick={this.handlePostDisLike}
718 aria-label={i18n.t("downvote")}
720 <Icon icon="arrow-down1" classes="icon-inline small" />
723 className={classNames("ml-2", {
724 invisible: this.state.downvotes === 0,
727 {numToSI(this.state.downvotes)}
738 let saved = this.props.post_view.saved;
739 let label = saved ? i18n.t("unsave") : i18n.t("save");
742 className="btn btn-link btn-animate text-muted py-0"
743 onClick={linkEvent(this, this.handleSavePostClick)}
744 data-tippy-content={label}
749 classes={classNames({ "text-warning": saved })}
756 get crossPostButton() {
759 className="btn btn-link btn-animate text-muted py-0"
760 to={`/create_post${this.crossPostParams}`}
761 title={i18n.t("cross_post")}
763 <Icon icon="copy" inline />
771 className="btn btn-link btn-animate text-muted py-0"
772 onClick={linkEvent(this, this.handleShowReportDialog)}
773 data-tippy-content={i18n.t("show_report_dialog")}
774 aria-label={i18n.t("show_report_dialog")}
776 <Icon icon="flag" inline />
784 className="btn btn-link btn-animate text-muted py-0"
785 onClick={linkEvent(this, this.handleBlockUserClick)}
786 data-tippy-content={i18n.t("block_user")}
787 aria-label={i18n.t("block_user")}
789 <Icon icon="slash" inline />
797 className="btn btn-link btn-animate text-muted py-0"
798 onClick={linkEvent(this, this.handleEditClick)}
799 data-tippy-content={i18n.t("edit")}
800 aria-label={i18n.t("edit")}
802 <Icon icon="edit" inline />
808 let deleted = this.props.post_view.post.deleted;
809 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
812 className="btn btn-link btn-animate text-muted py-0"
813 onClick={linkEvent(this, this.handleDeleteClick)}
814 data-tippy-content={label}
819 classes={classNames({ "text-danger": deleted })}
826 get showMoreButton() {
829 className="btn btn-link btn-animate text-muted py-0"
830 onClick={linkEvent(this, this.handleShowAdvanced)}
831 data-tippy-content={i18n.t("more")}
832 aria-label={i18n.t("more")}
834 <Icon icon="more-vertical" inline />
839 get viewSourceButton() {
842 className="btn btn-link btn-animate text-muted py-0"
843 onClick={linkEvent(this, this.handleViewSource)}
844 data-tippy-content={i18n.t("view_source")}
845 aria-label={i18n.t("view_source")}
849 classes={classNames({ "text-success": this.state.viewSource })}
857 let locked = this.props.post_view.post.locked;
858 let label = locked ? i18n.t("unlock") : i18n.t("lock");
861 className="btn btn-link btn-animate text-muted py-0"
862 onClick={linkEvent(this, this.handleModLock)}
863 data-tippy-content={label}
868 classes={classNames({ "text-danger": locked })}
875 get featureButton() {
876 const featured_community = this.props.post_view.post.featured_community;
877 const label_community = featured_community
878 ? i18n.t("unfeature_from_community")
879 : i18n.t("feature_in_community");
881 const is_admin = amAdmin();
882 const featured_local = this.props.post_view.post.featured_local;
883 const label_local = featured_local
884 ? i18n.t("unfeature_from_local")
885 : i18n.t("feature_in_local");
889 className="btn btn-link btn-animate text-muted py-0 pl-0"
890 onClick={() => this.handleModFeaturePost(this, true)}
891 data-tippy-content={label_community}
892 aria-label={label_community}
896 classes={classNames({ "text-success": featured_community })}
903 className="btn btn-link btn-animate text-muted py-0"
904 onClick={() => this.handleModFeaturePost(this, false)}
905 data-tippy-content={label_local}
906 aria-label={label_local}
910 classes={classNames({ "text-success": featured_local })}
920 get modRemoveButton() {
921 let removed = this.props.post_view.post.removed;
924 className="btn btn-link btn-animate text-muted py-0"
927 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
930 {/* TODO: Find an icon for this. */}
931 {!removed ? i18n.t("remove") : i18n.t("restore")}
937 * Mod/Admin actions to be taken against the author.
941 let post_view = this.props.post_view;
943 this.state.showAdvanced && (
947 {!this.creatorIsMod_ &&
948 (!post_view.creator_banned_from_community ? (
950 className="btn btn-link btn-animate text-muted py-0"
953 this.handleModBanFromCommunityShow
955 aria-label={i18n.t("ban")}
961 className="btn btn-link btn-animate text-muted py-0"
964 this.handleModBanFromCommunitySubmit
966 aria-label={i18n.t("unban")}
971 {!post_view.creator_banned_from_community && (
973 className="btn btn-link btn-animate text-muted py-0"
974 onClick={linkEvent(this, this.handleAddModToCommunity)}
977 ? i18n.t("remove_as_mod")
978 : i18n.t("appoint_as_mod")
982 ? i18n.t("remove_as_mod")
983 : i18n.t("appoint_as_mod")}
988 {/* Community creators and admins can transfer community to another mod */}
989 {(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
991 this.creatorIsMod_ &&
992 (!this.state.showConfirmTransferCommunity ? (
994 className="btn btn-link btn-animate text-muted py-0"
997 this.handleShowConfirmTransferCommunity
999 aria-label={i18n.t("transfer_community")}
1001 {i18n.t("transfer_community")}
1006 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1007 aria-label={i18n.t("are_you_sure")}
1009 {i18n.t("are_you_sure")}
1012 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1013 aria-label={i18n.t("yes")}
1014 onClick={linkEvent(this, this.handleTransferCommunity)}
1019 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1022 this.handleCancelShowConfirmTransferCommunity
1024 aria-label={i18n.t("no")}
1030 {/* Admins can ban from all, and appoint other admins */}
1031 {this.canAdmin_ && (
1033 {!this.creatorIsAdmin_ && (
1035 {!isBanned(post_view.creator) ? (
1037 className="btn btn-link btn-animate text-muted py-0"
1038 onClick={linkEvent(this, this.handleModBanShow)}
1039 aria-label={i18n.t("ban_from_site")}
1041 {i18n.t("ban_from_site")}
1045 className="btn btn-link btn-animate text-muted py-0"
1046 onClick={linkEvent(this, this.handleModBanSubmit)}
1047 aria-label={i18n.t("unban_from_site")}
1049 {i18n.t("unban_from_site")}
1053 className="btn btn-link btn-animate text-muted py-0"
1054 onClick={linkEvent(this, this.handlePurgePersonShow)}
1055 aria-label={i18n.t("purge_user")}
1057 {i18n.t("purge_user")}
1060 className="btn btn-link btn-animate text-muted py-0"
1061 onClick={linkEvent(this, this.handlePurgePostShow)}
1062 aria-label={i18n.t("purge_post")}
1064 {i18n.t("purge_post")}
1068 {!isBanned(post_view.creator) && post_view.creator.local && (
1070 className="btn btn-link btn-animate text-muted py-0"
1071 onClick={linkEvent(this, this.handleAddAdmin)}
1073 this.creatorIsAdmin_
1074 ? i18n.t("remove_as_admin")
1075 : i18n.t("appoint_as_admin")
1078 {this.creatorIsAdmin_
1079 ? i18n.t("remove_as_admin")
1080 : i18n.t("appoint_as_admin")}
1090 removeAndBanDialogs() {
1091 let post = this.props.post_view;
1092 let purgeTypeText: string;
1093 if (this.state.purgeType == PurgeType.Post) {
1094 purgeTypeText = i18n.t("purge_post");
1095 } else if (this.state.purgeType == PurgeType.Person) {
1096 purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
1100 {this.state.showRemoveDialog && (
1102 className="form-inline"
1103 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1105 <label className="sr-only" htmlFor="post-listing-remove-reason">
1110 id="post-listing-remove-reason"
1111 className="form-control mr-2"
1112 placeholder={i18n.t("reason")}
1113 value={toUndefined(this.state.removeReason)}
1114 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1118 className="btn btn-secondary"
1119 aria-label={i18n.t("remove_post")}
1121 {i18n.t("remove_post")}
1125 {this.state.showBanDialog && (
1126 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1127 <div className="form-group row col-12">
1129 className="col-form-label"
1130 htmlFor="post-listing-ban-reason"
1136 id="post-listing-ban-reason"
1137 className="form-control mr-2"
1138 placeholder={i18n.t("reason")}
1139 value={toUndefined(this.state.banReason)}
1140 onInput={linkEvent(this, this.handleModBanReasonChange)}
1142 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1147 id={`mod-ban-expires`}
1148 className="form-control mr-2"
1149 placeholder={i18n.t("number_of_days")}
1150 value={toUndefined(this.state.banExpireDays)}
1151 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1153 <div className="form-group">
1154 <div className="form-check">
1156 className="form-check-input"
1157 id="mod-ban-remove-data"
1159 checked={this.state.removeData}
1160 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1163 className="form-check-label"
1164 htmlFor="mod-ban-remove-data"
1165 title={i18n.t("remove_content_more")}
1167 {i18n.t("remove_content")}
1172 {/* TODO hold off on expires until later */}
1173 {/* <div class="form-group row"> */}
1174 {/* <label class="col-form-label">Expires</label> */}
1175 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1177 <div className="form-group row">
1180 className="btn btn-secondary"
1181 aria-label={i18n.t("ban")}
1183 {i18n.t("ban")} {post.creator.name}
1188 {this.state.showReportDialog && (
1190 className="form-inline"
1191 onSubmit={linkEvent(this, this.handleReportSubmit)}
1193 <label className="sr-only" htmlFor="post-report-reason">
1198 id="post-report-reason"
1199 className="form-control mr-2"
1200 placeholder={i18n.t("reason")}
1202 value={toUndefined(this.state.reportReason)}
1203 onInput={linkEvent(this, this.handleReportReasonChange)}
1207 className="btn btn-secondary"
1208 aria-label={i18n.t("create_report")}
1210 {i18n.t("create_report")}
1214 {this.state.showPurgeDialog && (
1216 className="form-inline"
1217 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1220 <label className="sr-only" htmlFor="purge-reason">
1226 className="form-control mr-2"
1227 placeholder={i18n.t("reason")}
1228 value={toUndefined(this.state.purgeReason)}
1229 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1231 {this.state.purgeLoading ? (
1236 className="btn btn-secondary"
1237 aria-label={purgeTypeText}
1249 let post = this.props.post_view.post;
1250 return post.thumbnail_url.isSome() ||
1251 post.url.map(isImage).unwrapOr(false) ? (
1252 <div className="row">
1253 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1254 {this.postTitleLine()}
1256 <div className="col-4">
1257 {/* Post body prev or thumbnail */}
1258 {!this.state.imageExpanded && this.thumbnail()}
1262 this.postTitleLine()
1266 showMobilePreview() {
1267 let post = this.props.post_view.post;
1271 some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
1280 {/* The mobile view*/}
1281 <div className="d-block d-sm-none">
1282 <div className="row">
1283 <div className="col-12">
1284 {this.createdLine()}
1286 {/* If it has a thumbnail, do a right aligned thumbnail */}
1287 {this.mobileThumbnail()}
1289 {/* Show a preview of the post body */}
1290 {this.showMobilePreview()}
1292 {this.commentsLine(true)}
1293 {this.userActionsLine()}
1294 {this.duplicatesLine()}
1295 {this.removeAndBanDialogs()}
1300 {/* The larger view*/}
1301 <div className="d-none d-sm-block">
1302 <div className="row">
1303 {!this.props.viewOnly && this.voteBar()}
1304 <div className="col-sm-2 pr-0">
1305 <div className="">{this.thumbnail()}</div>
1307 <div className="col-12 col-sm-9">
1308 <div className="row">
1309 <div className="col-12">
1310 {this.postTitleLine()}
1311 {this.createdLine()}
1312 {this.commentsLine()}
1313 {this.duplicatesLine()}
1314 {this.userActionsLine()}
1315 {this.removeAndBanDialogs()}
1325 private get myPost(): boolean {
1326 return UserService.Instance.myUserInfo.match({
1328 this.props.post_view.creator.id == mui.local_user_view.person.id,
1333 handlePostLike(event: any) {
1334 event.preventDefault();
1335 if (UserService.Instance.myUserInfo.isNone()) {
1336 this.context.router.history.push(`/login`);
1339 let myVote = this.state.my_vote.unwrapOr(0);
1340 let newVote = myVote == 1 ? 0 : 1;
1344 score: this.state.score - 1,
1345 upvotes: this.state.upvotes - 1,
1347 } else if (myVote == -1) {
1349 score: this.state.score + 2,
1350 upvotes: this.state.upvotes + 1,
1351 downvotes: this.state.downvotes - 1,
1355 score: this.state.score + 1,
1356 upvotes: this.state.upvotes + 1,
1360 this.setState({ my_vote: Some(newVote) });
1362 let form = new CreatePostLike({
1363 post_id: this.props.post_view.post.id,
1365 auth: auth().unwrap(),
1368 WebSocketService.Instance.send(wsClient.likePost(form));
1369 this.setState(this.state);
1373 handlePostDisLike(event: any) {
1374 event.preventDefault();
1375 if (UserService.Instance.myUserInfo.isNone()) {
1376 this.context.router.history.push(`/login`);
1379 let myVote = this.state.my_vote.unwrapOr(0);
1380 let newVote = myVote == -1 ? 0 : -1;
1384 score: this.state.score - 2,
1385 upvotes: this.state.upvotes - 1,
1386 downvotes: this.state.downvotes + 1,
1388 } else if (myVote == -1) {
1390 score: this.state.score + 1,
1391 downvotes: this.state.downvotes - 1,
1395 score: this.state.score - 1,
1396 downvotes: this.state.downvotes + 1,
1400 this.setState({ my_vote: Some(newVote) });
1402 let form = new CreatePostLike({
1403 post_id: this.props.post_view.post.id,
1405 auth: auth().unwrap(),
1408 WebSocketService.Instance.send(wsClient.likePost(form));
1409 this.setState(this.state);
1413 handleEditClick(i: PostListing) {
1414 i.setState({ showEdit: true });
1417 handleEditCancel() {
1418 this.setState({ showEdit: false });
1421 // The actual editing is done in the recieve for post
1423 this.setState({ showEdit: false });
1426 handleShowReportDialog(i: PostListing) {
1427 i.setState({ showReportDialog: !i.state.showReportDialog });
1430 handleReportReasonChange(i: PostListing, event: any) {
1431 i.setState({ reportReason: Some(event.target.value) });
1434 handleReportSubmit(i: PostListing, event: any) {
1435 event.preventDefault();
1436 let form = new CreatePostReport({
1437 post_id: i.props.post_view.post.id,
1438 reason: toUndefined(i.state.reportReason),
1439 auth: auth().unwrap(),
1441 WebSocketService.Instance.send(wsClient.createPostReport(form));
1443 i.setState({ showReportDialog: false });
1446 handleBlockUserClick(i: PostListing) {
1447 let blockUserForm = new BlockPerson({
1448 person_id: i.props.post_view.creator.id,
1450 auth: auth().unwrap(),
1452 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1455 handleDeleteClick(i: PostListing) {
1456 let deleteForm = new DeletePost({
1457 post_id: i.props.post_view.post.id,
1458 deleted: !i.props.post_view.post.deleted,
1459 auth: auth().unwrap(),
1461 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1464 handleSavePostClick(i: PostListing) {
1466 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1467 let form = new SavePost({
1468 post_id: i.props.post_view.post.id,
1470 auth: auth().unwrap(),
1473 WebSocketService.Instance.send(wsClient.savePost(form));
1476 get crossPostParams(): string {
1477 let post = this.props.post_view.post;
1478 let params = `?title=${encodeURIComponent(post.name)}`;
1480 if (post.url.isSome()) {
1481 params += `&url=${encodeURIComponent(post.url.unwrap())}`;
1483 if (post.body.isSome()) {
1484 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1489 crossPostBody(): string {
1490 let post = this.props.post_view.post;
1491 let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
1493 .replace(/^/gm, "> ")}`;
1497 get showBody(): boolean {
1498 return this.props.showBody || this.state.showBody;
1501 handleModRemoveShow(i: PostListing) {
1503 showRemoveDialog: !i.state.showRemoveDialog,
1504 showBanDialog: false,
1508 handleModRemoveReasonChange(i: PostListing, event: any) {
1509 i.setState({ removeReason: Some(event.target.value) });
1512 handleModRemoveDataChange(i: PostListing, event: any) {
1513 i.setState({ removeData: event.target.checked });
1516 handleModRemoveSubmit(i: PostListing, event: any) {
1517 event.preventDefault();
1518 let form = new RemovePost({
1519 post_id: i.props.post_view.post.id,
1520 removed: !i.props.post_view.post.removed,
1521 reason: i.state.removeReason,
1522 auth: auth().unwrap(),
1524 WebSocketService.Instance.send(wsClient.removePost(form));
1526 i.setState({ showRemoveDialog: false });
1529 handleModLock(i: PostListing) {
1530 let form = new LockPost({
1531 post_id: i.props.post_view.post.id,
1532 locked: !i.props.post_view.post.locked,
1533 auth: auth().unwrap(),
1535 WebSocketService.Instance.send(wsClient.lockPost(form));
1538 handleModFeaturePost(i: PostListing, is_community: boolean) {
1539 let form = new FeaturePost({
1540 post_id: i.props.post_view.post.id,
1541 featured: is_community
1542 ? !i.props.post_view.post.featured_community
1543 : !i.props.post_view.post.featured_local,
1544 feature_type: is_community
1545 ? PostFeatureType.Community
1546 : PostFeatureType.Local,
1547 auth: auth().unwrap(),
1549 WebSocketService.Instance.send(wsClient.featurePost(form));
1552 handleModBanFromCommunityShow(i: PostListing) {
1554 showBanDialog: true,
1555 banType: BanType.Community,
1556 showRemoveDialog: false,
1560 handleModBanShow(i: PostListing) {
1562 showBanDialog: true,
1563 banType: BanType.Site,
1564 showRemoveDialog: false,
1568 handlePurgePersonShow(i: PostListing) {
1570 showPurgeDialog: true,
1571 purgeType: PurgeType.Person,
1572 showRemoveDialog: false,
1576 handlePurgePostShow(i: PostListing) {
1578 showPurgeDialog: true,
1579 purgeType: PurgeType.Post,
1580 showRemoveDialog: false,
1584 handlePurgeReasonChange(i: PostListing, event: any) {
1585 i.setState({ purgeReason: Some(event.target.value) });
1588 handlePurgeSubmit(i: PostListing, event: any) {
1589 event.preventDefault();
1591 if (i.state.purgeType == PurgeType.Person) {
1592 let form = new PurgePerson({
1593 person_id: i.props.post_view.creator.id,
1594 reason: i.state.purgeReason,
1595 auth: auth().unwrap(),
1597 WebSocketService.Instance.send(wsClient.purgePerson(form));
1598 } else if (i.state.purgeType == PurgeType.Post) {
1599 let form = new PurgePost({
1600 post_id: i.props.post_view.post.id,
1601 reason: i.state.purgeReason,
1602 auth: auth().unwrap(),
1604 WebSocketService.Instance.send(wsClient.purgePost(form));
1607 i.setState({ purgeLoading: true });
1610 handleModBanReasonChange(i: PostListing, event: any) {
1611 i.setState({ banReason: Some(event.target.value) });
1614 handleModBanExpireDaysChange(i: PostListing, event: any) {
1615 i.setState({ banExpireDays: Some(event.target.value) });
1618 handleModBanFromCommunitySubmit(i: PostListing) {
1619 i.setState({ banType: BanType.Community });
1620 i.handleModBanBothSubmit(i);
1623 handleModBanSubmit(i: PostListing) {
1624 i.setState({ banType: BanType.Site });
1625 i.handleModBanBothSubmit(i);
1628 handleModBanBothSubmit(i: PostListing, event?: any) {
1629 if (event) event.preventDefault();
1631 if (i.state.banType == BanType.Community) {
1632 // If its an unban, restore all their data
1633 let ban = !i.props.post_view.creator_banned_from_community;
1635 i.setState({ removeData: false });
1637 let form = new BanFromCommunity({
1638 person_id: i.props.post_view.creator.id,
1639 community_id: i.props.post_view.community.id,
1641 remove_data: Some(i.state.removeData),
1642 reason: i.state.banReason,
1643 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1644 auth: auth().unwrap(),
1646 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1648 // If its an unban, restore all their data
1649 let ban = !i.props.post_view.creator.banned;
1651 i.setState({ removeData: false });
1653 let form = new BanPerson({
1654 person_id: i.props.post_view.creator.id,
1656 remove_data: Some(i.state.removeData),
1657 reason: i.state.banReason,
1658 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1659 auth: auth().unwrap(),
1661 WebSocketService.Instance.send(wsClient.banPerson(form));
1664 i.setState({ showBanDialog: false });
1667 handleAddModToCommunity(i: PostListing) {
1668 let form = new AddModToCommunity({
1669 person_id: i.props.post_view.creator.id,
1670 community_id: i.props.post_view.community.id,
1671 added: !i.creatorIsMod_,
1672 auth: auth().unwrap(),
1674 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1675 i.setState(i.state);
1678 handleAddAdmin(i: PostListing) {
1679 let form = new AddAdmin({
1680 person_id: i.props.post_view.creator.id,
1681 added: !i.creatorIsAdmin_,
1682 auth: auth().unwrap(),
1684 WebSocketService.Instance.send(wsClient.addAdmin(form));
1685 i.setState(i.state);
1688 handleShowConfirmTransferCommunity(i: PostListing) {
1689 i.setState({ showConfirmTransferCommunity: true });
1692 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1693 i.setState({ showConfirmTransferCommunity: false });
1696 handleTransferCommunity(i: PostListing) {
1697 let form = new TransferCommunity({
1698 community_id: i.props.post_view.community.id,
1699 person_id: i.props.post_view.creator.id,
1700 auth: auth().unwrap(),
1702 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1703 i.setState({ showConfirmTransferCommunity: false });
1706 handleShowConfirmTransferSite(i: PostListing) {
1707 i.setState({ showConfirmTransferSite: true });
1710 handleCancelShowConfirmTransferSite(i: PostListing) {
1711 i.setState({ showConfirmTransferSite: false });
1714 handleImageExpandClick(i: PostListing, event: any) {
1715 event.preventDefault();
1716 i.setState({ imageExpanded: !i.state.imageExpanded });
1720 handleViewSource(i: PostListing) {
1721 i.setState({ viewSource: !i.state.viewSource });
1724 handleShowAdvanced(i: PostListing) {
1725 i.setState({ showAdvanced: !i.state.showAdvanced });
1729 handleShowMoreMobile(i: PostListing) {
1731 showMoreMobile: !i.state.showMoreMobile,
1732 showAdvanced: !i.state.showAdvanced,
1737 handleShowBody(i: PostListing) {
1738 i.setState({ showBody: !i.state.showBody });
1742 get pointsTippy(): string {
1743 let points = i18n.t("number_of_points", {
1744 count: this.state.score,
1745 formattedCount: this.state.score,
1748 let upvotes = i18n.t("number_of_upvotes", {
1749 count: this.state.upvotes,
1750 formattedCount: this.state.upvotes,
1753 let downvotes = i18n.t("number_of_downvotes", {
1754 count: this.state.downvotes,
1755 formattedCount: this.state.downvotes,
1758 return `${points} • ${upvotes} • ${downvotes}`;
1761 get canModOnSelf_(): boolean {
1763 this.props.moderators,
1765 this.props.post_view.creator.id,
1771 get canMod_(): boolean {
1773 this.props.moderators,
1775 this.props.post_view.creator.id
1779 get canAdmin_(): boolean {
1780 return canAdmin(this.props.admins, this.props.post_view.creator.id);
1783 get creatorIsMod_(): boolean {
1784 return isMod(this.props.moderators, this.props.post_view.creator.id);
1787 get creatorIsAdmin_(): boolean {
1788 return isAdmin(this.props.admins, this.props.post_view.creator.id);