8 import { futureDaysToUnixTime, numToSI } from "@utils/helpers";
16 } from "@utils/roles";
17 import classNames from "classnames";
18 import isBefore from "date-fns/isBefore";
19 import parseISO from "date-fns/parseISO";
20 import subMinutes from "date-fns/subMinutes";
21 import { Component, InfernoNode, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
32 CommunityModeratorView,
41 MarkCommentReplyAsRead,
42 MarkPersonMentionAsRead,
50 } from "lemmy-js-client";
51 import deepEqual from "lodash.isequal";
52 import { commentTreeMaxDepth } from "../../config";
59 } from "../../interfaces";
60 import { mdToHtml, mdToHtmlNoImages } from "../../markdown";
61 import { I18NextService, UserService } from "../../services";
62 import { setupTippy } from "../../tippy";
63 import { Icon, PurgeWarning, Spinner } from "../common/icon";
64 import { MomentTime } from "../common/moment-time";
65 import { VoteButtonsCompact } from "../common/vote-buttons";
66 import { CommunityLink } from "../community/community-link";
67 import { PersonListing } from "../person/person-listing";
68 import { CommentForm } from "./comment-form";
69 import { CommentNodes } from "./comment-nodes";
71 interface CommentNodeState {
74 showRemoveDialog: boolean;
75 removeReason?: string;
76 showBanDialog: boolean;
79 banExpireDays?: number;
81 showPurgeDialog: boolean;
84 showConfirmTransferSite: boolean;
85 showConfirmTransferCommunity: boolean;
86 showConfirmAppointAsMod: boolean;
87 showConfirmAppointAsAdmin: boolean;
90 showAdvanced: boolean;
91 showReportDialog: boolean;
92 reportReason?: string;
93 createOrEditCommentLoading: boolean;
94 upvoteLoading: boolean;
95 downvoteLoading: boolean;
98 blockPersonLoading: boolean;
99 deleteLoading: boolean;
100 removeLoading: boolean;
101 distinguishLoading: boolean;
103 addModLoading: boolean;
104 addAdminLoading: boolean;
105 transferCommunityLoading: boolean;
106 fetchChildrenLoading: boolean;
107 reportLoading: boolean;
108 purgeLoading: boolean;
111 interface CommentNodeProps {
113 moderators?: CommunityModeratorView[];
114 admins?: PersonView[];
120 showContext?: boolean;
121 showCommunity?: boolean;
122 enableDownvotes?: boolean;
123 viewType: CommentViewType;
124 allLanguages: Language[];
125 siteLanguages: number[];
126 hideImages?: boolean;
127 finished: Map<CommentId, boolean | undefined>;
128 onSaveComment(form: SaveComment): void;
129 onCommentReplyRead(form: MarkCommentReplyAsRead): void;
130 onPersonMentionRead(form: MarkPersonMentionAsRead): void;
131 onCreateComment(form: EditComment | CreateComment): void;
132 onEditComment(form: EditComment | CreateComment): void;
133 onCommentVote(form: CreateCommentLike): void;
134 onBlockPerson(form: BlockPerson): void;
135 onDeleteComment(form: DeleteComment): void;
136 onRemoveComment(form: RemoveComment): void;
137 onDistinguishComment(form: DistinguishComment): void;
138 onAddModToCommunity(form: AddModToCommunity): void;
139 onAddAdmin(form: AddAdmin): void;
140 onBanPersonFromCommunity(form: BanFromCommunity): void;
141 onBanPerson(form: BanPerson): void;
142 onTransferCommunity(form: TransferCommunity): void;
143 onFetchChildren?(form: GetComments): void;
144 onCommentReport(form: CreateCommentReport): void;
145 onPurgePerson(form: PurgePerson): void;
146 onPurgeComment(form: PurgeComment): void;
149 export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
150 state: CommentNodeState = {
153 showRemoveDialog: false,
154 showBanDialog: false,
156 banType: BanType.Community,
157 showPurgeDialog: false,
158 purgeType: PurgeType.Person,
162 showConfirmTransferSite: false,
163 showConfirmTransferCommunity: false,
164 showConfirmAppointAsMod: false,
165 showConfirmAppointAsAdmin: false,
166 showReportDialog: false,
167 createOrEditCommentLoading: false,
168 upvoteLoading: false,
169 downvoteLoading: false,
172 blockPersonLoading: false,
173 deleteLoading: false,
174 removeLoading: false,
175 distinguishLoading: false,
177 addModLoading: false,
178 addAdminLoading: false,
179 transferCommunityLoading: false,
180 fetchChildrenLoading: false,
181 reportLoading: false,
185 constructor(props: any, context: any) {
186 super(props, context);
188 this.handleReplyCancel = this.handleReplyCancel.bind(this);
191 get commentView(): CommentView {
192 return this.props.node.comment_view;
195 get commentId(): CommentId {
196 return this.commentView.comment.id;
199 componentWillReceiveProps(
200 nextProps: Readonly<{ children?: InfernoNode } & CommentNodeProps>
202 if (!deepEqual(this.props, nextProps)) {
206 showRemoveDialog: false,
207 showBanDialog: false,
209 banType: BanType.Community,
210 showPurgeDialog: false,
211 purgeType: PurgeType.Person,
215 showConfirmTransferSite: false,
216 showConfirmTransferCommunity: false,
217 showConfirmAppointAsMod: false,
218 showConfirmAppointAsAdmin: false,
219 showReportDialog: false,
220 createOrEditCommentLoading: false,
221 upvoteLoading: false,
222 downvoteLoading: false,
225 blockPersonLoading: false,
226 deleteLoading: false,
227 removeLoading: false,
228 distinguishLoading: false,
230 addModLoading: false,
231 addAdminLoading: false,
232 transferCommunityLoading: false,
233 fetchChildrenLoading: false,
234 reportLoading: false,
241 const node = this.props.node;
242 const cv = this.commentView;
244 const purgeTypeText =
245 this.state.purgeType == PurgeType.Comment
246 ? I18NextService.i18n.t("purge_comment")
247 : `${I18NextService.i18n.t("purge")} ${cv.creator.name}`;
249 const canMod_ = canMod(
251 this.props.moderators,
254 const canModOnSelf = canMod(
256 this.props.moderators,
258 UserService.Instance.myUserInfo,
261 const canAdmin_ = canAdmin(cv.creator.id, this.props.admins);
262 const canAdminOnSelf = canAdmin(
265 UserService.Instance.myUserInfo,
268 const isMod_ = isMod(cv.creator.id, this.props.moderators);
269 const isAdmin_ = isAdmin(cv.creator.id, this.props.admins);
270 const amCommunityCreator_ = amCommunityCreator(
272 this.props.moderators
275 const moreRepliesBorderColor = this.props.node.depth
276 ? colorList[this.props.node.depth % colorList.length]
279 const showMoreChildren =
280 this.props.viewType == CommentViewType.Tree &&
281 !this.state.collapsed &&
282 node.children.length == 0 &&
283 node.comment_view.counts.child_count > 0;
286 <li className="comment">
288 id={`comment-${cv.comment.id}`}
289 className={classNames(`details comment-node py-2`, {
290 "border-top border-light": !this.props.noBorder,
291 mark: this.isCommentNew || this.commentView.comment.distinguished,
295 className={classNames({
296 "ms-2": !this.props.noIndent,
299 <div className="d-flex flex-wrap align-items-center text-muted small">
301 className="btn btn-sm text-muted me-2"
302 onClick={linkEvent(this, this.handleCommentCollapse)}
303 aria-label={this.expandText}
304 data-tippy-content={this.expandText}
307 icon={`${this.state.collapsed ? "plus" : "minus"}-square`}
308 classes="icon-inline"
312 <span className="me-2">
313 <PersonListing person={cv.creator} />
316 {cv.comment.distinguished && (
317 <Icon icon="shield" inline classes="text-danger me-2" />
320 {this.isPostCreator &&
321 this.getRoleLabelPill({
322 label: I18NextService.i18n.t("op").toUpperCase(),
323 tooltip: I18NextService.i18n.t("creator"),
324 textClasses: "text-info",
329 this.getRoleLabelPill({
330 label: I18NextService.i18n.t("mod"),
331 tooltip: I18NextService.i18n.t("mod"),
336 this.getRoleLabelPill({
337 label: I18NextService.i18n.t("admin"),
338 tooltip: I18NextService.i18n.t("admin"),
342 {cv.creator.bot_account &&
343 this.getRoleLabelPill({
344 label: I18NextService.i18n.t("bot_account").toLowerCase(),
345 tooltip: I18NextService.i18n.t("bot_account"),
349 {this.props.showCommunity && (
351 <span className="mx-1">{I18NextService.i18n.t("to")}</span>
352 <CommunityLink community={cv.community} />
353 <span className="mx-2">•</span>
354 <Link className="me-2" to={`/post/${cv.post.id}`}>
360 {this.getLinkButton(true)}
362 {cv.comment.language_id !== 0 && (
363 <span className="badge text-bg-light d-none d-sm-inline me-2">
365 this.props.allLanguages.find(
366 lang => lang.id === cv.comment.language_id
371 {/* This is an expanding spacer for mobile */}
372 <div className="me-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
377 className="me-1 fw-bold"
378 aria-label={I18NextService.i18n.t("number_of_points", {
379 count: Number(this.commentView.counts.score),
380 formattedCount: numToSI(this.commentView.counts.score),
383 {numToSI(this.commentView.counts.score)}
385 <span className="me-1">•</span>
390 published={cv.comment.published}
391 updated={cv.comment.updated}
395 {/* end of user row */}
396 {this.state.showEdit && (
400 onReplyCancel={this.handleReplyCancel}
401 disabled={this.props.locked}
402 finished={this.props.finished.get(
403 this.props.node.comment_view.comment.id
406 allLanguages={this.props.allLanguages}
407 siteLanguages={this.props.siteLanguages}
408 containerClass="comment-comment-container"
409 onUpsertComment={this.props.onEditComment}
412 {!this.state.showEdit && !this.state.collapsed && (
414 {this.state.viewSource ? (
415 <pre>{this.commentUnlessRemoved}</pre>
419 dangerouslySetInnerHTML={
420 this.props.hideImages
421 ? mdToHtmlNoImages(this.commentUnlessRemoved)
422 : mdToHtml(this.commentUnlessRemoved)
426 <div className="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted fw-bold">
427 {this.props.showContext && this.getLinkButton()}
428 {this.props.markable && (
430 className="btn btn-link btn-animate text-muted"
431 onClick={linkEvent(this, this.handleMarkAsRead)}
433 this.commentReplyOrMentionRead
434 ? I18NextService.i18n.t("mark_as_unread")
435 : I18NextService.i18n.t("mark_as_read")
438 this.commentReplyOrMentionRead
439 ? I18NextService.i18n.t("mark_as_unread")
440 : I18NextService.i18n.t("mark_as_read")
443 {this.state.readLoading ? (
448 classes={`icon-inline ${
449 this.commentReplyOrMentionRead && "text-success"
455 {UserService.Instance.myUserInfo && !this.props.viewOnly && (
458 voteContentType={VoteContentType.Comment}
459 id={this.commentView.comment.id}
460 onVote={this.props.onCommentVote}
461 enableDownvotes={this.props.enableDownvotes}
462 counts={this.commentView.counts}
463 my_vote={this.commentView.my_vote}
466 className="btn btn-link btn-animate text-muted"
467 onClick={linkEvent(this, this.handleReplyClick)}
468 data-tippy-content={I18NextService.i18n.t("reply")}
469 aria-label={I18NextService.i18n.t("reply")}
471 <Icon icon="reply1" classes="icon-inline" />
473 {!this.state.showAdvanced ? (
475 className="btn btn-link btn-animate text-muted btn-more"
476 onClick={linkEvent(this, this.handleShowAdvanced)}
477 data-tippy-content={I18NextService.i18n.t("more")}
478 aria-label={I18NextService.i18n.t("more")}
480 <Icon icon="more-vertical" classes="icon-inline" />
484 {!this.myComment && (
487 className="btn btn-link btn-animate text-muted"
488 to={`/create_private_message/${cv.creator.id}`}
489 title={I18NextService.i18n
496 className="btn btn-link btn-animate text-muted"
499 this.handleShowReportDialog
501 data-tippy-content={I18NextService.i18n.t(
504 aria-label={I18NextService.i18n.t(
511 className="btn btn-link btn-animate text-muted"
514 this.handleBlockPerson
516 data-tippy-content={I18NextService.i18n.t(
519 aria-label={I18NextService.i18n.t("block_user")}
521 {this.state.blockPersonLoading ? (
524 <Icon icon="slash" />
530 className="btn btn-link btn-animate text-muted"
531 onClick={linkEvent(this, this.handleSaveComment)}
534 ? I18NextService.i18n.t("unsave")
535 : I18NextService.i18n.t("save")
539 ? I18NextService.i18n.t("unsave")
540 : I18NextService.i18n.t("save")
543 {this.state.saveLoading ? (
548 classes={`icon-inline ${
549 cv.saved && "text-warning"
555 className="btn btn-link btn-animate text-muted"
556 onClick={linkEvent(this, this.handleViewSource)}
557 data-tippy-content={I18NextService.i18n.t(
560 aria-label={I18NextService.i18n.t("view_source")}
564 classes={`icon-inline ${
565 this.state.viewSource && "text-success"
572 className="btn btn-link btn-animate text-muted"
573 onClick={linkEvent(this, this.handleEditClick)}
574 data-tippy-content={I18NextService.i18n.t(
577 aria-label={I18NextService.i18n.t("edit")}
579 <Icon icon="edit" classes="icon-inline" />
582 className="btn btn-link btn-animate text-muted"
585 this.handleDeleteComment
589 ? I18NextService.i18n.t("delete")
590 : I18NextService.i18n.t("restore")
594 ? I18NextService.i18n.t("delete")
595 : I18NextService.i18n.t("restore")
598 {this.state.deleteLoading ? (
603 classes={`icon-inline ${
604 cv.comment.deleted && "text-danger"
610 {(canModOnSelf || canAdminOnSelf) && (
612 className="btn btn-link btn-animate text-muted"
615 this.handleDistinguishComment
618 !cv.comment.distinguished
619 ? I18NextService.i18n.t("distinguish")
620 : I18NextService.i18n.t("undistinguish")
623 !cv.comment.distinguished
624 ? I18NextService.i18n.t("distinguish")
625 : I18NextService.i18n.t("undistinguish")
630 classes={`icon-inline ${
631 cv.comment.distinguished && "text-danger"
638 {/* Admins and mods can remove comments */}
639 {(canMod_ || canAdmin_) && (
641 {!cv.comment.removed ? (
643 className="btn btn-link btn-animate text-muted"
646 this.handleModRemoveShow
648 aria-label={I18NextService.i18n.t("remove")}
650 {I18NextService.i18n.t("remove")}
654 className="btn btn-link btn-animate text-muted"
657 this.handleRemoveComment
659 aria-label={I18NextService.i18n.t("restore")}
661 {this.state.removeLoading ? (
664 I18NextService.i18n.t("restore")
670 {/* Mods can ban from community, and appoint as mods to community */}
674 (!cv.creator_banned_from_community ? (
676 className="btn btn-link btn-animate text-muted"
679 this.handleModBanFromCommunityShow
681 aria-label={I18NextService.i18n.t(
685 {I18NextService.i18n.t(
691 className="btn btn-link btn-animate text-muted"
694 this.handleBanPersonFromCommunity
696 aria-label={I18NextService.i18n.t("unban")}
698 {this.state.banLoading ? (
701 I18NextService.i18n.t("unban")
705 {!cv.creator_banned_from_community &&
706 (!this.state.showConfirmAppointAsMod ? (
708 className="btn btn-link btn-animate text-muted"
711 this.handleShowConfirmAppointAsMod
715 ? I18NextService.i18n.t("remove_as_mod")
716 : I18NextService.i18n.t(
722 ? I18NextService.i18n.t("remove_as_mod")
723 : I18NextService.i18n.t("appoint_as_mod")}
728 className="btn btn-link btn-animate text-muted"
729 aria-label={I18NextService.i18n.t(
733 {I18NextService.i18n.t("are_you_sure")}
736 className="btn btn-link btn-animate text-muted"
739 this.handleAddModToCommunity
741 aria-label={I18NextService.i18n.t("yes")}
743 {this.state.addModLoading ? (
746 I18NextService.i18n.t("yes")
750 className="btn btn-link btn-animate text-muted"
753 this.handleCancelConfirmAppointAsMod
755 aria-label={I18NextService.i18n.t("no")}
757 {I18NextService.i18n.t("no")}
763 {/* Community creators and admins can transfer community to another mod */}
764 {(amCommunityCreator_ || canAdmin_) &&
767 (!this.state.showConfirmTransferCommunity ? (
769 className="btn btn-link btn-animate text-muted"
772 this.handleShowConfirmTransferCommunity
774 aria-label={I18NextService.i18n.t(
778 {I18NextService.i18n.t("transfer_community")}
783 className="btn btn-link btn-animate text-muted"
784 aria-label={I18NextService.i18n.t(
788 {I18NextService.i18n.t("are_you_sure")}
791 className="btn btn-link btn-animate text-muted"
794 this.handleTransferCommunity
796 aria-label={I18NextService.i18n.t("yes")}
798 {this.state.transferCommunityLoading ? (
801 I18NextService.i18n.t("yes")
805 className="btn btn-link btn-animate text-muted"
809 .handleCancelShowConfirmTransferCommunity
811 aria-label={I18NextService.i18n.t("no")}
813 {I18NextService.i18n.t("no")}
817 {/* Admins can ban from all, and appoint other admins */}
823 className="btn btn-link btn-animate text-muted"
826 this.handlePurgePersonShow
828 aria-label={I18NextService.i18n.t(
832 {I18NextService.i18n.t("purge_user")}
835 className="btn btn-link btn-animate text-muted"
838 this.handlePurgeCommentShow
840 aria-label={I18NextService.i18n.t(
844 {I18NextService.i18n.t("purge_comment")}
847 {!isBanned(cv.creator) ? (
849 className="btn btn-link btn-animate text-muted"
852 this.handleModBanShow
854 aria-label={I18NextService.i18n.t(
858 {I18NextService.i18n.t("ban_from_site")}
862 className="btn btn-link btn-animate text-muted"
867 aria-label={I18NextService.i18n.t(
871 {this.state.banLoading ? (
874 I18NextService.i18n.t("unban_from_site")
880 {!isBanned(cv.creator) &&
882 (!this.state.showConfirmAppointAsAdmin ? (
884 className="btn btn-link btn-animate text-muted"
887 this.handleShowConfirmAppointAsAdmin
891 ? I18NextService.i18n.t(
894 : I18NextService.i18n.t(
900 ? I18NextService.i18n.t("remove_as_admin")
901 : I18NextService.i18n.t(
907 <button className="btn btn-link btn-animate text-muted">
908 {I18NextService.i18n.t("are_you_sure")}
911 className="btn btn-link btn-animate text-muted"
916 aria-label={I18NextService.i18n.t("yes")}
918 {this.state.addAdminLoading ? (
921 I18NextService.i18n.t("yes")
925 className="btn btn-link btn-animate text-muted"
928 this.handleCancelConfirmAppointAsAdmin
930 aria-label={I18NextService.i18n.t("no")}
932 {I18NextService.i18n.t("no")}
943 {/* end of button group */}
948 {showMoreChildren && (
950 className={classNames("details ms-1 comment-node py-2", {
951 "border-top border-light": !this.props.noBorder,
953 style={`border-left: 2px ${moreRepliesBorderColor} solid !important`}
956 className="btn btn-link text-muted"
957 onClick={linkEvent(this, this.handleFetchChildren)}
959 {this.state.fetchChildrenLoading ? (
963 {I18NextService.i18n.t("x_more_replies", {
964 count: node.comment_view.counts.child_count,
965 formattedCount: numToSI(
966 node.comment_view.counts.child_count
975 {/* end of details */}
976 {this.state.showRemoveDialog && (
978 className="form-inline"
979 onSubmit={linkEvent(this, this.handleRemoveComment)}
982 className="visually-hidden"
983 htmlFor={`mod-remove-reason-${cv.comment.id}`}
985 {I18NextService.i18n.t("reason")}
989 id={`mod-remove-reason-${cv.comment.id}`}
990 className="form-control me-2"
991 placeholder={I18NextService.i18n.t("reason")}
992 value={this.state.removeReason}
993 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
997 className="btn btn-secondary"
998 aria-label={I18NextService.i18n.t("remove_comment")}
1000 {I18NextService.i18n.t("remove_comment")}
1004 {this.state.showReportDialog && (
1006 className="form-inline"
1007 onSubmit={linkEvent(this, this.handleReportComment)}
1010 className="visually-hidden"
1011 htmlFor={`report-reason-${cv.comment.id}`}
1013 {I18NextService.i18n.t("reason")}
1018 id={`report-reason-${cv.comment.id}`}
1019 className="form-control me-2"
1020 placeholder={I18NextService.i18n.t("reason")}
1021 value={this.state.reportReason}
1022 onInput={linkEvent(this, this.handleReportReasonChange)}
1026 className="btn btn-secondary"
1027 aria-label={I18NextService.i18n.t("create_report")}
1029 {I18NextService.i18n.t("create_report")}
1033 {this.state.showBanDialog && (
1034 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1035 <div className="mb-3 row col-12">
1037 className="col-form-label"
1038 htmlFor={`mod-ban-reason-${cv.comment.id}`}
1040 {I18NextService.i18n.t("reason")}
1044 id={`mod-ban-reason-${cv.comment.id}`}
1045 className="form-control me-2"
1046 placeholder={I18NextService.i18n.t("reason")}
1047 value={this.state.banReason}
1048 onInput={linkEvent(this, this.handleModBanReasonChange)}
1051 className="col-form-label"
1052 htmlFor={`mod-ban-expires-${cv.comment.id}`}
1054 {I18NextService.i18n.t("expires")}
1058 id={`mod-ban-expires-${cv.comment.id}`}
1059 className="form-control me-2"
1060 placeholder={I18NextService.i18n.t("number_of_days")}
1061 value={this.state.banExpireDays}
1062 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1064 <div className="input-group mb-3">
1065 <div className="form-check">
1067 className="form-check-input"
1068 id="mod-ban-remove-data"
1070 checked={this.state.removeData}
1071 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1074 className="form-check-label"
1075 htmlFor="mod-ban-remove-data"
1076 title={I18NextService.i18n.t("remove_content_more")}
1078 {I18NextService.i18n.t("remove_content")}
1083 {/* TODO hold off on expires until later */}
1084 {/* <div class="mb-3 row"> */}
1085 {/* <label class="col-form-label">Expires</label> */}
1086 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1088 <div className="mb-3 row">
1091 className="btn btn-secondary"
1092 aria-label={I18NextService.i18n.t("ban")}
1094 {this.state.banLoading ? (
1098 {I18NextService.i18n.t("ban")} {cv.creator.name}
1106 {this.state.showPurgeDialog && (
1107 <form onSubmit={linkEvent(this, this.handlePurgeBothSubmit)}>
1109 <label className="visually-hidden" htmlFor="purge-reason">
1110 {I18NextService.i18n.t("reason")}
1115 className="form-control my-3"
1116 placeholder={I18NextService.i18n.t("reason")}
1117 value={this.state.purgeReason}
1118 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1120 <div className="mb-3 row col-12">
1121 {this.state.purgeLoading ? (
1126 className="btn btn-secondary"
1127 aria-label={purgeTypeText}
1135 {this.state.showReply && (
1138 onReplyCancel={this.handleReplyCancel}
1139 disabled={this.props.locked}
1140 finished={this.props.finished.get(
1141 this.props.node.comment_view.comment.id
1144 allLanguages={this.props.allLanguages}
1145 siteLanguages={this.props.siteLanguages}
1146 containerClass="comment-comment-container"
1147 onUpsertComment={this.props.onCreateComment}
1150 {!this.state.collapsed && node.children.length > 0 && (
1152 nodes={node.children}
1153 locked={this.props.locked}
1154 moderators={this.props.moderators}
1155 admins={this.props.admins}
1156 enableDownvotes={this.props.enableDownvotes}
1157 viewType={this.props.viewType}
1158 allLanguages={this.props.allLanguages}
1159 siteLanguages={this.props.siteLanguages}
1160 hideImages={this.props.hideImages}
1161 isChild={!this.props.noIndent}
1162 depth={this.props.node.depth + 1}
1163 finished={this.props.finished}
1164 onCommentReplyRead={this.props.onCommentReplyRead}
1165 onPersonMentionRead={this.props.onPersonMentionRead}
1166 onCreateComment={this.props.onCreateComment}
1167 onEditComment={this.props.onEditComment}
1168 onCommentVote={this.props.onCommentVote}
1169 onBlockPerson={this.props.onBlockPerson}
1170 onSaveComment={this.props.onSaveComment}
1171 onDeleteComment={this.props.onDeleteComment}
1172 onRemoveComment={this.props.onRemoveComment}
1173 onDistinguishComment={this.props.onDistinguishComment}
1174 onAddModToCommunity={this.props.onAddModToCommunity}
1175 onAddAdmin={this.props.onAddAdmin}
1176 onBanPersonFromCommunity={this.props.onBanPersonFromCommunity}
1177 onBanPerson={this.props.onBanPerson}
1178 onTransferCommunity={this.props.onTransferCommunity}
1179 onFetchChildren={this.props.onFetchChildren}
1180 onCommentReport={this.props.onCommentReport}
1181 onPurgePerson={this.props.onPurgePerson}
1182 onPurgeComment={this.props.onPurgeComment}
1185 {/* A collapsed clearfix */}
1186 {this.state.collapsed && <div className="row col-12" />}
1191 get commentReplyOrMentionRead(): boolean {
1192 const cv = this.commentView;
1194 if (this.isPersonMentionType(cv)) {
1195 return cv.person_mention.read;
1196 } else if (this.isCommentReplyType(cv)) {
1197 return cv.comment_reply.read;
1211 textClasses?: string;
1212 hideOnMobile?: boolean;
1214 const classnames = classNames(`badge me-2 text-bg-light ${textClasses}`, {
1215 "d-none d-md-inline": hideOnMobile,
1220 className={classnames}
1221 aria-label={tooltip}
1222 data-tippy-content={tooltip}
1229 getLinkButton(small = false) {
1230 const cv = this.commentView;
1232 const classnames = classNames("btn btn-link btn-animate text-muted", {
1236 const title = this.props.showContext
1237 ? I18NextService.i18n.t("show_context")
1238 : I18NextService.i18n.t("link");
1240 // The context button should show the parent comment by default
1241 const parentCommentId = getCommentParentId(cv.comment) ?? cv.comment.id;
1246 className={classnames}
1247 to={`/comment/${parentCommentId}`}
1250 <Icon icon="link" classes="icon-inline" />
1253 <a className={classnames} title={title} href={cv.comment.ap_id}>
1254 <Icon icon="fedilink" classes="icon-inline" />
1261 get myComment(): boolean {
1263 UserService.Instance.myUserInfo?.local_user_view.person.id ==
1264 this.commentView.creator.id
1268 get isPostCreator(): boolean {
1269 return this.commentView.creator.id == this.commentView.post.creator_id;
1273 if (this.commentView.my_vote == 1) {
1275 } else if (this.commentView.my_vote == -1) {
1276 return "text-danger";
1278 return "text-muted";
1282 get pointsTippy(): string {
1283 const points = I18NextService.i18n.t("number_of_points", {
1284 count: Number(this.commentView.counts.score),
1285 formattedCount: numToSI(this.commentView.counts.score),
1288 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1289 count: Number(this.commentView.counts.upvotes),
1290 formattedCount: numToSI(this.commentView.counts.upvotes),
1293 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1294 count: Number(this.commentView.counts.downvotes),
1295 formattedCount: numToSI(this.commentView.counts.downvotes),
1298 return `${points} • ${upvotes} • ${downvotes}`;
1301 get expandText(): string {
1302 return this.state.collapsed
1303 ? I18NextService.i18n.t("expand")
1304 : I18NextService.i18n.t("collapse");
1307 get commentUnlessRemoved(): string {
1308 const comment = this.commentView.comment;
1309 return comment.removed
1310 ? `*${I18NextService.i18n.t("removed")}*`
1312 ? `*${I18NextService.i18n.t("deleted")}*`
1316 handleReplyClick(i: CommentNode) {
1317 i.setState({ showReply: true });
1320 handleEditClick(i: CommentNode) {
1321 i.setState({ showEdit: true });
1324 handleReplyCancel() {
1325 this.setState({ showReply: false, showEdit: false });
1328 handleShowReportDialog(i: CommentNode) {
1329 i.setState({ showReportDialog: !i.state.showReportDialog });
1332 handleReportReasonChange(i: CommentNode, event: any) {
1333 i.setState({ reportReason: event.target.value });
1336 handleModRemoveShow(i: CommentNode) {
1338 showRemoveDialog: !i.state.showRemoveDialog,
1339 showBanDialog: false,
1343 handleModRemoveReasonChange(i: CommentNode, event: any) {
1344 i.setState({ removeReason: event.target.value });
1347 handleModRemoveDataChange(i: CommentNode, event: any) {
1348 i.setState({ removeData: event.target.checked });
1351 isPersonMentionType(
1352 item: CommentView | PersonMentionView | CommentReplyView
1353 ): item is PersonMentionView {
1354 return (item as PersonMentionView).person_mention?.id !== undefined;
1358 item: CommentView | PersonMentionView | CommentReplyView
1359 ): item is CommentReplyView {
1360 return (item as CommentReplyView).comment_reply?.id !== undefined;
1363 handleModBanFromCommunityShow(i: CommentNode) {
1365 showBanDialog: true,
1366 banType: BanType.Community,
1367 showRemoveDialog: false,
1371 handleModBanShow(i: CommentNode) {
1373 showBanDialog: true,
1374 banType: BanType.Site,
1375 showRemoveDialog: false,
1379 handleModBanReasonChange(i: CommentNode, event: any) {
1380 i.setState({ banReason: event.target.value });
1383 handleModBanExpireDaysChange(i: CommentNode, event: any) {
1384 i.setState({ banExpireDays: event.target.value });
1387 handlePurgePersonShow(i: CommentNode) {
1389 showPurgeDialog: true,
1390 purgeType: PurgeType.Person,
1391 showRemoveDialog: false,
1395 handlePurgeCommentShow(i: CommentNode) {
1397 showPurgeDialog: true,
1398 purgeType: PurgeType.Comment,
1399 showRemoveDialog: false,
1403 handlePurgeReasonChange(i: CommentNode, event: any) {
1404 i.setState({ purgeReason: event.target.value });
1407 handleShowConfirmAppointAsMod(i: CommentNode) {
1408 i.setState({ showConfirmAppointAsMod: true });
1411 handleCancelConfirmAppointAsMod(i: CommentNode) {
1412 i.setState({ showConfirmAppointAsMod: false });
1415 handleShowConfirmAppointAsAdmin(i: CommentNode) {
1416 i.setState({ showConfirmAppointAsAdmin: true });
1419 handleCancelConfirmAppointAsAdmin(i: CommentNode) {
1420 i.setState({ showConfirmAppointAsAdmin: false });
1423 handleShowConfirmTransferCommunity(i: CommentNode) {
1424 i.setState({ showConfirmTransferCommunity: true });
1427 handleCancelShowConfirmTransferCommunity(i: CommentNode) {
1428 i.setState({ showConfirmTransferCommunity: false });
1431 handleShowConfirmTransferSite(i: CommentNode) {
1432 i.setState({ showConfirmTransferSite: true });
1435 handleCancelShowConfirmTransferSite(i: CommentNode) {
1436 i.setState({ showConfirmTransferSite: false });
1439 get isCommentNew(): boolean {
1440 const now = subMinutes(new Date(), 10);
1441 const then = parseISO(this.commentView.comment.published);
1442 return isBefore(now, then);
1445 handleCommentCollapse(i: CommentNode) {
1446 i.setState({ collapsed: !i.state.collapsed });
1450 handleViewSource(i: CommentNode) {
1451 i.setState({ viewSource: !i.state.viewSource });
1454 handleShowAdvanced(i: CommentNode) {
1455 i.setState({ showAdvanced: !i.state.showAdvanced });
1459 handleSaveComment(i: CommentNode) {
1460 i.setState({ saveLoading: true });
1462 i.props.onSaveComment({
1463 comment_id: i.commentView.comment.id,
1464 save: !i.commentView.saved,
1465 auth: myAuthRequired(),
1469 handleBlockPerson(i: CommentNode) {
1470 i.setState({ blockPersonLoading: true });
1471 i.props.onBlockPerson({
1472 person_id: i.commentView.creator.id,
1474 auth: myAuthRequired(),
1478 handleMarkAsRead(i: CommentNode) {
1479 i.setState({ readLoading: true });
1480 const cv = i.commentView;
1481 if (i.isPersonMentionType(cv)) {
1482 i.props.onPersonMentionRead({
1483 person_mention_id: cv.person_mention.id,
1484 read: !cv.person_mention.read,
1485 auth: myAuthRequired(),
1487 } else if (i.isCommentReplyType(cv)) {
1488 i.props.onCommentReplyRead({
1489 comment_reply_id: cv.comment_reply.id,
1490 read: !cv.comment_reply.read,
1491 auth: myAuthRequired(),
1496 handleDeleteComment(i: CommentNode) {
1497 i.setState({ deleteLoading: true });
1498 i.props.onDeleteComment({
1499 comment_id: i.commentId,
1500 deleted: !i.commentView.comment.deleted,
1501 auth: myAuthRequired(),
1505 handleRemoveComment(i: CommentNode, event: any) {
1506 event.preventDefault();
1507 i.setState({ removeLoading: true });
1508 i.props.onRemoveComment({
1509 comment_id: i.commentId,
1510 removed: !i.commentView.comment.removed,
1511 auth: myAuthRequired(),
1515 handleDistinguishComment(i: CommentNode) {
1516 i.setState({ distinguishLoading: true });
1517 i.props.onDistinguishComment({
1518 comment_id: i.commentId,
1519 distinguished: !i.commentView.comment.distinguished,
1520 auth: myAuthRequired(),
1524 handleBanPersonFromCommunity(i: CommentNode) {
1525 i.setState({ banLoading: true });
1526 i.props.onBanPersonFromCommunity({
1527 community_id: i.commentView.community.id,
1528 person_id: i.commentView.creator.id,
1529 ban: !i.commentView.creator_banned_from_community,
1530 reason: i.state.banReason,
1531 remove_data: i.state.removeData,
1532 expires: futureDaysToUnixTime(i.state.banExpireDays),
1533 auth: myAuthRequired(),
1537 handleBanPerson(i: CommentNode) {
1538 i.setState({ banLoading: true });
1539 i.props.onBanPerson({
1540 person_id: i.commentView.creator.id,
1541 ban: !i.commentView.creator_banned_from_community,
1542 reason: i.state.banReason,
1543 remove_data: i.state.removeData,
1544 expires: futureDaysToUnixTime(i.state.banExpireDays),
1545 auth: myAuthRequired(),
1549 handleModBanBothSubmit(i: CommentNode, event: any) {
1550 event.preventDefault();
1551 if (i.state.banType == BanType.Community) {
1552 i.handleBanPersonFromCommunity(i);
1554 i.handleBanPerson(i);
1558 handleAddModToCommunity(i: CommentNode) {
1559 i.setState({ addModLoading: true });
1561 const added = !isMod(i.commentView.comment.creator_id, i.props.moderators);
1562 i.props.onAddModToCommunity({
1563 community_id: i.commentView.community.id,
1564 person_id: i.commentView.creator.id,
1566 auth: myAuthRequired(),
1570 handleAddAdmin(i: CommentNode) {
1571 i.setState({ addAdminLoading: true });
1573 const added = !isAdmin(i.commentView.comment.creator_id, i.props.admins);
1574 i.props.onAddAdmin({
1575 person_id: i.commentView.creator.id,
1577 auth: myAuthRequired(),
1581 handleTransferCommunity(i: CommentNode) {
1582 i.setState({ transferCommunityLoading: true });
1583 i.props.onTransferCommunity({
1584 community_id: i.commentView.community.id,
1585 person_id: i.commentView.creator.id,
1586 auth: myAuthRequired(),
1590 handleReportComment(i: CommentNode, event: any) {
1591 event.preventDefault();
1592 i.setState({ reportLoading: true });
1593 i.props.onCommentReport({
1594 comment_id: i.commentId,
1595 reason: i.state.reportReason ?? "",
1596 auth: myAuthRequired(),
1600 handlePurgeBothSubmit(i: CommentNode, event: any) {
1601 event.preventDefault();
1602 i.setState({ purgeLoading: true });
1604 if (i.state.purgeType == PurgeType.Person) {
1605 i.props.onPurgePerson({
1606 person_id: i.commentView.creator.id,
1607 reason: i.state.purgeReason,
1608 auth: myAuthRequired(),
1611 i.props.onPurgeComment({
1612 comment_id: i.commentId,
1613 reason: i.state.purgeReason,
1614 auth: myAuthRequired(),
1619 handleFetchChildren(i: CommentNode) {
1620 i.setState({ fetchChildrenLoading: true });
1621 i.props.onFetchChildren?.({
1622 parent_id: i.commentId,
1623 max_depth: commentTreeMaxDepth,