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 const 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 const 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 const post_view = this.props.post_view;
226 nsfw={post_view.post.nsfw || post_view.community.nsfw}
231 get imageSrc(): string | undefined {
232 const post = this.props.post_view.post;
233 const url = post.url;
234 const thumbnail = post.thumbnail_url;
236 if (url && isImage(url)) {
237 if (url.includes("pictrs")) {
239 } else if (thumbnail) {
244 } else if (thumbnail) {
252 const post = this.props.post_view.post;
253 const url = post.url;
254 const 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 const post_view = this.props.post_view;
322 const url = post_view.post.url;
323 const 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">{i18n.t("mod")}</span>
332 {this.creatorIsAdmin_ && (
333 <span className="mx-1 badge">{i18n.t("admin")}</span>
335 {post_view.creator.bot_account && (
336 <span className="mx-1 badge">
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">
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")}
409 aria-pressed={this.state.my_vote === 1}
411 <Icon icon="arrow-up1" classes="upvote" />
415 className={`unselectable pointer font-weight-bold text-muted px-1`}
416 data-tippy-content={this.pointsTippy}
418 {numToSI(this.state.score)}
421 <div className="p-1"></div>
423 {this.props.enableDownvotes && (
425 className={`btn-animate btn btn-link p-0 ${
426 this.state.my_vote === -1 ? "text-danger" : "text-muted"
428 onClick={this.handlePostDisLike}
429 data-tippy-content={i18n.t("downvote")}
430 aria-label={i18n.t("downvote")}
431 aria-pressed={this.state.my_vote === -1}
433 <Icon icon="arrow-down1" classes="downvote" />
441 const post = this.props.post_view.post;
444 className={`d-inline-block ${
445 !post.featured_community && !post.featured_local
449 to={`/post/${post.id}`}
450 title={i18n.t("comments")}
453 className="d-inline-block"
454 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
461 const post = this.props.post_view.post;
462 const url = post.url;
465 <div className="post-title overflow-hidden">
468 this.props.showBody ? (
470 className={`d-inline-block ${
471 !post.featured_community && !post.featured_local
480 className="d-inline-block"
481 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
490 {(url && isImage(url)) ||
491 (post.thumbnail_url && (
493 className="btn btn-link text-monospace text-muted small d-inline-block"
494 data-tippy-content={i18n.t("expand_here")}
495 onClick={linkEvent(this, this.handleImageExpandClick)}
499 !this.state.imageExpanded ? "plus-square" : "minus-square"
501 classes="icon-inline"
506 <small className="ml-2 text-muted font-italic">
512 className="unselectable pointer ml-2 text-muted font-italic"
513 data-tippy-content={i18n.t("deleted")}
515 <Icon icon="trash" classes="icon-inline text-danger" />
520 className="unselectable pointer ml-2 text-muted font-italic"
521 data-tippy-content={i18n.t("locked")}
523 <Icon icon="lock" classes="icon-inline text-danger" />
526 {post.featured_community && (
528 className="unselectable pointer ml-2 text-muted font-italic"
529 data-tippy-content={i18n.t("featured")}
531 <Icon icon="pin" classes="icon-inline text-primary" />
534 {post.featured_local && (
536 className="unselectable pointer ml-2 text-muted font-italic"
537 data-tippy-content={i18n.t("featured")}
539 <Icon icon="pin" classes="icon-inline text-secondary" />
543 <small className="ml-2 text-muted font-italic">
553 const dupes = this.props.duplicates;
554 return dupes && dupes.length > 0 ? (
555 <ul className="list-inline mb-1 small text-muted">
557 <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
559 <li key={pv.post.id} className="list-inline-item mr-2">
560 <Link to={`/post/${pv.post.id}`}>
563 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
574 commentsLine(mobile = false) {
575 const post = this.props.post_view.post;
578 <div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
579 {this.commentsButton}
582 className="btn btn-link"
583 onClick={linkEvent(this, this.handleShare)}
586 <Icon icon="share" inline />
591 className="btn btn-link btn-animate text-muted py-0"
592 title={i18n.t("link")}
595 <Icon icon="fedilink" inline />
598 {mobile && !this.props.viewOnly && this.mobileVotes}
599 {UserService.Instance.myUserInfo &&
600 !this.props.viewOnly &&
601 this.postActions(mobile)}
606 postActions(mobile = false) {
607 // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
608 // Possible enhancement: Make each button a component.
609 const post_view = this.props.post_view;
613 {this.crossPostButton}
614 {mobile && this.showMoreButton}
615 {(!mobile || this.state.showAdvanced) && (
623 {this.myPost && (this.showBody || this.state.showAdvanced) && (
631 {this.state.showAdvanced && (
633 {this.showBody && post_view.post.body && this.viewSourceButton}
634 {/* Any mod can do these, not limited to hierarchy*/}
635 {(amMod(this.props.moderators) || amAdmin()) && (
641 {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
644 {!mobile && this.showMoreButton}
649 get commentsButton() {
650 const post_view = this.props.post_view;
653 className="btn btn-link text-muted py-0 pl-0 text-muted"
654 title={i18n.t("number_of_comments", {
655 count: Number(post_view.counts.comments),
656 formattedCount: Number(post_view.counts.comments),
658 to={`/post/${post_view.post.id}?scrollToComments=true`}
660 <Icon icon="message-square" classes="mr-1" inline />
661 <span className="mr-2">
662 {i18n.t("number_of_comments", {
663 count: Number(post_view.counts.comments),
664 formattedCount: numToSI(post_view.counts.comments),
667 {this.unreadCount && (
668 <span className="small text-warning">
669 ({this.unreadCount} {i18n.t("new")})
676 get unreadCount(): number | undefined {
677 const pv = this.props.post_view;
678 return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
680 : pv.unread_comments;
685 const tippy = showScores()
686 ? { "data-tippy-content": this.pointsTippy }
692 className={`btn-animate btn py-0 px-1 ${
693 this.state.my_vote === 1 ? "text-info" : "text-muted"
696 onClick={this.handlePostLike}
697 aria-label={i18n.t("upvote")}
698 aria-pressed={this.state.my_vote === 1}
700 <Icon icon="arrow-up1" classes="icon-inline small" />
702 <span className="ml-2">{numToSI(this.state.upvotes)}</span>
705 {this.props.enableDownvotes && (
707 className={`ml-2 btn-animate btn py-0 px-1 ${
708 this.state.my_vote === -1 ? "text-danger" : "text-muted"
710 onClick={this.handlePostDisLike}
712 aria-label={i18n.t("downvote")}
713 aria-pressed={this.state.my_vote === -1}
715 <Icon icon="arrow-down1" classes="icon-inline small" />
718 className={classNames("ml-2", {
719 invisible: this.state.downvotes === 0,
722 {numToSI(this.state.downvotes)}
733 const saved = this.props.post_view.saved;
734 const label = saved ? i18n.t("unsave") : i18n.t("save");
737 className="btn btn-link btn-animate text-muted py-0"
738 onClick={linkEvent(this, this.handleSavePostClick)}
739 data-tippy-content={label}
744 classes={classNames({ "text-warning": saved })}
751 get crossPostButton() {
754 className="btn btn-link btn-animate text-muted py-0"
756 /* Empty string properties are required to satisfy type*/
757 pathname: "/create_post",
758 state: { ...this.crossPostParams },
763 title={i18n.t("cross_post")}
765 <Icon icon="copy" inline />
773 className="btn btn-link btn-animate text-muted py-0"
774 onClick={linkEvent(this, this.handleShowReportDialog)}
775 data-tippy-content={i18n.t("show_report_dialog")}
776 aria-label={i18n.t("show_report_dialog")}
778 <Icon icon="flag" inline />
786 className="btn btn-link btn-animate text-muted py-0"
787 onClick={linkEvent(this, this.handleBlockUserClick)}
788 data-tippy-content={i18n.t("block_user")}
789 aria-label={i18n.t("block_user")}
791 <Icon icon="slash" inline />
799 className="btn btn-link btn-animate text-muted py-0"
800 onClick={linkEvent(this, this.handleEditClick)}
801 data-tippy-content={i18n.t("edit")}
802 aria-label={i18n.t("edit")}
804 <Icon icon="edit" inline />
810 const deleted = this.props.post_view.post.deleted;
811 const label = !deleted ? i18n.t("delete") : i18n.t("restore");
814 className="btn btn-link btn-animate text-muted py-0"
815 onClick={linkEvent(this, this.handleDeleteClick)}
816 data-tippy-content={label}
821 classes={classNames({ "text-danger": deleted })}
828 get showMoreButton() {
831 className="btn btn-link btn-animate text-muted py-0"
832 onClick={linkEvent(this, this.handleShowAdvanced)}
833 data-tippy-content={i18n.t("more")}
834 aria-label={i18n.t("more")}
836 <Icon icon="more-vertical" inline />
841 get viewSourceButton() {
844 className="btn btn-link btn-animate text-muted py-0"
845 onClick={linkEvent(this, this.handleViewSource)}
846 data-tippy-content={i18n.t("view_source")}
847 aria-label={i18n.t("view_source")}
851 classes={classNames({ "text-success": this.state.viewSource })}
859 const locked = this.props.post_view.post.locked;
860 const label = locked ? i18n.t("unlock") : i18n.t("lock");
863 className="btn btn-link btn-animate text-muted py-0"
864 onClick={linkEvent(this, this.handleModLock)}
865 data-tippy-content={label}
870 classes={classNames({ "text-danger": locked })}
877 get featureButton() {
878 const featuredCommunity = this.props.post_view.post.featured_community;
879 const labelCommunity = featuredCommunity
880 ? i18n.t("unfeature_from_community")
881 : i18n.t("feature_in_community");
883 const featuredLocal = this.props.post_view.post.featured_local;
884 const labelLocal = featuredLocal
885 ? i18n.t("unfeature_from_local")
886 : i18n.t("feature_in_local");
890 className="btn btn-link btn-animate text-muted py-0 pl-0"
891 onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
892 data-tippy-content={labelCommunity}
893 aria-label={labelCommunity}
897 classes={classNames({ "text-success": featuredCommunity })}
904 className="btn btn-link btn-animate text-muted py-0"
905 onClick={linkEvent(this, this.handleModFeaturePostLocal)}
906 data-tippy-content={labelLocal}
907 aria-label={labelLocal}
911 classes={classNames({ "text-success": featuredLocal })}
921 get modRemoveButton() {
922 const removed = this.props.post_view.post.removed;
925 className="btn btn-link btn-animate text-muted py-0"
928 !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
931 {/* TODO: Find an icon for this. */}
932 {!removed ? i18n.t("remove") : i18n.t("restore")}
938 * Mod/Admin actions to be taken against the author.
942 const post_view = this.props.post_view;
944 this.state.showAdvanced && (
948 {!this.creatorIsMod_ &&
949 (!post_view.creator_banned_from_community ? (
951 className="btn btn-link btn-animate text-muted py-0"
954 this.handleModBanFromCommunityShow
956 aria-label={i18n.t("ban_from_community")}
958 {i18n.t("ban_from_community")}
962 className="btn btn-link btn-animate text-muted py-0"
965 this.handleModBanFromCommunitySubmit
967 aria-label={i18n.t("unban")}
972 {!post_view.creator_banned_from_community && (
974 className="btn btn-link btn-animate text-muted py-0"
975 onClick={linkEvent(this, this.handleAddModToCommunity)}
978 ? i18n.t("remove_as_mod")
979 : i18n.t("appoint_as_mod")
983 ? i18n.t("remove_as_mod")
984 : i18n.t("appoint_as_mod")}
989 {/* Community creators and admins can transfer community to another mod */}
990 {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
992 this.creatorIsMod_ &&
993 (!this.state.showConfirmTransferCommunity ? (
995 className="btn btn-link btn-animate text-muted py-0"
998 this.handleShowConfirmTransferCommunity
1000 aria-label={i18n.t("transfer_community")}
1002 {i18n.t("transfer_community")}
1007 className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1008 aria-label={i18n.t("are_you_sure")}
1010 {i18n.t("are_you_sure")}
1013 className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1014 aria-label={i18n.t("yes")}
1015 onClick={linkEvent(this, this.handleTransferCommunity)}
1020 className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1023 this.handleCancelShowConfirmTransferCommunity
1025 aria-label={i18n.t("no")}
1031 {/* Admins can ban from all, and appoint other admins */}
1032 {this.canAdmin_ && (
1034 {!this.creatorIsAdmin_ && (
1036 {!isBanned(post_view.creator) ? (
1038 className="btn btn-link btn-animate text-muted py-0"
1039 onClick={linkEvent(this, this.handleModBanShow)}
1040 aria-label={i18n.t("ban_from_site")}
1042 {i18n.t("ban_from_site")}
1046 className="btn btn-link btn-animate text-muted py-0"
1047 onClick={linkEvent(this, this.handleModBanSubmit)}
1048 aria-label={i18n.t("unban_from_site")}
1050 {i18n.t("unban_from_site")}
1054 className="btn btn-link btn-animate text-muted py-0"
1055 onClick={linkEvent(this, this.handlePurgePersonShow)}
1056 aria-label={i18n.t("purge_user")}
1058 {i18n.t("purge_user")}
1061 className="btn btn-link btn-animate text-muted py-0"
1062 onClick={linkEvent(this, this.handlePurgePostShow)}
1063 aria-label={i18n.t("purge_post")}
1065 {i18n.t("purge_post")}
1069 {!isBanned(post_view.creator) && post_view.creator.local && (
1071 className="btn btn-link btn-animate text-muted py-0"
1072 onClick={linkEvent(this, this.handleAddAdmin)}
1074 this.creatorIsAdmin_
1075 ? i18n.t("remove_as_admin")
1076 : i18n.t("appoint_as_admin")
1079 {this.creatorIsAdmin_
1080 ? i18n.t("remove_as_admin")
1081 : i18n.t("appoint_as_admin")}
1091 removeAndBanDialogs() {
1092 const post = this.props.post_view;
1093 const purgeTypeText =
1094 this.state.purgeType == PurgeType.Post
1095 ? i18n.t("purge_post")
1096 : `${i18n.t("purge")} ${post.creator.name}`;
1099 {this.state.showRemoveDialog && (
1101 className="form-inline"
1102 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1104 <label className="sr-only" htmlFor="post-listing-remove-reason">
1109 id="post-listing-remove-reason"
1110 className="form-control mr-2"
1111 placeholder={i18n.t("reason")}
1112 value={this.state.removeReason}
1113 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1117 className="btn btn-secondary"
1118 aria-label={i18n.t("remove_post")}
1120 {i18n.t("remove_post")}
1124 {this.state.showBanDialog && (
1125 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1126 <div className="form-group row col-12">
1128 className="col-form-label"
1129 htmlFor="post-listing-ban-reason"
1135 id="post-listing-ban-reason"
1136 className="form-control mr-2"
1137 placeholder={i18n.t("reason")}
1138 value={this.state.banReason}
1139 onInput={linkEvent(this, this.handleModBanReasonChange)}
1141 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1146 id={`mod-ban-expires`}
1147 className="form-control mr-2"
1148 placeholder={i18n.t("number_of_days")}
1149 value={this.state.banExpireDays}
1150 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1152 <div className="form-group">
1153 <div className="form-check">
1155 className="form-check-input"
1156 id="mod-ban-remove-data"
1158 checked={this.state.removeData}
1159 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1162 className="form-check-label"
1163 htmlFor="mod-ban-remove-data"
1164 title={i18n.t("remove_content_more")}
1166 {i18n.t("remove_content")}
1171 {/* TODO hold off on expires until later */}
1172 {/* <div class="form-group row"> */}
1173 {/* <label class="col-form-label">Expires</label> */}
1174 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1176 <div className="form-group row">
1179 className="btn btn-secondary"
1180 aria-label={i18n.t("ban")}
1182 {i18n.t("ban")} {post.creator.name}
1187 {this.state.showReportDialog && (
1189 className="form-inline"
1190 onSubmit={linkEvent(this, this.handleReportSubmit)}
1192 <label className="sr-only" htmlFor="post-report-reason">
1197 id="post-report-reason"
1198 className="form-control mr-2"
1199 placeholder={i18n.t("reason")}
1201 value={this.state.reportReason}
1202 onInput={linkEvent(this, this.handleReportReasonChange)}
1206 className="btn btn-secondary"
1207 aria-label={i18n.t("create_report")}
1209 {i18n.t("create_report")}
1213 {this.state.showPurgeDialog && (
1215 className="form-inline"
1216 onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1219 <label className="sr-only" htmlFor="purge-reason">
1225 className="form-control mr-2"
1226 placeholder={i18n.t("reason")}
1227 value={this.state.purgeReason}
1228 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1230 {this.state.purgeLoading ? (
1235 className="btn btn-secondary"
1236 aria-label={purgeTypeText}
1248 const post = this.props.post_view.post;
1249 return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1250 <div className="row">
1251 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1252 {this.postTitleLine()}
1254 <div className="col-4">
1255 {/* Post body prev or thumbnail */}
1256 {!this.state.imageExpanded && this.thumbnail()}
1260 this.postTitleLine()
1264 showMobilePreview() {
1265 const body = this.props.post_view.post.body;
1266 return !this.showBody && body ? (
1267 <div className="md-div mb-1 preview-lines">{body}</div>
1276 {/* The mobile view*/}
1277 <div className="d-block d-sm-none">
1278 <div className="row">
1279 <div className="col-12">
1280 {this.createdLine()}
1282 {/* If it has a thumbnail, do a right aligned thumbnail */}
1283 {this.mobileThumbnail()}
1285 {/* Show a preview of the post body */}
1286 {this.showMobilePreview()}
1288 {this.commentsLine(true)}
1289 {this.userActionsLine()}
1290 {this.duplicatesLine()}
1291 {this.removeAndBanDialogs()}
1296 {/* The larger view*/}
1297 <div className="d-none d-sm-block">
1298 <div className="row">
1299 {!this.props.viewOnly && this.voteBar()}
1300 <div className="col-sm-2 pr-0">
1301 <div className="">{this.thumbnail()}</div>
1303 <div className="col-12 col-sm-9">
1304 <div className="row">
1305 <div className="col-12">
1306 {this.postTitleLine()}
1307 {this.createdLine()}
1308 {this.commentsLine()}
1309 {this.duplicatesLine()}
1310 {this.userActionsLine()}
1311 {this.removeAndBanDialogs()}
1321 private get myPost(): boolean {
1323 this.props.post_view.creator.id ==
1324 UserService.Instance.myUserInfo?.local_user_view.person.id
1328 handlePostLike(event: any) {
1329 event.preventDefault();
1330 if (!UserService.Instance.myUserInfo) {
1331 this.context.router.history.push(`/login`);
1334 const myVote = this.state.my_vote;
1335 const newVote = myVote == 1 ? 0 : 1;
1339 score: this.state.score - 1,
1340 upvotes: this.state.upvotes - 1,
1342 } else if (myVote == -1) {
1344 score: this.state.score + 2,
1345 upvotes: this.state.upvotes + 1,
1346 downvotes: this.state.downvotes - 1,
1350 score: this.state.score + 1,
1351 upvotes: this.state.upvotes + 1,
1355 this.setState({ my_vote: newVote });
1357 const auth = myAuth();
1359 const form: CreatePostLike = {
1360 post_id: this.props.post_view.post.id,
1365 WebSocketService.Instance.send(wsClient.likePost(form));
1366 this.setState(this.state);
1371 handlePostDisLike(event: any) {
1372 event.preventDefault();
1373 if (!UserService.Instance.myUserInfo) {
1374 this.context.router.history.push(`/login`);
1377 const myVote = this.state.my_vote;
1378 const newVote = myVote == -1 ? 0 : -1;
1382 score: this.state.score - 2,
1383 upvotes: this.state.upvotes - 1,
1384 downvotes: this.state.downvotes + 1,
1386 } else if (myVote == -1) {
1388 score: this.state.score + 1,
1389 downvotes: this.state.downvotes - 1,
1393 score: this.state.score - 1,
1394 downvotes: this.state.downvotes + 1,
1398 this.setState({ my_vote: newVote });
1400 const auth = myAuth();
1402 const form: CreatePostLike = {
1403 post_id: this.props.post_view.post.id,
1408 WebSocketService.Instance.send(wsClient.likePost(form));
1409 this.setState(this.state);
1414 handleEditClick(i: PostListing) {
1415 i.setState({ showEdit: true });
1418 handleEditCancel() {
1419 this.setState({ showEdit: false });
1422 // The actual editing is done in the recieve for post
1424 this.setState({ showEdit: false });
1427 handleShare(i: PostListing) {
1428 const { name, body, id } = i.props.post_view.post;
1431 text: body?.slice(0, 50),
1432 url: `${getHttpBase()}/post/${id}`,
1436 handleShowReportDialog(i: PostListing) {
1437 i.setState({ showReportDialog: !i.state.showReportDialog });
1440 handleReportReasonChange(i: PostListing, event: any) {
1441 i.setState({ reportReason: event.target.value });
1444 handleReportSubmit(i: PostListing, event: any) {
1445 event.preventDefault();
1446 const auth = myAuth();
1447 const reason = i.state.reportReason;
1448 if (auth && reason) {
1449 const form: CreatePostReport = {
1450 post_id: i.props.post_view.post.id,
1454 WebSocketService.Instance.send(wsClient.createPostReport(form));
1456 i.setState({ showReportDialog: false });
1460 handleBlockUserClick(i: PostListing) {
1461 const auth = myAuth();
1463 const blockUserForm: BlockPerson = {
1464 person_id: i.props.post_view.creator.id,
1468 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1472 handleDeleteClick(i: PostListing) {
1473 const auth = myAuth();
1475 const deleteForm: DeletePost = {
1476 post_id: i.props.post_view.post.id,
1477 deleted: !i.props.post_view.post.deleted,
1480 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1484 handleSavePostClick(i: PostListing) {
1485 const auth = myAuth();
1488 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1489 const form: SavePost = {
1490 post_id: i.props.post_view.post.id,
1494 WebSocketService.Instance.send(wsClient.savePost(form));
1498 get crossPostParams(): PostFormParams {
1499 const queryParams: PostFormParams = {};
1500 const { name, url } = this.props.post_view.post;
1502 queryParams.name = name;
1505 queryParams.url = url;
1508 const crossPostBody = this.crossPostBody();
1509 if (crossPostBody) {
1510 queryParams.body = crossPostBody;
1516 crossPostBody(): string | undefined {
1517 const post = this.props.post_view.post;
1518 const body = post.body;
1521 ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1528 get showBody(): boolean {
1529 return this.props.showBody || this.state.showBody;
1532 handleModRemoveShow(i: PostListing) {
1534 showRemoveDialog: !i.state.showRemoveDialog,
1535 showBanDialog: false,
1539 handleModRemoveReasonChange(i: PostListing, event: any) {
1540 i.setState({ removeReason: event.target.value });
1543 handleModRemoveDataChange(i: PostListing, event: any) {
1544 i.setState({ removeData: event.target.checked });
1547 handleModRemoveSubmit(i: PostListing, event: any) {
1548 event.preventDefault();
1550 const auth = myAuth();
1552 const form: RemovePost = {
1553 post_id: i.props.post_view.post.id,
1554 removed: !i.props.post_view.post.removed,
1555 reason: i.state.removeReason,
1558 WebSocketService.Instance.send(wsClient.removePost(form));
1559 i.setState({ showRemoveDialog: false });
1563 handleModLock(i: PostListing) {
1564 const auth = myAuth();
1566 const form: LockPost = {
1567 post_id: i.props.post_view.post.id,
1568 locked: !i.props.post_view.post.locked,
1571 WebSocketService.Instance.send(wsClient.lockPost(form));
1575 handleModFeaturePostLocal(i: PostListing) {
1576 const auth = myAuth();
1578 const form: FeaturePost = {
1579 post_id: i.props.post_view.post.id,
1580 feature_type: "Local",
1581 featured: !i.props.post_view.post.featured_local,
1584 WebSocketService.Instance.send(wsClient.featurePost(form));
1588 handleModFeaturePostCommunity(i: PostListing) {
1589 const auth = myAuth();
1591 const form: FeaturePost = {
1592 post_id: i.props.post_view.post.id,
1593 feature_type: "Community",
1594 featured: !i.props.post_view.post.featured_community,
1597 WebSocketService.Instance.send(wsClient.featurePost(form));
1601 handleModBanFromCommunityShow(i: PostListing) {
1603 showBanDialog: true,
1604 banType: BanType.Community,
1605 showRemoveDialog: false,
1609 handleModBanShow(i: PostListing) {
1611 showBanDialog: true,
1612 banType: BanType.Site,
1613 showRemoveDialog: false,
1617 handlePurgePersonShow(i: PostListing) {
1619 showPurgeDialog: true,
1620 purgeType: PurgeType.Person,
1621 showRemoveDialog: false,
1625 handlePurgePostShow(i: PostListing) {
1627 showPurgeDialog: true,
1628 purgeType: PurgeType.Post,
1629 showRemoveDialog: false,
1633 handlePurgeReasonChange(i: PostListing, event: any) {
1634 i.setState({ purgeReason: event.target.value });
1637 handlePurgeSubmit(i: PostListing, event: any) {
1638 event.preventDefault();
1640 const auth = myAuth();
1642 if (i.state.purgeType == PurgeType.Person) {
1643 const form: PurgePerson = {
1644 person_id: i.props.post_view.creator.id,
1645 reason: i.state.purgeReason,
1648 WebSocketService.Instance.send(wsClient.purgePerson(form));
1649 } else if (i.state.purgeType == PurgeType.Post) {
1650 const form: PurgePost = {
1651 post_id: i.props.post_view.post.id,
1652 reason: i.state.purgeReason,
1655 WebSocketService.Instance.send(wsClient.purgePost(form));
1658 i.setState({ purgeLoading: true });
1662 handleModBanReasonChange(i: PostListing, event: any) {
1663 i.setState({ banReason: event.target.value });
1666 handleModBanExpireDaysChange(i: PostListing, event: any) {
1667 i.setState({ banExpireDays: event.target.value });
1670 handleModBanFromCommunitySubmit(i: PostListing) {
1671 i.setState({ banType: BanType.Community });
1672 i.handleModBanBothSubmit(i);
1675 handleModBanSubmit(i: PostListing) {
1676 i.setState({ banType: BanType.Site });
1677 i.handleModBanBothSubmit(i);
1680 handleModBanBothSubmit(i: PostListing, event?: any) {
1681 if (event) event.preventDefault();
1682 const auth = myAuth();
1684 const ban = !i.props.post_view.creator_banned_from_community;
1685 const person_id = i.props.post_view.creator.id;
1686 const remove_data = i.state.removeData;
1687 const reason = i.state.banReason;
1688 const expires = futureDaysToUnixTime(i.state.banExpireDays);
1690 if (i.state.banType == BanType.Community) {
1691 // If its an unban, restore all their data
1693 i.setState({ removeData: false });
1696 const form: BanFromCommunity = {
1698 community_id: i.props.post_view.community.id,
1705 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1707 // If its an unban, restore all their data
1708 const ban = !i.props.post_view.creator.banned;
1710 i.setState({ removeData: false });
1712 const form: BanPerson = {
1720 WebSocketService.Instance.send(wsClient.banPerson(form));
1723 i.setState({ showBanDialog: false });
1727 handleAddModToCommunity(i: PostListing) {
1728 const auth = myAuth();
1730 const form: AddModToCommunity = {
1731 person_id: i.props.post_view.creator.id,
1732 community_id: i.props.post_view.community.id,
1733 added: !i.creatorIsMod_,
1736 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1737 i.setState(i.state);
1741 handleAddAdmin(i: PostListing) {
1742 const auth = myAuth();
1744 const form: AddAdmin = {
1745 person_id: i.props.post_view.creator.id,
1746 added: !i.creatorIsAdmin_,
1749 WebSocketService.Instance.send(wsClient.addAdmin(form));
1750 i.setState(i.state);
1754 handleShowConfirmTransferCommunity(i: PostListing) {
1755 i.setState({ showConfirmTransferCommunity: true });
1758 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1759 i.setState({ showConfirmTransferCommunity: false });
1762 handleTransferCommunity(i: PostListing) {
1763 const auth = myAuth();
1765 const form: TransferCommunity = {
1766 community_id: i.props.post_view.community.id,
1767 person_id: i.props.post_view.creator.id,
1770 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1771 i.setState({ showConfirmTransferCommunity: false });
1775 handleShowConfirmTransferSite(i: PostListing) {
1776 i.setState({ showConfirmTransferSite: true });
1779 handleCancelShowConfirmTransferSite(i: PostListing) {
1780 i.setState({ showConfirmTransferSite: false });
1783 handleImageExpandClick(i: PostListing, event: any) {
1784 event.preventDefault();
1785 i.setState({ imageExpanded: !i.state.imageExpanded });
1789 handleViewSource(i: PostListing) {
1790 i.setState({ viewSource: !i.state.viewSource });
1793 handleShowAdvanced(i: PostListing) {
1794 i.setState({ showAdvanced: !i.state.showAdvanced });
1798 handleShowMoreMobile(i: PostListing) {
1800 showMoreMobile: !i.state.showMoreMobile,
1801 showAdvanced: !i.state.showAdvanced,
1806 handleShowBody(i: PostListing) {
1807 i.setState({ showBody: !i.state.showBody });
1811 get pointsTippy(): string {
1812 const points = i18n.t("number_of_points", {
1813 count: Number(this.state.score),
1814 formattedCount: Number(this.state.score),
1817 const upvotes = i18n.t("number_of_upvotes", {
1818 count: Number(this.state.upvotes),
1819 formattedCount: Number(this.state.upvotes),
1822 const downvotes = i18n.t("number_of_downvotes", {
1823 count: Number(this.state.downvotes),
1824 formattedCount: Number(this.state.downvotes),
1827 return `${points} • ${upvotes} • ${downvotes}`;
1830 get canModOnSelf_(): boolean {
1832 this.props.post_view.creator.id,
1833 this.props.moderators,
1840 get canMod_(): boolean {
1842 this.props.post_view.creator.id,
1843 this.props.moderators,
1848 get canAdmin_(): boolean {
1849 return canAdmin(this.props.post_view.creator.id, this.props.admins);
1852 get creatorIsMod_(): boolean {
1853 return isMod(this.props.post_view.creator.id, this.props.moderators);
1856 get creatorIsAdmin_(): boolean {
1857 return isAdmin(this.props.post_view.creator.id, this.props.admins);