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"
311 <span className="me-2">
312 <PersonListing person={cv.creator} />
314 {cv.comment.distinguished && (
315 <Icon icon="shield" inline classes="text-danger me-2" />
317 {this.isPostCreator && (
319 className="badge text-info text-bg-light d-sm-inline me-2"
320 aria-label={I18NextService.i18n.t("creator")}
321 data-tippy-content={I18NextService.i18n.t("creator")}
323 {I18NextService.i18n.t("op")}
327 <span className="badge text-bg-light d-none d-sm-inline me-2">
328 {I18NextService.i18n.t("mod")}
332 <span className="badge text-bg-light d-none d-sm-inline me-2">
333 {I18NextService.i18n.t("admin")}
336 {cv.creator.bot_account && (
337 <span className="badge text-bg-light d-none d-sm-inline me-2">
338 {I18NextService.i18n.t("bot_account").toLowerCase()}
341 {this.props.showCommunity && (
343 <span className="mx-1">{I18NextService.i18n.t("to")}</span>
344 <CommunityLink community={cv.community} />
345 <span className="mx-2">•</span>
346 <Link className="me-2" to={`/post/${cv.post.id}`}>
352 {cv.comment.language_id !== 0 && (
353 <span className="badge text-bg-light d-none d-sm-inline me-2">
355 this.props.allLanguages.find(
356 lang => lang.id === cv.comment.language_id
361 {/* This is an expanding spacer for mobile */}
362 <div className="me-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
367 className="me-1 fw-bold"
368 aria-label={I18NextService.i18n.t("number_of_points", {
369 count: Number(this.commentView.counts.score),
370 formattedCount: numToSI(this.commentView.counts.score),
373 {numToSI(this.commentView.counts.score)}
375 <span className="me-1">•</span>
380 published={cv.comment.published}
381 updated={cv.comment.updated}
385 {/* end of user row */}
386 {this.state.showEdit && (
390 onReplyCancel={this.handleReplyCancel}
391 disabled={this.props.locked}
392 finished={this.props.finished.get(
393 this.props.node.comment_view.comment.id
396 allLanguages={this.props.allLanguages}
397 siteLanguages={this.props.siteLanguages}
398 containerClass="comment-comment-container"
399 onUpsertComment={this.props.onEditComment}
402 {!this.state.showEdit && !this.state.collapsed && (
404 {this.state.viewSource ? (
405 <pre>{this.commentUnlessRemoved}</pre>
409 dangerouslySetInnerHTML={
410 this.props.hideImages
411 ? mdToHtmlNoImages(this.commentUnlessRemoved)
412 : mdToHtml(this.commentUnlessRemoved)
416 <div className="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted fw-bold">
417 {this.props.showContext && this.linkBtn()}
418 {this.props.markable && (
420 className="btn btn-link btn-animate text-muted"
421 onClick={linkEvent(this, this.handleMarkAsRead)}
423 this.commentReplyOrMentionRead
424 ? I18NextService.i18n.t("mark_as_unread")
425 : I18NextService.i18n.t("mark_as_read")
428 this.commentReplyOrMentionRead
429 ? I18NextService.i18n.t("mark_as_unread")
430 : I18NextService.i18n.t("mark_as_read")
433 {this.state.readLoading ? (
438 classes={`icon-inline ${
439 this.commentReplyOrMentionRead && "text-success"
445 {UserService.Instance.myUserInfo && !this.props.viewOnly && (
448 voteContentType={VoteContentType.Comment}
449 id={this.commentView.comment.id}
450 onVote={this.props.onCommentVote}
451 enableDownvotes={this.props.enableDownvotes}
452 counts={this.commentView.counts}
453 my_vote={this.commentView.my_vote}
456 className="btn btn-link btn-animate text-muted"
457 onClick={linkEvent(this, this.handleReplyClick)}
458 data-tippy-content={I18NextService.i18n.t("reply")}
459 aria-label={I18NextService.i18n.t("reply")}
461 <Icon icon="reply1" classes="icon-inline" />
463 {!this.state.showAdvanced ? (
465 className="btn btn-link btn-animate text-muted btn-more"
466 onClick={linkEvent(this, this.handleShowAdvanced)}
467 data-tippy-content={I18NextService.i18n.t("more")}
468 aria-label={I18NextService.i18n.t("more")}
470 <Icon icon="more-vertical" classes="icon-inline" />
474 {!this.myComment && (
477 className="btn btn-link btn-animate text-muted"
478 to={`/create_private_message/${cv.creator.id}`}
479 title={I18NextService.i18n
486 className="btn btn-link btn-animate text-muted"
489 this.handleShowReportDialog
491 data-tippy-content={I18NextService.i18n.t(
494 aria-label={I18NextService.i18n.t(
501 className="btn btn-link btn-animate text-muted"
504 this.handleBlockPerson
506 data-tippy-content={I18NextService.i18n.t(
509 aria-label={I18NextService.i18n.t("block_user")}
511 {this.state.blockPersonLoading ? (
514 <Icon icon="slash" />
520 className="btn btn-link btn-animate text-muted"
521 onClick={linkEvent(this, this.handleSaveComment)}
524 ? I18NextService.i18n.t("unsave")
525 : I18NextService.i18n.t("save")
529 ? I18NextService.i18n.t("unsave")
530 : I18NextService.i18n.t("save")
533 {this.state.saveLoading ? (
538 classes={`icon-inline ${
539 cv.saved && "text-warning"
545 className="btn btn-link btn-animate text-muted"
546 onClick={linkEvent(this, this.handleViewSource)}
547 data-tippy-content={I18NextService.i18n.t(
550 aria-label={I18NextService.i18n.t("view_source")}
554 classes={`icon-inline ${
555 this.state.viewSource && "text-success"
562 className="btn btn-link btn-animate text-muted"
563 onClick={linkEvent(this, this.handleEditClick)}
564 data-tippy-content={I18NextService.i18n.t(
567 aria-label={I18NextService.i18n.t("edit")}
569 <Icon icon="edit" classes="icon-inline" />
572 className="btn btn-link btn-animate text-muted"
575 this.handleDeleteComment
579 ? I18NextService.i18n.t("delete")
580 : I18NextService.i18n.t("restore")
584 ? I18NextService.i18n.t("delete")
585 : I18NextService.i18n.t("restore")
588 {this.state.deleteLoading ? (
593 classes={`icon-inline ${
594 cv.comment.deleted && "text-danger"
600 {(canModOnSelf || canAdminOnSelf) && (
602 className="btn btn-link btn-animate text-muted"
605 this.handleDistinguishComment
608 !cv.comment.distinguished
609 ? I18NextService.i18n.t("distinguish")
610 : I18NextService.i18n.t("undistinguish")
613 !cv.comment.distinguished
614 ? I18NextService.i18n.t("distinguish")
615 : I18NextService.i18n.t("undistinguish")
620 classes={`icon-inline ${
621 cv.comment.distinguished && "text-danger"
628 {/* Admins and mods can remove comments */}
629 {(canMod_ || canAdmin_) && (
631 {!cv.comment.removed ? (
633 className="btn btn-link btn-animate text-muted"
636 this.handleModRemoveShow
638 aria-label={I18NextService.i18n.t("remove")}
640 {I18NextService.i18n.t("remove")}
644 className="btn btn-link btn-animate text-muted"
647 this.handleRemoveComment
649 aria-label={I18NextService.i18n.t("restore")}
651 {this.state.removeLoading ? (
654 I18NextService.i18n.t("restore")
660 {/* Mods can ban from community, and appoint as mods to community */}
664 (!cv.creator_banned_from_community ? (
666 className="btn btn-link btn-animate text-muted"
669 this.handleModBanFromCommunityShow
671 aria-label={I18NextService.i18n.t(
675 {I18NextService.i18n.t(
681 className="btn btn-link btn-animate text-muted"
684 this.handleBanPersonFromCommunity
686 aria-label={I18NextService.i18n.t("unban")}
688 {this.state.banLoading ? (
691 I18NextService.i18n.t("unban")
695 {!cv.creator_banned_from_community &&
696 (!this.state.showConfirmAppointAsMod ? (
698 className="btn btn-link btn-animate text-muted"
701 this.handleShowConfirmAppointAsMod
705 ? I18NextService.i18n.t("remove_as_mod")
706 : I18NextService.i18n.t(
712 ? I18NextService.i18n.t("remove_as_mod")
713 : I18NextService.i18n.t("appoint_as_mod")}
718 className="btn btn-link btn-animate text-muted"
719 aria-label={I18NextService.i18n.t(
723 {I18NextService.i18n.t("are_you_sure")}
726 className="btn btn-link btn-animate text-muted"
729 this.handleAddModToCommunity
731 aria-label={I18NextService.i18n.t("yes")}
733 {this.state.addModLoading ? (
736 I18NextService.i18n.t("yes")
740 className="btn btn-link btn-animate text-muted"
743 this.handleCancelConfirmAppointAsMod
745 aria-label={I18NextService.i18n.t("no")}
747 {I18NextService.i18n.t("no")}
753 {/* Community creators and admins can transfer community to another mod */}
754 {(amCommunityCreator_ || canAdmin_) &&
757 (!this.state.showConfirmTransferCommunity ? (
759 className="btn btn-link btn-animate text-muted"
762 this.handleShowConfirmTransferCommunity
764 aria-label={I18NextService.i18n.t(
768 {I18NextService.i18n.t("transfer_community")}
773 className="btn btn-link btn-animate text-muted"
774 aria-label={I18NextService.i18n.t(
778 {I18NextService.i18n.t("are_you_sure")}
781 className="btn btn-link btn-animate text-muted"
784 this.handleTransferCommunity
786 aria-label={I18NextService.i18n.t("yes")}
788 {this.state.transferCommunityLoading ? (
791 I18NextService.i18n.t("yes")
795 className="btn btn-link btn-animate text-muted"
799 .handleCancelShowConfirmTransferCommunity
801 aria-label={I18NextService.i18n.t("no")}
803 {I18NextService.i18n.t("no")}
807 {/* Admins can ban from all, and appoint other admins */}
813 className="btn btn-link btn-animate text-muted"
816 this.handlePurgePersonShow
818 aria-label={I18NextService.i18n.t(
822 {I18NextService.i18n.t("purge_user")}
825 className="btn btn-link btn-animate text-muted"
828 this.handlePurgeCommentShow
830 aria-label={I18NextService.i18n.t(
834 {I18NextService.i18n.t("purge_comment")}
837 {!isBanned(cv.creator) ? (
839 className="btn btn-link btn-animate text-muted"
842 this.handleModBanShow
844 aria-label={I18NextService.i18n.t(
848 {I18NextService.i18n.t("ban_from_site")}
852 className="btn btn-link btn-animate text-muted"
857 aria-label={I18NextService.i18n.t(
861 {this.state.banLoading ? (
864 I18NextService.i18n.t("unban_from_site")
870 {!isBanned(cv.creator) &&
872 (!this.state.showConfirmAppointAsAdmin ? (
874 className="btn btn-link btn-animate text-muted"
877 this.handleShowConfirmAppointAsAdmin
881 ? I18NextService.i18n.t(
884 : I18NextService.i18n.t(
890 ? I18NextService.i18n.t("remove_as_admin")
891 : I18NextService.i18n.t(
897 <button className="btn btn-link btn-animate text-muted">
898 {I18NextService.i18n.t("are_you_sure")}
901 className="btn btn-link btn-animate text-muted"
906 aria-label={I18NextService.i18n.t("yes")}
908 {this.state.addAdminLoading ? (
911 I18NextService.i18n.t("yes")
915 className="btn btn-link btn-animate text-muted"
918 this.handleCancelConfirmAppointAsAdmin
920 aria-label={I18NextService.i18n.t("no")}
922 {I18NextService.i18n.t("no")}
933 {/* end of button group */}
938 {showMoreChildren && (
940 className={classNames("details ms-1 comment-node py-2", {
941 "border-top border-light": !this.props.noBorder,
943 style={`border-left: 2px ${moreRepliesBorderColor} solid !important`}
946 className="btn btn-link text-muted"
947 onClick={linkEvent(this, this.handleFetchChildren)}
949 {this.state.fetchChildrenLoading ? (
953 {I18NextService.i18n.t("x_more_replies", {
954 count: node.comment_view.counts.child_count,
955 formattedCount: numToSI(
956 node.comment_view.counts.child_count
965 {/* end of details */}
966 {this.state.showRemoveDialog && (
968 className="form-inline"
969 onSubmit={linkEvent(this, this.handleRemoveComment)}
972 className="visually-hidden"
973 htmlFor={`mod-remove-reason-${cv.comment.id}`}
975 {I18NextService.i18n.t("reason")}
979 id={`mod-remove-reason-${cv.comment.id}`}
980 className="form-control me-2"
981 placeholder={I18NextService.i18n.t("reason")}
982 value={this.state.removeReason}
983 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
987 className="btn btn-secondary"
988 aria-label={I18NextService.i18n.t("remove_comment")}
990 {I18NextService.i18n.t("remove_comment")}
994 {this.state.showReportDialog && (
996 className="form-inline"
997 onSubmit={linkEvent(this, this.handleReportComment)}
1000 className="visually-hidden"
1001 htmlFor={`report-reason-${cv.comment.id}`}
1003 {I18NextService.i18n.t("reason")}
1008 id={`report-reason-${cv.comment.id}`}
1009 className="form-control me-2"
1010 placeholder={I18NextService.i18n.t("reason")}
1011 value={this.state.reportReason}
1012 onInput={linkEvent(this, this.handleReportReasonChange)}
1016 className="btn btn-secondary"
1017 aria-label={I18NextService.i18n.t("create_report")}
1019 {I18NextService.i18n.t("create_report")}
1023 {this.state.showBanDialog && (
1024 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1025 <div className="mb-3 row col-12">
1027 className="col-form-label"
1028 htmlFor={`mod-ban-reason-${cv.comment.id}`}
1030 {I18NextService.i18n.t("reason")}
1034 id={`mod-ban-reason-${cv.comment.id}`}
1035 className="form-control me-2"
1036 placeholder={I18NextService.i18n.t("reason")}
1037 value={this.state.banReason}
1038 onInput={linkEvent(this, this.handleModBanReasonChange)}
1041 className="col-form-label"
1042 htmlFor={`mod-ban-expires-${cv.comment.id}`}
1044 {I18NextService.i18n.t("expires")}
1048 id={`mod-ban-expires-${cv.comment.id}`}
1049 className="form-control me-2"
1050 placeholder={I18NextService.i18n.t("number_of_days")}
1051 value={this.state.banExpireDays}
1052 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1054 <div className="input-group mb-3">
1055 <div className="form-check">
1057 className="form-check-input"
1058 id="mod-ban-remove-data"
1060 checked={this.state.removeData}
1061 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1064 className="form-check-label"
1065 htmlFor="mod-ban-remove-data"
1066 title={I18NextService.i18n.t("remove_content_more")}
1068 {I18NextService.i18n.t("remove_content")}
1073 {/* TODO hold off on expires until later */}
1074 {/* <div class="mb-3 row"> */}
1075 {/* <label class="col-form-label">Expires</label> */}
1076 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1078 <div className="mb-3 row">
1081 className="btn btn-secondary"
1082 aria-label={I18NextService.i18n.t("ban")}
1084 {this.state.banLoading ? (
1088 {I18NextService.i18n.t("ban")} {cv.creator.name}
1096 {this.state.showPurgeDialog && (
1097 <form onSubmit={linkEvent(this, this.handlePurgeBothSubmit)}>
1099 <label className="visually-hidden" htmlFor="purge-reason">
1100 {I18NextService.i18n.t("reason")}
1105 className="form-control my-3"
1106 placeholder={I18NextService.i18n.t("reason")}
1107 value={this.state.purgeReason}
1108 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1110 <div className="mb-3 row col-12">
1111 {this.state.purgeLoading ? (
1116 className="btn btn-secondary"
1117 aria-label={purgeTypeText}
1125 {this.state.showReply && (
1128 onReplyCancel={this.handleReplyCancel}
1129 disabled={this.props.locked}
1130 finished={this.props.finished.get(
1131 this.props.node.comment_view.comment.id
1134 allLanguages={this.props.allLanguages}
1135 siteLanguages={this.props.siteLanguages}
1136 containerClass="comment-comment-container"
1137 onUpsertComment={this.props.onCreateComment}
1140 {!this.state.collapsed && node.children.length > 0 && (
1142 nodes={node.children}
1143 locked={this.props.locked}
1144 moderators={this.props.moderators}
1145 admins={this.props.admins}
1146 enableDownvotes={this.props.enableDownvotes}
1147 viewType={this.props.viewType}
1148 allLanguages={this.props.allLanguages}
1149 siteLanguages={this.props.siteLanguages}
1150 hideImages={this.props.hideImages}
1151 isChild={!this.props.noIndent}
1152 depth={this.props.node.depth + 1}
1153 finished={this.props.finished}
1154 onCommentReplyRead={this.props.onCommentReplyRead}
1155 onPersonMentionRead={this.props.onPersonMentionRead}
1156 onCreateComment={this.props.onCreateComment}
1157 onEditComment={this.props.onEditComment}
1158 onCommentVote={this.props.onCommentVote}
1159 onBlockPerson={this.props.onBlockPerson}
1160 onSaveComment={this.props.onSaveComment}
1161 onDeleteComment={this.props.onDeleteComment}
1162 onRemoveComment={this.props.onRemoveComment}
1163 onDistinguishComment={this.props.onDistinguishComment}
1164 onAddModToCommunity={this.props.onAddModToCommunity}
1165 onAddAdmin={this.props.onAddAdmin}
1166 onBanPersonFromCommunity={this.props.onBanPersonFromCommunity}
1167 onBanPerson={this.props.onBanPerson}
1168 onTransferCommunity={this.props.onTransferCommunity}
1169 onFetchChildren={this.props.onFetchChildren}
1170 onCommentReport={this.props.onCommentReport}
1171 onPurgePerson={this.props.onPurgePerson}
1172 onPurgeComment={this.props.onPurgeComment}
1175 {/* A collapsed clearfix */}
1176 {this.state.collapsed && <div className="row col-12" />}
1181 get commentReplyOrMentionRead(): boolean {
1182 const cv = this.commentView;
1184 if (this.isPersonMentionType(cv)) {
1185 return cv.person_mention.read;
1186 } else if (this.isCommentReplyType(cv)) {
1187 return cv.comment_reply.read;
1193 linkBtn(small = false) {
1194 const cv = this.commentView;
1196 const classnames = classNames("btn btn-link btn-animate text-muted", {
1200 const title = this.props.showContext
1201 ? I18NextService.i18n.t("show_context")
1202 : I18NextService.i18n.t("link");
1204 // The context button should show the parent comment by default
1205 const parentCommentId = getCommentParentId(cv.comment) ?? cv.comment.id;
1210 className={classnames}
1211 to={`/comment/${parentCommentId}`}
1214 <Icon icon="link" classes="icon-inline" />
1217 <a className={classnames} title={title} href={cv.comment.ap_id}>
1218 <Icon icon="fedilink" classes="icon-inline" />
1225 get myComment(): boolean {
1227 UserService.Instance.myUserInfo?.local_user_view.person.id ==
1228 this.commentView.creator.id
1232 get isPostCreator(): boolean {
1233 return this.commentView.creator.id == this.commentView.post.creator_id;
1237 if (this.commentView.my_vote == 1) {
1239 } else if (this.commentView.my_vote == -1) {
1240 return "text-danger";
1242 return "text-muted";
1246 get pointsTippy(): string {
1247 const points = I18NextService.i18n.t("number_of_points", {
1248 count: Number(this.commentView.counts.score),
1249 formattedCount: numToSI(this.commentView.counts.score),
1252 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1253 count: Number(this.commentView.counts.upvotes),
1254 formattedCount: numToSI(this.commentView.counts.upvotes),
1257 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1258 count: Number(this.commentView.counts.downvotes),
1259 formattedCount: numToSI(this.commentView.counts.downvotes),
1262 return `${points} • ${upvotes} • ${downvotes}`;
1265 get expandText(): string {
1266 return this.state.collapsed
1267 ? I18NextService.i18n.t("expand")
1268 : I18NextService.i18n.t("collapse");
1271 get commentUnlessRemoved(): string {
1272 const comment = this.commentView.comment;
1273 return comment.removed
1274 ? `*${I18NextService.i18n.t("removed")}*`
1276 ? `*${I18NextService.i18n.t("deleted")}*`
1280 handleReplyClick(i: CommentNode) {
1281 i.setState({ showReply: true });
1284 handleEditClick(i: CommentNode) {
1285 i.setState({ showEdit: true });
1288 handleReplyCancel() {
1289 this.setState({ showReply: false, showEdit: false });
1292 handleShowReportDialog(i: CommentNode) {
1293 i.setState({ showReportDialog: !i.state.showReportDialog });
1296 handleReportReasonChange(i: CommentNode, event: any) {
1297 i.setState({ reportReason: event.target.value });
1300 handleModRemoveShow(i: CommentNode) {
1302 showRemoveDialog: !i.state.showRemoveDialog,
1303 showBanDialog: false,
1307 handleModRemoveReasonChange(i: CommentNode, event: any) {
1308 i.setState({ removeReason: event.target.value });
1311 handleModRemoveDataChange(i: CommentNode, event: any) {
1312 i.setState({ removeData: event.target.checked });
1315 isPersonMentionType(
1316 item: CommentView | PersonMentionView | CommentReplyView
1317 ): item is PersonMentionView {
1318 return (item as PersonMentionView).person_mention?.id !== undefined;
1322 item: CommentView | PersonMentionView | CommentReplyView
1323 ): item is CommentReplyView {
1324 return (item as CommentReplyView).comment_reply?.id !== undefined;
1327 handleModBanFromCommunityShow(i: CommentNode) {
1329 showBanDialog: true,
1330 banType: BanType.Community,
1331 showRemoveDialog: false,
1335 handleModBanShow(i: CommentNode) {
1337 showBanDialog: true,
1338 banType: BanType.Site,
1339 showRemoveDialog: false,
1343 handleModBanReasonChange(i: CommentNode, event: any) {
1344 i.setState({ banReason: event.target.value });
1347 handleModBanExpireDaysChange(i: CommentNode, event: any) {
1348 i.setState({ banExpireDays: event.target.value });
1351 handlePurgePersonShow(i: CommentNode) {
1353 showPurgeDialog: true,
1354 purgeType: PurgeType.Person,
1355 showRemoveDialog: false,
1359 handlePurgeCommentShow(i: CommentNode) {
1361 showPurgeDialog: true,
1362 purgeType: PurgeType.Comment,
1363 showRemoveDialog: false,
1367 handlePurgeReasonChange(i: CommentNode, event: any) {
1368 i.setState({ purgeReason: event.target.value });
1371 handleShowConfirmAppointAsMod(i: CommentNode) {
1372 i.setState({ showConfirmAppointAsMod: true });
1375 handleCancelConfirmAppointAsMod(i: CommentNode) {
1376 i.setState({ showConfirmAppointAsMod: false });
1379 handleShowConfirmAppointAsAdmin(i: CommentNode) {
1380 i.setState({ showConfirmAppointAsAdmin: true });
1383 handleCancelConfirmAppointAsAdmin(i: CommentNode) {
1384 i.setState({ showConfirmAppointAsAdmin: false });
1387 handleShowConfirmTransferCommunity(i: CommentNode) {
1388 i.setState({ showConfirmTransferCommunity: true });
1391 handleCancelShowConfirmTransferCommunity(i: CommentNode) {
1392 i.setState({ showConfirmTransferCommunity: false });
1395 handleShowConfirmTransferSite(i: CommentNode) {
1396 i.setState({ showConfirmTransferSite: true });
1399 handleCancelShowConfirmTransferSite(i: CommentNode) {
1400 i.setState({ showConfirmTransferSite: false });
1403 get isCommentNew(): boolean {
1404 const now = subMinutes(new Date(), 10);
1405 const then = parseISO(this.commentView.comment.published);
1406 return isBefore(now, then);
1409 handleCommentCollapse(i: CommentNode) {
1410 i.setState({ collapsed: !i.state.collapsed });
1414 handleViewSource(i: CommentNode) {
1415 i.setState({ viewSource: !i.state.viewSource });
1418 handleShowAdvanced(i: CommentNode) {
1419 i.setState({ showAdvanced: !i.state.showAdvanced });
1423 handleSaveComment(i: CommentNode) {
1424 i.setState({ saveLoading: true });
1426 i.props.onSaveComment({
1427 comment_id: i.commentView.comment.id,
1428 save: !i.commentView.saved,
1429 auth: myAuthRequired(),
1433 handleBlockPerson(i: CommentNode) {
1434 i.setState({ blockPersonLoading: true });
1435 i.props.onBlockPerson({
1436 person_id: i.commentView.creator.id,
1438 auth: myAuthRequired(),
1442 handleMarkAsRead(i: CommentNode) {
1443 i.setState({ readLoading: true });
1444 const cv = i.commentView;
1445 if (i.isPersonMentionType(cv)) {
1446 i.props.onPersonMentionRead({
1447 person_mention_id: cv.person_mention.id,
1448 read: !cv.person_mention.read,
1449 auth: myAuthRequired(),
1451 } else if (i.isCommentReplyType(cv)) {
1452 i.props.onCommentReplyRead({
1453 comment_reply_id: cv.comment_reply.id,
1454 read: !cv.comment_reply.read,
1455 auth: myAuthRequired(),
1460 handleDeleteComment(i: CommentNode) {
1461 i.setState({ deleteLoading: true });
1462 i.props.onDeleteComment({
1463 comment_id: i.commentId,
1464 deleted: !i.commentView.comment.deleted,
1465 auth: myAuthRequired(),
1469 handleRemoveComment(i: CommentNode, event: any) {
1470 event.preventDefault();
1471 i.setState({ removeLoading: true });
1472 i.props.onRemoveComment({
1473 comment_id: i.commentId,
1474 removed: !i.commentView.comment.removed,
1475 auth: myAuthRequired(),
1479 handleDistinguishComment(i: CommentNode) {
1480 i.setState({ distinguishLoading: true });
1481 i.props.onDistinguishComment({
1482 comment_id: i.commentId,
1483 distinguished: !i.commentView.comment.distinguished,
1484 auth: myAuthRequired(),
1488 handleBanPersonFromCommunity(i: CommentNode) {
1489 i.setState({ banLoading: true });
1490 i.props.onBanPersonFromCommunity({
1491 community_id: i.commentView.community.id,
1492 person_id: i.commentView.creator.id,
1493 ban: !i.commentView.creator_banned_from_community,
1494 reason: i.state.banReason,
1495 remove_data: i.state.removeData,
1496 expires: futureDaysToUnixTime(i.state.banExpireDays),
1497 auth: myAuthRequired(),
1501 handleBanPerson(i: CommentNode) {
1502 i.setState({ banLoading: true });
1503 i.props.onBanPerson({
1504 person_id: i.commentView.creator.id,
1505 ban: !i.commentView.creator_banned_from_community,
1506 reason: i.state.banReason,
1507 remove_data: i.state.removeData,
1508 expires: futureDaysToUnixTime(i.state.banExpireDays),
1509 auth: myAuthRequired(),
1513 handleModBanBothSubmit(i: CommentNode, event: any) {
1514 event.preventDefault();
1515 if (i.state.banType == BanType.Community) {
1516 i.handleBanPersonFromCommunity(i);
1518 i.handleBanPerson(i);
1522 handleAddModToCommunity(i: CommentNode) {
1523 i.setState({ addModLoading: true });
1525 const added = !isMod(i.commentView.comment.creator_id, i.props.moderators);
1526 i.props.onAddModToCommunity({
1527 community_id: i.commentView.community.id,
1528 person_id: i.commentView.creator.id,
1530 auth: myAuthRequired(),
1534 handleAddAdmin(i: CommentNode) {
1535 i.setState({ addAdminLoading: true });
1537 const added = !isAdmin(i.commentView.comment.creator_id, i.props.admins);
1538 i.props.onAddAdmin({
1539 person_id: i.commentView.creator.id,
1541 auth: myAuthRequired(),
1545 handleTransferCommunity(i: CommentNode) {
1546 i.setState({ transferCommunityLoading: true });
1547 i.props.onTransferCommunity({
1548 community_id: i.commentView.community.id,
1549 person_id: i.commentView.creator.id,
1550 auth: myAuthRequired(),
1554 handleReportComment(i: CommentNode, event: any) {
1555 event.preventDefault();
1556 i.setState({ reportLoading: true });
1557 i.props.onCommentReport({
1558 comment_id: i.commentId,
1559 reason: i.state.reportReason ?? "",
1560 auth: myAuthRequired(),
1564 handlePurgeBothSubmit(i: CommentNode, event: any) {
1565 event.preventDefault();
1566 i.setState({ purgeLoading: true });
1568 if (i.state.purgeType == PurgeType.Person) {
1569 i.props.onPurgePerson({
1570 person_id: i.commentView.creator.id,
1571 reason: i.state.purgeReason,
1572 auth: myAuthRequired(),
1575 i.props.onPurgeComment({
1576 comment_id: i.commentId,
1577 reason: i.state.purgeReason,
1578 auth: myAuthRequired(),
1583 handleFetchChildren(i: CommentNode) {
1584 i.setState({ fetchChildrenLoading: true });
1585 i.props.onFetchChildren?.({
1586 parent_id: i.commentId,
1587 max_depth: commentTreeMaxDepth,