1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
12 CommunityModeratorView,
19 MarkCommentReplyAsRead,
20 MarkPersonMentionAsRead,
28 } from "lemmy-js-client";
29 import moment from "moment";
30 import { i18n } from "../../i18next";
36 } from "../../interfaces";
37 import { UserService, WebSocketService } from "../../services";
57 import { Icon, PurgeWarning, Spinner } from "../common/icon";
58 import { MomentTime } from "../common/moment-time";
59 import { CommunityLink } from "../community/community-link";
60 import { PersonListing } from "../person/person-listing";
61 import { CommentForm } from "./comment-form";
62 import { CommentNodes } from "./comment-nodes";
64 interface CommentNodeState {
67 showRemoveDialog: boolean;
68 removeReason?: string;
69 showBanDialog: boolean;
72 banExpireDays?: number;
74 showPurgeDialog: boolean;
77 purgeLoading: boolean;
78 showConfirmTransferSite: boolean;
79 showConfirmTransferCommunity: boolean;
80 showConfirmAppointAsMod: boolean;
81 showConfirmAppointAsAdmin: boolean;
84 showAdvanced: boolean;
85 showReportDialog: boolean;
86 reportReason?: string;
95 interface CommentNodeProps {
97 moderators?: CommunityModeratorView[];
98 admins?: PersonView[];
104 showContext?: boolean;
105 showCommunity?: boolean;
106 enableDownvotes?: boolean;
107 viewType: CommentViewType;
108 allLanguages: Language[];
109 siteLanguages: number[];
110 hideImages?: boolean;
113 export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
114 state: CommentNodeState = {
117 showRemoveDialog: false,
118 showBanDialog: false,
120 banType: BanType.Community,
121 showPurgeDialog: false,
123 purgeType: PurgeType.Person,
127 showConfirmTransferSite: false,
128 showConfirmTransferCommunity: false,
129 showConfirmAppointAsMod: false,
130 showConfirmAppointAsAdmin: false,
131 showReportDialog: false,
132 my_vote: this.props.node.comment_view.my_vote,
133 score: this.props.node.comment_view.counts.score,
134 upvotes: this.props.node.comment_view.counts.upvotes,
135 downvotes: this.props.node.comment_view.counts.downvotes,
140 constructor(props: any, context: any) {
141 super(props, context);
143 this.handleReplyCancel = this.handleReplyCancel.bind(this);
144 this.handleCommentUpvote = this.handleCommentUpvote.bind(this);
145 this.handleCommentDownvote = this.handleCommentDownvote.bind(this);
148 // TODO see if there's a better way to do this, and all willReceiveProps
149 componentWillReceiveProps(nextProps: CommentNodeProps) {
150 let cv = nextProps.node.comment_view;
153 upvotes: cv.counts.upvotes,
154 downvotes: cv.counts.downvotes,
155 score: cv.counts.score,
162 const node = this.props.node;
163 const cv = this.props.node.comment_view;
165 const purgeTypeText =
166 this.state.purgeType == PurgeType.Comment
167 ? i18n.t("purge_comment")
168 : `${i18n.t("purge")} ${cv.creator.name}`;
171 canMod(cv.creator.id, this.props.moderators, this.props.admins) &&
176 this.props.moderators,
178 UserService.Instance.myUserInfo,
180 ) && cv.community.local;
182 canAdmin(cv.creator.id, this.props.admins) && cv.community.local;
183 const canAdminOnSelf =
187 UserService.Instance.myUserInfo,
189 ) && cv.community.local;
190 const isMod_ = isMod(cv.creator.id, this.props.moderators);
192 isAdmin(cv.creator.id, this.props.admins) && cv.community.local;
193 const amCommunityCreator_ = amCommunityCreator(
195 this.props.moderators
198 const moreRepliesBorderColor = this.props.node.depth
199 ? colorList[this.props.node.depth % colorList.length]
202 const showMoreChildren =
203 this.props.viewType == CommentViewType.Tree &&
204 !this.state.collapsed &&
205 node.children.length == 0 &&
206 node.comment_view.counts.child_count > 0;
209 <li className="comment" role="comment">
211 id={`comment-${cv.comment.id}`}
212 className={classNames(`details comment-node py-2`, {
215 this.props.node.comment_view.comment.distinguished,
219 className={classNames({
220 "ml-2": !this.props.noIndent,
223 <div className="d-flex flex-wrap align-items-center text-muted small">
224 <span className="mr-2">
225 <PersonListing person={cv.creator} />
227 {cv.comment.distinguished && (
228 <Icon icon="shield" inline classes={`text-danger mr-2`} />
230 {this.isPostCreator && (
231 <div className="badge badge-light d-none d-sm-inline mr-2">
236 <div className="badge d-none d-sm-inline mr-2">
241 <div className="badge d-none d-sm-inline mr-2">
245 {cv.creator.bot_account && (
246 <div className="badge d-none d-sm-inline mr-2">
247 {i18n.t("bot_account").toLowerCase()}
250 {this.props.showCommunity && (
252 <span className="mx-1">{i18n.t("to")}</span>
253 <CommunityLink community={cv.community} />
254 <span className="mx-2">•</span>
255 <Link className="mr-2" to={`/post/${cv.post.id}`}>
261 className="btn btn-sm text-muted"
262 onClick={linkEvent(this, this.handleCommentCollapse)}
263 aria-label={this.expandText}
264 data-tippy-content={this.expandText}
266 {this.state.collapsed ? (
267 <Icon icon="plus-square" classes="icon-inline" />
269 <Icon icon="minus-square" classes="icon-inline" />
273 {cv.comment.language_id !== 0 && (
274 <span className="badge d-none d-sm-inline mr-2">
276 this.props.allLanguages.find(
277 lang => lang.id === cv.comment.language_id
282 {/* This is an expanding spacer for mobile */}
283 <div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
287 className={`unselectable pointer ${this.scoreColor}`}
288 onClick={this.handleCommentUpvote}
289 data-tippy-content={this.pointsTippy}
292 className="mr-1 font-weight-bold"
293 aria-label={i18n.t("number_of_points", {
294 count: Number(this.state.score),
295 formattedCount: numToSI(this.state.score),
298 {numToSI(this.state.score)}
301 <span className="mr-1">•</span>
306 published={cv.comment.published}
307 updated={cv.comment.updated}
311 {/* end of user row */}
312 {this.state.showEdit && (
316 onReplyCancel={this.handleReplyCancel}
317 disabled={this.props.locked}
319 allLanguages={this.props.allLanguages}
320 siteLanguages={this.props.siteLanguages}
323 {!this.state.showEdit && !this.state.collapsed && (
325 {this.state.viewSource ? (
326 <pre>{this.commentUnlessRemoved}</pre>
330 dangerouslySetInnerHTML={
331 this.props.hideImages
332 ? mdToHtmlNoImages(this.commentUnlessRemoved)
333 : mdToHtml(this.commentUnlessRemoved)
337 <div className="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold">
338 {this.props.showContext && this.linkBtn()}
339 {this.props.markable && (
341 className="btn btn-link btn-animate text-muted"
342 onClick={linkEvent(this, this.handleMarkRead)}
344 this.commentReplyOrMentionRead
345 ? i18n.t("mark_as_unread")
346 : i18n.t("mark_as_read")
349 this.commentReplyOrMentionRead
350 ? i18n.t("mark_as_unread")
351 : i18n.t("mark_as_read")
354 {this.state.readLoading ? (
359 classes={`icon-inline ${
360 this.commentReplyOrMentionRead && "text-success"
366 {UserService.Instance.myUserInfo && !this.props.viewOnly && (
369 className={`btn btn-link btn-animate ${
370 this.state.my_vote == 1 ? "text-info" : "text-muted"
372 onClick={this.handleCommentUpvote}
373 data-tippy-content={i18n.t("upvote")}
374 aria-label={i18n.t("upvote")}
376 <Icon icon="arrow-up1" classes="icon-inline" />
378 this.state.upvotes !== this.state.score && (
379 <span className="ml-1">
380 {numToSI(this.state.upvotes)}
384 {this.props.enableDownvotes && (
386 className={`btn btn-link btn-animate ${
387 this.state.my_vote == -1
391 onClick={this.handleCommentDownvote}
392 data-tippy-content={i18n.t("downvote")}
393 aria-label={i18n.t("downvote")}
395 <Icon icon="arrow-down1" classes="icon-inline" />
397 this.state.upvotes !== this.state.score && (
398 <span className="ml-1">
399 {numToSI(this.state.downvotes)}
405 className="btn btn-link btn-animate text-muted"
406 onClick={linkEvent(this, this.handleReplyClick)}
407 data-tippy-content={i18n.t("reply")}
408 aria-label={i18n.t("reply")}
410 <Icon icon="reply1" classes="icon-inline" />
412 {!this.state.showAdvanced ? (
414 className="btn btn-link btn-animate text-muted"
415 onClick={linkEvent(this, this.handleShowAdvanced)}
416 data-tippy-content={i18n.t("more")}
417 aria-label={i18n.t("more")}
419 <Icon icon="more-vertical" classes="icon-inline" />
423 {!this.myComment && (
425 <button className="btn btn-link btn-animate">
427 className="text-muted"
428 to={`/create_private_message/${cv.creator.id}`}
429 title={i18n.t("message").toLowerCase()}
435 className="btn btn-link btn-animate text-muted"
438 this.handleShowReportDialog
440 data-tippy-content={i18n.t(
443 aria-label={i18n.t("show_report_dialog")}
448 className="btn btn-link btn-animate text-muted"
451 this.handleBlockUserClick
453 data-tippy-content={i18n.t("block_user")}
454 aria-label={i18n.t("block_user")}
456 <Icon icon="slash" />
461 className="btn btn-link btn-animate text-muted"
464 this.handleSaveCommentClick
467 cv.saved ? i18n.t("unsave") : i18n.t("save")
470 cv.saved ? i18n.t("unsave") : i18n.t("save")
473 {this.state.saveLoading ? (
478 classes={`icon-inline ${
479 cv.saved && "text-warning"
485 className="btn btn-link btn-animate text-muted"
486 onClick={linkEvent(this, this.handleViewSource)}
487 data-tippy-content={i18n.t("view_source")}
488 aria-label={i18n.t("view_source")}
492 classes={`icon-inline ${
493 this.state.viewSource && "text-success"
500 className="btn btn-link btn-animate text-muted"
501 onClick={linkEvent(this, this.handleEditClick)}
502 data-tippy-content={i18n.t("edit")}
503 aria-label={i18n.t("edit")}
505 <Icon icon="edit" classes="icon-inline" />
508 className="btn btn-link btn-animate text-muted"
511 this.handleDeleteClick
526 classes={`icon-inline ${
527 cv.comment.deleted && "text-danger"
532 {(canModOnSelf || canAdminOnSelf) && (
534 className="btn btn-link btn-animate text-muted"
537 this.handleDistinguishClick
540 !cv.comment.distinguished
541 ? i18n.t("distinguish")
542 : i18n.t("undistinguish")
545 !cv.comment.distinguished
546 ? i18n.t("distinguish")
547 : i18n.t("undistinguish")
552 classes={`icon-inline ${
553 cv.comment.distinguished && "text-danger"
560 {/* Admins and mods can remove comments */}
561 {(canMod_ || canAdmin_) && (
563 {!cv.comment.removed ? (
565 className="btn btn-link btn-animate text-muted"
568 this.handleModRemoveShow
570 aria-label={i18n.t("remove")}
576 className="btn btn-link btn-animate text-muted"
579 this.handleModRemoveSubmit
581 aria-label={i18n.t("restore")}
588 {/* Mods can ban from community, and appoint as mods to community */}
592 (!cv.creator_banned_from_community ? (
594 className="btn btn-link btn-animate text-muted"
597 this.handleModBanFromCommunityShow
599 aria-label={i18n.t("ban_from_community")}
601 {i18n.t("ban_from_community")}
605 className="btn btn-link btn-animate text-muted"
608 this.handleModBanFromCommunitySubmit
610 aria-label={i18n.t("unban")}
615 {!cv.creator_banned_from_community &&
616 (!this.state.showConfirmAppointAsMod ? (
618 className="btn btn-link btn-animate text-muted"
621 this.handleShowConfirmAppointAsMod
625 ? i18n.t("remove_as_mod")
626 : i18n.t("appoint_as_mod")
630 ? i18n.t("remove_as_mod")
631 : i18n.t("appoint_as_mod")}
636 className="btn btn-link btn-animate text-muted"
637 aria-label={i18n.t("are_you_sure")}
639 {i18n.t("are_you_sure")}
642 className="btn btn-link btn-animate text-muted"
645 this.handleAddModToCommunity
647 aria-label={i18n.t("yes")}
652 className="btn btn-link btn-animate text-muted"
655 this.handleCancelConfirmAppointAsMod
657 aria-label={i18n.t("no")}
665 {/* Community creators and admins can transfer community to another mod */}
666 {(amCommunityCreator_ || canAdmin_) &&
669 (!this.state.showConfirmTransferCommunity ? (
671 className="btn btn-link btn-animate text-muted"
674 this.handleShowConfirmTransferCommunity
676 aria-label={i18n.t("transfer_community")}
678 {i18n.t("transfer_community")}
683 className="btn btn-link btn-animate text-muted"
684 aria-label={i18n.t("are_you_sure")}
686 {i18n.t("are_you_sure")}
689 className="btn btn-link btn-animate text-muted"
692 this.handleTransferCommunity
694 aria-label={i18n.t("yes")}
699 className="btn btn-link btn-animate text-muted"
703 .handleCancelShowConfirmTransferCommunity
705 aria-label={i18n.t("no")}
711 {/* Admins can ban from all, and appoint other admins */}
717 className="btn btn-link btn-animate text-muted"
720 this.handlePurgePersonShow
722 aria-label={i18n.t("purge_user")}
724 {i18n.t("purge_user")}
727 className="btn btn-link btn-animate text-muted"
730 this.handlePurgeCommentShow
732 aria-label={i18n.t("purge_comment")}
734 {i18n.t("purge_comment")}
737 {!isBanned(cv.creator) ? (
739 className="btn btn-link btn-animate text-muted"
742 this.handleModBanShow
744 aria-label={i18n.t("ban_from_site")}
746 {i18n.t("ban_from_site")}
750 className="btn btn-link btn-animate text-muted"
753 this.handleModBanSubmit
755 aria-label={i18n.t("unban_from_site")}
757 {i18n.t("unban_from_site")}
762 {!isBanned(cv.creator) &&
764 (!this.state.showConfirmAppointAsAdmin ? (
766 className="btn btn-link btn-animate text-muted"
769 this.handleShowConfirmAppointAsAdmin
773 ? i18n.t("remove_as_admin")
774 : i18n.t("appoint_as_admin")
778 ? i18n.t("remove_as_admin")
779 : i18n.t("appoint_as_admin")}
783 <button className="btn btn-link btn-animate text-muted">
784 {i18n.t("are_you_sure")}
787 className="btn btn-link btn-animate text-muted"
792 aria-label={i18n.t("yes")}
797 className="btn btn-link btn-animate text-muted"
800 this.handleCancelConfirmAppointAsAdmin
802 aria-label={i18n.t("no")}
815 {/* end of button group */}
820 {showMoreChildren && (
822 className={`details ml-1 comment-node py-2 ${
823 !this.props.noBorder ? "border-top border-light" : ""
825 style={`border-left: 2px ${moreRepliesBorderColor} solid !important`}
828 className="btn btn-link text-muted"
829 onClick={linkEvent(this, this.handleFetchChildren)}
831 {i18n.t("x_more_replies", {
832 count: node.comment_view.counts.child_count,
833 formattedCount: numToSI(node.comment_view.counts.child_count),
839 {/* end of details */}
840 {this.state.showRemoveDialog && (
842 className="form-inline"
843 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
847 htmlFor={`mod-remove-reason-${cv.comment.id}`}
853 id={`mod-remove-reason-${cv.comment.id}`}
854 className="form-control mr-2"
855 placeholder={i18n.t("reason")}
856 value={this.state.removeReason}
857 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
861 className="btn btn-secondary"
862 aria-label={i18n.t("remove_comment")}
864 {i18n.t("remove_comment")}
868 {this.state.showReportDialog && (
870 className="form-inline"
871 onSubmit={linkEvent(this, this.handleReportSubmit)}
875 htmlFor={`report-reason-${cv.comment.id}`}
882 id={`report-reason-${cv.comment.id}`}
883 className="form-control mr-2"
884 placeholder={i18n.t("reason")}
885 value={this.state.reportReason}
886 onInput={linkEvent(this, this.handleReportReasonChange)}
890 className="btn btn-secondary"
891 aria-label={i18n.t("create_report")}
893 {i18n.t("create_report")}
897 {this.state.showBanDialog && (
898 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
899 <div className="form-group row col-12">
901 className="col-form-label"
902 htmlFor={`mod-ban-reason-${cv.comment.id}`}
908 id={`mod-ban-reason-${cv.comment.id}`}
909 className="form-control mr-2"
910 placeholder={i18n.t("reason")}
911 value={this.state.banReason}
912 onInput={linkEvent(this, this.handleModBanReasonChange)}
915 className="col-form-label"
916 htmlFor={`mod-ban-expires-${cv.comment.id}`}
922 id={`mod-ban-expires-${cv.comment.id}`}
923 className="form-control mr-2"
924 placeholder={i18n.t("number_of_days")}
925 value={this.state.banExpireDays}
926 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
928 <div className="form-group">
929 <div className="form-check">
931 className="form-check-input"
932 id="mod-ban-remove-data"
934 checked={this.state.removeData}
935 onChange={linkEvent(this, this.handleModRemoveDataChange)}
938 className="form-check-label"
939 htmlFor="mod-ban-remove-data"
940 title={i18n.t("remove_content_more")}
942 {i18n.t("remove_content")}
947 {/* TODO hold off on expires until later */}
948 {/* <div class="form-group row"> */}
949 {/* <label class="col-form-label">Expires</label> */}
950 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
952 <div className="form-group row">
955 className="btn btn-secondary"
956 aria-label={i18n.t("ban")}
958 {i18n.t("ban")} {cv.creator.name}
964 {this.state.showPurgeDialog && (
965 <form onSubmit={linkEvent(this, this.handlePurgeSubmit)}>
967 <label className="sr-only" htmlFor="purge-reason">
973 className="form-control my-3"
974 placeholder={i18n.t("reason")}
975 value={this.state.purgeReason}
976 onInput={linkEvent(this, this.handlePurgeReasonChange)}
978 <div className="form-group row col-12">
979 {this.state.purgeLoading ? (
984 className="btn btn-secondary"
985 aria-label={purgeTypeText}
993 {this.state.showReply && (
996 onReplyCancel={this.handleReplyCancel}
997 disabled={this.props.locked}
999 allLanguages={this.props.allLanguages}
1000 siteLanguages={this.props.siteLanguages}
1003 {!this.state.collapsed && node.children.length > 0 && (
1005 nodes={node.children}
1006 locked={this.props.locked}
1007 moderators={this.props.moderators}
1008 admins={this.props.admins}
1009 enableDownvotes={this.props.enableDownvotes}
1010 viewType={this.props.viewType}
1011 allLanguages={this.props.allLanguages}
1012 siteLanguages={this.props.siteLanguages}
1013 hideImages={this.props.hideImages}
1014 isChild={!this.props.noIndent}
1015 depth={this.props.node.depth + 1}
1018 {/* A collapsed clearfix */}
1019 {this.state.collapsed && <div className="row col-12" />}
1024 get commentReplyOrMentionRead(): boolean {
1025 let cv = this.props.node.comment_view;
1027 if (this.isPersonMentionType(cv)) {
1028 return cv.person_mention.read;
1029 } else if (this.isCommentReplyType(cv)) {
1030 return cv.comment_reply.read;
1036 linkBtn(small = false) {
1037 let cv = this.props.node.comment_view;
1038 let classnames = classNames("btn btn-link btn-animate text-muted", {
1042 let title = this.props.showContext
1043 ? i18n.t("show_context")
1046 // The context button should show the parent comment by default
1047 const parentCommentId = getCommentParentId(cv.comment) ?? cv.comment.id;
1052 className={classnames}
1053 to={`/comment/${parentCommentId}`}
1056 <Icon icon="link" classes="icon-inline" />
1059 <a className={classnames} title={title} href={cv.comment.ap_id}>
1060 <Icon icon="fedilink" classes="icon-inline" />
1071 get myComment(): boolean {
1073 UserService.Instance.myUserInfo?.local_user_view.person.id ==
1074 this.props.node.comment_view.creator.id
1078 get isPostCreator(): boolean {
1080 this.props.node.comment_view.creator.id ==
1081 this.props.node.comment_view.post.creator_id
1085 get commentUnlessRemoved(): string {
1086 let comment = this.props.node.comment_view.comment;
1087 return comment.removed
1088 ? `*${i18n.t("removed")}*`
1090 ? `*${i18n.t("deleted")}*`
1094 handleReplyClick(i: CommentNode) {
1095 i.setState({ showReply: true });
1098 handleEditClick(i: CommentNode) {
1099 i.setState({ showEdit: true });
1102 handleBlockUserClick(i: CommentNode) {
1103 let auth = myAuth();
1105 let blockUserForm: BlockPerson = {
1106 person_id: i.props.node.comment_view.creator.id,
1110 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1114 handleDeleteClick(i: CommentNode) {
1115 let comment = i.props.node.comment_view.comment;
1116 let auth = myAuth();
1118 let deleteForm: DeleteComment = {
1119 comment_id: comment.id,
1120 deleted: !comment.deleted,
1123 WebSocketService.Instance.send(wsClient.deleteComment(deleteForm));
1127 handleSaveCommentClick(i: CommentNode) {
1128 let cv = i.props.node.comment_view;
1129 let save = cv.saved == undefined ? true : !cv.saved;
1130 let auth = myAuth();
1132 let form: SaveComment = {
1133 comment_id: cv.comment.id,
1138 WebSocketService.Instance.send(wsClient.saveComment(form));
1140 i.setState({ saveLoading: true });
1144 handleReplyCancel() {
1145 this.setState({ showReply: false, showEdit: false });
1148 handleCommentUpvote(event: any) {
1149 event.preventDefault();
1150 let myVote = this.state.my_vote;
1151 let newVote = myVote == 1 ? 0 : 1;
1155 score: this.state.score - 1,
1156 upvotes: this.state.upvotes - 1,
1158 } else if (myVote == -1) {
1160 downvotes: this.state.downvotes - 1,
1161 upvotes: this.state.upvotes + 1,
1162 score: this.state.score + 2,
1166 score: this.state.score + 1,
1167 upvotes: this.state.upvotes + 1,
1171 this.setState({ my_vote: newVote });
1173 let auth = myAuth();
1175 let form: CreateCommentLike = {
1176 comment_id: this.props.node.comment_view.comment.id,
1180 WebSocketService.Instance.send(wsClient.likeComment(form));
1185 handleCommentDownvote(event: any) {
1186 event.preventDefault();
1187 let myVote = this.state.my_vote;
1188 let newVote = myVote == -1 ? 0 : -1;
1192 downvotes: this.state.downvotes + 1,
1193 upvotes: this.state.upvotes - 1,
1194 score: this.state.score - 2,
1196 } else if (myVote == -1) {
1198 downvotes: this.state.downvotes - 1,
1199 score: this.state.score + 1,
1203 downvotes: this.state.downvotes + 1,
1204 score: this.state.score - 1,
1208 this.setState({ my_vote: newVote });
1210 let auth = myAuth();
1212 let form: CreateCommentLike = {
1213 comment_id: this.props.node.comment_view.comment.id,
1218 WebSocketService.Instance.send(wsClient.likeComment(form));
1223 handleShowReportDialog(i: CommentNode) {
1224 i.setState({ showReportDialog: !i.state.showReportDialog });
1227 handleReportReasonChange(i: CommentNode, event: any) {
1228 i.setState({ reportReason: event.target.value });
1231 handleReportSubmit(i: CommentNode) {
1232 let comment = i.props.node.comment_view.comment;
1233 let reason = i.state.reportReason;
1234 let auth = myAuth();
1235 if (reason && auth) {
1236 let form: CreateCommentReport = {
1237 comment_id: comment.id,
1241 WebSocketService.Instance.send(wsClient.createCommentReport(form));
1242 i.setState({ showReportDialog: false });
1246 handleModRemoveShow(i: CommentNode) {
1248 showRemoveDialog: !i.state.showRemoveDialog,
1249 showBanDialog: false,
1253 handleModRemoveReasonChange(i: CommentNode, event: any) {
1254 i.setState({ removeReason: event.target.value });
1257 handleModRemoveDataChange(i: CommentNode, event: any) {
1258 i.setState({ removeData: event.target.checked });
1261 handleModRemoveSubmit(i: CommentNode) {
1262 let comment = i.props.node.comment_view.comment;
1263 let auth = myAuth();
1265 let form: RemoveComment = {
1266 comment_id: comment.id,
1267 removed: !comment.removed,
1268 reason: i.state.removeReason,
1271 WebSocketService.Instance.send(wsClient.removeComment(form));
1273 i.setState({ showRemoveDialog: false });
1277 handleDistinguishClick(i: CommentNode) {
1278 let comment = i.props.node.comment_view.comment;
1279 let auth = myAuth();
1281 let form: DistinguishComment = {
1282 comment_id: comment.id,
1283 distinguished: !comment.distinguished,
1286 WebSocketService.Instance.send(wsClient.editComment(form));
1287 i.setState(i.state);
1291 isPersonMentionType(
1292 item: CommentView | PersonMentionView | CommentReplyView
1293 ): item is PersonMentionView {
1294 return (item as PersonMentionView).person_mention?.id !== undefined;
1298 item: CommentView | PersonMentionView | CommentReplyView
1299 ): item is CommentReplyView {
1300 return (item as CommentReplyView).comment_reply?.id !== undefined;
1303 handleMarkRead(i: CommentNode) {
1304 let auth = myAuth();
1306 if (i.isPersonMentionType(i.props.node.comment_view)) {
1307 let form: MarkPersonMentionAsRead = {
1308 person_mention_id: i.props.node.comment_view.person_mention.id,
1309 read: !i.props.node.comment_view.person_mention.read,
1312 WebSocketService.Instance.send(wsClient.markPersonMentionAsRead(form));
1313 } else if (i.isCommentReplyType(i.props.node.comment_view)) {
1314 let form: MarkCommentReplyAsRead = {
1315 comment_reply_id: i.props.node.comment_view.comment_reply.id,
1316 read: !i.props.node.comment_view.comment_reply.read,
1319 WebSocketService.Instance.send(wsClient.markCommentReplyAsRead(form));
1322 i.setState({ readLoading: true });
1326 handleModBanFromCommunityShow(i: CommentNode) {
1328 showBanDialog: true,
1329 banType: BanType.Community,
1330 showRemoveDialog: false,
1334 handleModBanShow(i: CommentNode) {
1336 showBanDialog: true,
1337 banType: BanType.Site,
1338 showRemoveDialog: false,
1342 handleModBanReasonChange(i: CommentNode, event: any) {
1343 i.setState({ banReason: event.target.value });
1346 handleModBanExpireDaysChange(i: CommentNode, event: any) {
1347 i.setState({ banExpireDays: event.target.value });
1350 handleModBanFromCommunitySubmit(i: CommentNode) {
1351 i.setState({ banType: BanType.Community });
1352 i.handleModBanBothSubmit(i);
1355 handleModBanSubmit(i: CommentNode) {
1356 i.setState({ banType: BanType.Site });
1357 i.handleModBanBothSubmit(i);
1360 handleModBanBothSubmit(i: CommentNode) {
1361 let cv = i.props.node.comment_view;
1362 let auth = myAuth();
1364 if (i.state.banType == BanType.Community) {
1365 // If its an unban, restore all their data
1366 let ban = !cv.creator_banned_from_community;
1368 i.setState({ removeData: false });
1370 let form: BanFromCommunity = {
1371 person_id: cv.creator.id,
1372 community_id: cv.community.id,
1374 remove_data: i.state.removeData,
1375 reason: i.state.banReason,
1376 expires: futureDaysToUnixTime(i.state.banExpireDays),
1379 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1381 // If its an unban, restore all their data
1382 let ban = !cv.creator.banned;
1384 i.setState({ removeData: false });
1386 let form: BanPerson = {
1387 person_id: cv.creator.id,
1389 remove_data: i.state.removeData,
1390 reason: i.state.banReason,
1391 expires: futureDaysToUnixTime(i.state.banExpireDays),
1394 WebSocketService.Instance.send(wsClient.banPerson(form));
1397 i.setState({ showBanDialog: false });
1401 handlePurgePersonShow(i: CommentNode) {
1403 showPurgeDialog: true,
1404 purgeType: PurgeType.Person,
1405 showRemoveDialog: false,
1409 handlePurgeCommentShow(i: CommentNode) {
1411 showPurgeDialog: true,
1412 purgeType: PurgeType.Comment,
1413 showRemoveDialog: false,
1417 handlePurgeReasonChange(i: CommentNode, event: any) {
1418 i.setState({ purgeReason: event.target.value });
1421 handlePurgeSubmit(i: CommentNode, event: any) {
1422 event.preventDefault();
1423 let auth = myAuth();
1425 if (i.state.purgeType == PurgeType.Person) {
1426 let form: PurgePerson = {
1427 person_id: i.props.node.comment_view.creator.id,
1428 reason: i.state.purgeReason,
1431 WebSocketService.Instance.send(wsClient.purgePerson(form));
1432 } else if (i.state.purgeType == PurgeType.Comment) {
1433 let form: PurgeComment = {
1434 comment_id: i.props.node.comment_view.comment.id,
1435 reason: i.state.purgeReason,
1438 WebSocketService.Instance.send(wsClient.purgeComment(form));
1441 i.setState({ purgeLoading: true });
1445 handleShowConfirmAppointAsMod(i: CommentNode) {
1446 i.setState({ showConfirmAppointAsMod: true });
1449 handleCancelConfirmAppointAsMod(i: CommentNode) {
1450 i.setState({ showConfirmAppointAsMod: false });
1453 handleAddModToCommunity(i: CommentNode) {
1454 let cv = i.props.node.comment_view;
1455 let auth = myAuth();
1457 let form: AddModToCommunity = {
1458 person_id: cv.creator.id,
1459 community_id: cv.community.id,
1460 added: !isMod(cv.creator.id, i.props.moderators),
1463 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1464 i.setState({ showConfirmAppointAsMod: false });
1468 handleShowConfirmAppointAsAdmin(i: CommentNode) {
1469 i.setState({ showConfirmAppointAsAdmin: true });
1472 handleCancelConfirmAppointAsAdmin(i: CommentNode) {
1473 i.setState({ showConfirmAppointAsAdmin: false });
1476 handleAddAdmin(i: CommentNode) {
1477 let auth = myAuth();
1479 let creatorId = i.props.node.comment_view.creator.id;
1480 let form: AddAdmin = {
1481 person_id: creatorId,
1482 added: !isAdmin(creatorId, i.props.admins),
1485 WebSocketService.Instance.send(wsClient.addAdmin(form));
1486 i.setState({ showConfirmAppointAsAdmin: false });
1490 handleShowConfirmTransferCommunity(i: CommentNode) {
1491 i.setState({ showConfirmTransferCommunity: true });
1494 handleCancelShowConfirmTransferCommunity(i: CommentNode) {
1495 i.setState({ showConfirmTransferCommunity: false });
1498 handleTransferCommunity(i: CommentNode) {
1499 let cv = i.props.node.comment_view;
1500 let auth = myAuth();
1502 let form: TransferCommunity = {
1503 community_id: cv.community.id,
1504 person_id: cv.creator.id,
1507 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1508 i.setState({ showConfirmTransferCommunity: false });
1512 handleShowConfirmTransferSite(i: CommentNode) {
1513 i.setState({ showConfirmTransferSite: true });
1516 handleCancelShowConfirmTransferSite(i: CommentNode) {
1517 i.setState({ showConfirmTransferSite: false });
1520 get isCommentNew(): boolean {
1521 let now = moment.utc().subtract(10, "minutes");
1522 let then = moment.utc(this.props.node.comment_view.comment.published);
1523 return now.isBefore(then);
1526 handleCommentCollapse(i: CommentNode) {
1527 i.setState({ collapsed: !i.state.collapsed });
1531 handleViewSource(i: CommentNode) {
1532 i.setState({ viewSource: !i.state.viewSource });
1535 handleShowAdvanced(i: CommentNode) {
1536 i.setState({ showAdvanced: !i.state.showAdvanced });
1540 handleFetchChildren(i: CommentNode) {
1541 let form: GetComments = {
1542 post_id: i.props.node.comment_view.post.id,
1543 parent_id: i.props.node.comment_view.comment.id,
1544 max_depth: commentTreeMaxDepth,
1548 auth: myAuth(false),
1551 WebSocketService.Instance.send(wsClient.getComments(form));
1555 if (this.state.my_vote == 1) {
1557 } else if (this.state.my_vote == -1) {
1558 return "text-danger";
1560 return "text-muted";
1564 get pointsTippy(): string {
1565 let points = i18n.t("number_of_points", {
1566 count: Number(this.state.score),
1567 formattedCount: numToSI(this.state.score),
1570 let upvotes = i18n.t("number_of_upvotes", {
1571 count: Number(this.state.upvotes),
1572 formattedCount: numToSI(this.state.upvotes),
1575 let downvotes = i18n.t("number_of_downvotes", {
1576 count: Number(this.state.downvotes),
1577 formattedCount: numToSI(this.state.downvotes),
1580 return `${points} • ${upvotes} • ${downvotes}`;
1583 get expandText(): string {
1584 return this.state.collapsed ? i18n.t("expand") : i18n.t("collapse");