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 } from "../../env";
26 import { i18n } from "../../i18next";
27 import { BanType, PostFormParams, PurgeType } from "../../interfaces";
28 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?: PersonView[];
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 const post = this.props.post_view.post;
152 <div className="post-listing">
153 {!this.state.showEdit ? (
156 {this.state.imageExpanded && !this.props.hideImage && this.img}
157 {post.url && this.showBody && post.embed_title && (
158 <MetadataCard post={post} />
160 {this.showBody && this.body()}
163 <div className="col-12">
165 post_view={this.props.post_view}
166 onEdit={this.handleEditPost}
167 onCancel={this.handleEditCancel}
168 enableNsfw={this.props.enableNsfw}
169 enableDownvotes={this.props.enableDownvotes}
170 allLanguages={this.props.allLanguages}
171 siteLanguages={this.props.siteLanguages}
180 let body = this.props.post_view.post.body;
182 <div className="col-12 card my-2 p-2">
183 {this.state.viewSource ? (
186 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
195 let src = this.imageSrc;
198 <div className="offset-sm-3 my-2 d-none d-sm-block">
199 <a href={src} className="d-inline-block">
200 <PictrsImage src={src} />
203 <div className="my-2 d-block d-sm-none">
205 className="d-inline-block"
206 onClick={linkEvent(this, this.handleImageExpandClick)}
208 <PictrsImage src={src} />
217 imgThumb(src: string) {
218 let post_view = this.props.post_view;
224 nsfw={post_view.post.nsfw || post_view.community.nsfw}
229 get imageSrc(): string | undefined {
230 let post = this.props.post_view.post;
232 let thumbnail = post.thumbnail_url;
234 if (url && isImage(url)) {
235 if (url.includes("pictrs")) {
237 } else if (thumbnail) {
242 } else if (thumbnail) {
250 let post = this.props.post_view.post;
252 let thumbnail = post.thumbnail_url;
254 if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
258 className="text-body d-inline-block position-relative mb-2"
259 data-tippy-content={i18n.t("expand_here")}
260 onClick={linkEvent(this, this.handleImageExpandClick)}
261 aria-label={i18n.t("expand_here")}
263 {this.imgThumb(this.imageSrc)}
264 <Icon icon="image" classes="mini-overlay" />
267 } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
270 className="text-body d-inline-block position-relative mb-2"
275 {this.imgThumb(this.imageSrc)}
276 <Icon icon="external-link" classes="mini-overlay" />
280 if (!this.props.hideImage && isVideo(url)) {
282 <div className="embed-responsive embed-responsive-16by9">
288 className="embed-responsive-item"
290 <source src={url} type="video/mp4" />
296 <a className="text-body" href={url} title={url} rel={relTags}>
297 <div className="thumbnail rounded bg-light d-flex justify-content-center">
298 <Icon icon="external-link" classes="d-flex align-items-center" />
306 className="text-body"
307 to={`/post/${post.id}`}
308 title={i18n.t("comments")}
310 <div className="thumbnail rounded bg-light d-flex justify-content-center">
311 <Icon icon="message-square" classes="d-flex align-items-center" />
319 let post_view = this.props.post_view;
320 let url = post_view.post.url;
321 let body = post_view.post.body;
323 <ul className="list-inline mb-1 text-muted small">
324 <li className="list-inline-item">
325 <PersonListing person={post_view.creator} />
327 {this.creatorIsMod_ && (
328 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
330 {this.creatorIsAdmin_ && (
331 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
333 {post_view.creator.bot_account && (
334 <span className="mx-1 badge badge-light">
335 {i18n.t("bot_account").toLowerCase()}
338 {this.props.showCommunity && (
340 <span className="mx-1"> {i18n.t("to")} </span>
341 <CommunityLink community={post_view.community} />
345 <li className="list-inline-item">•</li>
346 {url && !(hostname(url) === getExternalHost()) && (
348 <li className="list-inline-item">
350 className="text-muted font-italic"
358 <li className="list-inline-item">•</li>
361 <li className="list-inline-item">
364 published={post_view.post.published}
365 updated={post_view.post.updated}
371 <li className="list-inline-item">•</li>
372 <li className="list-inline-item">
374 className="text-muted btn btn-sm btn-link p-0"
375 data-tippy-content={mdNoImages.render(body)}
376 data-tippy-allowHtml={true}
377 onClick={linkEvent(this, this.handleShowBody)}
379 <Icon icon="book-open" classes="icon-inline mr-1" />
390 <div className={`vote-bar col-1 pr-0 small text-center`}>
392 className={`btn-animate btn btn-link p-0 ${
393 this.state.my_vote == 1 ? "text-info" : "text-muted"
395 onClick={this.handlePostLike}
396 data-tippy-content={i18n.t("upvote")}
397 aria-label={i18n.t("upvote")}
399 <Icon icon="arrow-up1" classes="upvote" />
403 className={`unselectable pointer font-weight-bold text-muted px-1`}
404 data-tippy-content={this.pointsTippy}
406 {numToSI(this.state.score)}
409 <div className="p-1"></div>
411 {this.props.enableDownvotes && (
413 className={`btn-animate btn btn-link p-0 ${
414 this.state.my_vote == -1 ? "text-danger" : "text-muted"
416 onClick={this.handlePostDisLike}
417 data-tippy-content={i18n.t("downvote")}
418 aria-label={i18n.t("downvote")}
420 <Icon icon="arrow-down1" classes="downvote" />
428 let post = this.props.post_view.post;
431 className={`d-inline-block ${
432 !post.featured_community && !post.featured_local
436 to={`/post/${post.id}`}
437 title={i18n.t("comments")}
440 className="d-inline-block"
441 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
448 let post = this.props.post_view.post;
452 <div className="post-title overflow-hidden">
455 this.props.showBody ? (
457 className={`d-inline-block ${
458 !post.featured_community && !post.featured_local
467 className="d-inline-block"
468 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"
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 {/* Any mod can do these, not limited to hierarchy*/}
612 {(amMod(this.props.moderators) || amAdmin()) && (
618 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
621 {!mobile && this.showMoreButton}
626 get commentsButton() {
627 let post_view = this.props.post_view;
629 <button className="btn btn-link text-muted py-0 pl-0">
631 className="text-muted"
632 title={i18n.t("number_of_comments", {
633 count: Number(post_view.counts.comments),
634 formattedCount: Number(post_view.counts.comments),
636 to={`/post/${post_view.post.id}?scrollToComments=true`}
638 <Icon icon="message-square" classes="mr-1" inline />
639 <span className="mr-2">
640 {i18n.t("number_of_comments", {
641 count: Number(post_view.counts.comments),
642 formattedCount: numToSI(post_view.counts.comments),
645 {this.unreadCount && (
646 <span className="small text-warning">
647 ({this.unreadCount} {i18n.t("new")})
655 get unreadCount(): bigint | undefined {
656 let pv = this.props.post_view;
657 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0n
659 : pv.unread_comments;
664 let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
669 className={`btn-animate btn py-0 px-1 ${
670 this.state.my_vote == 1 ? "text-info" : "text-muted"
673 onClick={this.handlePostLike}
674 aria-label={i18n.t("upvote")}
676 <Icon icon="arrow-up1" classes="icon-inline small" />
678 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
681 {this.props.enableDownvotes && (
683 className={`ml-2 btn-animate btn py-0 px-1 ${
684 this.state.my_vote == -1 ? "text-danger" : "text-muted"
686 onClick={this.handlePostDisLike}
688 aria-label={i18n.t("downvote")}
690 <Icon icon="arrow-down1" classes="icon-inline small" />
693 className={classNames("ml-2", {
694 invisible: this.state.downvotes === 0n,
697 {numToSI(this.state.downvotes)}
708 let saved = this.props.post_view.saved;
709 let label = saved ? i18n.t("unsave") : i18n.t("save");
712 className="btn btn-link btn-animate text-muted py-0"
713 onClick={linkEvent(this, this.handleSavePostClick)}
714 data-tippy-content={label}
719 classes={classNames({ "text-warning": saved })}
726 get crossPostButton() {
729 className="btn btn-link btn-animate text-muted py-0"
731 /* Empty string properties are required to satisfy type*/
732 pathname: "/create_post",
733 state: { ...this.crossPostParams },
738 title={i18n.t("cross_post")}
740 <Icon icon="copy" inline />
748 className="btn btn-link btn-animate text-muted py-0"
749 onClick={linkEvent(this, this.handleShowReportDialog)}
750 data-tippy-content={i18n.t("show_report_dialog")}
751 aria-label={i18n.t("show_report_dialog")}
753 <Icon icon="flag" inline />
761 className="btn btn-link btn-animate text-muted py-0"
762 onClick={linkEvent(this, this.handleBlockUserClick)}
763 data-tippy-content={i18n.t("block_user")}
764 aria-label={i18n.t("block_user")}
766 <Icon icon="slash" inline />
774 className="btn btn-link btn-animate text-muted py-0"
775 onClick={linkEvent(this, this.handleEditClick)}
776 data-tippy-content={i18n.t("edit")}
777 aria-label={i18n.t("edit")}
779 <Icon icon="edit" inline />
785 let deleted = this.props.post_view.post.deleted;
786 let label = !deleted ? i18n.t("delete") : i18n.t("restore");
789 className="btn btn-link btn-animate text-muted py-0"
790 onClick={linkEvent(this, this.handleDeleteClick)}
791 data-tippy-content={label}
796 classes={classNames({ "text-danger": deleted })}
803 get showMoreButton() {
806 className="btn btn-link btn-animate text-muted py-0"
807 onClick={linkEvent(this, this.handleShowAdvanced)}
808 data-tippy-content={i18n.t("more")}
809 aria-label={i18n.t("more")}
811 <Icon icon="more-vertical" inline />
816 get viewSourceButton() {
819 className="btn btn-link btn-animate text-muted py-0"
820 onClick={linkEvent(this, this.handleViewSource)}
821 data-tippy-content={i18n.t("view_source")}
822 aria-label={i18n.t("view_source")}
826 classes={classNames({ "text-success": this.state.viewSource })}
834 let locked = this.props.post_view.post.locked;
835 let label = locked ? i18n.t("unlock") : i18n.t("lock");
838 className="btn btn-link btn-animate text-muted py-0"
839 onClick={linkEvent(this, this.handleModLock)}
840 data-tippy-content={label}
845 classes={classNames({ "text-danger": locked })}
852 get featureButton() {
853 const featuredCommunity = this.props.post_view.post.featured_community;
854 const labelCommunity = featuredCommunity
855 ? i18n.t("unfeature_from_community")
856 : i18n.t("feature_in_community");
858 const featuredLocal = this.props.post_view.post.featured_local;
859 const labelLocal = featuredLocal
860 ? i18n.t("unfeature_from_local")
861 : i18n.t("feature_in_local");
865 className="btn btn-link btn-animate text-muted py-0 pl-0"
866 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
867 data-tippy-content={labelCommunity}
868 aria-label={labelCommunity}
872 classes={classNames({ "text-success": featuredCommunity })}
879 className="btn btn-link btn-animate text-muted py-0"
880 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
881 data-tippy-content={labelLocal}
882 aria-label={labelLocal}
886 classes={classNames({ "text-success": featuredLocal })}
896 get modRemoveButton() {
897 let removed = this.props.post_view.post.removed;
900 className="btn btn-link btn-animate text-muted py-0"
903 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
906 {/* TODO: Find an icon for this. */}
907 {!removed ? i18n.t("remove") : i18n.t("restore")}
913 * Mod/Admin actions to be taken against the author.
917 let post_view = this.props.post_view;
919 this.state.showAdvanced && (
923 {!this.creatorIsMod_ &&
924 (!post_view.creator_banned_from_community ? (
926 className="btn btn-link btn-animate text-muted py-0"
929 this.handleModBanFromCommunityShow
931 aria-label={i18n.t("ban_from_community")}
933 {i18n.t("ban_from_community")}
937 className="btn btn-link btn-animate text-muted py-0"
940 this.handleModBanFromCommunitySubmit
942 aria-label={i18n.t("unban")}
947 {!post_view.creator_banned_from_community && (
949 className="btn btn-link btn-animate text-muted py-0"
950 onClick={linkEvent(this, this.handleAddModToCommunity)}
953 ? i18n.t("remove_as_mod")
954 : i18n.t("appoint_as_mod")
958 ? i18n.t("remove_as_mod")
959 : i18n.t("appoint_as_mod")}
964 {/* Community creators and admins can transfer community to another mod */}
965 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
967 this.creatorIsMod_ &&
968 (!this.state.showConfirmTransferCommunity ? (
970 className="btn btn-link btn-animate text-muted py-0"
973 this.handleShowConfirmTransferCommunity
975 aria-label={i18n.t("transfer_community")}
977 {i18n.t("transfer_community")}
982 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
983 aria-label={i18n.t("are_you_sure")}
985 {i18n.t("are_you_sure")}
988 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
989 aria-label={i18n.t("yes")}
990 onClick={linkEvent(this, this.handleTransferCommunity)}
995 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
998 this.handleCancelShowConfirmTransferCommunity
1000 aria-label={i18n.t("no")}
1006 {/* Admins can ban from all, and appoint other admins */}
1007 {this.canAdmin_ && (
1009 {!this.creatorIsAdmin_ && (
1011 {!isBanned(post_view.creator) ? (
1013 className="btn btn-link btn-animate text-muted py-0"
1014 onClick={linkEvent(this, this.handleModBanShow)}
1015 aria-label={i18n.t("ban_from_site")}
1017 {i18n.t("ban_from_site")}
1021 className="btn btn-link btn-animate text-muted py-0"
1022 onClick={linkEvent(this, this.handleModBanSubmit)}
1023 aria-label={i18n.t("unban_from_site")}
1025 {i18n.t("unban_from_site")}
1029 className="btn btn-link btn-animate text-muted py-0"
1030 onClick={linkEvent(this, this.handlePurgePersonShow)}
1031 aria-label={i18n.t("purge_user")}
1033 {i18n.t("purge_user")}
1036 className="btn btn-link btn-animate text-muted py-0"
1037 onClick={linkEvent(this, this.handlePurgePostShow)}
1038 aria-label={i18n.t("purge_post")}
1040 {i18n.t("purge_post")}
1044 {!isBanned(post_view.creator) && post_view.creator.local && (
1046 className="btn btn-link btn-animate text-muted py-0"
1047 onClick={linkEvent(this, this.handleAddAdmin)}
1049 this.creatorIsAdmin_
1050 ? i18n.t("remove_as_admin")
1051 : i18n.t("appoint_as_admin")
1054 {this.creatorIsAdmin_
1055 ? i18n.t("remove_as_admin")
1056 : i18n.t("appoint_as_admin")}
1066 removeAndBanDialogs() {
1067 let post = this.props.post_view;
1069 this.state.purgeType == PurgeType.Post
1070 ? i18n.t("purge_post")
1071 : `${i18n.t("purge")} ${post.creator.name}`;
1074 {this.state.showRemoveDialog && (
1076 className="form-inline"
1077 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1079 <label className="sr-only" htmlFor="post-listing-remove-reason">
1084 id="post-listing-remove-reason"
1085 className="form-control mr-2"
1086 placeholder={i18n.t("reason")}
1087 value={this.state.removeReason}
1088 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1092 className="btn btn-secondary"
1093 aria-label={i18n.t("remove_post")}
1095 {i18n.t("remove_post")}
1099 {this.state.showBanDialog && (
1100 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1101 <div className="form-group row col-12">
1103 className="col-form-label"
1104 htmlFor="post-listing-ban-reason"
1110 id="post-listing-ban-reason"
1111 className="form-control mr-2"
1112 placeholder={i18n.t("reason")}
1113 value={this.state.banReason}
1114 onInput={linkEvent(this, this.handleModBanReasonChange)}
1116 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1121 id={`mod-ban-expires`}
1122 className="form-control mr-2"
1123 placeholder={i18n.t("number_of_days")}
1124 value={this.state.banExpireDays}
1125 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1127 <div className="form-group">
1128 <div className="form-check">
1130 className="form-check-input"
1131 id="mod-ban-remove-data"
1133 checked={this.state.removeData}
1134 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1137 className="form-check-label"
1138 htmlFor="mod-ban-remove-data"
1139 title={i18n.t("remove_content_more")}
1141 {i18n.t("remove_content")}
1146 {/* TODO hold off on expires until later */}
1147 {/* <div class="form-group row"> */}
1148 {/* <label class="col-form-label">Expires</label> */}
1149 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1151 <div className="form-group row">
1154 className="btn btn-secondary"
1155 aria-label={i18n.t("ban")}
1157 {i18n.t("ban")} {post.creator.name}
1162 {this.state.showReportDialog && (
1164 className="form-inline"
1165 onSubmit={linkEvent(this, this.handleReportSubmit)}
1167 <label className="sr-only" htmlFor="post-report-reason">
1172 id="post-report-reason"
1173 className="form-control mr-2"
1174 placeholder={i18n.t("reason")}
1176 value={this.state.reportReason}
1177 onInput={linkEvent(this, this.handleReportReasonChange)}
1181 className="btn btn-secondary"
1182 aria-label={i18n.t("create_report")}
1184 {i18n.t("create_report")}
1188 {this.state.showPurgeDialog && (
1190 className="form-inline"
1191 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1194 <label className="sr-only" htmlFor="purge-reason">
1200 className="form-control mr-2"
1201 placeholder={i18n.t("reason")}
1202 value={this.state.purgeReason}
1203 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1205 {this.state.purgeLoading ? (
1210 className="btn btn-secondary"
1211 aria-label={purgeTypeText}
1223 let post = this.props.post_view.post;
1224 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1225 <div className="row">
1226 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1227 {this.postTitleLine()}
1229 <div className="col-4">
1230 {/* Post body prev or thumbnail */}
1231 {!this.state.imageExpanded && this.thumbnail()}
1235 this.postTitleLine()
1239 showMobilePreview() {
1240 let body = this.props.post_view.post.body;
1241 return !this.showBody && body ? (
1242 <div className="md-div mb-1 preview-lines">{body}</div>
1251 {/* The mobile view*/}
1252 <div className="d-block d-sm-none">
1253 <div className="row">
1254 <div className="col-12">
1255 {this.createdLine()}
1257 {/* If it has a thumbnail, do a right aligned thumbnail */}
1258 {this.mobileThumbnail()}
1260 {/* Show a preview of the post body */}
1261 {this.showMobilePreview()}
1263 {this.commentsLine(true)}
1264 {this.userActionsLine()}
1265 {this.duplicatesLine()}
1266 {this.removeAndBanDialogs()}
1271 {/* The larger view*/}
1272 <div className="d-none d-sm-block">
1273 <div className="row">
1274 {!this.props.viewOnly && this.voteBar()}
1275 <div className="col-sm-2 pr-0">
1276 <div className="">{this.thumbnail()}</div>
1278 <div className="col-12 col-sm-9">
1279 <div className="row">
1280 <div className="col-12">
1281 {this.postTitleLine()}
1282 {this.createdLine()}
1283 {this.commentsLine()}
1284 {this.duplicatesLine()}
1285 {this.userActionsLine()}
1286 {this.removeAndBanDialogs()}
1296 private get myPost(): boolean {
1298 this.props.post_view.creator.id ==
1299 UserService.Instance.myUserInfo?.local_user_view.person.id
1303 handlePostLike(event: any) {
1304 event.preventDefault();
1305 if (!UserService.Instance.myUserInfo) {
1306 this.context.router.history.push(`/login`);
1309 let myVote = this.state.my_vote;
1310 let newVote = myVote == 1 ? 0 : 1;
1314 score: this.state.score - 1n,
1315 upvotes: this.state.upvotes - 1n,
1317 } else if (myVote == -1) {
1319 score: this.state.score + 2n,
1320 upvotes: this.state.upvotes + 1n,
1321 downvotes: this.state.downvotes - 1n,
1325 score: this.state.score + 1n,
1326 upvotes: this.state.upvotes + 1n,
1330 this.setState({ my_vote: newVote });
1332 let auth = myAuth();
1334 let form: CreatePostLike = {
1335 post_id: this.props.post_view.post.id,
1340 WebSocketService.Instance.send(wsClient.likePost(form));
1341 this.setState(this.state);
1346 handlePostDisLike(event: any) {
1347 event.preventDefault();
1348 if (!UserService.Instance.myUserInfo) {
1349 this.context.router.history.push(`/login`);
1352 let myVote = this.state.my_vote;
1353 let newVote = myVote == -1 ? 0 : -1;
1357 score: this.state.score - 2n,
1358 upvotes: this.state.upvotes - 1n,
1359 downvotes: this.state.downvotes + 1n,
1361 } else if (myVote == -1) {
1363 score: this.state.score + 1n,
1364 downvotes: this.state.downvotes - 1n,
1368 score: this.state.score - 1n,
1369 downvotes: this.state.downvotes + 1n,
1373 this.setState({ my_vote: newVote });
1375 let auth = myAuth();
1377 let form: CreatePostLike = {
1378 post_id: this.props.post_view.post.id,
1383 WebSocketService.Instance.send(wsClient.likePost(form));
1384 this.setState(this.state);
1389 handleEditClick(i: PostListing) {
1390 i.setState({ showEdit: true });
1393 handleEditCancel() {
1394 this.setState({ showEdit: false });
1397 // The actual editing is done in the recieve for post
1399 this.setState({ showEdit: false });
1402 handleShowReportDialog(i: PostListing) {
1403 i.setState({ showReportDialog: !i.state.showReportDialog });
1406 handleReportReasonChange(i: PostListing, event: any) {
1407 i.setState({ reportReason: event.target.value });
1410 handleReportSubmit(i: PostListing, event: any) {
1411 event.preventDefault();
1412 let auth = myAuth();
1413 let reason = i.state.reportReason;
1414 if (auth && reason) {
1415 let form: CreatePostReport = {
1416 post_id: i.props.post_view.post.id,
1420 WebSocketService.Instance.send(wsClient.createPostReport(form));
1422 i.setState({ showReportDialog: false });
1426 handleBlockUserClick(i: PostListing) {
1427 let auth = myAuth();
1429 let blockUserForm: BlockPerson = {
1430 person_id: i.props.post_view.creator.id,
1434 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1438 handleDeleteClick(i: PostListing) {
1439 let auth = myAuth();
1441 let deleteForm: DeletePost = {
1442 post_id: i.props.post_view.post.id,
1443 deleted: !i.props.post_view.post.deleted,
1446 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1450 handleSavePostClick(i: PostListing) {
1451 let auth = myAuth();
1454 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1455 let form: SavePost = {
1456 post_id: i.props.post_view.post.id,
1460 WebSocketService.Instance.send(wsClient.savePost(form));
1464 get crossPostParams(): PostFormParams {
1465 const queryParams: PostFormParams = {};
1466 const { name, url } = this.props.post_view.post;
1468 queryParams.name = name;
1471 queryParams.url = url;
1474 const crossPostBody = this.crossPostBody();
1475 if (crossPostBody) {
1476 queryParams.body = crossPostBody;
1482 crossPostBody(): string | undefined {
1483 let post = this.props.post_view.post;
1484 let body = post.body;
1487 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1494 get showBody(): boolean {
1495 return this.props.showBody || this.state.showBody;
1498 handleModRemoveShow(i: PostListing) {
1500 showRemoveDialog: !i.state.showRemoveDialog,
1501 showBanDialog: false,
1505 handleModRemoveReasonChange(i: PostListing, event: any) {
1506 i.setState({ removeReason: event.target.value });
1509 handleModRemoveDataChange(i: PostListing, event: any) {
1510 i.setState({ removeData: event.target.checked });
1513 handleModRemoveSubmit(i: PostListing, event: any) {
1514 event.preventDefault();
1516 let auth = myAuth();
1518 let form: RemovePost = {
1519 post_id: i.props.post_view.post.id,
1520 removed: !i.props.post_view.post.removed,
1521 reason: i.state.removeReason,
1524 WebSocketService.Instance.send(wsClient.removePost(form));
1525 i.setState({ showRemoveDialog: false });
1529 handleModLock(i: PostListing) {
1530 let auth = myAuth();
1532 let form: LockPost = {
1533 post_id: i.props.post_view.post.id,
1534 locked: !i.props.post_view.post.locked,
1537 WebSocketService.Instance.send(wsClient.lockPost(form));
1541 handleModFeaturePostLocal(i: PostListing) {
1542 let auth = myAuth();
1544 let form: FeaturePost = {
1545 post_id: i.props.post_view.post.id,
1546 feature_type: "Local",
1547 featured: !i.props.post_view.post.featured_local,
1550 WebSocketService.Instance.send(wsClient.featurePost(form));
1554 handleModFeaturePostCommunity(i: PostListing) {
1555 let auth = myAuth();
1557 let form: FeaturePost = {
1558 post_id: i.props.post_view.post.id,
1559 feature_type: "Community",
1560 featured: !i.props.post_view.post.featured_community,
1563 WebSocketService.Instance.send(wsClient.featurePost(form));
1567 handleModBanFromCommunityShow(i: PostListing) {
1569 showBanDialog: true,
1570 banType: BanType.Community,
1571 showRemoveDialog: false,
1575 handleModBanShow(i: PostListing) {
1577 showBanDialog: true,
1578 banType: BanType.Site,
1579 showRemoveDialog: false,
1583 handlePurgePersonShow(i: PostListing) {
1585 showPurgeDialog: true,
1586 purgeType: PurgeType.Person,
1587 showRemoveDialog: false,
1591 handlePurgePostShow(i: PostListing) {
1593 showPurgeDialog: true,
1594 purgeType: PurgeType.Post,
1595 showRemoveDialog: false,
1599 handlePurgeReasonChange(i: PostListing, event: any) {
1600 i.setState({ purgeReason: event.target.value });
1603 handlePurgeSubmit(i: PostListing, event: any) {
1604 event.preventDefault();
1606 let auth = myAuth();
1608 if (i.state.purgeType == PurgeType.Person) {
1609 let form: PurgePerson = {
1610 person_id: i.props.post_view.creator.id,
1611 reason: i.state.purgeReason,
1614 WebSocketService.Instance.send(wsClient.purgePerson(form));
1615 } else if (i.state.purgeType == PurgeType.Post) {
1616 let form: PurgePost = {
1617 post_id: i.props.post_view.post.id,
1618 reason: i.state.purgeReason,
1621 WebSocketService.Instance.send(wsClient.purgePost(form));
1624 i.setState({ purgeLoading: true });
1628 handleModBanReasonChange(i: PostListing, event: any) {
1629 i.setState({ banReason: event.target.value });
1632 handleModBanExpireDaysChange(i: PostListing, event: any) {
1633 i.setState({ banExpireDays: event.target.value });
1636 handleModBanFromCommunitySubmit(i: PostListing) {
1637 i.setState({ banType: BanType.Community });
1638 i.handleModBanBothSubmit(i);
1641 handleModBanSubmit(i: PostListing) {
1642 i.setState({ banType: BanType.Site });
1643 i.handleModBanBothSubmit(i);
1646 handleModBanBothSubmit(i: PostListing, event?: any) {
1647 if (event) event.preventDefault();
1648 let auth = myAuth();
1650 let ban = !i.props.post_view.creator_banned_from_community;
1651 let person_id = i.props.post_view.creator.id;
1652 let remove_data = i.state.removeData;
1653 let reason = i.state.banReason;
1654 let expires = futureDaysToUnixTime(i.state.banExpireDays);
1656 if (i.state.banType == BanType.Community) {
1657 // If its an unban, restore all their data
1659 i.setState({ removeData: false });
1662 let form: BanFromCommunity = {
1664 community_id: i.props.post_view.community.id,
1671 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1673 // If its an unban, restore all their data
1674 let ban = !i.props.post_view.creator.banned;
1676 i.setState({ removeData: false });
1678 let form: BanPerson = {
1686 WebSocketService.Instance.send(wsClient.banPerson(form));
1689 i.setState({ showBanDialog: false });
1693 handleAddModToCommunity(i: PostListing) {
1694 let auth = myAuth();
1696 let form: AddModToCommunity = {
1697 person_id: i.props.post_view.creator.id,
1698 community_id: i.props.post_view.community.id,
1699 added: !i.creatorIsMod_,
1702 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1703 i.setState(i.state);
1707 handleAddAdmin(i: PostListing) {
1708 let auth = myAuth();
1710 let form: AddAdmin = {
1711 person_id: i.props.post_view.creator.id,
1712 added: !i.creatorIsAdmin_,
1715 WebSocketService.Instance.send(wsClient.addAdmin(form));
1716 i.setState(i.state);
1720 handleShowConfirmTransferCommunity(i: PostListing) {
1721 i.setState({ showConfirmTransferCommunity: true });
1724 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1725 i.setState({ showConfirmTransferCommunity: false });
1728 handleTransferCommunity(i: PostListing) {
1729 let auth = myAuth();
1731 let form: TransferCommunity = {
1732 community_id: i.props.post_view.community.id,
1733 person_id: i.props.post_view.creator.id,
1736 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1737 i.setState({ showConfirmTransferCommunity: false });
1741 handleShowConfirmTransferSite(i: PostListing) {
1742 i.setState({ showConfirmTransferSite: true });
1745 handleCancelShowConfirmTransferSite(i: PostListing) {
1746 i.setState({ showConfirmTransferSite: false });
1749 handleImageExpandClick(i: PostListing, event: any) {
1750 event.preventDefault();
1751 i.setState({ imageExpanded: !i.state.imageExpanded });
1755 handleViewSource(i: PostListing) {
1756 i.setState({ viewSource: !i.state.viewSource });
1759 handleShowAdvanced(i: PostListing) {
1760 i.setState({ showAdvanced: !i.state.showAdvanced });
1764 handleShowMoreMobile(i: PostListing) {
1766 showMoreMobile: !i.state.showMoreMobile,
1767 showAdvanced: !i.state.showAdvanced,
1772 handleShowBody(i: PostListing) {
1773 i.setState({ showBody: !i.state.showBody });
1777 get pointsTippy(): string {
1778 let points = i18n.t("number_of_points", {
1779 count: Number(this.state.score),
1780 formattedCount: Number(this.state.score),
1783 let upvotes = i18n.t("number_of_upvotes", {
1784 count: Number(this.state.upvotes),
1785 formattedCount: Number(this.state.upvotes),
1788 let downvotes = i18n.t("number_of_downvotes", {
1789 count: Number(this.state.downvotes),
1790 formattedCount: Number(this.state.downvotes),
1793 return `${points} • ${upvotes} • ${downvotes}`;
1796 get canModOnSelf_(): boolean {
1798 this.props.post_view.creator.id,
1799 this.props.moderators,
1806 get canMod_(): boolean {
1808 this.props.post_view.creator.id,
1809 this.props.moderators,
1814 get canAdmin_(): boolean {
1815 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1818 get creatorIsMod_(): boolean {
1819 return isMod(this.props.post_view.creator.id, this.props.moderators);
1822 get creatorIsAdmin_(): boolean {
1823 return isAdmin(this.props.post_view.creator.id, this.props.admins);