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 const 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 borderColor = this.props.node.depth
199 ? colorList[(this.props.node.depth - 1) % colorList.length]
201 const moreRepliesBorderColor = this.props.node.depth
202 ? colorList[this.props.node.depth % colorList.length]
205 const showMoreChildren =
206 this.props.viewType == CommentViewType.Tree &&
207 !this.state.collapsed &&
208 node.children.length == 0 &&
209 node.comment_view.counts.child_count > 0;
213 className={`comment ${
214 this.props.node.depth && !this.props.noIndent ? "ml-1" : ""
218 id={`comment-${cv.comment.id}`}
219 className={classNames(`details comment-node py-2`, {
220 "border-top border-light": !this.props.noBorder,
223 this.props.node.comment_view.comment.distinguished,
226 !this.props.noIndent && this.props.node.depth
227 ? `border-left: 2px ${borderColor} solid !important`
232 className={classNames({
233 "ml-2": !this.props.noIndent && this.props.node.depth,
236 <div className="d-flex flex-wrap align-items-center text-muted small">
238 className="btn btn-sm text-muted mr-2"
239 onClick={linkEvent(this, this.handleCommentCollapse)}
240 aria-label={this.expandText}
241 data-tippy-content={this.expandText}
244 icon={`${this.state.collapsed ? "plus" : "minus"}-square`}
245 classes="icon-inline"
248 <span className="mr-2">
249 <PersonListing person={cv.creator} />
251 {cv.comment.distinguished && (
252 <Icon icon="shield" inline classes={`text-danger mr-2`} />
254 {this.isPostCreator && (
255 <div className="badge badge-light d-none d-sm-inline mr-2">
260 <div className="badge d-none d-sm-inline mr-2">
265 <div className="badge d-none d-sm-inline mr-2">
269 {cv.creator.bot_account && (
270 <div className="badge d-none d-sm-inline mr-2">
271 {i18n.t("bot_account").toLowerCase()}
274 {this.props.showCommunity && (
276 <span className="mx-1">{i18n.t("to")}</span>
277 <CommunityLink community={cv.community} />
278 <span className="mx-2">•</span>
279 <Link className="mr-2" to={`/post/${cv.post.id}`}>
285 {cv.comment.language_id !== 0 && (
286 <span className="badge d-none d-sm-inline mr-2">
288 this.props.allLanguages.find(
289 lang => lang.id === cv.comment.language_id
294 {/* This is an expanding spacer for mobile */}
295 <div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
299 className={`unselectable pointer ${this.scoreColor}`}
300 onClick={this.handleCommentUpvote}
301 data-tippy-content={this.pointsTippy}
304 className="mr-1 font-weight-bold"
305 aria-label={i18n.t("number_of_points", {
306 count: Number(this.state.score),
307 formattedCount: numToSI(this.state.score),
310 {numToSI(this.state.score)}
313 <span className="mr-1">•</span>
318 published={cv.comment.published}
319 updated={cv.comment.updated}
323 {/* end of user row */}
324 {this.state.showEdit && (
328 onReplyCancel={this.handleReplyCancel}
329 disabled={this.props.locked}
331 allLanguages={this.props.allLanguages}
332 siteLanguages={this.props.siteLanguages}
335 {!this.state.showEdit && !this.state.collapsed && (
337 {this.state.viewSource ? (
338 <pre>{this.commentUnlessRemoved}</pre>
342 dangerouslySetInnerHTML={
343 this.props.hideImages
344 ? mdToHtmlNoImages(this.commentUnlessRemoved)
345 : mdToHtml(this.commentUnlessRemoved)
349 <div className="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold">
350 {this.props.showContext && this.linkBtn()}
351 {this.props.markable && (
353 className="btn btn-link btn-animate text-muted"
354 onClick={linkEvent(this, this.handleMarkRead)}
356 this.commentReplyOrMentionRead
357 ? i18n.t("mark_as_unread")
358 : i18n.t("mark_as_read")
361 this.commentReplyOrMentionRead
362 ? i18n.t("mark_as_unread")
363 : i18n.t("mark_as_read")
366 {this.state.readLoading ? (
371 classes={`icon-inline ${
372 this.commentReplyOrMentionRead && "text-success"
378 {UserService.Instance.myUserInfo && !this.props.viewOnly && (
381 className={`btn btn-link btn-animate ${
382 this.state.my_vote === 1 ? "text-info" : "text-muted"
384 onClick={this.handleCommentUpvote}
385 data-tippy-content={i18n.t("upvote")}
386 aria-label={i18n.t("upvote")}
387 aria-pressed={this.state.my_vote === 1}
389 <Icon icon="arrow-up1" classes="icon-inline" />
391 this.state.upvotes !== this.state.score && (
392 <span className="ml-1">
393 {numToSI(this.state.upvotes)}
397 {this.props.enableDownvotes && (
399 className={`btn btn-link btn-animate ${
400 this.state.my_vote === -1
404 onClick={this.handleCommentDownvote}
405 data-tippy-content={i18n.t("downvote")}
406 aria-label={i18n.t("downvote")}
407 aria-pressed={this.state.my_vote === -1}
409 <Icon icon="arrow-down1" classes="icon-inline" />
411 this.state.upvotes !== this.state.score && (
412 <span className="ml-1">
413 {numToSI(this.state.downvotes)}
419 className="btn btn-link btn-animate text-muted"
420 onClick={linkEvent(this, this.handleReplyClick)}
421 data-tippy-content={i18n.t("reply")}
422 aria-label={i18n.t("reply")}
424 <Icon icon="reply1" classes="icon-inline" />
426 {!this.state.showAdvanced ? (
428 className="btn btn-link btn-animate text-muted"
429 onClick={linkEvent(this, this.handleShowAdvanced)}
430 data-tippy-content={i18n.t("more")}
431 aria-label={i18n.t("more")}
433 <Icon icon="more-vertical" classes="icon-inline" />
437 {!this.myComment && (
440 className="btn btn-link btn-animate text-muted"
441 to={`/create_private_message/${cv.creator.id}`}
442 title={i18n.t("message").toLowerCase()}
447 className="btn btn-link btn-animate text-muted"
450 this.handleShowReportDialog
452 data-tippy-content={i18n.t(
455 aria-label={i18n.t("show_report_dialog")}
460 className="btn btn-link btn-animate text-muted"
463 this.handleBlockUserClick
465 data-tippy-content={i18n.t("block_user")}
466 aria-label={i18n.t("block_user")}
468 <Icon icon="slash" />
473 className="btn btn-link btn-animate text-muted"
476 this.handleSaveCommentClick
479 cv.saved ? i18n.t("unsave") : i18n.t("save")
482 cv.saved ? i18n.t("unsave") : i18n.t("save")
485 {this.state.saveLoading ? (
490 classes={`icon-inline ${
491 cv.saved && "text-warning"
497 className="btn btn-link btn-animate text-muted"
498 onClick={linkEvent(this, this.handleViewSource)}
499 data-tippy-content={i18n.t("view_source")}
500 aria-label={i18n.t("view_source")}
504 classes={`icon-inline ${
505 this.state.viewSource && "text-success"
512 className="btn btn-link btn-animate text-muted"
513 onClick={linkEvent(this, this.handleEditClick)}
514 data-tippy-content={i18n.t("edit")}
515 aria-label={i18n.t("edit")}
517 <Icon icon="edit" classes="icon-inline" />
520 className="btn btn-link btn-animate text-muted"
523 this.handleDeleteClick
538 classes={`icon-inline ${
539 cv.comment.deleted && "text-danger"
544 {(canModOnSelf || canAdminOnSelf) && (
546 className="btn btn-link btn-animate text-muted"
549 this.handleDistinguishClick
552 !cv.comment.distinguished
553 ? i18n.t("distinguish")
554 : i18n.t("undistinguish")
557 !cv.comment.distinguished
558 ? i18n.t("distinguish")
559 : i18n.t("undistinguish")
564 classes={`icon-inline ${
565 cv.comment.distinguished && "text-danger"
572 {/* Admins and mods can remove comments */}
573 {(canMod_ || canAdmin_) && (
575 {!cv.comment.removed ? (
577 className="btn btn-link btn-animate text-muted"
580 this.handleModRemoveShow
582 aria-label={i18n.t("remove")}
588 className="btn btn-link btn-animate text-muted"
591 this.handleModRemoveSubmit
593 aria-label={i18n.t("restore")}
600 {/* Mods can ban from community, and appoint as mods to community */}
604 (!cv.creator_banned_from_community ? (
606 className="btn btn-link btn-animate text-muted"
609 this.handleModBanFromCommunityShow
611 aria-label={i18n.t("ban_from_community")}
613 {i18n.t("ban_from_community")}
617 className="btn btn-link btn-animate text-muted"
620 this.handleModBanFromCommunitySubmit
622 aria-label={i18n.t("unban")}
627 {!cv.creator_banned_from_community &&
628 (!this.state.showConfirmAppointAsMod ? (
630 className="btn btn-link btn-animate text-muted"
633 this.handleShowConfirmAppointAsMod
637 ? i18n.t("remove_as_mod")
638 : i18n.t("appoint_as_mod")
642 ? i18n.t("remove_as_mod")
643 : i18n.t("appoint_as_mod")}
648 className="btn btn-link btn-animate text-muted"
649 aria-label={i18n.t("are_you_sure")}
651 {i18n.t("are_you_sure")}
654 className="btn btn-link btn-animate text-muted"
657 this.handleAddModToCommunity
659 aria-label={i18n.t("yes")}
664 className="btn btn-link btn-animate text-muted"
667 this.handleCancelConfirmAppointAsMod
669 aria-label={i18n.t("no")}
677 {/* Community creators and admins can transfer community to another mod */}
678 {(amCommunityCreator_ || canAdmin_) &&
681 (!this.state.showConfirmTransferCommunity ? (
683 className="btn btn-link btn-animate text-muted"
686 this.handleShowConfirmTransferCommunity
688 aria-label={i18n.t("transfer_community")}
690 {i18n.t("transfer_community")}
695 className="btn btn-link btn-animate text-muted"
696 aria-label={i18n.t("are_you_sure")}
698 {i18n.t("are_you_sure")}
701 className="btn btn-link btn-animate text-muted"
704 this.handleTransferCommunity
706 aria-label={i18n.t("yes")}
711 className="btn btn-link btn-animate text-muted"
715 .handleCancelShowConfirmTransferCommunity
717 aria-label={i18n.t("no")}
723 {/* Admins can ban from all, and appoint other admins */}
729 className="btn btn-link btn-animate text-muted"
732 this.handlePurgePersonShow
734 aria-label={i18n.t("purge_user")}
736 {i18n.t("purge_user")}
739 className="btn btn-link btn-animate text-muted"
742 this.handlePurgeCommentShow
744 aria-label={i18n.t("purge_comment")}
746 {i18n.t("purge_comment")}
749 {!isBanned(cv.creator) ? (
751 className="btn btn-link btn-animate text-muted"
754 this.handleModBanShow
756 aria-label={i18n.t("ban_from_site")}
758 {i18n.t("ban_from_site")}
762 className="btn btn-link btn-animate text-muted"
765 this.handleModBanSubmit
767 aria-label={i18n.t("unban_from_site")}
769 {i18n.t("unban_from_site")}
774 {!isBanned(cv.creator) &&
776 (!this.state.showConfirmAppointAsAdmin ? (
778 className="btn btn-link btn-animate text-muted"
781 this.handleShowConfirmAppointAsAdmin
785 ? i18n.t("remove_as_admin")
786 : i18n.t("appoint_as_admin")
790 ? i18n.t("remove_as_admin")
791 : i18n.t("appoint_as_admin")}
795 <button className="btn btn-link btn-animate text-muted">
796 {i18n.t("are_you_sure")}
799 className="btn btn-link btn-animate text-muted"
804 aria-label={i18n.t("yes")}
809 className="btn btn-link btn-animate text-muted"
812 this.handleCancelConfirmAppointAsAdmin
814 aria-label={i18n.t("no")}
827 {/* end of button group */}
832 {showMoreChildren && (
834 className={`details ml-1 comment-node py-2 ${
835 !this.props.noBorder ? "border-top border-light" : ""
837 style={`border-left: 2px ${moreRepliesBorderColor} solid !important`}
840 className="btn btn-link text-muted"
841 onClick={linkEvent(this, this.handleFetchChildren)}
843 {i18n.t("x_more_replies", {
844 count: node.comment_view.counts.child_count,
845 formattedCount: numToSI(node.comment_view.counts.child_count),
851 {/* end of details */}
852 {this.state.showRemoveDialog && (
854 className="form-inline"
855 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
859 htmlFor={`mod-remove-reason-${cv.comment.id}`}
865 id={`mod-remove-reason-${cv.comment.id}`}
866 className="form-control mr-2"
867 placeholder={i18n.t("reason")}
868 value={this.state.removeReason}
869 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
873 className="btn btn-secondary"
874 aria-label={i18n.t("remove_comment")}
876 {i18n.t("remove_comment")}
880 {this.state.showReportDialog && (
882 className="form-inline"
883 onSubmit={linkEvent(this, this.handleReportSubmit)}
887 htmlFor={`report-reason-${cv.comment.id}`}
894 id={`report-reason-${cv.comment.id}`}
895 className="form-control mr-2"
896 placeholder={i18n.t("reason")}
897 value={this.state.reportReason}
898 onInput={linkEvent(this, this.handleReportReasonChange)}
902 className="btn btn-secondary"
903 aria-label={i18n.t("create_report")}
905 {i18n.t("create_report")}
909 {this.state.showBanDialog && (
910 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
911 <div className="form-group row col-12">
913 className="col-form-label"
914 htmlFor={`mod-ban-reason-${cv.comment.id}`}
920 id={`mod-ban-reason-${cv.comment.id}`}
921 className="form-control mr-2"
922 placeholder={i18n.t("reason")}
923 value={this.state.banReason}
924 onInput={linkEvent(this, this.handleModBanReasonChange)}
927 className="col-form-label"
928 htmlFor={`mod-ban-expires-${cv.comment.id}`}
934 id={`mod-ban-expires-${cv.comment.id}`}
935 className="form-control mr-2"
936 placeholder={i18n.t("number_of_days")}
937 value={this.state.banExpireDays}
938 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
940 <div className="form-group">
941 <div className="form-check">
943 className="form-check-input"
944 id="mod-ban-remove-data"
946 checked={this.state.removeData}
947 onChange={linkEvent(this, this.handleModRemoveDataChange)}
950 className="form-check-label"
951 htmlFor="mod-ban-remove-data"
952 title={i18n.t("remove_content_more")}
954 {i18n.t("remove_content")}
959 {/* TODO hold off on expires until later */}
960 {/* <div class="form-group row"> */}
961 {/* <label class="col-form-label">Expires</label> */}
962 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
964 <div className="form-group row">
967 className="btn btn-secondary"
968 aria-label={i18n.t("ban")}
970 {i18n.t("ban")} {cv.creator.name}
976 {this.state.showPurgeDialog && (
977 <form onSubmit={linkEvent(this, this.handlePurgeSubmit)}>
979 <label className="sr-only" htmlFor="purge-reason">
985 className="form-control my-3"
986 placeholder={i18n.t("reason")}
987 value={this.state.purgeReason}
988 onInput={linkEvent(this, this.handlePurgeReasonChange)}
990 <div className="form-group row col-12">
991 {this.state.purgeLoading ? (
996 className="btn btn-secondary"
997 aria-label={purgeTypeText}
1005 {this.state.showReply && (
1008 onReplyCancel={this.handleReplyCancel}
1009 disabled={this.props.locked}
1011 allLanguages={this.props.allLanguages}
1012 siteLanguages={this.props.siteLanguages}
1015 {!this.state.collapsed && node.children.length > 0 && (
1017 nodes={node.children}
1018 locked={this.props.locked}
1019 moderators={this.props.moderators}
1020 admins={this.props.admins}
1021 enableDownvotes={this.props.enableDownvotes}
1022 viewType={this.props.viewType}
1023 allLanguages={this.props.allLanguages}
1024 siteLanguages={this.props.siteLanguages}
1025 hideImages={this.props.hideImages}
1028 {/* A collapsed clearfix */}
1029 {this.state.collapsed && <div className="row col-12"></div>}
1034 get commentReplyOrMentionRead(): boolean {
1035 const cv = this.props.node.comment_view;
1037 if (this.isPersonMentionType(cv)) {
1038 return cv.person_mention.read;
1039 } else if (this.isCommentReplyType(cv)) {
1040 return cv.comment_reply.read;
1046 linkBtn(small = false) {
1047 const cv = this.props.node.comment_view;
1048 const classnames = classNames("btn btn-link btn-animate text-muted", {
1052 const title = this.props.showContext
1053 ? i18n.t("show_context")
1056 // The context button should show the parent comment by default
1057 const parentCommentId = getCommentParentId(cv.comment) ?? cv.comment.id;
1062 className={classnames}
1063 to={`/comment/${parentCommentId}`}
1066 <Icon icon="link" classes="icon-inline" />
1069 <a className={classnames} title={title} href={cv.comment.ap_id}>
1070 <Icon icon="fedilink" classes="icon-inline" />
1081 get myComment(): boolean {
1083 UserService.Instance.myUserInfo?.local_user_view.person.id ==
1084 this.props.node.comment_view.creator.id
1088 get isPostCreator(): boolean {
1090 this.props.node.comment_view.creator.id ==
1091 this.props.node.comment_view.post.creator_id
1095 get commentUnlessRemoved(): string {
1096 const comment = this.props.node.comment_view.comment;
1097 return comment.removed
1098 ? `*${i18n.t("removed")}*`
1100 ? `*${i18n.t("deleted")}*`
1104 handleReplyClick(i: CommentNode) {
1105 i.setState({ showReply: true });
1108 handleEditClick(i: CommentNode) {
1109 i.setState({ showEdit: true });
1112 handleBlockUserClick(i: CommentNode) {
1113 const auth = myAuth();
1115 const blockUserForm: BlockPerson = {
1116 person_id: i.props.node.comment_view.creator.id,
1120 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
1124 handleDeleteClick(i: CommentNode) {
1125 const comment = i.props.node.comment_view.comment;
1126 const auth = myAuth();
1128 const deleteForm: DeleteComment = {
1129 comment_id: comment.id,
1130 deleted: !comment.deleted,
1133 WebSocketService.Instance.send(wsClient.deleteComment(deleteForm));
1137 handleSaveCommentClick(i: CommentNode) {
1138 const cv = i.props.node.comment_view;
1139 const save = cv.saved == undefined ? true : !cv.saved;
1140 const auth = myAuth();
1142 const form: SaveComment = {
1143 comment_id: cv.comment.id,
1148 WebSocketService.Instance.send(wsClient.saveComment(form));
1150 i.setState({ saveLoading: true });
1154 handleReplyCancel() {
1155 this.setState({ showReply: false, showEdit: false });
1158 handleCommentUpvote(event: any) {
1159 event.preventDefault();
1160 const myVote = this.state.my_vote;
1161 const newVote = myVote == 1 ? 0 : 1;
1165 score: this.state.score - 1,
1166 upvotes: this.state.upvotes - 1,
1168 } else if (myVote == -1) {
1170 downvotes: this.state.downvotes - 1,
1171 upvotes: this.state.upvotes + 1,
1172 score: this.state.score + 2,
1176 score: this.state.score + 1,
1177 upvotes: this.state.upvotes + 1,
1181 this.setState({ my_vote: newVote });
1183 const auth = myAuth();
1185 const form: CreateCommentLike = {
1186 comment_id: this.props.node.comment_view.comment.id,
1190 WebSocketService.Instance.send(wsClient.likeComment(form));
1195 handleCommentDownvote(event: any) {
1196 event.preventDefault();
1197 const myVote = this.state.my_vote;
1198 const newVote = myVote == -1 ? 0 : -1;
1202 downvotes: this.state.downvotes + 1,
1203 upvotes: this.state.upvotes - 1,
1204 score: this.state.score - 2,
1206 } else if (myVote == -1) {
1208 downvotes: this.state.downvotes - 1,
1209 score: this.state.score + 1,
1213 downvotes: this.state.downvotes + 1,
1214 score: this.state.score - 1,
1218 this.setState({ my_vote: newVote });
1220 const auth = myAuth();
1222 const form: CreateCommentLike = {
1223 comment_id: this.props.node.comment_view.comment.id,
1228 WebSocketService.Instance.send(wsClient.likeComment(form));
1233 handleShowReportDialog(i: CommentNode) {
1234 i.setState({ showReportDialog: !i.state.showReportDialog });
1237 handleReportReasonChange(i: CommentNode, event: any) {
1238 i.setState({ reportReason: event.target.value });
1241 handleReportSubmit(i: CommentNode) {
1242 const comment = i.props.node.comment_view.comment;
1243 const reason = i.state.reportReason;
1244 const auth = myAuth();
1245 if (reason && auth) {
1246 const form: CreateCommentReport = {
1247 comment_id: comment.id,
1251 WebSocketService.Instance.send(wsClient.createCommentReport(form));
1252 i.setState({ showReportDialog: false });
1256 handleModRemoveShow(i: CommentNode) {
1258 showRemoveDialog: !i.state.showRemoveDialog,
1259 showBanDialog: false,
1263 handleModRemoveReasonChange(i: CommentNode, event: any) {
1264 i.setState({ removeReason: event.target.value });
1267 handleModRemoveDataChange(i: CommentNode, event: any) {
1268 i.setState({ removeData: event.target.checked });
1271 handleModRemoveSubmit(i: CommentNode) {
1272 const comment = i.props.node.comment_view.comment;
1273 const auth = myAuth();
1275 const form: RemoveComment = {
1276 comment_id: comment.id,
1277 removed: !comment.removed,
1278 reason: i.state.removeReason,
1281 WebSocketService.Instance.send(wsClient.removeComment(form));
1283 i.setState({ showRemoveDialog: false });
1287 handleDistinguishClick(i: CommentNode) {
1288 const comment = i.props.node.comment_view.comment;
1289 const auth = myAuth();
1291 const form: DistinguishComment = {
1292 comment_id: comment.id,
1293 distinguished: !comment.distinguished,
1296 WebSocketService.Instance.send(wsClient.editComment(form));
1297 i.setState(i.state);
1301 isPersonMentionType(
1302 item: CommentView | PersonMentionView | CommentReplyView
1303 ): item is PersonMentionView {
1304 return (item as PersonMentionView).person_mention?.id !== undefined;
1308 item: CommentView | PersonMentionView | CommentReplyView
1309 ): item is CommentReplyView {
1310 return (item as CommentReplyView).comment_reply?.id !== undefined;
1313 handleMarkRead(i: CommentNode) {
1314 const auth = myAuth();
1316 if (i.isPersonMentionType(i.props.node.comment_view)) {
1317 const form: MarkPersonMentionAsRead = {
1318 person_mention_id: i.props.node.comment_view.person_mention.id,
1319 read: !i.props.node.comment_view.person_mention.read,
1322 WebSocketService.Instance.send(wsClient.markPersonMentionAsRead(form));
1323 } else if (i.isCommentReplyType(i.props.node.comment_view)) {
1324 const form: MarkCommentReplyAsRead = {
1325 comment_reply_id: i.props.node.comment_view.comment_reply.id,
1326 read: !i.props.node.comment_view.comment_reply.read,
1329 WebSocketService.Instance.send(wsClient.markCommentReplyAsRead(form));
1332 i.setState({ readLoading: true });
1336 handleModBanFromCommunityShow(i: CommentNode) {
1338 showBanDialog: true,
1339 banType: BanType.Community,
1340 showRemoveDialog: false,
1344 handleModBanShow(i: CommentNode) {
1346 showBanDialog: true,
1347 banType: BanType.Site,
1348 showRemoveDialog: false,
1352 handleModBanReasonChange(i: CommentNode, event: any) {
1353 i.setState({ banReason: event.target.value });
1356 handleModBanExpireDaysChange(i: CommentNode, event: any) {
1357 i.setState({ banExpireDays: event.target.value });
1360 handleModBanFromCommunitySubmit(i: CommentNode) {
1361 i.setState({ banType: BanType.Community });
1362 i.handleModBanBothSubmit(i);
1365 handleModBanSubmit(i: CommentNode) {
1366 i.setState({ banType: BanType.Site });
1367 i.handleModBanBothSubmit(i);
1370 handleModBanBothSubmit(i: CommentNode) {
1371 const cv = i.props.node.comment_view;
1372 const auth = myAuth();
1374 if (i.state.banType == BanType.Community) {
1375 // If its an unban, restore all their data
1376 const ban = !cv.creator_banned_from_community;
1378 i.setState({ removeData: false });
1380 const form: BanFromCommunity = {
1381 person_id: cv.creator.id,
1382 community_id: cv.community.id,
1384 remove_data: i.state.removeData,
1385 reason: i.state.banReason,
1386 expires: futureDaysToUnixTime(i.state.banExpireDays),
1389 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1391 // If its an unban, restore all their data
1392 const ban = !cv.creator.banned;
1394 i.setState({ removeData: false });
1396 const form: BanPerson = {
1397 person_id: cv.creator.id,
1399 remove_data: i.state.removeData,
1400 reason: i.state.banReason,
1401 expires: futureDaysToUnixTime(i.state.banExpireDays),
1404 WebSocketService.Instance.send(wsClient.banPerson(form));
1407 i.setState({ showBanDialog: false });
1411 handlePurgePersonShow(i: CommentNode) {
1413 showPurgeDialog: true,
1414 purgeType: PurgeType.Person,
1415 showRemoveDialog: false,
1419 handlePurgeCommentShow(i: CommentNode) {
1421 showPurgeDialog: true,
1422 purgeType: PurgeType.Comment,
1423 showRemoveDialog: false,
1427 handlePurgeReasonChange(i: CommentNode, event: any) {
1428 i.setState({ purgeReason: event.target.value });
1431 handlePurgeSubmit(i: CommentNode, event: any) {
1432 event.preventDefault();
1433 const auth = myAuth();
1435 if (i.state.purgeType == PurgeType.Person) {
1436 const form: PurgePerson = {
1437 person_id: i.props.node.comment_view.creator.id,
1438 reason: i.state.purgeReason,
1441 WebSocketService.Instance.send(wsClient.purgePerson(form));
1442 } else if (i.state.purgeType == PurgeType.Comment) {
1443 const form: PurgeComment = {
1444 comment_id: i.props.node.comment_view.comment.id,
1445 reason: i.state.purgeReason,
1448 WebSocketService.Instance.send(wsClient.purgeComment(form));
1451 i.setState({ purgeLoading: true });
1455 handleShowConfirmAppointAsMod(i: CommentNode) {
1456 i.setState({ showConfirmAppointAsMod: true });
1459 handleCancelConfirmAppointAsMod(i: CommentNode) {
1460 i.setState({ showConfirmAppointAsMod: false });
1463 handleAddModToCommunity(i: CommentNode) {
1464 const cv = i.props.node.comment_view;
1465 const auth = myAuth();
1467 const form: AddModToCommunity = {
1468 person_id: cv.creator.id,
1469 community_id: cv.community.id,
1470 added: !isMod(cv.creator.id, i.props.moderators),
1473 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1474 i.setState({ showConfirmAppointAsMod: false });
1478 handleShowConfirmAppointAsAdmin(i: CommentNode) {
1479 i.setState({ showConfirmAppointAsAdmin: true });
1482 handleCancelConfirmAppointAsAdmin(i: CommentNode) {
1483 i.setState({ showConfirmAppointAsAdmin: false });
1486 handleAddAdmin(i: CommentNode) {
1487 const auth = myAuth();
1489 const creatorId = i.props.node.comment_view.creator.id;
1490 const form: AddAdmin = {
1491 person_id: creatorId,
1492 added: !isAdmin(creatorId, i.props.admins),
1495 WebSocketService.Instance.send(wsClient.addAdmin(form));
1496 i.setState({ showConfirmAppointAsAdmin: false });
1500 handleShowConfirmTransferCommunity(i: CommentNode) {
1501 i.setState({ showConfirmTransferCommunity: true });
1504 handleCancelShowConfirmTransferCommunity(i: CommentNode) {
1505 i.setState({ showConfirmTransferCommunity: false });
1508 handleTransferCommunity(i: CommentNode) {
1509 const cv = i.props.node.comment_view;
1510 const auth = myAuth();
1512 const form: TransferCommunity = {
1513 community_id: cv.community.id,
1514 person_id: cv.creator.id,
1517 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1518 i.setState({ showConfirmTransferCommunity: false });
1522 handleShowConfirmTransferSite(i: CommentNode) {
1523 i.setState({ showConfirmTransferSite: true });
1526 handleCancelShowConfirmTransferSite(i: CommentNode) {
1527 i.setState({ showConfirmTransferSite: false });
1530 get isCommentNew(): boolean {
1531 const now = moment.utc().subtract(10, "minutes");
1532 const then = moment.utc(this.props.node.comment_view.comment.published);
1533 return now.isBefore(then);
1536 handleCommentCollapse(i: CommentNode) {
1537 i.setState({ collapsed: !i.state.collapsed });
1541 handleViewSource(i: CommentNode) {
1542 i.setState({ viewSource: !i.state.viewSource });
1545 handleShowAdvanced(i: CommentNode) {
1546 i.setState({ showAdvanced: !i.state.showAdvanced });
1550 handleFetchChildren(i: CommentNode) {
1551 const form: GetComments = {
1552 post_id: i.props.node.comment_view.post.id,
1553 parent_id: i.props.node.comment_view.comment.id,
1554 max_depth: commentTreeMaxDepth,
1558 auth: myAuth(false),
1561 WebSocketService.Instance.send(wsClient.getComments(form));
1565 if (this.state.my_vote == 1) {
1567 } else if (this.state.my_vote == -1) {
1568 return "text-danger";
1570 return "text-muted";
1574 get pointsTippy(): string {
1575 const points = i18n.t("number_of_points", {
1576 count: Number(this.state.score),
1577 formattedCount: numToSI(this.state.score),
1580 const upvotes = i18n.t("number_of_upvotes", {
1581 count: Number(this.state.upvotes),
1582 formattedCount: numToSI(this.state.upvotes),
1585 const downvotes = i18n.t("number_of_downvotes", {
1586 count: Number(this.state.downvotes),
1587 formattedCount: numToSI(this.state.downvotes),
1590 return `${points} • ${upvotes} • ${downvotes}`;
1593 get expandText(): string {
1594 return this.state.collapsed ? i18n.t("expand") : i18n.t("collapse");