1 import { None, Option, Some } from "@sniptt/monads";
2 import classNames from "classnames";
3 import { Component, linkEvent } from "inferno";
4 import { Link } from "inferno-router";
11 CommunityModeratorView,
26 } from "lemmy-js-client";
27 import { externalHost } from "../../env";
28 import { i18n } from "../../i18next";
29 import { BanType, PurgeType } from "../../interfaces";
30 import { UserService, WebSocketService } from "../../services";
51 import { Icon, PurgeWarning, Spinner } from "../common/icon";
52 import { MomentTime } from "../common/moment-time";
53 import { PictrsImage } from "../common/pictrs-image";
54 import { CommunityLink } from "../community/community-link";
55 import { PersonListing } from "../person/person-listing";
56 import { MetadataCard } from "./metadata-card";
57 import { PostForm } from "./post-form";
59 interface PostListingState {
61 showRemoveDialog: boolean;
62 showPurgeDialog: boolean;
63 purgeReason: Option<string>;
65 purgeLoading: boolean;
66 removeReason: Option<string>;
67 showBanDialog: boolean;
68 banReason: Option<string>;
69 banExpireDays: Option<number>;
72 showConfirmTransferSite: boolean;
73 showConfirmTransferCommunity: boolean;
74 imageExpanded: boolean;
76 showAdvanced: boolean;
77 showMoreMobile: boolean;
79 showReportDialog: boolean;
80 reportReason: Option<string>;
81 my_vote: Option<number>;
87 interface PostListingProps {
89 duplicates: Option<PostView[]>;
90 moderators: Option<CommunityModeratorView[]>;
91 admins: Option<PersonViewSafe[]>;
92 allLanguages: Language[];
93 showCommunity?: boolean;
95 enableDownvotes?: boolean;
100 export class PostListing extends Component<PostListingProps, PostListingState> {
101 private emptyState: PostListingState = {
103 showRemoveDialog: false,
104 showPurgeDialog: false,
106 purgeType: PurgeType.Person,
109 showBanDialog: false,
112 banType: BanType.Community,
114 showConfirmTransferSite: false,
115 showConfirmTransferCommunity: false,
116 imageExpanded: false,
119 showMoreMobile: false,
121 showReportDialog: false,
123 my_vote: this.props.post_view.my_vote,
124 score: this.props.post_view.counts.score,
125 upvotes: this.props.post_view.counts.upvotes,
126 downvotes: this.props.post_view.counts.downvotes,
129 constructor(props: any, context: any) {
130 super(props, context);
132 this.state = this.emptyState;
133 this.handlePostLike = this.handlePostLike.bind(this);
134 this.handlePostDisLike = this.handlePostDisLike.bind(this);
135 this.handleEditPost = this.handleEditPost.bind(this);
136 this.handleEditCancel = this.handleEditCancel.bind(this);
139 componentWillReceiveProps(nextProps: PostListingProps) {
141 my_vote: nextProps.post_view.my_vote,
142 upvotes: nextProps.post_view.counts.upvotes,
143 downvotes: nextProps.post_view.counts.downvotes,
144 score: nextProps.post_view.counts.score,
146 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
147 this.setState({ imageExpanded: false });
152 let post = this.props.post_view.post;
154 <div className="post-listing">
155 {!this.state.showEdit ? (
158 {this.state.imageExpanded && this.img}
159 {post.url.isSome() &&
161 post.embed_title.isSome() && <MetadataCard post={post} />}
162 {this.showBody && this.body()}
165 <div className="col-12">
167 post_view={Some(this.props.post_view)}
170 onEdit={this.handleEditPost}
171 onCancel={this.handleEditCancel}
172 enableNsfw={this.props.enableNsfw}
173 enableDownvotes={this.props.enableDownvotes}
174 allLanguages={this.props.allLanguages}
183 return this.props.post_view.post.body.match({
185 <div className="col-12 card my-2 p-2">
186 {this.state.viewSource ? (
189 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
198 return this.imageSrc.match({
201 <div className="offset-sm-3 my-2 d-none d-sm-block">
202 <a href={src} className="d-inline-block">
203 <PictrsImage src={src} />
206 <div className="my-2 d-block d-sm-none">
208 className="d-inline-block"
209 onClick={linkEvent(this, this.handleImageExpandClick)}
211 <PictrsImage src={src} />
220 imgThumb(src: string) {
221 let post_view = this.props.post_view;
227 nsfw={post_view.post.nsfw || post_view.community.nsfw}
232 get imageSrc(): Option<string> {
233 let post = this.props.post_view.post;
235 let thumbnail = post.thumbnail_url;
237 if (url.isSome() && isImage(url.unwrap())) {
238 if (url.unwrap().includes("pictrs")) {
240 } else if (thumbnail.isSome()) {
245 } else if (thumbnail.isSome()) {
253 let post = this.props.post_view.post;
255 let thumbnail = post.thumbnail_url;
257 if (url.isSome() && isImage(url.unwrap())) {
260 href={this.imageSrc.unwrap()}
261 className="text-body d-inline-block position-relative mb-2"
262 data-tippy-content={i18n.t("expand_here")}
263 onClick={linkEvent(this, this.handleImageExpandClick)}
264 aria-label={i18n.t("expand_here")}
266 {this.imgThumb(this.imageSrc.unwrap())}
267 <Icon icon="image" classes="mini-overlay" />
270 } else if (url.isSome() && thumbnail.isSome()) {
273 className="text-body d-inline-block position-relative mb-2"
278 {this.imgThumb(this.imageSrc.unwrap())}
279 <Icon icon="external-link" classes="mini-overlay" />
282 } else if (url.isSome()) {
283 if (isVideo(url.unwrap())) {
285 <div className="embed-responsive embed-responsive-16by9">
291 className="embed-responsive-item"
293 <source src={url.unwrap()} type="video/mp4" />
300 className="text-body"
305 <div className="thumbnail rounded bg-light d-flex justify-content-center">
306 <Icon icon="external-link" classes="d-flex align-items-center" />
314 className="text-body"
315 to={`/post/${post.id}`}
316 title={i18n.t("comments")}
318 <div className="thumbnail rounded bg-light d-flex justify-content-center">
319 <Icon icon="message-square" classes="d-flex align-items-center" />
327 let post_view = this.props.post_view;
329 <ul className="list-inline mb-1 text-muted small">
330 <li className="list-inline-item">
331 <PersonListing person={post_view.creator} />
333 {this.creatorIsMod_ && (
334 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
336 {this.creatorIsAdmin_ && (
337 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
339 {post_view.creator.bot_account && (
340 <span className="mx-1 badge badge-light">
341 {i18n.t("bot_account").toLowerCase()}
344 {(post_view.creator_banned_from_community ||
345 isBanned(post_view.creator)) && (
346 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
348 {post_view.creator_blocked && (
349 <span className="mx-1 badge badge-danger">{"blocked"}</span>
351 {this.props.showCommunity && (
353 <span className="mx-1"> {i18n.t("to")} </span>
354 <CommunityLink community={post_view.community} />
358 <li className="list-inline-item">•</li>
359 {post_view.post.url.match({
361 !(hostname(url) == externalHost) && (
363 <li className="list-inline-item">
365 className="text-muted font-italic"
373 <li className="list-inline-item">•</li>
378 <li className="list-inline-item">
381 published={post_view.post.published}
382 updated={post_view.post.updated}
386 {post_view.post.body.match({
389 <li className="list-inline-item">•</li>
390 <li className="list-inline-item">
392 className="text-muted btn btn-sm btn-link p-0"
393 data-tippy-content={md.render(body)}
394 data-tippy-allowHtml={true}
395 onClick={linkEvent(this, this.handleShowBody)}
397 <Icon icon="book-open" classes="icon-inline mr-1" />
410 <div className={`vote-bar col-1 pr-0 small text-center`}>
412 className={`btn-animate btn btn-link p-0 ${
413 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
415 onClick={this.handlePostLike}
416 data-tippy-content={i18n.t("upvote")}
417 aria-label={i18n.t("upvote")}
419 <Icon icon="arrow-up1" classes="upvote" />
423 className={`unselectable pointer font-weight-bold text-muted px-1`}
424 data-tippy-content={this.pointsTippy}
426 {numToSI(this.state.score)}
429 <div className="p-1"></div>
431 {this.props.enableDownvotes && (
433 className={`btn-animate btn btn-link p-0 ${
434 this.state.my_vote.unwrapOr(0) == -1
438 onClick={this.handlePostDisLike}
439 data-tippy-content={i18n.t("downvote")}
440 aria-label={i18n.t("downvote")}
442 <Icon icon="arrow-down1" classes="downvote" />
450 let post = this.props.post_view.post;
452 <div className="post-title overflow-hidden">
457 className={!post.stickied ? "text-body" : "text-primary"}
467 className={!post.stickied ? "text-body" : "text-primary"}
468 to={`/post/${post.id}`}
469 title={i18n.t("comments")}
475 {post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
477 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
478 data-tippy-content={i18n.t("expand_here")}
479 onClick={linkEvent(this, this.handleImageExpandClick)}
483 !this.state.imageExpanded ? "plus-square" : "minus-square"
485 classes="icon-inline"
490 <small className="ml-2 text-muted font-italic">
496 className="unselectable pointer ml-2 text-muted font-italic"
497 data-tippy-content={i18n.t("deleted")}
499 <Icon icon="trash" classes="icon-inline text-danger" />
504 className="unselectable pointer ml-2 text-muted font-italic"
505 data-tippy-content={i18n.t("locked")}
507 <Icon icon="lock" classes="icon-inline text-danger" />
512 className="unselectable pointer ml-2 text-muted font-italic"
513 data-tippy-content={i18n.t("stickied")}
515 <Icon icon="pin" classes="icon-inline text-primary" />
519 <small className="ml-2 text-muted font-italic">
529 return this.props.duplicates.match({
531 dupes.length > 0 && (
532 <ul className="list-inline mb-1 small text-muted">
534 <li className="list-inline-item mr-2">
535 {i18n.t("cross_posted_to")}
538 <li key={pv.post.id} className="list-inline-item mr-2">
539 <Link to={`/post/${pv.post.id}`}>
542 : `${pv.community.name}@${hostname(
543 pv.community.actor_id
555 commentsLine(mobile = false) {
556 let post = this.props.post_view.post;
558 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
559 {this.commentsButton}
562 className="btn btn-link btn-animate text-muted py-0"
563 title={i18n.t("link")}
566 <Icon icon="fedilink" inline />
569 {mobile && !this.props.viewOnly && this.mobileVotes}
570 {UserService.Instance.myUserInfo.isSome() &&
571 !this.props.viewOnly &&
572 this.postActions(mobile)}
577 postActions(mobile = false) {
578 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
579 // Possible enhancement: Make each button a component.
580 let post_view = this.props.post_view;
584 {this.crossPostButton}
585 {mobile && this.showMoreButton}
586 {(!mobile || this.state.showAdvanced) && (
594 {this.myPost && (this.showBody || this.state.showAdvanced) && (
602 {this.state.showAdvanced && (
605 post_view.post.body.isSome() &&
606 this.viewSourceButton}
607 {this.canModOnSelf_ && (
613 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
616 {!mobile && this.showMoreButton}
621 get commentsButton() {
622 let post_view = this.props.post_view;
624 <button className="btn btn-link text-muted py-0 pl-0">
626 className="text-muted"
627 title={i18n.t("number_of_comments", {
628 count: post_view.counts.comments,
629 formattedCount: post_view.counts.comments,
631 to={`/post/${post_view.post.id}?scrollToComments=true`}
633 <Icon icon="message-square" classes="mr-1" inline />
634 {i18n.t("number_of_comments", {
635 count: post_view.counts.comments,
636 formattedCount: numToSI(post_view.counts.comments),
645 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
650 className={`btn-animate btn py-0 px-1 ${
651 this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
654 onClick={this.handlePostLike}
655 aria-label={i18n.t("upvote")}
657 <Icon icon="arrow-up1" classes="icon-inline small" />
659 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
662 {this.props.enableDownvotes && (
664 className={`ml-2 btn-animate btn py-0 px-1 ${
665 this.state.my_vote.unwrapOr(0) == -1
669 onClick={this.handlePostDisLike}
671 aria-label={i18n.t("downvote")}
673 <Icon icon="arrow-down1" classes="icon-inline small" />
676 className={classNames("ml-2", {
677 invisible: this.state.downvotes === 0,
680 {numToSI(this.state.downvotes)}
691 let saved = this.props.post_view.saved;
692 let label = saved ? i18n.t("unsave") : i18n.t("save");
695 className="btn btn-link btn-animate text-muted py-0"
696 onClick={linkEvent(this, this.handleSavePostClick)}
697 data-tippy-content={label}
702 classes={classNames({ "text-warning": saved })}
709 get crossPostButton() {
712 className="btn btn-link btn-animate text-muted py-0"
713 to={`/create_post${this.crossPostParams}`}
714 title={i18n.t("cross_post")}
716 <Icon icon="copy" inline />
724 className="btn btn-link btn-animate text-muted py-0"
725 onClick={linkEvent(this, this.handleShowReportDialog)}
726 data-tippy-content={i18n.t("show_report_dialog")}
727 aria-label={i18n.t("show_report_dialog")}
729 <Icon icon="flag" inline />
737 className="btn btn-link btn-animate text-muted py-0"
738 onClick={linkEvent(this, this.handleBlockUserClick)}
739 data-tippy-content={i18n.t("block_user")}
740 aria-label={i18n.t("block_user")}
742 <Icon icon="slash" inline />
750 className="btn btn-link btn-animate text-muted py-0"
751 onClick={linkEvent(this, this.handleEditClick)}
752 data-tippy-content={i18n.t("edit")}
753 aria-label={i18n.t("edit")}
755 <Icon icon="edit" inline />
761 let deleted = this.props.post_view.post.deleted;
762 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
765 className="btn btn-link btn-animate text-muted py-0"
766 onClick={linkEvent(this, this.handleDeleteClick)}
767 data-tippy-content={label}
772 classes={classNames({ "text-danger": deleted })}
779 get showMoreButton() {
782 className="btn btn-link btn-animate text-muted py-0"
783 onClick={linkEvent(this, this.handleShowAdvanced)}
784 data-tippy-content={i18n.t("more")}
785 aria-label={i18n.t("more")}
787 <Icon icon="more-vertical" inline />
792 get viewSourceButton() {
795 className="btn btn-link btn-animate text-muted py-0"
796 onClick={linkEvent(this, this.handleViewSource)}
797 data-tippy-content={i18n.t("view_source")}
798 aria-label={i18n.t("view_source")}
802 classes={classNames({ "text-success": this.state.viewSource })}
810 let locked = this.props.post_view.post.locked;
811 let label = locked ? i18n.t("unlock") : i18n.t("lock");
814 className="btn btn-link btn-animate text-muted py-0"
815 onClick={linkEvent(this, this.handleModLock)}
816 data-tippy-content={label}
821 classes={classNames({ "text-danger": locked })}
829 let stickied = this.props.post_view.post.stickied;
830 let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
833 className="btn btn-link btn-animate text-muted py-0"
834 onClick={linkEvent(this, this.handleModSticky)}
835 data-tippy-content={label}
840 classes={classNames({ "text-success": stickied })}
847 get modRemoveButton() {
848 let removed = this.props.post_view.post.removed;
851 className="btn btn-link btn-animate text-muted py-0"
854 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
857 {/* TODO: Find an icon for this. */}
858 {!removed ? i18n.t("remove") : i18n.t("restore")}
864 * Mod/Admin actions to be taken against the author.
868 let post_view = this.props.post_view;
870 this.state.showAdvanced && (
874 {!this.creatorIsMod_ &&
875 (!post_view.creator_banned_from_community ? (
877 className="btn btn-link btn-animate text-muted py-0"
880 this.handleModBanFromCommunityShow
882 aria-label={i18n.t("ban")}
888 className="btn btn-link btn-animate text-muted py-0"
891 this.handleModBanFromCommunitySubmit
893 aria-label={i18n.t("unban")}
898 {!post_view.creator_banned_from_community && (
900 className="btn btn-link btn-animate text-muted py-0"
901 onClick={linkEvent(this, this.handleAddModToCommunity)}
904 ? i18n.t("remove_as_mod")
905 : i18n.t("appoint_as_mod")
909 ? i18n.t("remove_as_mod")
910 : i18n.t("appoint_as_mod")}
915 {/* Community creators and admins can transfer community to another mod */}
916 {(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
918 this.creatorIsMod_ &&
919 (!this.state.showConfirmTransferCommunity ? (
921 className="btn btn-link btn-animate text-muted py-0"
924 this.handleShowConfirmTransferCommunity
926 aria-label={i18n.t("transfer_community")}
928 {i18n.t("transfer_community")}
933 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
934 aria-label={i18n.t("are_you_sure")}
936 {i18n.t("are_you_sure")}
939 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
940 aria-label={i18n.t("yes")}
941 onClick={linkEvent(this, this.handleTransferCommunity)}
946 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
949 this.handleCancelShowConfirmTransferCommunity
951 aria-label={i18n.t("no")}
957 {/* Admins can ban from all, and appoint other admins */}
960 {!this.creatorIsAdmin_ && (
962 {!isBanned(post_view.creator) ? (
964 className="btn btn-link btn-animate text-muted py-0"
965 onClick={linkEvent(this, this.handleModBanShow)}
966 aria-label={i18n.t("ban_from_site")}
968 {i18n.t("ban_from_site")}
972 className="btn btn-link btn-animate text-muted py-0"
973 onClick={linkEvent(this, this.handleModBanSubmit)}
974 aria-label={i18n.t("unban_from_site")}
976 {i18n.t("unban_from_site")}
980 className="btn btn-link btn-animate text-muted py-0"
981 onClick={linkEvent(this, this.handlePurgePersonShow)}
982 aria-label={i18n.t("purge_user")}
984 {i18n.t("purge_user")}
987 className="btn btn-link btn-animate text-muted py-0"
988 onClick={linkEvent(this, this.handlePurgePostShow)}
989 aria-label={i18n.t("purge_post")}
991 {i18n.t("purge_post")}
995 {!isBanned(post_view.creator) && post_view.creator.local && (
997 className="btn btn-link btn-animate text-muted py-0"
998 onClick={linkEvent(this, this.handleAddAdmin)}
1000 this.creatorIsAdmin_
1001 ? i18n.t("remove_as_admin")
1002 : i18n.t("appoint_as_admin")
1005 {this.creatorIsAdmin_
1006 ? i18n.t("remove_as_admin")
1007 : i18n.t("appoint_as_admin")}
1017 removeAndBanDialogs() {
1018 let post = this.props.post_view;
1019 let purgeTypeText: string;
1020 if (this.state.purgeType == PurgeType.Post) {
1021 purgeTypeText = i18n.t("purge_post");
1022 } else if (this.state.purgeType == PurgeType.Person) {
1023 purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
1027 {this.state.showRemoveDialog && (
1029 className="form-inline"
1030 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1032 <label className="sr-only" htmlFor="post-listing-remove-reason">
1037 id="post-listing-remove-reason"
1038 className="form-control mr-2"
1039 placeholder={i18n.t("reason")}
1040 value={toUndefined(this.state.removeReason)}
1041 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1045 className="btn btn-secondary"
1046 aria-label={i18n.t("remove_post")}
1048 {i18n.t("remove_post")}
1052 {this.state.showBanDialog && (
1053 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1054 <div className="form-group row col-12">
1056 className="col-form-label"
1057 htmlFor="post-listing-ban-reason"
1063 id="post-listing-ban-reason"
1064 className="form-control mr-2"
1065 placeholder={i18n.t("reason")}
1066 value={toUndefined(this.state.banReason)}
1067 onInput={linkEvent(this, this.handleModBanReasonChange)}
1069 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1074 id={`mod-ban-expires`}
1075 className="form-control mr-2"
1076 placeholder={i18n.t("number_of_days")}
1077 value={toUndefined(this.state.banExpireDays)}
1078 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1080 <div className="form-group">
1081 <div className="form-check">
1083 className="form-check-input"
1084 id="mod-ban-remove-data"
1086 checked={this.state.removeData}
1087 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1090 className="form-check-label"
1091 htmlFor="mod-ban-remove-data"
1092 title={i18n.t("remove_content_more")}
1094 {i18n.t("remove_content")}
1099 {/* TODO hold off on expires until later */}
1100 {/* <div class="form-group row"> */}
1101 {/* <label class="col-form-label">Expires</label> */}
1102 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1104 <div className="form-group row">
1107 className="btn btn-secondary"
1108 aria-label={i18n.t("ban")}
1110 {i18n.t("ban")} {post.creator.name}
1115 {this.state.showReportDialog && (
1117 className="form-inline"
1118 onSubmit={linkEvent(this, this.handleReportSubmit)}
1120 <label className="sr-only" htmlFor="post-report-reason">
1125 id="post-report-reason"
1126 className="form-control mr-2"
1127 placeholder={i18n.t("reason")}
1129 value={toUndefined(this.state.reportReason)}
1130 onInput={linkEvent(this, this.handleReportReasonChange)}
1134 className="btn btn-secondary"
1135 aria-label={i18n.t("create_report")}
1137 {i18n.t("create_report")}
1141 {this.state.showPurgeDialog && (
1143 className="form-inline"
1144 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1147 <label className="sr-only" htmlFor="purge-reason">
1153 className="form-control mr-2"
1154 placeholder={i18n.t("reason")}
1155 value={toUndefined(this.state.purgeReason)}
1156 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1158 {this.state.purgeLoading ? (
1163 className="btn btn-secondary"
1164 aria-label={purgeTypeText}
1176 let post = this.props.post_view.post;
1177 return post.thumbnail_url.isSome() ||
1178 post.url.map(isImage).unwrapOr(false) ? (
1179 <div className="row">
1180 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1181 {this.postTitleLine()}
1183 <div className="col-4">
1184 {/* Post body prev or thumbnail */}
1185 {!this.state.imageExpanded && this.thumbnail()}
1189 this.postTitleLine()
1193 showMobilePreview() {
1194 let post = this.props.post_view.post;
1198 some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
1207 {/* The mobile view*/}
1208 <div className="d-block d-sm-none">
1209 <div className="row">
1210 <div className="col-12">
1211 {this.createdLine()}
1213 {/* If it has a thumbnail, do a right aligned thumbnail */}
1214 {this.mobileThumbnail()}
1216 {/* Show a preview of the post body */}
1217 {this.showMobilePreview()}
1219 {this.commentsLine(true)}
1220 {this.userActionsLine()}
1221 {this.duplicatesLine()}
1222 {this.removeAndBanDialogs()}
1227 {/* The larger view*/}
1228 <div className="d-none d-sm-block">
1229 <div className="row">
1230 {!this.props.viewOnly && this.voteBar()}
1231 <div className="col-sm-2 pr-0">
1232 <div className="">{this.thumbnail()}</div>
1234 <div className="col-12 col-sm-9">
1235 <div className="row">
1236 <div className="col-12">
1237 {this.postTitleLine()}
1238 {this.createdLine()}
1239 {this.commentsLine()}
1240 {this.duplicatesLine()}
1241 {this.userActionsLine()}
1242 {this.removeAndBanDialogs()}
1252 private get myPost(): boolean {
1253 return UserService.Instance.myUserInfo.match({
1255 this.props.post_view.creator.id == mui.local_user_view.person.id,
1260 handlePostLike(event: any) {
1261 event.preventDefault();
1262 if (UserService.Instance.myUserInfo.isNone()) {
1263 this.context.router.history.push(`/login`);
1266 let myVote = this.state.my_vote.unwrapOr(0);
1267 let newVote = myVote == 1 ? 0 : 1;
1271 score: this.state.score - 1,
1272 upvotes: this.state.upvotes - 1,
1274 } else if (myVote == -1) {
1276 score: this.state.score + 2,
1277 upvotes: this.state.upvotes + 1,
1278 downvotes: this.state.downvotes - 1,
1282 score: this.state.score + 1,
1283 upvotes: this.state.upvotes + 1,
1287 this.setState({ my_vote: Some(newVote) });
1289 let form = new CreatePostLike({
1290 post_id: this.props.post_view.post.id,
1292 auth: auth().unwrap(),
1295 WebSocketService.Instance.send(wsClient.likePost(form));
1296 this.setState(this.state);
1300 handlePostDisLike(event: any) {
1301 event.preventDefault();
1302 if (UserService.Instance.myUserInfo.isNone()) {
1303 this.context.router.history.push(`/login`);
1306 let myVote = this.state.my_vote.unwrapOr(0);
1307 let newVote = myVote == -1 ? 0 : -1;
1311 score: this.state.score - 2,
1312 upvotes: this.state.upvotes - 1,
1313 downvotes: this.state.downvotes + 1,
1315 } else if (myVote == -1) {
1317 score: this.state.score + 1,
1318 downvotes: this.state.downvotes - 1,
1322 score: this.state.score - 1,
1323 downvotes: this.state.downvotes + 1,
1327 this.setState({ my_vote: Some(newVote) });
1329 let form = new CreatePostLike({
1330 post_id: this.props.post_view.post.id,
1332 auth: auth().unwrap(),
1335 WebSocketService.Instance.send(wsClient.likePost(form));
1336 this.setState(this.state);
1340 handleEditClick(i: PostListing) {
1341 i.setState({ showEdit: true });
1344 handleEditCancel() {
1345 this.setState({ showEdit: false });
1348 // The actual editing is done in the recieve for post
1350 this.setState({ showEdit: false });
1353 handleShowReportDialog(i: PostListing) {
1354 i.setState({ showReportDialog: !i.state.showReportDialog });
1357 handleReportReasonChange(i: PostListing, event: any) {
1358 i.setState({ reportReason: Some(event.target.value) });
1361 handleReportSubmit(i: PostListing, event: any) {
1362 event.preventDefault();
1363 let form = new CreatePostReport({
1364 post_id: i.props.post_view.post.id,
1365 reason: toUndefined(i.state.reportReason),
1366 auth: auth().unwrap(),
1368 WebSocketService.Instance.send(wsClient.createPostReport(form));
1370 i.setState({ showReportDialog: false });
1373 handleBlockUserClick(i: PostListing) {
1374 let blockUserForm = new BlockPerson({
1375 person_id: i.props.post_view.creator.id,
1377 auth: auth().unwrap(),
1379 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1382 handleDeleteClick(i: PostListing) {
1383 let deleteForm = new DeletePost({
1384 post_id: i.props.post_view.post.id,
1385 deleted: !i.props.post_view.post.deleted,
1386 auth: auth().unwrap(),
1388 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1391 handleSavePostClick(i: PostListing) {
1393 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1394 let form = new SavePost({
1395 post_id: i.props.post_view.post.id,
1397 auth: auth().unwrap(),
1400 WebSocketService.Instance.send(wsClient.savePost(form));
1403 get crossPostParams(): string {
1404 let post = this.props.post_view.post;
1405 let params = `?title=${encodeURIComponent(post.name)}`;
1407 if (post.url.isSome()) {
1408 params += `&url=${encodeURIComponent(post.url.unwrap())}`;
1410 if (post.body.isSome()) {
1411 params += `&body=${encodeURIComponent(this.crossPostBody())}`;
1416 crossPostBody(): string {
1417 let post = this.props.post_view.post;
1418 let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
1420 .replace(/^/gm, "> ")}`;
1424 get showBody(): boolean {
1425 return this.props.showBody || this.state.showBody;
1428 handleModRemoveShow(i: PostListing) {
1430 showRemoveDialog: !i.state.showRemoveDialog,
1431 showBanDialog: false,
1435 handleModRemoveReasonChange(i: PostListing, event: any) {
1436 i.setState({ removeReason: Some(event.target.value) });
1439 handleModRemoveDataChange(i: PostListing, event: any) {
1440 i.setState({ removeData: event.target.checked });
1443 handleModRemoveSubmit(i: PostListing, event: any) {
1444 event.preventDefault();
1445 let form = new RemovePost({
1446 post_id: i.props.post_view.post.id,
1447 removed: !i.props.post_view.post.removed,
1448 reason: i.state.removeReason,
1449 auth: auth().unwrap(),
1451 WebSocketService.Instance.send(wsClient.removePost(form));
1453 i.setState({ showRemoveDialog: false });
1456 handleModLock(i: PostListing) {
1457 let form = new LockPost({
1458 post_id: i.props.post_view.post.id,
1459 locked: !i.props.post_view.post.locked,
1460 auth: auth().unwrap(),
1462 WebSocketService.Instance.send(wsClient.lockPost(form));
1465 handleModSticky(i: PostListing) {
1466 let form = new StickyPost({
1467 post_id: i.props.post_view.post.id,
1468 stickied: !i.props.post_view.post.stickied,
1469 auth: auth().unwrap(),
1471 WebSocketService.Instance.send(wsClient.stickyPost(form));
1474 handleModBanFromCommunityShow(i: PostListing) {
1476 showBanDialog: true,
1477 banType: BanType.Community,
1478 showRemoveDialog: false,
1482 handleModBanShow(i: PostListing) {
1484 showBanDialog: true,
1485 banType: BanType.Site,
1486 showRemoveDialog: false,
1490 handlePurgePersonShow(i: PostListing) {
1492 showPurgeDialog: true,
1493 purgeType: PurgeType.Person,
1494 showRemoveDialog: false,
1498 handlePurgePostShow(i: PostListing) {
1500 showPurgeDialog: true,
1501 purgeType: PurgeType.Post,
1502 showRemoveDialog: false,
1506 handlePurgeReasonChange(i: PostListing, event: any) {
1507 i.setState({ purgeReason: Some(event.target.value) });
1510 handlePurgeSubmit(i: PostListing, event: any) {
1511 event.preventDefault();
1513 if (i.state.purgeType == PurgeType.Person) {
1514 let form = new PurgePerson({
1515 person_id: i.props.post_view.creator.id,
1516 reason: i.state.purgeReason,
1517 auth: auth().unwrap(),
1519 WebSocketService.Instance.send(wsClient.purgePerson(form));
1520 } else if (i.state.purgeType == PurgeType.Post) {
1521 let form = new PurgePost({
1522 post_id: i.props.post_view.post.id,
1523 reason: i.state.purgeReason,
1524 auth: auth().unwrap(),
1526 WebSocketService.Instance.send(wsClient.purgePost(form));
1529 i.setState({ purgeLoading: true });
1532 handleModBanReasonChange(i: PostListing, event: any) {
1533 i.setState({ banReason: Some(event.target.value) });
1536 handleModBanExpireDaysChange(i: PostListing, event: any) {
1537 i.setState({ banExpireDays: Some(event.target.value) });
1540 handleModBanFromCommunitySubmit(i: PostListing) {
1541 i.setState({ banType: BanType.Community });
1542 i.handleModBanBothSubmit(i);
1545 handleModBanSubmit(i: PostListing) {
1546 i.setState({ banType: BanType.Site });
1547 i.handleModBanBothSubmit(i);
1550 handleModBanBothSubmit(i: PostListing, event?: any) {
1551 if (event) event.preventDefault();
1553 if (i.state.banType == BanType.Community) {
1554 // If its an unban, restore all their data
1555 let ban = !i.props.post_view.creator_banned_from_community;
1557 i.setState({ removeData: false });
1559 let form = new BanFromCommunity({
1560 person_id: i.props.post_view.creator.id,
1561 community_id: i.props.post_view.community.id,
1563 remove_data: Some(i.state.removeData),
1564 reason: i.state.banReason,
1565 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1566 auth: auth().unwrap(),
1568 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1570 // If its an unban, restore all their data
1571 let ban = !i.props.post_view.creator.banned;
1573 i.setState({ removeData: false });
1575 let form = new BanPerson({
1576 person_id: i.props.post_view.creator.id,
1578 remove_data: Some(i.state.removeData),
1579 reason: i.state.banReason,
1580 expires: i.state.banExpireDays.map(futureDaysToUnixTime),
1581 auth: auth().unwrap(),
1583 WebSocketService.Instance.send(wsClient.banPerson(form));
1586 i.setState({ showBanDialog: false });
1589 handleAddModToCommunity(i: PostListing) {
1590 let form = new AddModToCommunity({
1591 person_id: i.props.post_view.creator.id,
1592 community_id: i.props.post_view.community.id,
1593 added: !i.creatorIsMod_,
1594 auth: auth().unwrap(),
1596 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1597 i.setState(i.state);
1600 handleAddAdmin(i: PostListing) {
1601 let form = new AddAdmin({
1602 person_id: i.props.post_view.creator.id,
1603 added: !i.creatorIsAdmin_,
1604 auth: auth().unwrap(),
1606 WebSocketService.Instance.send(wsClient.addAdmin(form));
1607 i.setState(i.state);
1610 handleShowConfirmTransferCommunity(i: PostListing) {
1611 i.setState({ showConfirmTransferCommunity: true });
1614 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1615 i.setState({ showConfirmTransferCommunity: false });
1618 handleTransferCommunity(i: PostListing) {
1619 let form = new TransferCommunity({
1620 community_id: i.props.post_view.community.id,
1621 person_id: i.props.post_view.creator.id,
1622 auth: auth().unwrap(),
1624 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1625 i.setState({ showConfirmTransferCommunity: false });
1628 handleShowConfirmTransferSite(i: PostListing) {
1629 i.setState({ showConfirmTransferSite: true });
1632 handleCancelShowConfirmTransferSite(i: PostListing) {
1633 i.setState({ showConfirmTransferSite: false });
1636 handleImageExpandClick(i: PostListing, event: any) {
1637 event.preventDefault();
1638 i.setState({ imageExpanded: !i.state.imageExpanded });
1642 handleViewSource(i: PostListing) {
1643 i.setState({ viewSource: !i.state.viewSource });
1646 handleShowAdvanced(i: PostListing) {
1647 i.setState({ showAdvanced: !i.state.showAdvanced });
1651 handleShowMoreMobile(i: PostListing) {
1653 showMoreMobile: !i.state.showMoreMobile,
1654 showAdvanced: !i.state.showAdvanced,
1659 handleShowBody(i: PostListing) {
1660 i.setState({ showBody: !i.state.showBody });
1664 get pointsTippy(): string {
1665 let points = i18n.t("number_of_points", {
1666 count: this.state.score,
1667 formattedCount: this.state.score,
1670 let upvotes = i18n.t("number_of_upvotes", {
1671 count: this.state.upvotes,
1672 formattedCount: this.state.upvotes,
1675 let downvotes = i18n.t("number_of_downvotes", {
1676 count: this.state.downvotes,
1677 formattedCount: this.state.downvotes,
1680 return `${points} • ${upvotes} • ${downvotes}`;
1683 get canModOnSelf_(): boolean {
1685 this.props.moderators,
1687 this.props.post_view.creator.id,
1693 get canMod_(): boolean {
1695 this.props.moderators,
1697 this.props.post_view.creator.id
1701 get canAdmin_(): boolean {
1702 return canAdmin(this.props.admins, this.props.post_view.creator.id);
1705 get creatorIsMod_(): boolean {
1706 return isMod(this.props.moderators, this.props.post_view.creator.id);
1709 get creatorIsAdmin_(): boolean {
1710 return isAdmin(this.props.admins, this.props.post_view.creator.id);