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-light">{i18n.t("mod")}</span>
332 {this.creatorIsAdmin_ && (
333 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
335 {post_view.creator.bot_account && (
336 <span className="mx-1 badge badge-light">
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 <span className="mx-1 badge badge-secondary">
349 this.props.allLanguages.find(
350 lang => lang.id === post_view.post.language_id
354 <li className="list-inline-item">•</li>
355 {url && !(hostname(url) === getExternalHost()) && (
357 <li className="list-inline-item">
359 className="text-muted font-italic"
367 <li className="list-inline-item">•</li>
370 <li className="list-inline-item">
373 published={post_view.post.published}
374 updated={post_view.post.updated}
380 <li className="list-inline-item">•</li>
381 <li className="list-inline-item">
383 className="text-muted btn btn-sm btn-link p-0"
384 data-tippy-content={mdNoImages.render(body)}
385 data-tippy-allowHtml={true}
386 onClick={linkEvent(this, this.handleShowBody)}
388 <Icon icon="book-open" classes="icon-inline mr-1" />
399 <div className={`vote-bar col-1 pr-0 small text-center`}>
401 className={`btn-animate btn btn-link p-0 ${
402 this.state.my_vote == 1 ? "text-info" : "text-muted"
404 onClick={this.handlePostLike}
405 data-tippy-content={i18n.t("upvote")}
406 aria-label={i18n.t("upvote")}
408 <Icon icon="arrow-up1" classes="upvote" />
412 className={`unselectable pointer font-weight-bold text-muted px-1`}
413 data-tippy-content={this.pointsTippy}
415 {numToSI(this.state.score)}
418 <div className="p-1"></div>
420 {this.props.enableDownvotes && (
422 className={`btn-animate btn btn-link p-0 ${
423 this.state.my_vote == -1 ? "text-danger" : "text-muted"
425 onClick={this.handlePostDisLike}
426 data-tippy-content={i18n.t("downvote")}
427 aria-label={i18n.t("downvote")}
429 <Icon icon="arrow-down1" classes="downvote" />
437 let post = this.props.post_view.post;
440 className={`d-inline-block ${
441 !post.featured_community && !post.featured_local
445 to={`/post/${post.id}`}
446 title={i18n.t("comments")}
449 className="d-inline-block"
450 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
457 let post = this.props.post_view.post;
461 <div className="post-title overflow-hidden">
464 this.props.showBody ? (
466 className={`d-inline-block ${
467 !post.featured_community && !post.featured_local
476 className="d-inline-block"
477 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
486 {(url && isImage(url)) ||
487 (post.thumbnail_url && (
489 className="btn btn-link text-monospace text-muted small d-inline-block"
490 data-tippy-content={i18n.t("expand_here")}
491 onClick={linkEvent(this, this.handleImageExpandClick)}
495 !this.state.imageExpanded ? "plus-square" : "minus-square"
497 classes="icon-inline"
502 <small className="ml-2 text-muted font-italic">
508 className="unselectable pointer ml-2 text-muted font-italic"
509 data-tippy-content={i18n.t("deleted")}
511 <Icon icon="trash" classes="icon-inline text-danger" />
516 className="unselectable pointer ml-2 text-muted font-italic"
517 data-tippy-content={i18n.t("locked")}
519 <Icon icon="lock" classes="icon-inline text-danger" />
522 {post.featured_community && (
524 className="unselectable pointer ml-2 text-muted font-italic"
525 data-tippy-content={i18n.t("featured")}
527 <Icon icon="pin" classes="icon-inline text-primary" />
530 {post.featured_local && (
532 className="unselectable pointer ml-2 text-muted font-italic"
533 data-tippy-content={i18n.t("featured")}
535 <Icon icon="pin" classes="icon-inline text-secondary" />
539 <small className="ml-2 text-muted font-italic">
549 let dupes = this.props.duplicates;
550 return dupes && dupes.length > 0 ? (
551 <ul className="list-inline mb-1 small text-muted">
553 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
555 <li key={pv.post.id} className="list-inline-item mr-2">
556 <Link to={`/post/${pv.post.id}`}>
559 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
570 commentsLine(mobile = false) {
571 let post = this.props.post_view.post;
574 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
575 {this.commentsButton}
578 className="btn btn-link"
579 onClick={linkEvent(this, this.handleShare)}
582 <Icon icon="share" inline />
587 className="btn btn-link btn-animate text-muted py-0"
588 title={i18n.t("link")}
591 <Icon icon="fedilink" inline />
594 {mobile && !this.props.viewOnly && this.mobileVotes}
595 {UserService.Instance.myUserInfo &&
596 !this.props.viewOnly &&
597 this.postActions(mobile)}
602 postActions(mobile = false) {
603 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
604 // Possible enhancement: Make each button a component.
605 let post_view = this.props.post_view;
609 {this.crossPostButton}
610 {mobile && this.showMoreButton}
611 {(!mobile || this.state.showAdvanced) && (
619 {this.myPost && (this.showBody || this.state.showAdvanced) && (
627 {this.state.showAdvanced && (
629 {this.showBody && post_view.post.body && this.viewSourceButton}
630 {/* Any mod can do these, not limited to hierarchy*/}
631 {(amMod(this.props.moderators) || amAdmin()) && (
637 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
640 {!mobile && this.showMoreButton}
645 get commentsButton() {
646 let post_view = this.props.post_view;
648 <button className="btn btn-link text-muted py-0 pl-0">
650 className="text-muted"
651 title={i18n.t("number_of_comments", {
652 count: Number(post_view.counts.comments),
653 formattedCount: Number(post_view.counts.comments),
655 to={`/post/${post_view.post.id}?scrollToComments=true`}
657 <Icon icon="message-square" classes="mr-1" inline />
658 <span className="mr-2">
659 {i18n.t("number_of_comments", {
660 count: Number(post_view.counts.comments),
661 formattedCount: numToSI(post_view.counts.comments),
664 {this.unreadCount && (
665 <span className="small text-warning">
666 ({this.unreadCount} {i18n.t("new")})
674 get unreadCount(): number | undefined {
675 let pv = this.props.post_view;
676 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
678 : pv.unread_comments;
683 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
688 className={`btn-animate btn py-0 px-1 ${
689 this.state.my_vote == 1 ? "text-info" : "text-muted"
692 onClick={this.handlePostLike}
693 aria-label={i18n.t("upvote")}
695 <Icon icon="arrow-up1" classes="icon-inline small" />
697 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
700 {this.props.enableDownvotes && (
702 className={`ml-2 btn-animate btn py-0 px-1 ${
703 this.state.my_vote == -1 ? "text-danger" : "text-muted"
705 onClick={this.handlePostDisLike}
707 aria-label={i18n.t("downvote")}
709 <Icon icon="arrow-down1" classes="icon-inline small" />
712 className={classNames("ml-2", {
713 invisible: this.state.downvotes === 0,
716 {numToSI(this.state.downvotes)}
727 let saved = this.props.post_view.saved;
728 let label = saved ? i18n.t("unsave") : i18n.t("save");
731 className="btn btn-link btn-animate text-muted py-0"
732 onClick={linkEvent(this, this.handleSavePostClick)}
733 data-tippy-content={label}
738 classes={classNames({ "text-warning": saved })}
745 get crossPostButton() {
748 className="btn btn-link btn-animate text-muted py-0"
750 /* Empty string properties are required to satisfy type*/
751 pathname: "/create_post",
752 state: { ...this.crossPostParams },
757 title={i18n.t("cross_post")}
759 <Icon icon="copy" inline />
767 className="btn btn-link btn-animate text-muted py-0"
768 onClick={linkEvent(this, this.handleShowReportDialog)}
769 data-tippy-content={i18n.t("show_report_dialog")}
770 aria-label={i18n.t("show_report_dialog")}
772 <Icon icon="flag" inline />
780 className="btn btn-link btn-animate text-muted py-0"
781 onClick={linkEvent(this, this.handleBlockUserClick)}
782 data-tippy-content={i18n.t("block_user")}
783 aria-label={i18n.t("block_user")}
785 <Icon icon="slash" inline />
793 className="btn btn-link btn-animate text-muted py-0"
794 onClick={linkEvent(this, this.handleEditClick)}
795 data-tippy-content={i18n.t("edit")}
796 aria-label={i18n.t("edit")}
798 <Icon icon="edit" inline />
804 let deleted = this.props.post_view.post.deleted;
805 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
808 className="btn btn-link btn-animate text-muted py-0"
809 onClick={linkEvent(this, this.handleDeleteClick)}
810 data-tippy-content={label}
815 classes={classNames({ "text-danger": deleted })}
822 get showMoreButton() {
825 className="btn btn-link btn-animate text-muted py-0"
826 onClick={linkEvent(this, this.handleShowAdvanced)}
827 data-tippy-content={i18n.t("more")}
828 aria-label={i18n.t("more")}
830 <Icon icon="more-vertical" inline />
835 get viewSourceButton() {
838 className="btn btn-link btn-animate text-muted py-0"
839 onClick={linkEvent(this, this.handleViewSource)}
840 data-tippy-content={i18n.t("view_source")}
841 aria-label={i18n.t("view_source")}
845 classes={classNames({ "text-success": this.state.viewSource })}
853 let locked = this.props.post_view.post.locked;
854 let label = locked ? i18n.t("unlock") : i18n.t("lock");
857 className="btn btn-link btn-animate text-muted py-0"
858 onClick={linkEvent(this, this.handleModLock)}
859 data-tippy-content={label}
864 classes={classNames({ "text-danger": locked })}
871 get featureButton() {
872 const featuredCommunity = this.props.post_view.post.featured_community;
873 const labelCommunity = featuredCommunity
874 ? i18n.t("unfeature_from_community")
875 : i18n.t("feature_in_community");
877 const featuredLocal = this.props.post_view.post.featured_local;
878 const labelLocal = featuredLocal
879 ? i18n.t("unfeature_from_local")
880 : i18n.t("feature_in_local");
884 className="btn btn-link btn-animate text-muted py-0 pl-0"
885 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
886 data-tippy-content={labelCommunity}
887 aria-label={labelCommunity}
891 classes={classNames({ "text-success": featuredCommunity })}
898 className="btn btn-link btn-animate text-muted py-0"
899 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
900 data-tippy-content={labelLocal}
901 aria-label={labelLocal}
905 classes={classNames({ "text-success": featuredLocal })}
915 get modRemoveButton() {
916 let removed = this.props.post_view.post.removed;
919 className="btn btn-link btn-animate text-muted py-0"
922 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
925 {/* TODO: Find an icon for this. */}
926 {!removed ? i18n.t("remove") : i18n.t("restore")}
932 * Mod/Admin actions to be taken against the author.
936 let post_view = this.props.post_view;
938 this.state.showAdvanced && (
942 {!this.creatorIsMod_ &&
943 (!post_view.creator_banned_from_community ? (
945 className="btn btn-link btn-animate text-muted py-0"
948 this.handleModBanFromCommunityShow
950 aria-label={i18n.t("ban_from_community")}
952 {i18n.t("ban_from_community")}
956 className="btn btn-link btn-animate text-muted py-0"
959 this.handleModBanFromCommunitySubmit
961 aria-label={i18n.t("unban")}
966 {!post_view.creator_banned_from_community && (
968 className="btn btn-link btn-animate text-muted py-0"
969 onClick={linkEvent(this, this.handleAddModToCommunity)}
972 ? i18n.t("remove_as_mod")
973 : i18n.t("appoint_as_mod")
977 ? i18n.t("remove_as_mod")
978 : i18n.t("appoint_as_mod")}
983 {/* Community creators and admins can transfer community to another mod */}
984 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
986 this.creatorIsMod_ &&
987 (!this.state.showConfirmTransferCommunity ? (
989 className="btn btn-link btn-animate text-muted py-0"
992 this.handleShowConfirmTransferCommunity
994 aria-label={i18n.t("transfer_community")}
996 {i18n.t("transfer_community")}
1001 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1002 aria-label={i18n.t("are_you_sure")}
1004 {i18n.t("are_you_sure")}
1007 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1008 aria-label={i18n.t("yes")}
1009 onClick={linkEvent(this, this.handleTransferCommunity)}
1014 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1017 this.handleCancelShowConfirmTransferCommunity
1019 aria-label={i18n.t("no")}
1025 {/* Admins can ban from all, and appoint other admins */}
1026 {this.canAdmin_ && (
1028 {!this.creatorIsAdmin_ && (
1030 {!isBanned(post_view.creator) ? (
1032 className="btn btn-link btn-animate text-muted py-0"
1033 onClick={linkEvent(this, this.handleModBanShow)}
1034 aria-label={i18n.t("ban_from_site")}
1036 {i18n.t("ban_from_site")}
1040 className="btn btn-link btn-animate text-muted py-0"
1041 onClick={linkEvent(this, this.handleModBanSubmit)}
1042 aria-label={i18n.t("unban_from_site")}
1044 {i18n.t("unban_from_site")}
1048 className="btn btn-link btn-animate text-muted py-0"
1049 onClick={linkEvent(this, this.handlePurgePersonShow)}
1050 aria-label={i18n.t("purge_user")}
1052 {i18n.t("purge_user")}
1055 className="btn btn-link btn-animate text-muted py-0"
1056 onClick={linkEvent(this, this.handlePurgePostShow)}
1057 aria-label={i18n.t("purge_post")}
1059 {i18n.t("purge_post")}
1063 {!isBanned(post_view.creator) && post_view.creator.local && (
1065 className="btn btn-link btn-animate text-muted py-0"
1066 onClick={linkEvent(this, this.handleAddAdmin)}
1068 this.creatorIsAdmin_
1069 ? i18n.t("remove_as_admin")
1070 : i18n.t("appoint_as_admin")
1073 {this.creatorIsAdmin_
1074 ? i18n.t("remove_as_admin")
1075 : i18n.t("appoint_as_admin")}
1085 removeAndBanDialogs() {
1086 let post = this.props.post_view;
1088 this.state.purgeType == PurgeType.Post
1089 ? i18n.t("purge_post")
1090 : `${i18n.t("purge")} ${post.creator.name}`;
1093 {this.state.showRemoveDialog && (
1095 className="form-inline"
1096 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1098 <label className="sr-only" htmlFor="post-listing-remove-reason">
1103 id="post-listing-remove-reason"
1104 className="form-control mr-2"
1105 placeholder={i18n.t("reason")}
1106 value={this.state.removeReason}
1107 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1111 className="btn btn-secondary"
1112 aria-label={i18n.t("remove_post")}
1114 {i18n.t("remove_post")}
1118 {this.state.showBanDialog && (
1119 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1120 <div className="form-group row col-12">
1122 className="col-form-label"
1123 htmlFor="post-listing-ban-reason"
1129 id="post-listing-ban-reason"
1130 className="form-control mr-2"
1131 placeholder={i18n.t("reason")}
1132 value={this.state.banReason}
1133 onInput={linkEvent(this, this.handleModBanReasonChange)}
1135 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1140 id={`mod-ban-expires`}
1141 className="form-control mr-2"
1142 placeholder={i18n.t("number_of_days")}
1143 value={this.state.banExpireDays}
1144 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1146 <div className="form-group">
1147 <div className="form-check">
1149 className="form-check-input"
1150 id="mod-ban-remove-data"
1152 checked={this.state.removeData}
1153 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1156 className="form-check-label"
1157 htmlFor="mod-ban-remove-data"
1158 title={i18n.t("remove_content_more")}
1160 {i18n.t("remove_content")}
1165 {/* TODO hold off on expires until later */}
1166 {/* <div class="form-group row"> */}
1167 {/* <label class="col-form-label">Expires</label> */}
1168 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1170 <div className="form-group row">
1173 className="btn btn-secondary"
1174 aria-label={i18n.t("ban")}
1176 {i18n.t("ban")} {post.creator.name}
1181 {this.state.showReportDialog && (
1183 className="form-inline"
1184 onSubmit={linkEvent(this, this.handleReportSubmit)}
1186 <label className="sr-only" htmlFor="post-report-reason">
1191 id="post-report-reason"
1192 className="form-control mr-2"
1193 placeholder={i18n.t("reason")}
1195 value={this.state.reportReason}
1196 onInput={linkEvent(this, this.handleReportReasonChange)}
1200 className="btn btn-secondary"
1201 aria-label={i18n.t("create_report")}
1203 {i18n.t("create_report")}
1207 {this.state.showPurgeDialog && (
1209 className="form-inline"
1210 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1213 <label className="sr-only" htmlFor="purge-reason">
1219 className="form-control mr-2"
1220 placeholder={i18n.t("reason")}
1221 value={this.state.purgeReason}
1222 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1224 {this.state.purgeLoading ? (
1229 className="btn btn-secondary"
1230 aria-label={purgeTypeText}
1242 let post = this.props.post_view.post;
1243 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1244 <div className="row">
1245 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1246 {this.postTitleLine()}
1248 <div className="col-4">
1249 {/* Post body prev or thumbnail */}
1250 {!this.state.imageExpanded && this.thumbnail()}
1254 this.postTitleLine()
1258 showMobilePreview() {
1259 let body = this.props.post_view.post.body;
1260 return !this.showBody && body ? (
1261 <div className="md-div mb-1 preview-lines">{body}</div>
1270 {/* The mobile view*/}
1271 <div className="d-block d-sm-none">
1272 <div className="row">
1273 <div className="col-12">
1274 {this.createdLine()}
1276 {/* If it has a thumbnail, do a right aligned thumbnail */}
1277 {this.mobileThumbnail()}
1279 {/* Show a preview of the post body */}
1280 {this.showMobilePreview()}
1282 {this.commentsLine(true)}
1283 {this.userActionsLine()}
1284 {this.duplicatesLine()}
1285 {this.removeAndBanDialogs()}
1290 {/* The larger view*/}
1291 <div className="d-none d-sm-block">
1292 <div className="row">
1293 {!this.props.viewOnly && this.voteBar()}
1294 <div className="col-sm-2 pr-0">
1295 <div className="">{this.thumbnail()}</div>
1297 <div className="col-12 col-sm-9">
1298 <div className="row">
1299 <div className="col-12">
1300 {this.postTitleLine()}
1301 {this.createdLine()}
1302 {this.commentsLine()}
1303 {this.duplicatesLine()}
1304 {this.userActionsLine()}
1305 {this.removeAndBanDialogs()}
1315 private get myPost(): boolean {
1317 this.props.post_view.creator.id ==
1318 UserService.Instance.myUserInfo?.local_user_view.person.id
1322 handlePostLike(event: any) {
1323 event.preventDefault();
1324 if (!UserService.Instance.myUserInfo) {
1325 this.context.router.history.push(`/login`);
1328 let myVote = this.state.my_vote;
1329 let newVote = myVote == 1 ? 0 : 1;
1333 score: this.state.score - 1,
1334 upvotes: this.state.upvotes - 1,
1336 } else if (myVote == -1) {
1338 score: this.state.score + 2,
1339 upvotes: this.state.upvotes + 1,
1340 downvotes: this.state.downvotes - 1,
1344 score: this.state.score + 1,
1345 upvotes: this.state.upvotes + 1,
1349 this.setState({ my_vote: newVote });
1351 let auth = myAuth();
1353 let form: CreatePostLike = {
1354 post_id: this.props.post_view.post.id,
1359 WebSocketService.Instance.send(wsClient.likePost(form));
1360 this.setState(this.state);
1365 handlePostDisLike(event: any) {
1366 event.preventDefault();
1367 if (!UserService.Instance.myUserInfo) {
1368 this.context.router.history.push(`/login`);
1371 let myVote = this.state.my_vote;
1372 let newVote = myVote == -1 ? 0 : -1;
1376 score: this.state.score - 2,
1377 upvotes: this.state.upvotes - 1,
1378 downvotes: this.state.downvotes + 1,
1380 } else if (myVote == -1) {
1382 score: this.state.score + 1,
1383 downvotes: this.state.downvotes - 1,
1387 score: this.state.score - 1,
1388 downvotes: this.state.downvotes + 1,
1392 this.setState({ my_vote: newVote });
1394 let auth = myAuth();
1396 let form: CreatePostLike = {
1397 post_id: this.props.post_view.post.id,
1402 WebSocketService.Instance.send(wsClient.likePost(form));
1403 this.setState(this.state);
1408 handleEditClick(i: PostListing) {
1409 i.setState({ showEdit: true });
1412 handleEditCancel() {
1413 this.setState({ showEdit: false });
1416 // The actual editing is done in the recieve for post
1418 this.setState({ showEdit: false });
1421 handleShare(i: PostListing) {
1422 const { name, body, id } = i.props.post_view.post;
1425 text: body?.slice(0, 50),
1426 url: `${getHttpBase()}/post/${id}`,
1430 handleShowReportDialog(i: PostListing) {
1431 i.setState({ showReportDialog: !i.state.showReportDialog });
1434 handleReportReasonChange(i: PostListing, event: any) {
1435 i.setState({ reportReason: event.target.value });
1438 handleReportSubmit(i: PostListing, event: any) {
1439 event.preventDefault();
1440 let auth = myAuth();
1441 let reason = i.state.reportReason;
1442 if (auth && reason) {
1443 let form: CreatePostReport = {
1444 post_id: i.props.post_view.post.id,
1448 WebSocketService.Instance.send(wsClient.createPostReport(form));
1450 i.setState({ showReportDialog: false });
1454 handleBlockUserClick(i: PostListing) {
1455 let auth = myAuth();
1457 let blockUserForm: BlockPerson = {
1458 person_id: i.props.post_view.creator.id,
1462 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1466 handleDeleteClick(i: PostListing) {
1467 let auth = myAuth();
1469 let deleteForm: DeletePost = {
1470 post_id: i.props.post_view.post.id,
1471 deleted: !i.props.post_view.post.deleted,
1474 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1478 handleSavePostClick(i: PostListing) {
1479 let auth = myAuth();
1482 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1483 let form: SavePost = {
1484 post_id: i.props.post_view.post.id,
1488 WebSocketService.Instance.send(wsClient.savePost(form));
1492 get crossPostParams(): PostFormParams {
1493 const queryParams: PostFormParams = {};
1494 const { name, url } = this.props.post_view.post;
1496 queryParams.name = name;
1499 queryParams.url = url;
1502 const crossPostBody = this.crossPostBody();
1503 if (crossPostBody) {
1504 queryParams.body = crossPostBody;
1510 crossPostBody(): string | undefined {
1511 let post = this.props.post_view.post;
1512 let body = post.body;
1515 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1522 get showBody(): boolean {
1523 return this.props.showBody || this.state.showBody;
1526 handleModRemoveShow(i: PostListing) {
1528 showRemoveDialog: !i.state.showRemoveDialog,
1529 showBanDialog: false,
1533 handleModRemoveReasonChange(i: PostListing, event: any) {
1534 i.setState({ removeReason: event.target.value });
1537 handleModRemoveDataChange(i: PostListing, event: any) {
1538 i.setState({ removeData: event.target.checked });
1541 handleModRemoveSubmit(i: PostListing, event: any) {
1542 event.preventDefault();
1544 let auth = myAuth();
1546 let form: RemovePost = {
1547 post_id: i.props.post_view.post.id,
1548 removed: !i.props.post_view.post.removed,
1549 reason: i.state.removeReason,
1552 WebSocketService.Instance.send(wsClient.removePost(form));
1553 i.setState({ showRemoveDialog: false });
1557 handleModLock(i: PostListing) {
1558 let auth = myAuth();
1560 let form: LockPost = {
1561 post_id: i.props.post_view.post.id,
1562 locked: !i.props.post_view.post.locked,
1565 WebSocketService.Instance.send(wsClient.lockPost(form));
1569 handleModFeaturePostLocal(i: PostListing) {
1570 let auth = myAuth();
1572 let form: FeaturePost = {
1573 post_id: i.props.post_view.post.id,
1574 feature_type: "Local",
1575 featured: !i.props.post_view.post.featured_local,
1578 WebSocketService.Instance.send(wsClient.featurePost(form));
1582 handleModFeaturePostCommunity(i: PostListing) {
1583 let auth = myAuth();
1585 let form: FeaturePost = {
1586 post_id: i.props.post_view.post.id,
1587 feature_type: "Community",
1588 featured: !i.props.post_view.post.featured_community,
1591 WebSocketService.Instance.send(wsClient.featurePost(form));
1595 handleModBanFromCommunityShow(i: PostListing) {
1597 showBanDialog: true,
1598 banType: BanType.Community,
1599 showRemoveDialog: false,
1603 handleModBanShow(i: PostListing) {
1605 showBanDialog: true,
1606 banType: BanType.Site,
1607 showRemoveDialog: false,
1611 handlePurgePersonShow(i: PostListing) {
1613 showPurgeDialog: true,
1614 purgeType: PurgeType.Person,
1615 showRemoveDialog: false,
1619 handlePurgePostShow(i: PostListing) {
1621 showPurgeDialog: true,
1622 purgeType: PurgeType.Post,
1623 showRemoveDialog: false,
1627 handlePurgeReasonChange(i: PostListing, event: any) {
1628 i.setState({ purgeReason: event.target.value });
1631 handlePurgeSubmit(i: PostListing, event: any) {
1632 event.preventDefault();
1634 let auth = myAuth();
1636 if (i.state.purgeType == PurgeType.Person) {
1637 let form: PurgePerson = {
1638 person_id: i.props.post_view.creator.id,
1639 reason: i.state.purgeReason,
1642 WebSocketService.Instance.send(wsClient.purgePerson(form));
1643 } else if (i.state.purgeType == PurgeType.Post) {
1644 let form: PurgePost = {
1645 post_id: i.props.post_view.post.id,
1646 reason: i.state.purgeReason,
1649 WebSocketService.Instance.send(wsClient.purgePost(form));
1652 i.setState({ purgeLoading: true });
1656 handleModBanReasonChange(i: PostListing, event: any) {
1657 i.setState({ banReason: event.target.value });
1660 handleModBanExpireDaysChange(i: PostListing, event: any) {
1661 i.setState({ banExpireDays: event.target.value });
1664 handleModBanFromCommunitySubmit(i: PostListing) {
1665 i.setState({ banType: BanType.Community });
1666 i.handleModBanBothSubmit(i);
1669 handleModBanSubmit(i: PostListing) {
1670 i.setState({ banType: BanType.Site });
1671 i.handleModBanBothSubmit(i);
1674 handleModBanBothSubmit(i: PostListing, event?: any) {
1675 if (event) event.preventDefault();
1676 let auth = myAuth();
1678 let ban = !i.props.post_view.creator_banned_from_community;
1679 let person_id = i.props.post_view.creator.id;
1680 let remove_data = i.state.removeData;
1681 let reason = i.state.banReason;
1682 let expires = futureDaysToUnixTime(i.state.banExpireDays);
1684 if (i.state.banType == BanType.Community) {
1685 // If its an unban, restore all their data
1687 i.setState({ removeData: false });
1690 let form: BanFromCommunity = {
1692 community_id: i.props.post_view.community.id,
1699 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1701 // If its an unban, restore all their data
1702 let ban = !i.props.post_view.creator.banned;
1704 i.setState({ removeData: false });
1706 let form: BanPerson = {
1714 WebSocketService.Instance.send(wsClient.banPerson(form));
1717 i.setState({ showBanDialog: false });
1721 handleAddModToCommunity(i: PostListing) {
1722 let auth = myAuth();
1724 let form: AddModToCommunity = {
1725 person_id: i.props.post_view.creator.id,
1726 community_id: i.props.post_view.community.id,
1727 added: !i.creatorIsMod_,
1730 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1731 i.setState(i.state);
1735 handleAddAdmin(i: PostListing) {
1736 let auth = myAuth();
1738 let form: AddAdmin = {
1739 person_id: i.props.post_view.creator.id,
1740 added: !i.creatorIsAdmin_,
1743 WebSocketService.Instance.send(wsClient.addAdmin(form));
1744 i.setState(i.state);
1748 handleShowConfirmTransferCommunity(i: PostListing) {
1749 i.setState({ showConfirmTransferCommunity: true });
1752 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1753 i.setState({ showConfirmTransferCommunity: false });
1756 handleTransferCommunity(i: PostListing) {
1757 let auth = myAuth();
1759 let form: TransferCommunity = {
1760 community_id: i.props.post_view.community.id,
1761 person_id: i.props.post_view.creator.id,
1764 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1765 i.setState({ showConfirmTransferCommunity: false });
1769 handleShowConfirmTransferSite(i: PostListing) {
1770 i.setState({ showConfirmTransferSite: true });
1773 handleCancelShowConfirmTransferSite(i: PostListing) {
1774 i.setState({ showConfirmTransferSite: false });
1777 handleImageExpandClick(i: PostListing, event: any) {
1778 event.preventDefault();
1779 i.setState({ imageExpanded: !i.state.imageExpanded });
1783 handleViewSource(i: PostListing) {
1784 i.setState({ viewSource: !i.state.viewSource });
1787 handleShowAdvanced(i: PostListing) {
1788 i.setState({ showAdvanced: !i.state.showAdvanced });
1792 handleShowMoreMobile(i: PostListing) {
1794 showMoreMobile: !i.state.showMoreMobile,
1795 showAdvanced: !i.state.showAdvanced,
1800 handleShowBody(i: PostListing) {
1801 i.setState({ showBody: !i.state.showBody });
1805 get pointsTippy(): string {
1806 let points = i18n.t("number_of_points", {
1807 count: Number(this.state.score),
1808 formattedCount: Number(this.state.score),
1811 let upvotes = i18n.t("number_of_upvotes", {
1812 count: Number(this.state.upvotes),
1813 formattedCount: Number(this.state.upvotes),
1816 let downvotes = i18n.t("number_of_downvotes", {
1817 count: Number(this.state.downvotes),
1818 formattedCount: Number(this.state.downvotes),
1821 return `${points} • ${upvotes} • ${downvotes}`;
1824 get canModOnSelf_(): boolean {
1826 this.props.post_view.creator.id,
1827 this.props.moderators,
1834 get canMod_(): boolean {
1836 this.props.post_view.creator.id,
1837 this.props.moderators,
1842 get canAdmin_(): boolean {
1843 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1846 get creatorIsMod_(): boolean {
1847 return isMod(this.props.post_view.creator.id, this.props.moderators);
1850 get creatorIsAdmin_(): boolean {
1851 return isAdmin(this.props.post_view.creator.id, this.props.admins);