1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
10 CommunityModeratorView,
24 } from "lemmy-js-client";
25 import { getExternalHost, getHttpBase } from "../../env";
26 import { i18n } from "../../i18next";
27 import { BanType, PostFormParams, PurgeType } from "../../interfaces";
28 import { UserService, WebSocketService } from "../../services";
54 import { Icon, PurgeWarning, Spinner } from "../common/icon";
55 import { MomentTime } from "../common/moment-time";
56 import { PictrsImage } from "../common/pictrs-image";
57 import { CommunityLink } from "../community/community-link";
58 import { PersonListing } from "../person/person-listing";
59 import { MetadataCard } from "./metadata-card";
60 import { PostForm } from "./post-form";
62 interface PostListingState {
64 showRemoveDialog: boolean;
65 showPurgeDialog: boolean;
67 purgeType?: PurgeType;
68 purgeLoading: boolean;
69 removeReason?: string;
70 showBanDialog: boolean;
72 banExpireDays?: number;
75 showConfirmTransferSite: boolean;
76 showConfirmTransferCommunity: boolean;
77 imageExpanded: boolean;
79 showAdvanced: boolean;
80 showMoreMobile: boolean;
82 showReportDialog: boolean;
83 reportReason?: string;
90 interface PostListingProps {
92 duplicates?: PostView[];
93 moderators?: CommunityModeratorView[];
94 admins?: PersonView[];
95 allLanguages: Language[];
96 siteLanguages: number[];
97 showCommunity?: boolean;
100 enableDownvotes?: boolean;
101 enableNsfw?: boolean;
105 export class PostListing extends Component<PostListingProps, PostListingState> {
106 state: PostListingState = {
108 showRemoveDialog: false,
109 showPurgeDialog: false,
110 purgeType: PurgeType.Person,
112 showBanDialog: false,
113 banType: BanType.Community,
115 showConfirmTransferSite: false,
116 showConfirmTransferCommunity: false,
117 imageExpanded: false,
120 showMoreMobile: false,
122 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.handlePostLike = this.handlePostLike.bind(this);
133 this.handlePostDisLike = this.handlePostDisLike.bind(this);
134 this.handleEditPost = this.handleEditPost.bind(this);
135 this.handleEditCancel = this.handleEditCancel.bind(this);
138 componentWillReceiveProps(nextProps: PostListingProps) {
140 my_vote: nextProps.post_view.my_vote,
141 upvotes: nextProps.post_view.counts.upvotes,
142 downvotes: nextProps.post_view.counts.downvotes,
143 score: nextProps.post_view.counts.score,
145 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
146 this.setState({ imageExpanded: false });
151 const post = this.props.post_view.post;
154 <div className="post-listing">
155 {!this.state.showEdit ? (
158 {this.state.imageExpanded && !this.props.hideImage && this.img}
159 {post.url && this.showBody && post.embed_title && (
160 <MetadataCard post={post} />
162 {this.showBody && this.body()}
165 <div className="col-12">
167 post_view={this.props.post_view}
168 onEdit={this.handleEditPost}
169 onCancel={this.handleEditCancel}
170 enableNsfw={this.props.enableNsfw}
171 enableDownvotes={this.props.enableDownvotes}
172 allLanguages={this.props.allLanguages}
173 siteLanguages={this.props.siteLanguages}
182 let body = this.props.post_view.post.body;
184 <div className="col-12 card my-2 p-2">
185 {this.state.viewSource ? (
188 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
197 let src = this.imageSrc;
200 <div className="offset-sm-3 my-2 d-none d-sm-block">
201 <a href={src} className="d-inline-block">
202 <PictrsImage src={src} />
205 <div className="my-2 d-block d-sm-none">
207 className="d-inline-block"
208 onClick={linkEvent(this, this.handleImageExpandClick)}
210 <PictrsImage src={src} />
219 imgThumb(src: string) {
220 let post_view = this.props.post_view;
226 nsfw={post_view.post.nsfw || post_view.community.nsfw}
231 get imageSrc(): string | undefined {
232 let post = this.props.post_view.post;
234 let thumbnail = post.thumbnail_url;
236 if (url && isImage(url)) {
237 if (url.includes("pictrs")) {
239 } else if (thumbnail) {
244 } else if (thumbnail) {
252 let post = this.props.post_view.post;
254 let thumbnail = post.thumbnail_url;
256 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
260 className="text-body d-inline-block position-relative mb-2"
261 data-tippy-content={i18n.t("expand_here")}
262 onClick={linkEvent(this, this.handleImageExpandClick)}
263 aria-label={i18n.t("expand_here")}
265 {this.imgThumb(this.imageSrc)}
266 <Icon icon="image" classes="mini-overlay" />
269 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
272 className="text-body d-inline-block position-relative mb-2"
277 {this.imgThumb(this.imageSrc)}
278 <Icon icon="external-link" classes="mini-overlay" />
282 if (!this.props.hideImage && isVideo(url)) {
284 <div className="embed-responsive embed-responsive-16by9">
290 className="embed-responsive-item"
292 <source src={url} type="video/mp4" />
298 <a className="text-body" href={url} title={url} rel={relTags}>
299 <div className="thumbnail rounded bg-light d-flex justify-content-center">
300 <Icon icon="external-link" classes="d-flex align-items-center" />
308 className="text-body"
309 to={`/post/${post.id}`}
310 title={i18n.t("comments")}
312 <div className="thumbnail rounded bg-light d-flex justify-content-center">
313 <Icon icon="message-square" classes="d-flex align-items-center" />
321 let post_view = this.props.post_view;
322 let url = post_view.post.url;
323 let body = post_view.post.body;
325 <ul className="list-inline mb-1 text-muted small">
326 <li className="list-inline-item">
327 <PersonListing person={post_view.creator} />
329 {this.creatorIsMod_ && (
330 <span className="mx-1 badge badge-muted">{i18n.t("mod")}</span>
332 {this.creatorIsAdmin_ && (
333 <span className="mx-1 badge badge-muted">{i18n.t("admin")}</span>
335 {post_view.creator.bot_account && (
336 <span className="mx-1 badge badge-muted">
337 {i18n.t("bot_account").toLowerCase()}
340 {this.props.showCommunity && (
342 <span className="mx-1"> {i18n.t("to")} </span>
343 <CommunityLink community={post_view.community} />
347 {post_view.post.language_id !== 0 && (
348 <span className="mx-1 badge badge-muted">
350 this.props.allLanguages.find(
351 lang => lang.id === post_view.post.language_id
356 <li className="list-inline-item">•</li>
357 {url && !(hostname(url) === getExternalHost()) && (
359 <li className="list-inline-item">
361 className="text-muted font-italic"
369 <li className="list-inline-item">•</li>
372 <li className="list-inline-item">
375 published={post_view.post.published}
376 updated={post_view.post.updated}
382 <li className="list-inline-item">•</li>
383 <li className="list-inline-item">
385 className="text-muted btn btn-sm btn-link p-0"
386 data-tippy-content={mdNoImages.render(body)}
387 data-tippy-allowHtml={true}
388 onClick={linkEvent(this, this.handleShowBody)}
390 <Icon icon="book-open" classes="icon-inline mr-1" />
401 <div className={`vote-bar col-1 pr-0 small text-center`}>
403 className={`btn-animate btn btn-link p-0 ${
404 this.state.my_vote == 1 ? "text-info" : "text-muted"
406 onClick={this.handlePostLike}
407 data-tippy-content={i18n.t("upvote")}
408 aria-label={i18n.t("upvote")}
410 <Icon icon="arrow-up1" classes="upvote" />
414 className={`unselectable pointer font-weight-bold text-muted px-1`}
415 data-tippy-content={this.pointsTippy}
417 {numToSI(this.state.score)}
420 <div className="p-1"></div>
422 {this.props.enableDownvotes && (
424 className={`btn-animate btn btn-link p-0 ${
425 this.state.my_vote == -1 ? "text-danger" : "text-muted"
427 onClick={this.handlePostDisLike}
428 data-tippy-content={i18n.t("downvote")}
429 aria-label={i18n.t("downvote")}
431 <Icon icon="arrow-down1" classes="downvote" />
439 let post = this.props.post_view.post;
442 className={`d-inline-block ${
443 !post.featured_community && !post.featured_local
447 to={`/post/${post.id}`}
448 title={i18n.t("comments")}
451 className="d-inline-block"
452 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
459 let post = this.props.post_view.post;
463 <div className="post-title overflow-hidden">
466 this.props.showBody ? (
468 className={`d-inline-block ${
469 !post.featured_community && !post.featured_local
478 className="d-inline-block"
479 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
488 {(url && isImage(url)) ||
489 (post.thumbnail_url && (
491 className="btn btn-link text-monospace text-muted small d-inline-block"
492 data-tippy-content={i18n.t("expand_here")}
493 onClick={linkEvent(this, this.handleImageExpandClick)}
497 !this.state.imageExpanded ? "plus-square" : "minus-square"
499 classes="icon-inline"
504 <small className="ml-2 text-muted font-italic">
510 className="unselectable pointer ml-2 text-muted font-italic"
511 data-tippy-content={i18n.t("deleted")}
513 <Icon icon="trash" classes="icon-inline text-danger" />
518 className="unselectable pointer ml-2 text-muted font-italic"
519 data-tippy-content={i18n.t("locked")}
521 <Icon icon="lock" classes="icon-inline text-danger" />
524 {post.featured_community && (
526 className="unselectable pointer ml-2 text-muted font-italic"
527 data-tippy-content={i18n.t("featured")}
529 <Icon icon="pin" classes="icon-inline text-primary" />
532 {post.featured_local && (
534 className="unselectable pointer ml-2 text-muted font-italic"
535 data-tippy-content={i18n.t("featured")}
537 <Icon icon="pin" classes="icon-inline text-secondary" />
541 <small className="ml-2 text-muted font-italic">
551 let dupes = this.props.duplicates;
552 return dupes && dupes.length > 0 ? (
553 <ul className="list-inline mb-1 small text-muted">
555 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
557 <li key={pv.post.id} className="list-inline-item mr-2">
558 <Link to={`/post/${pv.post.id}`}>
561 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
572 commentsLine(mobile = false) {
573 let post = this.props.post_view.post;
576 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
577 {this.commentsButton}
580 className="btn btn-link"
581 onClick={linkEvent(this, this.handleShare)}
584 <Icon icon="share" inline />
589 className="btn btn-link btn-animate text-muted py-0"
590 title={i18n.t("link")}
593 <Icon icon="fedilink" inline />
596 {mobile && !this.props.viewOnly && this.mobileVotes}
597 {UserService.Instance.myUserInfo &&
598 !this.props.viewOnly &&
599 this.postActions(mobile)}
604 postActions(mobile = false) {
605 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
606 // Possible enhancement: Make each button a component.
607 let post_view = this.props.post_view;
611 {this.crossPostButton}
612 {mobile && this.showMoreButton}
613 {(!mobile || this.state.showAdvanced) && (
621 {this.myPost && (this.showBody || this.state.showAdvanced) && (
629 {this.state.showAdvanced && (
631 {this.showBody && post_view.post.body && this.viewSourceButton}
632 {/* Any mod can do these, not limited to hierarchy*/}
633 {(amMod(this.props.moderators) || amAdmin()) && (
639 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
642 {!mobile && this.showMoreButton}
647 get commentsButton() {
648 let post_view = this.props.post_view;
650 <button className="btn btn-link text-muted py-0 pl-0">
652 className="text-muted"
653 title={i18n.t("number_of_comments", {
654 count: Number(post_view.counts.comments),
655 formattedCount: Number(post_view.counts.comments),
657 to={`/post/${post_view.post.id}?scrollToComments=true`}
659 <Icon icon="message-square" classes="mr-1" inline />
660 <span className="mr-2">
661 {i18n.t("number_of_comments", {
662 count: Number(post_view.counts.comments),
663 formattedCount: numToSI(post_view.counts.comments),
666 {this.unreadCount && (
667 <span className="small text-warning">
668 ({this.unreadCount} {i18n.t("new")})
676 get unreadCount(): number | undefined {
677 let pv = this.props.post_view;
678 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
680 : pv.unread_comments;
685 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
690 className={`btn-animate btn py-0 px-1 ${
691 this.state.my_vote == 1 ? "text-info" : "text-muted"
694 onClick={this.handlePostLike}
695 aria-label={i18n.t("upvote")}
697 <Icon icon="arrow-up1" classes="icon-inline small" />
699 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
702 {this.props.enableDownvotes && (
704 className={`ml-2 btn-animate btn py-0 px-1 ${
705 this.state.my_vote == -1 ? "text-danger" : "text-muted"
707 onClick={this.handlePostDisLike}
709 aria-label={i18n.t("downvote")}
711 <Icon icon="arrow-down1" classes="icon-inline small" />
714 className={classNames("ml-2", {
715 invisible: this.state.downvotes === 0,
718 {numToSI(this.state.downvotes)}
729 let saved = this.props.post_view.saved;
730 let label = saved ? i18n.t("unsave") : i18n.t("save");
733 className="btn btn-link btn-animate text-muted py-0"
734 onClick={linkEvent(this, this.handleSavePostClick)}
735 data-tippy-content={label}
740 classes={classNames({ "text-warning": saved })}
747 get crossPostButton() {
750 className="btn btn-link btn-animate text-muted py-0"
752 /* Empty string properties are required to satisfy type*/
753 pathname: "/create_post",
754 state: { ...this.crossPostParams },
759 title={i18n.t("cross_post")}
761 <Icon icon="copy" inline />
769 className="btn btn-link btn-animate text-muted py-0"
770 onClick={linkEvent(this, this.handleShowReportDialog)}
771 data-tippy-content={i18n.t("show_report_dialog")}
772 aria-label={i18n.t("show_report_dialog")}
774 <Icon icon="flag" inline />
782 className="btn btn-link btn-animate text-muted py-0"
783 onClick={linkEvent(this, this.handleBlockUserClick)}
784 data-tippy-content={i18n.t("block_user")}
785 aria-label={i18n.t("block_user")}
787 <Icon icon="slash" inline />
795 className="btn btn-link btn-animate text-muted py-0"
796 onClick={linkEvent(this, this.handleEditClick)}
797 data-tippy-content={i18n.t("edit")}
798 aria-label={i18n.t("edit")}
800 <Icon icon="edit" inline />
806 let deleted = this.props.post_view.post.deleted;
807 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
810 className="btn btn-link btn-animate text-muted py-0"
811 onClick={linkEvent(this, this.handleDeleteClick)}
812 data-tippy-content={label}
817 classes={classNames({ "text-danger": deleted })}
824 get showMoreButton() {
827 className="btn btn-link btn-animate text-muted py-0"
828 onClick={linkEvent(this, this.handleShowAdvanced)}
829 data-tippy-content={i18n.t("more")}
830 aria-label={i18n.t("more")}
832 <Icon icon="more-vertical" inline />
837 get viewSourceButton() {
840 className="btn btn-link btn-animate text-muted py-0"
841 onClick={linkEvent(this, this.handleViewSource)}
842 data-tippy-content={i18n.t("view_source")}
843 aria-label={i18n.t("view_source")}
847 classes={classNames({ "text-success": this.state.viewSource })}
855 let locked = this.props.post_view.post.locked;
856 let label = locked ? i18n.t("unlock") : i18n.t("lock");
859 className="btn btn-link btn-animate text-muted py-0"
860 onClick={linkEvent(this, this.handleModLock)}
861 data-tippy-content={label}
866 classes={classNames({ "text-danger": locked })}
873 get featureButton() {
874 const featuredCommunity = this.props.post_view.post.featured_community;
875 const labelCommunity = featuredCommunity
876 ? i18n.t("unfeature_from_community")
877 : i18n.t("feature_in_community");
879 const featuredLocal = this.props.post_view.post.featured_local;
880 const labelLocal = featuredLocal
881 ? i18n.t("unfeature_from_local")
882 : i18n.t("feature_in_local");
886 className="btn btn-link btn-animate text-muted py-0 pl-0"
887 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
888 data-tippy-content={labelCommunity}
889 aria-label={labelCommunity}
893 classes={classNames({ "text-success": featuredCommunity })}
900 className="btn btn-link btn-animate text-muted py-0"
901 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
902 data-tippy-content={labelLocal}
903 aria-label={labelLocal}
907 classes={classNames({ "text-success": featuredLocal })}
917 get modRemoveButton() {
918 let removed = this.props.post_view.post.removed;
921 className="btn btn-link btn-animate text-muted py-0"
924 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
927 {/* TODO: Find an icon for this. */}
928 {!removed ? i18n.t("remove") : i18n.t("restore")}
934 * Mod/Admin actions to be taken against the author.
938 let post_view = this.props.post_view;
940 this.state.showAdvanced && (
944 {!this.creatorIsMod_ &&
945 (!post_view.creator_banned_from_community ? (
947 className="btn btn-link btn-animate text-muted py-0"
950 this.handleModBanFromCommunityShow
952 aria-label={i18n.t("ban_from_community")}
954 {i18n.t("ban_from_community")}
958 className="btn btn-link btn-animate text-muted py-0"
961 this.handleModBanFromCommunitySubmit
963 aria-label={i18n.t("unban")}
968 {!post_view.creator_banned_from_community && (
970 className="btn btn-link btn-animate text-muted py-0"
971 onClick={linkEvent(this, this.handleAddModToCommunity)}
974 ? i18n.t("remove_as_mod")
975 : i18n.t("appoint_as_mod")
979 ? i18n.t("remove_as_mod")
980 : i18n.t("appoint_as_mod")}
985 {/* Community creators and admins can transfer community to another mod */}
986 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
988 this.creatorIsMod_ &&
989 (!this.state.showConfirmTransferCommunity ? (
991 className="btn btn-link btn-animate text-muted py-0"
994 this.handleShowConfirmTransferCommunity
996 aria-label={i18n.t("transfer_community")}
998 {i18n.t("transfer_community")}
1003 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1004 aria-label={i18n.t("are_you_sure")}
1006 {i18n.t("are_you_sure")}
1009 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1010 aria-label={i18n.t("yes")}
1011 onClick={linkEvent(this, this.handleTransferCommunity)}
1016 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1019 this.handleCancelShowConfirmTransferCommunity
1021 aria-label={i18n.t("no")}
1027 {/* Admins can ban from all, and appoint other admins */}
1028 {this.canAdmin_ && (
1030 {!this.creatorIsAdmin_ && (
1032 {!isBanned(post_view.creator) ? (
1034 className="btn btn-link btn-animate text-muted py-0"
1035 onClick={linkEvent(this, this.handleModBanShow)}
1036 aria-label={i18n.t("ban_from_site")}
1038 {i18n.t("ban_from_site")}
1042 className="btn btn-link btn-animate text-muted py-0"
1043 onClick={linkEvent(this, this.handleModBanSubmit)}
1044 aria-label={i18n.t("unban_from_site")}
1046 {i18n.t("unban_from_site")}
1050 className="btn btn-link btn-animate text-muted py-0"
1051 onClick={linkEvent(this, this.handlePurgePersonShow)}
1052 aria-label={i18n.t("purge_user")}
1054 {i18n.t("purge_user")}
1057 className="btn btn-link btn-animate text-muted py-0"
1058 onClick={linkEvent(this, this.handlePurgePostShow)}
1059 aria-label={i18n.t("purge_post")}
1061 {i18n.t("purge_post")}
1065 {!isBanned(post_view.creator) && post_view.creator.local && (
1067 className="btn btn-link btn-animate text-muted py-0"
1068 onClick={linkEvent(this, this.handleAddAdmin)}
1070 this.creatorIsAdmin_
1071 ? i18n.t("remove_as_admin")
1072 : i18n.t("appoint_as_admin")
1075 {this.creatorIsAdmin_
1076 ? i18n.t("remove_as_admin")
1077 : i18n.t("appoint_as_admin")}
1087 removeAndBanDialogs() {
1088 let post = this.props.post_view;
1090 this.state.purgeType == PurgeType.Post
1091 ? i18n.t("purge_post")
1092 : `${i18n.t("purge")} ${post.creator.name}`;
1095 {this.state.showRemoveDialog && (
1097 className="form-inline"
1098 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1100 <label className="sr-only" htmlFor="post-listing-remove-reason">
1105 id="post-listing-remove-reason"
1106 className="form-control mr-2"
1107 placeholder={i18n.t("reason")}
1108 value={this.state.removeReason}
1109 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1113 className="btn btn-secondary"
1114 aria-label={i18n.t("remove_post")}
1116 {i18n.t("remove_post")}
1120 {this.state.showBanDialog && (
1121 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1122 <div className="form-group row col-12">
1124 className="col-form-label"
1125 htmlFor="post-listing-ban-reason"
1131 id="post-listing-ban-reason"
1132 className="form-control mr-2"
1133 placeholder={i18n.t("reason")}
1134 value={this.state.banReason}
1135 onInput={linkEvent(this, this.handleModBanReasonChange)}
1137 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1142 id={`mod-ban-expires`}
1143 className="form-control mr-2"
1144 placeholder={i18n.t("number_of_days")}
1145 value={this.state.banExpireDays}
1146 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1148 <div className="form-group">
1149 <div className="form-check">
1151 className="form-check-input"
1152 id="mod-ban-remove-data"
1154 checked={this.state.removeData}
1155 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1158 className="form-check-label"
1159 htmlFor="mod-ban-remove-data"
1160 title={i18n.t("remove_content_more")}
1162 {i18n.t("remove_content")}
1167 {/* TODO hold off on expires until later */}
1168 {/* <div class="form-group row"> */}
1169 {/* <label class="col-form-label">Expires</label> */}
1170 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1172 <div className="form-group row">
1175 className="btn btn-secondary"
1176 aria-label={i18n.t("ban")}
1178 {i18n.t("ban")} {post.creator.name}
1183 {this.state.showReportDialog && (
1185 className="form-inline"
1186 onSubmit={linkEvent(this, this.handleReportSubmit)}
1188 <label className="sr-only" htmlFor="post-report-reason">
1193 id="post-report-reason"
1194 className="form-control mr-2"
1195 placeholder={i18n.t("reason")}
1197 value={this.state.reportReason}
1198 onInput={linkEvent(this, this.handleReportReasonChange)}
1202 className="btn btn-secondary"
1203 aria-label={i18n.t("create_report")}
1205 {i18n.t("create_report")}
1209 {this.state.showPurgeDialog && (
1211 className="form-inline"
1212 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1215 <label className="sr-only" htmlFor="purge-reason">
1221 className="form-control mr-2"
1222 placeholder={i18n.t("reason")}
1223 value={this.state.purgeReason}
1224 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1226 {this.state.purgeLoading ? (
1231 className="btn btn-secondary"
1232 aria-label={purgeTypeText}
1244 let post = this.props.post_view.post;
1245 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1246 <div className="row">
1247 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1248 {this.postTitleLine()}
1250 <div className="col-4">
1251 {/* Post body prev or thumbnail */}
1252 {!this.state.imageExpanded && this.thumbnail()}
1256 this.postTitleLine()
1260 showMobilePreview() {
1261 let body = this.props.post_view.post.body;
1262 return !this.showBody && body ? (
1263 <div className="md-div mb-1 preview-lines">{body}</div>
1272 {/* The mobile view*/}
1273 <div className="d-block d-sm-none">
1274 <div className="row">
1275 <div className="col-12">
1276 {this.createdLine()}
1278 {/* If it has a thumbnail, do a right aligned thumbnail */}
1279 {this.mobileThumbnail()}
1281 {/* Show a preview of the post body */}
1282 {this.showMobilePreview()}
1284 {this.commentsLine(true)}
1285 {this.userActionsLine()}
1286 {this.duplicatesLine()}
1287 {this.removeAndBanDialogs()}
1292 {/* The larger view*/}
1293 <div className="d-none d-sm-block">
1294 <div className="row">
1295 {!this.props.viewOnly && this.voteBar()}
1296 <div className="col-sm-2 pr-0">
1297 <div className="">{this.thumbnail()}</div>
1299 <div className="col-12 col-sm-9">
1300 <div className="row">
1301 <div className="col-12">
1302 {this.postTitleLine()}
1303 {this.createdLine()}
1304 {this.commentsLine()}
1305 {this.duplicatesLine()}
1306 {this.userActionsLine()}
1307 {this.removeAndBanDialogs()}
1317 private get myPost(): boolean {
1319 this.props.post_view.creator.id ==
1320 UserService.Instance.myUserInfo?.local_user_view.person.id
1324 handlePostLike(event: any) {
1325 event.preventDefault();
1326 if (!UserService.Instance.myUserInfo) {
1327 this.context.router.history.push(`/login`);
1330 let myVote = this.state.my_vote;
1331 let newVote = myVote == 1 ? 0 : 1;
1335 score: this.state.score - 1,
1336 upvotes: this.state.upvotes - 1,
1338 } else if (myVote == -1) {
1340 score: this.state.score + 2,
1341 upvotes: this.state.upvotes + 1,
1342 downvotes: this.state.downvotes - 1,
1346 score: this.state.score + 1,
1347 upvotes: this.state.upvotes + 1,
1351 this.setState({ my_vote: newVote });
1353 let auth = myAuth();
1355 let form: CreatePostLike = {
1356 post_id: this.props.post_view.post.id,
1361 WebSocketService.Instance.send(wsClient.likePost(form));
1362 this.setState(this.state);
1367 handlePostDisLike(event: any) {
1368 event.preventDefault();
1369 if (!UserService.Instance.myUserInfo) {
1370 this.context.router.history.push(`/login`);
1373 let myVote = this.state.my_vote;
1374 let newVote = myVote == -1 ? 0 : -1;
1378 score: this.state.score - 2,
1379 upvotes: this.state.upvotes - 1,
1380 downvotes: this.state.downvotes + 1,
1382 } else if (myVote == -1) {
1384 score: this.state.score + 1,
1385 downvotes: this.state.downvotes - 1,
1389 score: this.state.score - 1,
1390 downvotes: this.state.downvotes + 1,
1394 this.setState({ my_vote: newVote });
1396 let auth = myAuth();
1398 let form: CreatePostLike = {
1399 post_id: this.props.post_view.post.id,
1404 WebSocketService.Instance.send(wsClient.likePost(form));
1405 this.setState(this.state);
1410 handleEditClick(i: PostListing) {
1411 i.setState({ showEdit: true });
1414 handleEditCancel() {
1415 this.setState({ showEdit: false });
1418 // The actual editing is done in the recieve for post
1420 this.setState({ showEdit: false });
1423 handleShare(i: PostListing) {
1424 const { name, body, id } = i.props.post_view.post;
1427 text: body?.slice(0, 50),
1428 url: `${getHttpBase()}/post/${id}`,
1432 handleShowReportDialog(i: PostListing) {
1433 i.setState({ showReportDialog: !i.state.showReportDialog });
1436 handleReportReasonChange(i: PostListing, event: any) {
1437 i.setState({ reportReason: event.target.value });
1440 handleReportSubmit(i: PostListing, event: any) {
1441 event.preventDefault();
1442 let auth = myAuth();
1443 let reason = i.state.reportReason;
1444 if (auth && reason) {
1445 let form: CreatePostReport = {
1446 post_id: i.props.post_view.post.id,
1450 WebSocketService.Instance.send(wsClient.createPostReport(form));
1452 i.setState({ showReportDialog: false });
1456 handleBlockUserClick(i: PostListing) {
1457 let auth = myAuth();
1459 let blockUserForm: BlockPerson = {
1460 person_id: i.props.post_view.creator.id,
1464 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1468 handleDeleteClick(i: PostListing) {
1469 let auth = myAuth();
1471 let deleteForm: DeletePost = {
1472 post_id: i.props.post_view.post.id,
1473 deleted: !i.props.post_view.post.deleted,
1476 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1480 handleSavePostClick(i: PostListing) {
1481 let auth = myAuth();
1484 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1485 let form: SavePost = {
1486 post_id: i.props.post_view.post.id,
1490 WebSocketService.Instance.send(wsClient.savePost(form));
1494 get crossPostParams(): PostFormParams {
1495 const queryParams: PostFormParams = {};
1496 const { name, url } = this.props.post_view.post;
1498 queryParams.name = name;
1501 queryParams.url = url;
1504 const crossPostBody = this.crossPostBody();
1505 if (crossPostBody) {
1506 queryParams.body = crossPostBody;
1512 crossPostBody(): string | undefined {
1513 let post = this.props.post_view.post;
1514 let body = post.body;
1517 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1524 get showBody(): boolean {
1525 return this.props.showBody || this.state.showBody;
1528 handleModRemoveShow(i: PostListing) {
1530 showRemoveDialog: !i.state.showRemoveDialog,
1531 showBanDialog: false,
1535 handleModRemoveReasonChange(i: PostListing, event: any) {
1536 i.setState({ removeReason: event.target.value });
1539 handleModRemoveDataChange(i: PostListing, event: any) {
1540 i.setState({ removeData: event.target.checked });
1543 handleModRemoveSubmit(i: PostListing, event: any) {
1544 event.preventDefault();
1546 let auth = myAuth();
1548 let form: RemovePost = {
1549 post_id: i.props.post_view.post.id,
1550 removed: !i.props.post_view.post.removed,
1551 reason: i.state.removeReason,
1554 WebSocketService.Instance.send(wsClient.removePost(form));
1555 i.setState({ showRemoveDialog: false });
1559 handleModLock(i: PostListing) {
1560 let auth = myAuth();
1562 let form: LockPost = {
1563 post_id: i.props.post_view.post.id,
1564 locked: !i.props.post_view.post.locked,
1567 WebSocketService.Instance.send(wsClient.lockPost(form));
1571 handleModFeaturePostLocal(i: PostListing) {
1572 let auth = myAuth();
1574 let form: FeaturePost = {
1575 post_id: i.props.post_view.post.id,
1576 feature_type: "Local",
1577 featured: !i.props.post_view.post.featured_local,
1580 WebSocketService.Instance.send(wsClient.featurePost(form));
1584 handleModFeaturePostCommunity(i: PostListing) {
1585 let auth = myAuth();
1587 let form: FeaturePost = {
1588 post_id: i.props.post_view.post.id,
1589 feature_type: "Community",
1590 featured: !i.props.post_view.post.featured_community,
1593 WebSocketService.Instance.send(wsClient.featurePost(form));
1597 handleModBanFromCommunityShow(i: PostListing) {
1599 showBanDialog: true,
1600 banType: BanType.Community,
1601 showRemoveDialog: false,
1605 handleModBanShow(i: PostListing) {
1607 showBanDialog: true,
1608 banType: BanType.Site,
1609 showRemoveDialog: false,
1613 handlePurgePersonShow(i: PostListing) {
1615 showPurgeDialog: true,
1616 purgeType: PurgeType.Person,
1617 showRemoveDialog: false,
1621 handlePurgePostShow(i: PostListing) {
1623 showPurgeDialog: true,
1624 purgeType: PurgeType.Post,
1625 showRemoveDialog: false,
1629 handlePurgeReasonChange(i: PostListing, event: any) {
1630 i.setState({ purgeReason: event.target.value });
1633 handlePurgeSubmit(i: PostListing, event: any) {
1634 event.preventDefault();
1636 let auth = myAuth();
1638 if (i.state.purgeType == PurgeType.Person) {
1639 let form: PurgePerson = {
1640 person_id: i.props.post_view.creator.id,
1641 reason: i.state.purgeReason,
1644 WebSocketService.Instance.send(wsClient.purgePerson(form));
1645 } else if (i.state.purgeType == PurgeType.Post) {
1646 let form: PurgePost = {
1647 post_id: i.props.post_view.post.id,
1648 reason: i.state.purgeReason,
1651 WebSocketService.Instance.send(wsClient.purgePost(form));
1654 i.setState({ purgeLoading: true });
1658 handleModBanReasonChange(i: PostListing, event: any) {
1659 i.setState({ banReason: event.target.value });
1662 handleModBanExpireDaysChange(i: PostListing, event: any) {
1663 i.setState({ banExpireDays: event.target.value });
1666 handleModBanFromCommunitySubmit(i: PostListing) {
1667 i.setState({ banType: BanType.Community });
1668 i.handleModBanBothSubmit(i);
1671 handleModBanSubmit(i: PostListing) {
1672 i.setState({ banType: BanType.Site });
1673 i.handleModBanBothSubmit(i);
1676 handleModBanBothSubmit(i: PostListing, event?: any) {
1677 if (event) event.preventDefault();
1678 let auth = myAuth();
1680 let ban = !i.props.post_view.creator_banned_from_community;
1681 let person_id = i.props.post_view.creator.id;
1682 let remove_data = i.state.removeData;
1683 let reason = i.state.banReason;
1684 let expires = futureDaysToUnixTime(i.state.banExpireDays);
1686 if (i.state.banType == BanType.Community) {
1687 // If its an unban, restore all their data
1689 i.setState({ removeData: false });
1692 let form: BanFromCommunity = {
1694 community_id: i.props.post_view.community.id,
1701 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1703 // If its an unban, restore all their data
1704 let ban = !i.props.post_view.creator.banned;
1706 i.setState({ removeData: false });
1708 let form: BanPerson = {
1716 WebSocketService.Instance.send(wsClient.banPerson(form));
1719 i.setState({ showBanDialog: false });
1723 handleAddModToCommunity(i: PostListing) {
1724 let auth = myAuth();
1726 let form: AddModToCommunity = {
1727 person_id: i.props.post_view.creator.id,
1728 community_id: i.props.post_view.community.id,
1729 added: !i.creatorIsMod_,
1732 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1733 i.setState(i.state);
1737 handleAddAdmin(i: PostListing) {
1738 let auth = myAuth();
1740 let form: AddAdmin = {
1741 person_id: i.props.post_view.creator.id,
1742 added: !i.creatorIsAdmin_,
1745 WebSocketService.Instance.send(wsClient.addAdmin(form));
1746 i.setState(i.state);
1750 handleShowConfirmTransferCommunity(i: PostListing) {
1751 i.setState({ showConfirmTransferCommunity: true });
1754 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1755 i.setState({ showConfirmTransferCommunity: false });
1758 handleTransferCommunity(i: PostListing) {
1759 let auth = myAuth();
1761 let form: TransferCommunity = {
1762 community_id: i.props.post_view.community.id,
1763 person_id: i.props.post_view.creator.id,
1766 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1767 i.setState({ showConfirmTransferCommunity: false });
1771 handleShowConfirmTransferSite(i: PostListing) {
1772 i.setState({ showConfirmTransferSite: true });
1775 handleCancelShowConfirmTransferSite(i: PostListing) {
1776 i.setState({ showConfirmTransferSite: false });
1779 handleImageExpandClick(i: PostListing, event: any) {
1780 event.preventDefault();
1781 i.setState({ imageExpanded: !i.state.imageExpanded });
1785 handleViewSource(i: PostListing) {
1786 i.setState({ viewSource: !i.state.viewSource });
1789 handleShowAdvanced(i: PostListing) {
1790 i.setState({ showAdvanced: !i.state.showAdvanced });
1794 handleShowMoreMobile(i: PostListing) {
1796 showMoreMobile: !i.state.showMoreMobile,
1797 showAdvanced: !i.state.showAdvanced,
1802 handleShowBody(i: PostListing) {
1803 i.setState({ showBody: !i.state.showBody });
1807 get pointsTippy(): string {
1808 let points = i18n.t("number_of_points", {
1809 count: Number(this.state.score),
1810 formattedCount: Number(this.state.score),
1813 let upvotes = i18n.t("number_of_upvotes", {
1814 count: Number(this.state.upvotes),
1815 formattedCount: Number(this.state.upvotes),
1818 let downvotes = i18n.t("number_of_downvotes", {
1819 count: Number(this.state.downvotes),
1820 formattedCount: Number(this.state.downvotes),
1823 return `${points} • ${upvotes} • ${downvotes}`;
1826 get canModOnSelf_(): boolean {
1828 this.props.post_view.creator.id,
1829 this.props.moderators,
1836 get canMod_(): boolean {
1838 this.props.post_view.creator.id,
1839 this.props.moderators,
1844 get canAdmin_(): boolean {
1845 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1848 get creatorIsMod_(): boolean {
1849 return isMod(this.props.post_view.creator.id, this.props.moderators);
1852 get creatorIsAdmin_(): boolean {
1853 return isAdmin(this.props.post_view.creator.id, this.props.admins);