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;
438 !post.featured_community && !post.featured_local
442 to={`/post/${post.id}`}
443 title={i18n.t("comments")}
445 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
451 let post = this.props.post_view.post;
455 <div className="post-title overflow-hidden">
458 this.props.showBody ? (
461 !post.featured_community && !post.featured_local
469 <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
477 {(url && isImage(url)) ||
478 (post.thumbnail_url && (
480 className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
481 data-tippy-content={i18n.t("expand_here")}
482 onClick={linkEvent(this, this.handleImageExpandClick)}
486 !this.state.imageExpanded ? "plus-square" : "minus-square"
488 classes="icon-inline"
493 <small className="ml-2 text-muted font-italic">
499 className="unselectable pointer ml-2 text-muted font-italic"
500 data-tippy-content={i18n.t("deleted")}
502 <Icon icon="trash" classes="icon-inline text-danger" />
507 className="unselectable pointer ml-2 text-muted font-italic"
508 data-tippy-content={i18n.t("locked")}
510 <Icon icon="lock" classes="icon-inline text-danger" />
513 {post.featured_community && (
515 className="unselectable pointer ml-2 text-muted font-italic"
516 data-tippy-content={i18n.t("featured")}
518 <Icon icon="pin" classes="icon-inline text-primary" />
521 {post.featured_local && (
523 className="unselectable pointer ml-2 text-muted font-italic"
524 data-tippy-content={i18n.t("featured")}
526 <Icon icon="pin" classes="icon-inline text-secondary" />
530 <small className="ml-2 text-muted font-italic">
540 let dupes = this.props.duplicates;
541 return dupes && dupes.length > 0 ? (
542 <ul className="list-inline mb-1 small text-muted">
544 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
546 <li key={pv.post.id} className="list-inline-item mr-2">
547 <Link to={`/post/${pv.post.id}`}>
550 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
561 commentsLine(mobile = false) {
562 let post = this.props.post_view.post;
564 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
565 {this.commentsButton}
568 className="btn btn-link btn-animate text-muted py-0"
569 title={i18n.t("link")}
572 <Icon icon="fedilink" inline />
575 {mobile && !this.props.viewOnly && this.mobileVotes}
576 {UserService.Instance.myUserInfo &&
577 !this.props.viewOnly &&
578 this.postActions(mobile)}
583 postActions(mobile = false) {
584 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
585 // Possible enhancement: Make each button a component.
586 let post_view = this.props.post_view;
590 {this.crossPostButton}
591 {mobile && this.showMoreButton}
592 {(!mobile || this.state.showAdvanced) && (
600 {this.myPost && (this.showBody || this.state.showAdvanced) && (
608 {this.state.showAdvanced && (
610 {this.showBody && post_view.post.body && this.viewSourceButton}
611 {this.canModOnSelf_ && (
617 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
620 {!mobile && this.showMoreButton}
625 get commentsButton() {
626 let post_view = this.props.post_view;
628 <button className="btn btn-link text-muted py-0 pl-0">
630 className="text-muted"
631 title={i18n.t("number_of_comments", {
632 count: post_view.counts.comments,
633 formattedCount: post_view.counts.comments,
635 to={`/post/${post_view.post.id}?scrollToComments=true`}
637 <Icon icon="message-square" classes="mr-1" inline />
638 <span className="mr-2">
639 {i18n.t("number_of_comments", {
640 count: post_view.counts.comments,
641 formattedCount: numToSI(post_view.counts.comments),
644 {this.unreadCount && (
645 <span className="small text-warning">
646 ({this.unreadCount} {i18n.t("new")})
654 get unreadCount(): number | undefined {
655 let pv = this.props.post_view;
656 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
658 : pv.unread_comments;
663 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
668 className={`btn-animate btn py-0 px-1 ${
669 this.state.my_vote == 1 ? "text-info" : "text-muted"
672 onClick={this.handlePostLike}
673 aria-label={i18n.t("upvote")}
675 <Icon icon="arrow-up1" classes="icon-inline small" />
677 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
680 {this.props.enableDownvotes && (
682 className={`ml-2 btn-animate btn py-0 px-1 ${
683 this.state.my_vote == -1 ? "text-danger" : "text-muted"
685 onClick={this.handlePostDisLike}
687 aria-label={i18n.t("downvote")}
689 <Icon icon="arrow-down1" classes="icon-inline small" />
692 className={classNames("ml-2", {
693 invisible: this.state.downvotes === 0,
696 {numToSI(this.state.downvotes)}
707 let saved = this.props.post_view.saved;
708 let label = saved ? i18n.t("unsave") : i18n.t("save");
711 className="btn btn-link btn-animate text-muted py-0"
712 onClick={linkEvent(this, this.handleSavePostClick)}
713 data-tippy-content={label}
718 classes={classNames({ "text-warning": saved })}
725 get crossPostButton() {
728 className="btn btn-link btn-animate text-muted py-0"
729 to={`/create_post${this.crossPostParams}`}
730 title={i18n.t("cross_post")}
732 <Icon icon="copy" inline />
740 className="btn btn-link btn-animate text-muted py-0"
741 onClick={linkEvent(this, this.handleShowReportDialog)}
742 data-tippy-content={i18n.t("show_report_dialog")}
743 aria-label={i18n.t("show_report_dialog")}
745 <Icon icon="flag" inline />
753 className="btn btn-link btn-animate text-muted py-0"
754 onClick={linkEvent(this, this.handleBlockUserClick)}
755 data-tippy-content={i18n.t("block_user")}
756 aria-label={i18n.t("block_user")}
758 <Icon icon="slash" inline />
766 className="btn btn-link btn-animate text-muted py-0"
767 onClick={linkEvent(this, this.handleEditClick)}
768 data-tippy-content={i18n.t("edit")}
769 aria-label={i18n.t("edit")}
771 <Icon icon="edit" inline />
777 let deleted = this.props.post_view.post.deleted;
778 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
781 className="btn btn-link btn-animate text-muted py-0"
782 onClick={linkEvent(this, this.handleDeleteClick)}
783 data-tippy-content={label}
788 classes={classNames({ "text-danger": deleted })}
795 get showMoreButton() {
798 className="btn btn-link btn-animate text-muted py-0"
799 onClick={linkEvent(this, this.handleShowAdvanced)}
800 data-tippy-content={i18n.t("more")}
801 aria-label={i18n.t("more")}
803 <Icon icon="more-vertical" inline />
808 get viewSourceButton() {
811 className="btn btn-link btn-animate text-muted py-0"
812 onClick={linkEvent(this, this.handleViewSource)}
813 data-tippy-content={i18n.t("view_source")}
814 aria-label={i18n.t("view_source")}
818 classes={classNames({ "text-success": this.state.viewSource })}
826 let locked = this.props.post_view.post.locked;
827 let label = locked ? i18n.t("unlock") : i18n.t("lock");
830 className="btn btn-link btn-animate text-muted py-0"
831 onClick={linkEvent(this, this.handleModLock)}
832 data-tippy-content={label}
837 classes={classNames({ "text-danger": locked })}
844 get featureButton() {
845 const featured_community = this.props.post_view.post.featured_community;
846 const label_community = featured_community
847 ? i18n.t("unfeature_from_community")
848 : i18n.t("feature_in_community");
850 const is_admin = amAdmin();
851 const featured_local = this.props.post_view.post.featured_local;
852 const label_local = featured_local
853 ? i18n.t("unfeature_from_local")
854 : i18n.t("feature_in_local");
858 className="btn btn-link btn-animate text-muted py-0 pl-0"
859 onClick={() => this.handleModFeaturePost(this, true)}
860 data-tippy-content={label_community}
861 aria-label={label_community}
865 classes={classNames({ "text-success": featured_community })}
872 className="btn btn-link btn-animate text-muted py-0"
873 onClick={() => this.handleModFeaturePost(this, false)}
874 data-tippy-content={label_local}
875 aria-label={label_local}
879 classes={classNames({ "text-success": featured_local })}
889 get modRemoveButton() {
890 let removed = this.props.post_view.post.removed;
893 className="btn btn-link btn-animate text-muted py-0"
896 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
899 {/* TODO: Find an icon for this. */}
900 {!removed ? i18n.t("remove") : i18n.t("restore")}
906 * Mod/Admin actions to be taken against the author.
910 let post_view = this.props.post_view;
912 this.state.showAdvanced && (
916 {!this.creatorIsMod_ &&
917 (!post_view.creator_banned_from_community ? (
919 className="btn btn-link btn-animate text-muted py-0"
922 this.handleModBanFromCommunityShow
924 aria-label={i18n.t("ban")}
930 className="btn btn-link btn-animate text-muted py-0"
933 this.handleModBanFromCommunitySubmit
935 aria-label={i18n.t("unban")}
940 {!post_view.creator_banned_from_community && (
942 className="btn btn-link btn-animate text-muted py-0"
943 onClick={linkEvent(this, this.handleAddModToCommunity)}
946 ? i18n.t("remove_as_mod")
947 : i18n.t("appoint_as_mod")
951 ? i18n.t("remove_as_mod")
952 : i18n.t("appoint_as_mod")}
957 {/* Community creators and admins can transfer community to another mod */}
958 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
960 this.creatorIsMod_ &&
961 (!this.state.showConfirmTransferCommunity ? (
963 className="btn btn-link btn-animate text-muted py-0"
966 this.handleShowConfirmTransferCommunity
968 aria-label={i18n.t("transfer_community")}
970 {i18n.t("transfer_community")}
975 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
976 aria-label={i18n.t("are_you_sure")}
978 {i18n.t("are_you_sure")}
981 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
982 aria-label={i18n.t("yes")}
983 onClick={linkEvent(this, this.handleTransferCommunity)}
988 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
991 this.handleCancelShowConfirmTransferCommunity
993 aria-label={i18n.t("no")}
999 {/* Admins can ban from all, and appoint other admins */}
1000 {this.canAdmin_ && (
1002 {!this.creatorIsAdmin_ && (
1004 {!isBanned(post_view.creator) ? (
1006 className="btn btn-link btn-animate text-muted py-0"
1007 onClick={linkEvent(this, this.handleModBanShow)}
1008 aria-label={i18n.t("ban_from_site")}
1010 {i18n.t("ban_from_site")}
1014 className="btn btn-link btn-animate text-muted py-0"
1015 onClick={linkEvent(this, this.handleModBanSubmit)}
1016 aria-label={i18n.t("unban_from_site")}
1018 {i18n.t("unban_from_site")}
1022 className="btn btn-link btn-animate text-muted py-0"
1023 onClick={linkEvent(this, this.handlePurgePersonShow)}
1024 aria-label={i18n.t("purge_user")}
1026 {i18n.t("purge_user")}
1029 className="btn btn-link btn-animate text-muted py-0"
1030 onClick={linkEvent(this, this.handlePurgePostShow)}
1031 aria-label={i18n.t("purge_post")}
1033 {i18n.t("purge_post")}
1037 {!isBanned(post_view.creator) && post_view.creator.local && (
1039 className="btn btn-link btn-animate text-muted py-0"
1040 onClick={linkEvent(this, this.handleAddAdmin)}
1042 this.creatorIsAdmin_
1043 ? i18n.t("remove_as_admin")
1044 : i18n.t("appoint_as_admin")
1047 {this.creatorIsAdmin_
1048 ? i18n.t("remove_as_admin")
1049 : i18n.t("appoint_as_admin")}
1059 removeAndBanDialogs() {
1060 let post = this.props.post_view;
1062 this.state.purgeType == PurgeType.Post
1063 ? i18n.t("purge_post")
1064 : `${i18n.t("purge")} ${post.creator.name}`;
1067 {this.state.showRemoveDialog && (
1069 className="form-inline"
1070 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1072 <label className="sr-only" htmlFor="post-listing-remove-reason">
1077 id="post-listing-remove-reason"
1078 className="form-control mr-2"
1079 placeholder={i18n.t("reason")}
1080 value={this.state.removeReason}
1081 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1085 className="btn btn-secondary"
1086 aria-label={i18n.t("remove_post")}
1088 {i18n.t("remove_post")}
1092 {this.state.showBanDialog && (
1093 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1094 <div className="form-group row col-12">
1096 className="col-form-label"
1097 htmlFor="post-listing-ban-reason"
1103 id="post-listing-ban-reason"
1104 className="form-control mr-2"
1105 placeholder={i18n.t("reason")}
1106 value={this.state.banReason}
1107 onInput={linkEvent(this, this.handleModBanReasonChange)}
1109 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1114 id={`mod-ban-expires`}
1115 className="form-control mr-2"
1116 placeholder={i18n.t("number_of_days")}
1117 value={this.state.banExpireDays}
1118 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1120 <div className="form-group">
1121 <div className="form-check">
1123 className="form-check-input"
1124 id="mod-ban-remove-data"
1126 checked={this.state.removeData}
1127 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1130 className="form-check-label"
1131 htmlFor="mod-ban-remove-data"
1132 title={i18n.t("remove_content_more")}
1134 {i18n.t("remove_content")}
1139 {/* TODO hold off on expires until later */}
1140 {/* <div class="form-group row"> */}
1141 {/* <label class="col-form-label">Expires</label> */}
1142 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1144 <div className="form-group row">
1147 className="btn btn-secondary"
1148 aria-label={i18n.t("ban")}
1150 {i18n.t("ban")} {post.creator.name}
1155 {this.state.showReportDialog && (
1157 className="form-inline"
1158 onSubmit={linkEvent(this, this.handleReportSubmit)}
1160 <label className="sr-only" htmlFor="post-report-reason">
1165 id="post-report-reason"
1166 className="form-control mr-2"
1167 placeholder={i18n.t("reason")}
1169 value={this.state.reportReason}
1170 onInput={linkEvent(this, this.handleReportReasonChange)}
1174 className="btn btn-secondary"
1175 aria-label={i18n.t("create_report")}
1177 {i18n.t("create_report")}
1181 {this.state.showPurgeDialog && (
1183 className="form-inline"
1184 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1187 <label className="sr-only" htmlFor="purge-reason">
1193 className="form-control mr-2"
1194 placeholder={i18n.t("reason")}
1195 value={this.state.purgeReason}
1196 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1198 {this.state.purgeLoading ? (
1203 className="btn btn-secondary"
1204 aria-label={purgeTypeText}
1216 let post = this.props.post_view.post;
1217 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1218 <div className="row">
1219 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1220 {this.postTitleLine()}
1222 <div className="col-4">
1223 {/* Post body prev or thumbnail */}
1224 {!this.state.imageExpanded && this.thumbnail()}
1228 this.postTitleLine()
1232 showMobilePreview() {
1233 let body = this.props.post_view.post.body;
1234 return !this.showBody && body ? (
1235 <div className="md-div mb-1 preview-lines">{body}</div>
1244 {/* The mobile view*/}
1245 <div className="d-block d-sm-none">
1246 <div className="row">
1247 <div className="col-12">
1248 {this.createdLine()}
1250 {/* If it has a thumbnail, do a right aligned thumbnail */}
1251 {this.mobileThumbnail()}
1253 {/* Show a preview of the post body */}
1254 {this.showMobilePreview()}
1256 {this.commentsLine(true)}
1257 {this.userActionsLine()}
1258 {this.duplicatesLine()}
1259 {this.removeAndBanDialogs()}
1264 {/* The larger view*/}
1265 <div className="d-none d-sm-block">
1266 <div className="row">
1267 {!this.props.viewOnly && this.voteBar()}
1268 <div className="col-sm-2 pr-0">
1269 <div className="">{this.thumbnail()}</div>
1271 <div className="col-12 col-sm-9">
1272 <div className="row">
1273 <div className="col-12">
1274 {this.postTitleLine()}
1275 {this.createdLine()}
1276 {this.commentsLine()}
1277 {this.duplicatesLine()}
1278 {this.userActionsLine()}
1279 {this.removeAndBanDialogs()}
1289 private get myPost(): boolean {
1291 this.props.post_view.creator.id ==
1292 UserService.Instance.myUserInfo?.local_user_view.person.id
1296 handlePostLike(event: any) {
1297 event.preventDefault();
1298 if (!UserService.Instance.myUserInfo) {
1299 this.context.router.history.push(`/login`);
1302 let myVote = this.state.my_vote;
1303 let newVote = myVote == 1 ? 0 : 1;
1307 score: this.state.score - 1,
1308 upvotes: this.state.upvotes - 1,
1310 } else if (myVote == -1) {
1312 score: this.state.score + 2,
1313 upvotes: this.state.upvotes + 1,
1314 downvotes: this.state.downvotes - 1,
1318 score: this.state.score + 1,
1319 upvotes: this.state.upvotes + 1,
1323 this.setState({ my_vote: newVote });
1325 let auth = myAuth();
1327 let form: CreatePostLike = {
1328 post_id: this.props.post_view.post.id,
1333 WebSocketService.Instance.send(wsClient.likePost(form));
1334 this.setState(this.state);
1339 handlePostDisLike(event: any) {
1340 event.preventDefault();
1341 if (!UserService.Instance.myUserInfo) {
1342 this.context.router.history.push(`/login`);
1345 let myVote = this.state.my_vote;
1346 let newVote = myVote == -1 ? 0 : -1;
1350 score: this.state.score - 2,
1351 upvotes: this.state.upvotes - 1,
1352 downvotes: this.state.downvotes + 1,
1354 } else if (myVote == -1) {
1356 score: this.state.score + 1,
1357 downvotes: this.state.downvotes - 1,
1361 score: this.state.score - 1,
1362 downvotes: this.state.downvotes + 1,
1366 this.setState({ my_vote: newVote });
1368 let auth = myAuth();
1370 let form: CreatePostLike = {
1371 post_id: this.props.post_view.post.id,
1376 WebSocketService.Instance.send(wsClient.likePost(form));
1377 this.setState(this.state);
1382 handleEditClick(i: PostListing) {
1383 i.setState({ showEdit: true });
1386 handleEditCancel() {
1387 this.setState({ showEdit: false });
1390 // The actual editing is done in the recieve for post
1392 this.setState({ showEdit: false });
1395 handleShowReportDialog(i: PostListing) {
1396 i.setState({ showReportDialog: !i.state.showReportDialog });
1399 handleReportReasonChange(i: PostListing, event: any) {
1400 i.setState({ reportReason: event.target.value });
1403 handleReportSubmit(i: PostListing, event: any) {
1404 event.preventDefault();
1405 let auth = myAuth();
1406 let reason = i.state.reportReason;
1407 if (auth && reason) {
1408 let form: CreatePostReport = {
1409 post_id: i.props.post_view.post.id,
1413 WebSocketService.Instance.send(wsClient.createPostReport(form));
1415 i.setState({ showReportDialog: false });
1419 handleBlockUserClick(i: PostListing) {
1420 let auth = myAuth();
1422 let blockUserForm: BlockPerson = {
1423 person_id: i.props.post_view.creator.id,
1427 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1431 handleDeleteClick(i: PostListing) {
1432 let auth = myAuth();
1434 let deleteForm: DeletePost = {
1435 post_id: i.props.post_view.post.id,
1436 deleted: !i.props.post_view.post.deleted,
1439 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1443 handleSavePostClick(i: PostListing) {
1444 let auth = myAuth();
1447 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1448 let form: SavePost = {
1449 post_id: i.props.post_view.post.id,
1453 WebSocketService.Instance.send(wsClient.savePost(form));
1457 get crossPostParams(): string {
1458 let post = this.props.post_view.post;
1459 let params = `?title=${encodeURIComponent(post.name)}`;
1462 params += `&url=${encodeURIComponent(post.url)}`;
1464 let crossPostBody = this.crossPostBody();
1465 if (crossPostBody) {
1466 params += `&body=${encodeURIComponent(crossPostBody)}`;
1471 crossPostBody(): string | undefined {
1472 let post = this.props.post_view.post;
1473 let body = post.body;
1476 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1483 get showBody(): boolean {
1484 return this.props.showBody || this.state.showBody;
1487 handleModRemoveShow(i: PostListing) {
1489 showRemoveDialog: !i.state.showRemoveDialog,
1490 showBanDialog: false,
1494 handleModRemoveReasonChange(i: PostListing, event: any) {
1495 i.setState({ removeReason: event.target.value });
1498 handleModRemoveDataChange(i: PostListing, event: any) {
1499 i.setState({ removeData: event.target.checked });
1502 handleModRemoveSubmit(i: PostListing, event: any) {
1503 event.preventDefault();
1505 let auth = myAuth();
1507 let form: RemovePost = {
1508 post_id: i.props.post_view.post.id,
1509 removed: !i.props.post_view.post.removed,
1510 reason: i.state.removeReason,
1513 WebSocketService.Instance.send(wsClient.removePost(form));
1514 i.setState({ showRemoveDialog: false });
1518 handleModLock(i: PostListing) {
1519 let auth = myAuth();
1521 let form: LockPost = {
1522 post_id: i.props.post_view.post.id,
1523 locked: !i.props.post_view.post.locked,
1526 WebSocketService.Instance.send(wsClient.lockPost(form));
1530 handleModFeaturePost(i: PostListing, is_community: boolean) {
1531 let auth = myAuth();
1533 let featured: [PostFeatureType, boolean] = is_community
1535 PostFeatureType.Community,
1536 !i.props.post_view.post.featured_community,
1538 : [PostFeatureType.Local, !i.props.post_view.post.featured_local];
1540 let form: FeaturePost = {
1541 post_id: i.props.post_view.post.id,
1542 feature_type: featured[0],
1543 featured: featured[1],
1546 WebSocketService.Instance.send(wsClient.featurePost(form));
1550 handleModBanFromCommunityShow(i: PostListing) {
1552 showBanDialog: true,
1553 banType: BanType.Community,
1554 showRemoveDialog: false,
1558 handleModBanShow(i: PostListing) {
1560 showBanDialog: true,
1561 banType: BanType.Site,
1562 showRemoveDialog: false,
1566 handlePurgePersonShow(i: PostListing) {
1568 showPurgeDialog: true,
1569 purgeType: PurgeType.Person,
1570 showRemoveDialog: false,
1574 handlePurgePostShow(i: PostListing) {
1576 showPurgeDialog: true,
1577 purgeType: PurgeType.Post,
1578 showRemoveDialog: false,
1582 handlePurgeReasonChange(i: PostListing, event: any) {
1583 i.setState({ purgeReason: event.target.value });
1586 handlePurgeSubmit(i: PostListing, event: any) {
1587 event.preventDefault();
1589 let auth = myAuth();
1591 if (i.state.purgeType == PurgeType.Person) {
1592 let form: PurgePerson = {
1593 person_id: i.props.post_view.creator.id,
1594 reason: i.state.purgeReason,
1597 WebSocketService.Instance.send(wsClient.purgePerson(form));
1598 } else if (i.state.purgeType == PurgeType.Post) {
1599 let form: PurgePost = {
1600 post_id: i.props.post_view.post.id,
1601 reason: i.state.purgeReason,
1604 WebSocketService.Instance.send(wsClient.purgePost(form));
1607 i.setState({ purgeLoading: true });
1611 handleModBanReasonChange(i: PostListing, event: any) {
1612 i.setState({ banReason: event.target.value });
1615 handleModBanExpireDaysChange(i: PostListing, event: any) {
1616 i.setState({ banExpireDays: event.target.value });
1619 handleModBanFromCommunitySubmit(i: PostListing) {
1620 i.setState({ banType: BanType.Community });
1621 i.handleModBanBothSubmit(i);
1624 handleModBanSubmit(i: PostListing) {
1625 i.setState({ banType: BanType.Site });
1626 i.handleModBanBothSubmit(i);
1629 handleModBanBothSubmit(i: PostListing, event?: any) {
1630 if (event) event.preventDefault();
1631 let auth = myAuth();
1633 let ban = !i.props.post_view.creator_banned_from_community;
1634 let person_id = i.props.post_view.creator.id;
1635 let remove_data = i.state.removeData;
1636 let reason = i.state.banReason;
1637 let expires = futureDaysToUnixTime(i.state.banExpireDays);
1639 if (i.state.banType == BanType.Community) {
1640 // If its an unban, restore all their data
1642 i.setState({ removeData: false });
1645 let form: BanFromCommunity = {
1647 community_id: i.props.post_view.community.id,
1654 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1656 // If its an unban, restore all their data
1657 let ban = !i.props.post_view.creator.banned;
1659 i.setState({ removeData: false });
1661 let form: BanPerson = {
1669 WebSocketService.Instance.send(wsClient.banPerson(form));
1672 i.setState({ showBanDialog: false });
1676 handleAddModToCommunity(i: PostListing) {
1677 let auth = myAuth();
1679 let form: AddModToCommunity = {
1680 person_id: i.props.post_view.creator.id,
1681 community_id: i.props.post_view.community.id,
1682 added: !i.creatorIsMod_,
1685 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1686 i.setState(i.state);
1690 handleAddAdmin(i: PostListing) {
1691 let auth = myAuth();
1693 let form: AddAdmin = {
1694 person_id: i.props.post_view.creator.id,
1695 added: !i.creatorIsAdmin_,
1698 WebSocketService.Instance.send(wsClient.addAdmin(form));
1699 i.setState(i.state);
1703 handleShowConfirmTransferCommunity(i: PostListing) {
1704 i.setState({ showConfirmTransferCommunity: true });
1707 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1708 i.setState({ showConfirmTransferCommunity: false });
1711 handleTransferCommunity(i: PostListing) {
1712 let auth = myAuth();
1714 let form: TransferCommunity = {
1715 community_id: i.props.post_view.community.id,
1716 person_id: i.props.post_view.creator.id,
1719 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1720 i.setState({ showConfirmTransferCommunity: false });
1724 handleShowConfirmTransferSite(i: PostListing) {
1725 i.setState({ showConfirmTransferSite: true });
1728 handleCancelShowConfirmTransferSite(i: PostListing) {
1729 i.setState({ showConfirmTransferSite: false });
1732 handleImageExpandClick(i: PostListing, event: any) {
1733 event.preventDefault();
1734 i.setState({ imageExpanded: !i.state.imageExpanded });
1738 handleViewSource(i: PostListing) {
1739 i.setState({ viewSource: !i.state.viewSource });
1742 handleShowAdvanced(i: PostListing) {
1743 i.setState({ showAdvanced: !i.state.showAdvanced });
1747 handleShowMoreMobile(i: PostListing) {
1749 showMoreMobile: !i.state.showMoreMobile,
1750 showAdvanced: !i.state.showAdvanced,
1755 handleShowBody(i: PostListing) {
1756 i.setState({ showBody: !i.state.showBody });
1760 get pointsTippy(): string {
1761 let points = i18n.t("number_of_points", {
1762 count: this.state.score,
1763 formattedCount: this.state.score,
1766 let upvotes = i18n.t("number_of_upvotes", {
1767 count: this.state.upvotes,
1768 formattedCount: this.state.upvotes,
1771 let downvotes = i18n.t("number_of_downvotes", {
1772 count: this.state.downvotes,
1773 formattedCount: this.state.downvotes,
1776 return `${points} • ${upvotes} • ${downvotes}`;
1779 get canModOnSelf_(): boolean {
1781 this.props.post_view.creator.id,
1782 this.props.moderators,
1789 get canMod_(): boolean {
1791 this.props.post_view.creator.id,
1792 this.props.moderators,
1797 get canAdmin_(): boolean {
1798 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1801 get creatorIsMod_(): boolean {
1802 return isMod(this.props.post_view.creator.id, this.props.moderators);
1805 get creatorIsAdmin_(): boolean {
1806 return isAdmin(this.props.post_view.creator.id, this.props.admins);