1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
10 CommunityModeratorView,
25 } from "lemmy-js-client";
26 import { externalHost } from "../../env";
27 import { i18n } from "../../i18next";
28 import { BanType, PurgeType } from "../../interfaces";
29 import { UserService, WebSocketService } from "../../services";
52 import { Icon, PurgeWarning, Spinner } from "../common/icon";
53 import { MomentTime } from "../common/moment-time";
54 import { PictrsImage } from "../common/pictrs-image";
55 import { CommunityLink } from "../community/community-link";
56 import { PersonListing } from "../person/person-listing";
57 import { MetadataCard } from "./metadata-card";
58 import { PostForm } from "./post-form";
60 interface PostListingState {
62 showRemoveDialog: boolean;
63 showPurgeDialog: boolean;
65 purgeType?: PurgeType;
66 purgeLoading: boolean;
67 removeReason?: string;
68 showBanDialog: boolean;
70 banExpireDays?: number;
73 showConfirmTransferSite: boolean;
74 showConfirmTransferCommunity: boolean;
75 imageExpanded: boolean;
77 showAdvanced: boolean;
78 showMoreMobile: boolean;
80 showReportDialog: boolean;
81 reportReason?: string;
88 interface PostListingProps {
90 duplicates?: PostView[];
91 moderators?: CommunityModeratorView[];
92 admins?: PersonViewSafe[];
93 allLanguages: Language[];
94 siteLanguages: number[];
95 showCommunity?: boolean;
98 enableDownvotes?: boolean;
103 export class PostListing extends Component<PostListingProps, PostListingState> {
104 state: PostListingState = {
106 showRemoveDialog: false,
107 showPurgeDialog: false,
108 purgeType: PurgeType.Person,
110 showBanDialog: false,
111 banType: BanType.Community,
113 showConfirmTransferSite: false,
114 showConfirmTransferCommunity: false,
115 imageExpanded: false,
118 showMoreMobile: false,
120 showReportDialog: false,
121 my_vote: this.props.post_view.my_vote,
122 score: this.props.post_view.counts.score,
123 upvotes: this.props.post_view.counts.upvotes,
124 downvotes: this.props.post_view.counts.downvotes,
127 constructor(props: any, context: any) {
128 super(props, context);
130 this.handlePostLike = this.handlePostLike.bind(this);
131 this.handlePostDisLike = this.handlePostDisLike.bind(this);
132 this.handleEditPost = this.handleEditPost.bind(this);
133 this.handleEditCancel = this.handleEditCancel.bind(this);
136 componentWillReceiveProps(nextProps: PostListingProps) {
138 my_vote: nextProps.post_view.my_vote,
139 upvotes: nextProps.post_view.counts.upvotes,
140 downvotes: nextProps.post_view.counts.downvotes,
141 score: nextProps.post_view.counts.score,
143 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
144 this.setState({ imageExpanded: false });
149 let post = this.props.post_view.post;
151 <div className="post-listing">
152 {!this.state.showEdit ? (
155 {this.state.imageExpanded && !this.props.hideImage && this.img}
156 {post.url && this.showBody && post.embed_title && (
157 <MetadataCard post={post} />
159 {this.showBody && this.body()}
162 <div className="col-12">
164 post_view={this.props.post_view}
165 onEdit={this.handleEditPost}
166 onCancel={this.handleEditCancel}
167 enableNsfw={this.props.enableNsfw}
168 enableDownvotes={this.props.enableDownvotes}
169 allLanguages={this.props.allLanguages}
170 siteLanguages={this.props.siteLanguages}
179 let body = this.props.post_view.post.body;
181 <div className="col-12 card my-2 p-2">
182 {this.state.viewSource ? (
185 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
194 let src = this.imageSrc;
197 <div className="offset-sm-3 my-2 d-none d-sm-block">
198 <a href={src} className="d-inline-block">
199 <PictrsImage src={src} />
202 <div className="my-2 d-block d-sm-none">
204 className="d-inline-block"
205 onClick={linkEvent(this, this.handleImageExpandClick)}
207 <PictrsImage src={src} />
216 imgThumb(src: string) {
217 let post_view = this.props.post_view;
223 nsfw={post_view.post.nsfw || post_view.community.nsfw}
228 get imageSrc(): string | undefined {
229 let post = this.props.post_view.post;
231 let thumbnail = post.thumbnail_url;
233 if (url && isImage(url)) {
234 if (url.includes("pictrs")) {
236 } else if (thumbnail) {
241 } else if (thumbnail) {
249 let post = this.props.post_view.post;
251 let thumbnail = post.thumbnail_url;
253 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
257 className="text-body d-inline-block position-relative mb-2"
258 data-tippy-content={i18n.t("expand_here")}
259 onClick={linkEvent(this, this.handleImageExpandClick)}
260 aria-label={i18n.t("expand_here")}
262 {this.imgThumb(this.imageSrc)}
263 <Icon icon="image" classes="mini-overlay" />
266 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
269 className="text-body d-inline-block position-relative mb-2"
274 {this.imgThumb(this.imageSrc)}
275 <Icon icon="external-link" classes="mini-overlay" />
279 if (!this.props.hideImage && isVideo(url)) {
281 <div className="embed-responsive embed-responsive-16by9">
287 className="embed-responsive-item"
289 <source src={url} type="video/mp4" />
295 <a className="text-body" href={url} title={url} rel={relTags}>
296 <div className="thumbnail rounded bg-light d-flex justify-content-center">
297 <Icon icon="external-link" classes="d-flex align-items-center" />
305 className="text-body"
306 to={`/post/${post.id}`}
307 title={i18n.t("comments")}
309 <div className="thumbnail rounded bg-light d-flex justify-content-center">
310 <Icon icon="message-square" classes="d-flex align-items-center" />
318 let post_view = this.props.post_view;
319 let url = post_view.post.url;
320 let body = post_view.post.body;
322 <ul className="list-inline mb-1 text-muted small">
323 <li className="list-inline-item">
324 <PersonListing person={post_view.creator} />
326 {this.creatorIsMod_ && (
327 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
329 {this.creatorIsAdmin_ && (
330 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
332 {post_view.creator.bot_account && (
333 <span className="mx-1 badge badge-light">
334 {i18n.t("bot_account").toLowerCase()}
337 {(post_view.creator_banned_from_community ||
338 isBanned(post_view.creator)) && (
339 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
341 {post_view.creator_blocked && (
342 <span className="mx-1 badge badge-danger">{"blocked"}</span>
344 {this.props.showCommunity && (
346 <span className="mx-1"> {i18n.t("to")} </span>
347 <CommunityLink community={post_view.community} />
351 <li className="list-inline-item">•</li>
352 {url && !(hostname(url) == externalHost) && (
354 <li className="list-inline-item">
356 className="text-muted font-italic"
364 <li className="list-inline-item">•</li>
367 <li className="list-inline-item">
370 published={post_view.post.published}
371 updated={post_view.post.updated}
377 <li className="list-inline-item">•</li>
378 <li className="list-inline-item">
380 className="text-muted btn btn-sm btn-link p-0"
381 data-tippy-content={mdNoImages.render(body)}
382 data-tippy-allowHtml={true}
383 onClick={linkEvent(this, this.handleShowBody)}
385 <Icon icon="book-open" classes="icon-inline mr-1" />
396 <div className={`vote-bar col-1 pr-0 small text-center`}>
398 className={`btn-animate btn btn-link p-0 ${
399 this.state.my_vote == 1 ? "text-info" : "text-muted"
401 onClick={this.handlePostLike}
402 data-tippy-content={i18n.t("upvote")}
403 aria-label={i18n.t("upvote")}
405 <Icon icon="arrow-up1" classes="upvote" />
409 className={`unselectable pointer font-weight-bold text-muted px-1`}
410 data-tippy-content={this.pointsTippy}
412 {numToSI(this.state.score)}
415 <div className="p-1"></div>
417 {this.props.enableDownvotes && (
419 className={`btn-animate btn btn-link p-0 ${
420 this.state.my_vote == -1 ? "text-danger" : "text-muted"
422 onClick={this.handlePostDisLike}
423 data-tippy-content={i18n.t("downvote")}
424 aria-label={i18n.t("downvote")}
426 <Icon icon="arrow-down1" classes="downvote" />
434 let post = this.props.post_view.post;
437 className={`d-inline-block ${
438 !post.featured_community && !post.featured_local
442 to={`/post/${post.id}`}
443 title={i18n.t("comments")}
446 className="d-inline-block"
447 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
454 let post = this.props.post_view.post;
458 <div className="post-title overflow-hidden">
461 this.props.showBody ? (
463 className={`d-inline-block ${
464 !post.featured_community && !post.featured_local
473 className="d-inline-block"
474 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
483 {(url && isImage(url)) ||
484 (post.thumbnail_url && (
486 className="btn btn-link text-monospace text-muted small d-inline-block"
487 data-tippy-content={i18n.t("expand_here")}
488 onClick={linkEvent(this, this.handleImageExpandClick)}
492 !this.state.imageExpanded ? "plus-square" : "minus-square"
494 classes="icon-inline"
499 <small className="ml-2 text-muted font-italic">
505 className="unselectable pointer ml-2 text-muted font-italic"
506 data-tippy-content={i18n.t("deleted")}
508 <Icon icon="trash" classes="icon-inline text-danger" />
513 className="unselectable pointer ml-2 text-muted font-italic"
514 data-tippy-content={i18n.t("locked")}
516 <Icon icon="lock" classes="icon-inline text-danger" />
519 {post.featured_community && (
521 className="unselectable pointer ml-2 text-muted font-italic"
522 data-tippy-content={i18n.t("featured")}
524 <Icon icon="pin" classes="icon-inline text-primary" />
527 {post.featured_local && (
529 className="unselectable pointer ml-2 text-muted font-italic"
530 data-tippy-content={i18n.t("featured")}
532 <Icon icon="pin" classes="icon-inline text-secondary" />
536 <small className="ml-2 text-muted font-italic">
546 let dupes = this.props.duplicates;
547 return dupes && dupes.length > 0 ? (
548 <ul className="list-inline mb-1 small text-muted">
550 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
552 <li key={pv.post.id} className="list-inline-item mr-2">
553 <Link to={`/post/${pv.post.id}`}>
556 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
567 commentsLine(mobile = false) {
568 let post = this.props.post_view.post;
570 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
571 {this.commentsButton}
574 className="btn btn-link btn-animate text-muted py-0"
575 title={i18n.t("link")}
578 <Icon icon="fedilink" inline />
581 {mobile && !this.props.viewOnly && this.mobileVotes}
582 {UserService.Instance.myUserInfo &&
583 !this.props.viewOnly &&
584 this.postActions(mobile)}
589 postActions(mobile = false) {
590 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
591 // Possible enhancement: Make each button a component.
592 let post_view = this.props.post_view;
596 {this.crossPostButton}
597 {mobile && this.showMoreButton}
598 {(!mobile || this.state.showAdvanced) && (
606 {this.myPost && (this.showBody || this.state.showAdvanced) && (
614 {this.state.showAdvanced && (
616 {this.showBody && post_view.post.body && this.viewSourceButton}
617 {this.canModOnSelf_ && (
623 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
626 {!mobile && this.showMoreButton}
631 get commentsButton() {
632 let post_view = this.props.post_view;
634 <button className="btn btn-link text-muted py-0 pl-0">
636 className="text-muted"
637 title={i18n.t("number_of_comments", {
638 count: post_view.counts.comments,
639 formattedCount: post_view.counts.comments,
641 to={`/post/${post_view.post.id}?scrollToComments=true`}
643 <Icon icon="message-square" classes="mr-1" inline />
644 <span className="mr-2">
645 {i18n.t("number_of_comments", {
646 count: post_view.counts.comments,
647 formattedCount: numToSI(post_view.counts.comments),
650 {this.unreadCount && (
651 <span className="small text-warning">
652 ({this.unreadCount} {i18n.t("new")})
660 get unreadCount(): number | undefined {
661 let pv = this.props.post_view;
662 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
664 : pv.unread_comments;
669 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
674 className={`btn-animate btn py-0 px-1 ${
675 this.state.my_vote == 1 ? "text-info" : "text-muted"
678 onClick={this.handlePostLike}
679 aria-label={i18n.t("upvote")}
681 <Icon icon="arrow-up1" classes="icon-inline small" />
683 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
686 {this.props.enableDownvotes && (
688 className={`ml-2 btn-animate btn py-0 px-1 ${
689 this.state.my_vote == -1 ? "text-danger" : "text-muted"
691 onClick={this.handlePostDisLike}
693 aria-label={i18n.t("downvote")}
695 <Icon icon="arrow-down1" classes="icon-inline small" />
698 className={classNames("ml-2", {
699 invisible: this.state.downvotes === 0,
702 {numToSI(this.state.downvotes)}
713 let saved = this.props.post_view.saved;
714 let label = saved ? i18n.t("unsave") : i18n.t("save");
717 className="btn btn-link btn-animate text-muted py-0"
718 onClick={linkEvent(this, this.handleSavePostClick)}
719 data-tippy-content={label}
724 classes={classNames({ "text-warning": saved })}
731 get crossPostButton() {
734 className="btn btn-link btn-animate text-muted py-0"
735 to={`/create_post${this.crossPostParams}`}
736 title={i18n.t("cross_post")}
738 <Icon icon="copy" inline />
746 className="btn btn-link btn-animate text-muted py-0"
747 onClick={linkEvent(this, this.handleShowReportDialog)}
748 data-tippy-content={i18n.t("show_report_dialog")}
749 aria-label={i18n.t("show_report_dialog")}
751 <Icon icon="flag" inline />
759 className="btn btn-link btn-animate text-muted py-0"
760 onClick={linkEvent(this, this.handleBlockUserClick)}
761 data-tippy-content={i18n.t("block_user")}
762 aria-label={i18n.t("block_user")}
764 <Icon icon="slash" inline />
772 className="btn btn-link btn-animate text-muted py-0"
773 onClick={linkEvent(this, this.handleEditClick)}
774 data-tippy-content={i18n.t("edit")}
775 aria-label={i18n.t("edit")}
777 <Icon icon="edit" inline />
783 let deleted = this.props.post_view.post.deleted;
784 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
787 className="btn btn-link btn-animate text-muted py-0"
788 onClick={linkEvent(this, this.handleDeleteClick)}
789 data-tippy-content={label}
794 classes={classNames({ "text-danger": deleted })}
801 get showMoreButton() {
804 className="btn btn-link btn-animate text-muted py-0"
805 onClick={linkEvent(this, this.handleShowAdvanced)}
806 data-tippy-content={i18n.t("more")}
807 aria-label={i18n.t("more")}
809 <Icon icon="more-vertical" inline />
814 get viewSourceButton() {
817 className="btn btn-link btn-animate text-muted py-0"
818 onClick={linkEvent(this, this.handleViewSource)}
819 data-tippy-content={i18n.t("view_source")}
820 aria-label={i18n.t("view_source")}
824 classes={classNames({ "text-success": this.state.viewSource })}
832 let locked = this.props.post_view.post.locked;
833 let label = locked ? i18n.t("unlock") : i18n.t("lock");
836 className="btn btn-link btn-animate text-muted py-0"
837 onClick={linkEvent(this, this.handleModLock)}
838 data-tippy-content={label}
843 classes={classNames({ "text-danger": locked })}
850 get featureButton() {
851 const featured_community = this.props.post_view.post.featured_community;
852 const label_community = featured_community
853 ? i18n.t("unfeature_from_community")
854 : i18n.t("feature_in_community");
856 const is_admin = amAdmin();
857 const featured_local = this.props.post_view.post.featured_local;
858 const label_local = featured_local
859 ? i18n.t("unfeature_from_local")
860 : i18n.t("feature_in_local");
864 className="btn btn-link btn-animate text-muted py-0 pl-0"
865 onClick={() => this.handleModFeaturePost(this, true)}
866 data-tippy-content={label_community}
867 aria-label={label_community}
871 classes={classNames({ "text-success": featured_community })}
878 className="btn btn-link btn-animate text-muted py-0"
879 onClick={() => this.handleModFeaturePost(this, false)}
880 data-tippy-content={label_local}
881 aria-label={label_local}
885 classes={classNames({ "text-success": featured_local })}
895 get modRemoveButton() {
896 let removed = this.props.post_view.post.removed;
899 className="btn btn-link btn-animate text-muted py-0"
902 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
905 {/* TODO: Find an icon for this. */}
906 {!removed ? i18n.t("remove") : i18n.t("restore")}
912 * Mod/Admin actions to be taken against the author.
916 let post_view = this.props.post_view;
918 this.state.showAdvanced && (
922 {!this.creatorIsMod_ &&
923 (!post_view.creator_banned_from_community ? (
925 className="btn btn-link btn-animate text-muted py-0"
928 this.handleModBanFromCommunityShow
930 aria-label={i18n.t("ban")}
936 className="btn btn-link btn-animate text-muted py-0"
939 this.handleModBanFromCommunitySubmit
941 aria-label={i18n.t("unban")}
946 {!post_view.creator_banned_from_community && (
948 className="btn btn-link btn-animate text-muted py-0"
949 onClick={linkEvent(this, this.handleAddModToCommunity)}
952 ? i18n.t("remove_as_mod")
953 : i18n.t("appoint_as_mod")
957 ? i18n.t("remove_as_mod")
958 : i18n.t("appoint_as_mod")}
963 {/* Community creators and admins can transfer community to another mod */}
964 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
966 this.creatorIsMod_ &&
967 (!this.state.showConfirmTransferCommunity ? (
969 className="btn btn-link btn-animate text-muted py-0"
972 this.handleShowConfirmTransferCommunity
974 aria-label={i18n.t("transfer_community")}
976 {i18n.t("transfer_community")}
981 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
982 aria-label={i18n.t("are_you_sure")}
984 {i18n.t("are_you_sure")}
987 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
988 aria-label={i18n.t("yes")}
989 onClick={linkEvent(this, this.handleTransferCommunity)}
994 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
997 this.handleCancelShowConfirmTransferCommunity
999 aria-label={i18n.t("no")}
1005 {/* Admins can ban from all, and appoint other admins */}
1006 {this.canAdmin_ && (
1008 {!this.creatorIsAdmin_ && (
1010 {!isBanned(post_view.creator) ? (
1012 className="btn btn-link btn-animate text-muted py-0"
1013 onClick={linkEvent(this, this.handleModBanShow)}
1014 aria-label={i18n.t("ban_from_site")}
1016 {i18n.t("ban_from_site")}
1020 className="btn btn-link btn-animate text-muted py-0"
1021 onClick={linkEvent(this, this.handleModBanSubmit)}
1022 aria-label={i18n.t("unban_from_site")}
1024 {i18n.t("unban_from_site")}
1028 className="btn btn-link btn-animate text-muted py-0"
1029 onClick={linkEvent(this, this.handlePurgePersonShow)}
1030 aria-label={i18n.t("purge_user")}
1032 {i18n.t("purge_user")}
1035 className="btn btn-link btn-animate text-muted py-0"
1036 onClick={linkEvent(this, this.handlePurgePostShow)}
1037 aria-label={i18n.t("purge_post")}
1039 {i18n.t("purge_post")}
1043 {!isBanned(post_view.creator) && post_view.creator.local && (
1045 className="btn btn-link btn-animate text-muted py-0"
1046 onClick={linkEvent(this, this.handleAddAdmin)}
1048 this.creatorIsAdmin_
1049 ? i18n.t("remove_as_admin")
1050 : i18n.t("appoint_as_admin")
1053 {this.creatorIsAdmin_
1054 ? i18n.t("remove_as_admin")
1055 : i18n.t("appoint_as_admin")}
1065 removeAndBanDialogs() {
1066 let post = this.props.post_view;
1068 this.state.purgeType == PurgeType.Post
1069 ? i18n.t("purge_post")
1070 : `${i18n.t("purge")} ${post.creator.name}`;
1073 {this.state.showRemoveDialog && (
1075 className="form-inline"
1076 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1078 <label className="sr-only" htmlFor="post-listing-remove-reason">
1083 id="post-listing-remove-reason"
1084 className="form-control mr-2"
1085 placeholder={i18n.t("reason")}
1086 value={this.state.removeReason}
1087 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1091 className="btn btn-secondary"
1092 aria-label={i18n.t("remove_post")}
1094 {i18n.t("remove_post")}
1098 {this.state.showBanDialog && (
1099 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1100 <div className="form-group row col-12">
1102 className="col-form-label"
1103 htmlFor="post-listing-ban-reason"
1109 id="post-listing-ban-reason"
1110 className="form-control mr-2"
1111 placeholder={i18n.t("reason")}
1112 value={this.state.banReason}
1113 onInput={linkEvent(this, this.handleModBanReasonChange)}
1115 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1120 id={`mod-ban-expires`}
1121 className="form-control mr-2"
1122 placeholder={i18n.t("number_of_days")}
1123 value={this.state.banExpireDays}
1124 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1126 <div className="form-group">
1127 <div className="form-check">
1129 className="form-check-input"
1130 id="mod-ban-remove-data"
1132 checked={this.state.removeData}
1133 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1136 className="form-check-label"
1137 htmlFor="mod-ban-remove-data"
1138 title={i18n.t("remove_content_more")}
1140 {i18n.t("remove_content")}
1145 {/* TODO hold off on expires until later */}
1146 {/* <div class="form-group row"> */}
1147 {/* <label class="col-form-label">Expires</label> */}
1148 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1150 <div className="form-group row">
1153 className="btn btn-secondary"
1154 aria-label={i18n.t("ban")}
1156 {i18n.t("ban")} {post.creator.name}
1161 {this.state.showReportDialog && (
1163 className="form-inline"
1164 onSubmit={linkEvent(this, this.handleReportSubmit)}
1166 <label className="sr-only" htmlFor="post-report-reason">
1171 id="post-report-reason"
1172 className="form-control mr-2"
1173 placeholder={i18n.t("reason")}
1175 value={this.state.reportReason}
1176 onInput={linkEvent(this, this.handleReportReasonChange)}
1180 className="btn btn-secondary"
1181 aria-label={i18n.t("create_report")}
1183 {i18n.t("create_report")}
1187 {this.state.showPurgeDialog && (
1189 className="form-inline"
1190 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1193 <label className="sr-only" htmlFor="purge-reason">
1199 className="form-control mr-2"
1200 placeholder={i18n.t("reason")}
1201 value={this.state.purgeReason}
1202 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1204 {this.state.purgeLoading ? (
1209 className="btn btn-secondary"
1210 aria-label={purgeTypeText}
1222 let post = this.props.post_view.post;
1223 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1224 <div className="row">
1225 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1226 {this.postTitleLine()}
1228 <div className="col-4">
1229 {/* Post body prev or thumbnail */}
1230 {!this.state.imageExpanded && this.thumbnail()}
1234 this.postTitleLine()
1238 showMobilePreview() {
1239 let body = this.props.post_view.post.body;
1240 return !this.showBody && body ? (
1241 <div className="md-div mb-1 preview-lines">{body}</div>
1250 {/* The mobile view*/}
1251 <div className="d-block d-sm-none">
1252 <div className="row">
1253 <div className="col-12">
1254 {this.createdLine()}
1256 {/* If it has a thumbnail, do a right aligned thumbnail */}
1257 {this.mobileThumbnail()}
1259 {/* Show a preview of the post body */}
1260 {this.showMobilePreview()}
1262 {this.commentsLine(true)}
1263 {this.userActionsLine()}
1264 {this.duplicatesLine()}
1265 {this.removeAndBanDialogs()}
1270 {/* The larger view*/}
1271 <div className="d-none d-sm-block">
1272 <div className="row">
1273 {!this.props.viewOnly && this.voteBar()}
1274 <div className="col-sm-2 pr-0">
1275 <div className="">{this.thumbnail()}</div>
1277 <div className="col-12 col-sm-9">
1278 <div className="row">
1279 <div className="col-12">
1280 {this.postTitleLine()}
1281 {this.createdLine()}
1282 {this.commentsLine()}
1283 {this.duplicatesLine()}
1284 {this.userActionsLine()}
1285 {this.removeAndBanDialogs()}
1295 private get myPost(): boolean {
1297 this.props.post_view.creator.id ==
1298 UserService.Instance.myUserInfo?.local_user_view.person.id
1302 handlePostLike(event: any) {
1303 event.preventDefault();
1304 if (!UserService.Instance.myUserInfo) {
1305 this.context.router.history.push(`/login`);
1308 let myVote = this.state.my_vote;
1309 let newVote = myVote == 1 ? 0 : 1;
1313 score: this.state.score - 1,
1314 upvotes: this.state.upvotes - 1,
1316 } else if (myVote == -1) {
1318 score: this.state.score + 2,
1319 upvotes: this.state.upvotes + 1,
1320 downvotes: this.state.downvotes - 1,
1324 score: this.state.score + 1,
1325 upvotes: this.state.upvotes + 1,
1329 this.setState({ my_vote: newVote });
1331 let auth = myAuth();
1333 let form: CreatePostLike = {
1334 post_id: this.props.post_view.post.id,
1339 WebSocketService.Instance.send(wsClient.likePost(form));
1340 this.setState(this.state);
1345 handlePostDisLike(event: any) {
1346 event.preventDefault();
1347 if (!UserService.Instance.myUserInfo) {
1348 this.context.router.history.push(`/login`);
1351 let myVote = this.state.my_vote;
1352 let newVote = myVote == -1 ? 0 : -1;
1356 score: this.state.score - 2,
1357 upvotes: this.state.upvotes - 1,
1358 downvotes: this.state.downvotes + 1,
1360 } else if (myVote == -1) {
1362 score: this.state.score + 1,
1363 downvotes: this.state.downvotes - 1,
1367 score: this.state.score - 1,
1368 downvotes: this.state.downvotes + 1,
1372 this.setState({ my_vote: newVote });
1374 let auth = myAuth();
1376 let form: CreatePostLike = {
1377 post_id: this.props.post_view.post.id,
1382 WebSocketService.Instance.send(wsClient.likePost(form));
1383 this.setState(this.state);
1388 handleEditClick(i: PostListing) {
1389 i.setState({ showEdit: true });
1392 handleEditCancel() {
1393 this.setState({ showEdit: false });
1396 // The actual editing is done in the recieve for post
1398 this.setState({ showEdit: false });
1401 handleShowReportDialog(i: PostListing) {
1402 i.setState({ showReportDialog: !i.state.showReportDialog });
1405 handleReportReasonChange(i: PostListing, event: any) {
1406 i.setState({ reportReason: event.target.value });
1409 handleReportSubmit(i: PostListing, event: any) {
1410 event.preventDefault();
1411 let auth = myAuth();
1412 let reason = i.state.reportReason;
1413 if (auth && reason) {
1414 let form: CreatePostReport = {
1415 post_id: i.props.post_view.post.id,
1419 WebSocketService.Instance.send(wsClient.createPostReport(form));
1421 i.setState({ showReportDialog: false });
1425 handleBlockUserClick(i: PostListing) {
1426 let auth = myAuth();
1428 let blockUserForm: BlockPerson = {
1429 person_id: i.props.post_view.creator.id,
1433 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1437 handleDeleteClick(i: PostListing) {
1438 let auth = myAuth();
1440 let deleteForm: DeletePost = {
1441 post_id: i.props.post_view.post.id,
1442 deleted: !i.props.post_view.post.deleted,
1445 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1449 handleSavePostClick(i: PostListing) {
1450 let auth = myAuth();
1453 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1454 let form: SavePost = {
1455 post_id: i.props.post_view.post.id,
1459 WebSocketService.Instance.send(wsClient.savePost(form));
1463 get crossPostParams(): string {
1464 let post = this.props.post_view.post;
1465 let params = `?title=${encodeURIComponent(post.name)}`;
1468 params += `&url=${encodeURIComponent(post.url)}`;
1470 let crossPostBody = this.crossPostBody();
1471 if (crossPostBody) {
1472 params += `&body=${encodeURIComponent(crossPostBody)}`;
1477 crossPostBody(): string | undefined {
1478 let post = this.props.post_view.post;
1479 let body = post.body;
1482 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1489 get showBody(): boolean {
1490 return this.props.showBody || this.state.showBody;
1493 handleModRemoveShow(i: PostListing) {
1495 showRemoveDialog: !i.state.showRemoveDialog,
1496 showBanDialog: false,
1500 handleModRemoveReasonChange(i: PostListing, event: any) {
1501 i.setState({ removeReason: event.target.value });
1504 handleModRemoveDataChange(i: PostListing, event: any) {
1505 i.setState({ removeData: event.target.checked });
1508 handleModRemoveSubmit(i: PostListing, event: any) {
1509 event.preventDefault();
1511 let auth = myAuth();
1513 let form: RemovePost = {
1514 post_id: i.props.post_view.post.id,
1515 removed: !i.props.post_view.post.removed,
1516 reason: i.state.removeReason,
1519 WebSocketService.Instance.send(wsClient.removePost(form));
1520 i.setState({ showRemoveDialog: false });
1524 handleModLock(i: PostListing) {
1525 let auth = myAuth();
1527 let form: LockPost = {
1528 post_id: i.props.post_view.post.id,
1529 locked: !i.props.post_view.post.locked,
1532 WebSocketService.Instance.send(wsClient.lockPost(form));
1536 handleModFeaturePost(i: PostListing, is_community: boolean) {
1537 let auth = myAuth();
1539 let featured: [PostFeatureType, boolean] = is_community
1541 PostFeatureType.Community,
1542 !i.props.post_view.post.featured_community,
1544 : [PostFeatureType.Local, !i.props.post_view.post.featured_local];
1546 let form: FeaturePost = {
1547 post_id: i.props.post_view.post.id,
1548 feature_type: featured[0],
1549 featured: featured[1],
1552 WebSocketService.Instance.send(wsClient.featurePost(form));
1556 handleModBanFromCommunityShow(i: PostListing) {
1558 showBanDialog: true,
1559 banType: BanType.Community,
1560 showRemoveDialog: false,
1564 handleModBanShow(i: PostListing) {
1566 showBanDialog: true,
1567 banType: BanType.Site,
1568 showRemoveDialog: false,
1572 handlePurgePersonShow(i: PostListing) {
1574 showPurgeDialog: true,
1575 purgeType: PurgeType.Person,
1576 showRemoveDialog: false,
1580 handlePurgePostShow(i: PostListing) {
1582 showPurgeDialog: true,
1583 purgeType: PurgeType.Post,
1584 showRemoveDialog: false,
1588 handlePurgeReasonChange(i: PostListing, event: any) {
1589 i.setState({ purgeReason: event.target.value });
1592 handlePurgeSubmit(i: PostListing, event: any) {
1593 event.preventDefault();
1595 let auth = myAuth();
1597 if (i.state.purgeType == PurgeType.Person) {
1598 let form: PurgePerson = {
1599 person_id: i.props.post_view.creator.id,
1600 reason: i.state.purgeReason,
1603 WebSocketService.Instance.send(wsClient.purgePerson(form));
1604 } else if (i.state.purgeType == PurgeType.Post) {
1605 let form: PurgePost = {
1606 post_id: i.props.post_view.post.id,
1607 reason: i.state.purgeReason,
1610 WebSocketService.Instance.send(wsClient.purgePost(form));
1613 i.setState({ purgeLoading: true });
1617 handleModBanReasonChange(i: PostListing, event: any) {
1618 i.setState({ banReason: event.target.value });
1621 handleModBanExpireDaysChange(i: PostListing, event: any) {
1622 i.setState({ banExpireDays: event.target.value });
1625 handleModBanFromCommunitySubmit(i: PostListing) {
1626 i.setState({ banType: BanType.Community });
1627 i.handleModBanBothSubmit(i);
1630 handleModBanSubmit(i: PostListing) {
1631 i.setState({ banType: BanType.Site });
1632 i.handleModBanBothSubmit(i);
1635 handleModBanBothSubmit(i: PostListing, event?: any) {
1636 if (event) event.preventDefault();
1637 let auth = myAuth();
1639 let ban = !i.props.post_view.creator_banned_from_community;
1640 let person_id = i.props.post_view.creator.id;
1641 let remove_data = i.state.removeData;
1642 let reason = i.state.banReason;
1643 let expires = futureDaysToUnixTime(i.state.banExpireDays);
1645 if (i.state.banType == BanType.Community) {
1646 // If its an unban, restore all their data
1648 i.setState({ removeData: false });
1651 let form: BanFromCommunity = {
1653 community_id: i.props.post_view.community.id,
1660 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1662 // If its an unban, restore all their data
1663 let ban = !i.props.post_view.creator.banned;
1665 i.setState({ removeData: false });
1667 let form: BanPerson = {
1675 WebSocketService.Instance.send(wsClient.banPerson(form));
1678 i.setState({ showBanDialog: false });
1682 handleAddModToCommunity(i: PostListing) {
1683 let auth = myAuth();
1685 let form: AddModToCommunity = {
1686 person_id: i.props.post_view.creator.id,
1687 community_id: i.props.post_view.community.id,
1688 added: !i.creatorIsMod_,
1691 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1692 i.setState(i.state);
1696 handleAddAdmin(i: PostListing) {
1697 let auth = myAuth();
1699 let form: AddAdmin = {
1700 person_id: i.props.post_view.creator.id,
1701 added: !i.creatorIsAdmin_,
1704 WebSocketService.Instance.send(wsClient.addAdmin(form));
1705 i.setState(i.state);
1709 handleShowConfirmTransferCommunity(i: PostListing) {
1710 i.setState({ showConfirmTransferCommunity: true });
1713 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1714 i.setState({ showConfirmTransferCommunity: false });
1717 handleTransferCommunity(i: PostListing) {
1718 let auth = myAuth();
1720 let form: TransferCommunity = {
1721 community_id: i.props.post_view.community.id,
1722 person_id: i.props.post_view.creator.id,
1725 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1726 i.setState({ showConfirmTransferCommunity: false });
1730 handleShowConfirmTransferSite(i: PostListing) {
1731 i.setState({ showConfirmTransferSite: true });
1734 handleCancelShowConfirmTransferSite(i: PostListing) {
1735 i.setState({ showConfirmTransferSite: false });
1738 handleImageExpandClick(i: PostListing, event: any) {
1739 event.preventDefault();
1740 i.setState({ imageExpanded: !i.state.imageExpanded });
1744 handleViewSource(i: PostListing) {
1745 i.setState({ viewSource: !i.state.viewSource });
1748 handleShowAdvanced(i: PostListing) {
1749 i.setState({ showAdvanced: !i.state.showAdvanced });
1753 handleShowMoreMobile(i: PostListing) {
1755 showMoreMobile: !i.state.showMoreMobile,
1756 showAdvanced: !i.state.showAdvanced,
1761 handleShowBody(i: PostListing) {
1762 i.setState({ showBody: !i.state.showBody });
1766 get pointsTippy(): string {
1767 let points = i18n.t("number_of_points", {
1768 count: this.state.score,
1769 formattedCount: this.state.score,
1772 let upvotes = i18n.t("number_of_upvotes", {
1773 count: this.state.upvotes,
1774 formattedCount: this.state.upvotes,
1777 let downvotes = i18n.t("number_of_downvotes", {
1778 count: this.state.downvotes,
1779 formattedCount: this.state.downvotes,
1782 return `${points} • ${upvotes} • ${downvotes}`;
1785 get canModOnSelf_(): boolean {
1787 this.props.post_view.creator.id,
1788 this.props.moderators,
1795 get canMod_(): boolean {
1797 this.props.post_view.creator.id,
1798 this.props.moderators,
1803 get canAdmin_(): boolean {
1804 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1807 get creatorIsMod_(): boolean {
1808 return isMod(this.props.post_view.creator.id, this.props.moderators);
1811 get creatorIsAdmin_(): boolean {
1812 return isAdmin(this.props.post_view.creator.id, this.props.admins);