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 { UserBadges } from "../common/user-badges";
66 import { VoteButtonsCompact } from "../common/vote-buttons";
67 import { CommunityLink } from "../community/community-link";
68 import { PersonListing } from "../person/person-listing";
69 import { CommentForm } from "./comment-form";
70 import { CommentNodes } from "./comment-nodes";
72 interface CommentNodeState {
75 showRemoveDialog: boolean;
76 removeReason?: string;
77 showBanDialog: boolean;
80 banExpireDays?: number;
82 showPurgeDialog: boolean;
85 showConfirmTransferSite: boolean;
86 showConfirmTransferCommunity: boolean;
87 showConfirmAppointAsMod: boolean;
88 showConfirmAppointAsAdmin: boolean;
91 showAdvanced: boolean;
92 showReportDialog: boolean;
93 reportReason?: string;
94 createOrEditCommentLoading: boolean;
95 upvoteLoading: boolean;
96 downvoteLoading: boolean;
99 blockPersonLoading: boolean;
100 deleteLoading: boolean;
101 removeLoading: boolean;
102 distinguishLoading: boolean;
104 addModLoading: boolean;
105 addAdminLoading: boolean;
106 transferCommunityLoading: boolean;
107 fetchChildrenLoading: boolean;
108 reportLoading: boolean;
109 purgeLoading: boolean;
112 interface CommentNodeProps {
114 moderators?: CommunityModeratorView[];
115 admins?: PersonView[];
117 isTopLevel?: boolean;
121 showContext?: boolean;
122 showCommunity?: boolean;
123 enableDownvotes?: boolean;
124 viewType: CommentViewType;
125 allLanguages: Language[];
126 siteLanguages: number[];
127 hideImages?: boolean;
128 finished: Map<CommentId, boolean | undefined>;
129 onSaveComment(form: SaveComment): void;
130 onCommentReplyRead(form: MarkCommentReplyAsRead): void;
131 onPersonMentionRead(form: MarkPersonMentionAsRead): void;
132 onCreateComment(form: EditComment | CreateComment): void;
133 onEditComment(form: EditComment | CreateComment): void;
134 onCommentVote(form: CreateCommentLike): void;
135 onBlockPerson(form: BlockPerson): void;
136 onDeleteComment(form: DeleteComment): void;
137 onRemoveComment(form: RemoveComment): void;
138 onDistinguishComment(form: DistinguishComment): void;
139 onAddModToCommunity(form: AddModToCommunity): void;
140 onAddAdmin(form: AddAdmin): void;
141 onBanPersonFromCommunity(form: BanFromCommunity): void;
142 onBanPerson(form: BanPerson): void;
143 onTransferCommunity(form: TransferCommunity): void;
144 onFetchChildren?(form: GetComments): void;
145 onCommentReport(form: CreateCommentReport): void;
146 onPurgePerson(form: PurgePerson): void;
147 onPurgeComment(form: PurgeComment): void;
150 export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
151 state: CommentNodeState = {
154 showRemoveDialog: false,
155 showBanDialog: false,
157 banType: BanType.Community,
158 showPurgeDialog: false,
159 purgeType: PurgeType.Person,
163 showConfirmTransferSite: false,
164 showConfirmTransferCommunity: false,
165 showConfirmAppointAsMod: false,
166 showConfirmAppointAsAdmin: false,
167 showReportDialog: false,
168 createOrEditCommentLoading: false,
169 upvoteLoading: false,
170 downvoteLoading: false,
173 blockPersonLoading: false,
174 deleteLoading: false,
175 removeLoading: false,
176 distinguishLoading: false,
178 addModLoading: false,
179 addAdminLoading: false,
180 transferCommunityLoading: false,
181 fetchChildrenLoading: false,
182 reportLoading: false,
186 constructor(props: any, context: any) {
187 super(props, context);
189 this.handleReplyCancel = this.handleReplyCancel.bind(this);
192 get commentView(): CommentView {
193 return this.props.node.comment_view;
196 get commentId(): CommentId {
197 return this.commentView.comment.id;
200 componentWillReceiveProps(
201 nextProps: Readonly<{ children?: InfernoNode } & CommentNodeProps>
203 if (!deepEqual(this.props, nextProps)) {
207 showRemoveDialog: false,
208 showBanDialog: false,
210 banType: BanType.Community,
211 showPurgeDialog: false,
212 purgeType: PurgeType.Person,
216 showConfirmTransferSite: false,
217 showConfirmTransferCommunity: false,
218 showConfirmAppointAsMod: false,
219 showConfirmAppointAsAdmin: false,
220 showReportDialog: false,
221 createOrEditCommentLoading: false,
222 upvoteLoading: false,
223 downvoteLoading: false,
226 blockPersonLoading: false,
227 deleteLoading: false,
228 removeLoading: false,
229 distinguishLoading: false,
231 addModLoading: false,
232 addAdminLoading: false,
233 transferCommunityLoading: false,
234 fetchChildrenLoading: false,
235 reportLoading: false,
242 const node = this.props.node;
243 const cv = this.commentView;
245 const purgeTypeText =
246 this.state.purgeType == PurgeType.Comment
247 ? I18NextService.i18n.t("purge_comment")
248 : `${I18NextService.i18n.t("purge")} ${cv.creator.name}`;
250 const canMod_ = canMod(
252 this.props.moderators,
255 const canModOnSelf = canMod(
257 this.props.moderators,
259 UserService.Instance.myUserInfo,
262 const canAdmin_ = canAdmin(cv.creator.id, this.props.admins);
263 const canAdminOnSelf = canAdmin(
266 UserService.Instance.myUserInfo,
269 const isMod_ = isMod(cv.creator.id, this.props.moderators);
270 const isAdmin_ = isAdmin(cv.creator.id, this.props.admins);
271 const amCommunityCreator_ = amCommunityCreator(
273 this.props.moderators
276 const moreRepliesBorderColor = this.props.node.depth
277 ? colorList[this.props.node.depth % colorList.length]
280 const showMoreChildren =
281 this.props.viewType == CommentViewType.Tree &&
282 !this.state.collapsed &&
283 node.children.length == 0 &&
284 node.comment_view.counts.child_count > 0;
287 <li className="comment">
289 id={`comment-${cv.comment.id}`}
290 className={classNames(`details comment-node py-2`, {
291 "border-top border-light": !this.props.noBorder,
292 mark: this.isCommentNew || this.commentView.comment.distinguished,
295 <div className="ms-2">
296 <div className="d-flex flex-wrap align-items-center text-muted small">
298 className="btn btn-sm btn-link text-muted me-2"
299 onClick={linkEvent(this, this.handleCommentCollapse)}
300 aria-label={this.expandText}
301 data-tippy-content={this.expandText}
304 icon={`${this.state.collapsed ? "plus" : "minus"}-square`}
305 classes="icon-inline"
309 <PersonListing person={cv.creator} />
311 {cv.comment.distinguished && (
312 <Icon icon="shield" inline classes="text-danger ms-1" />
317 isPostCreator={this.isPostCreator}
320 isBot={cv.creator.bot_account}
323 {this.props.showCommunity && (
325 <span className="mx-1">{I18NextService.i18n.t("to")}</span>
326 <CommunityLink community={cv.community} />
327 <span className="mx-2">•</span>
328 <Link className="me-2" to={`/post/${cv.post.id}`}>
334 {this.getLinkButton(true)}
336 {cv.comment.language_id !== 0 && (
337 <span className="badge text-bg-light d-none d-sm-inline me-2">
339 this.props.allLanguages.find(
340 lang => lang.id === cv.comment.language_id
345 {/* This is an expanding spacer for mobile */}
346 <div className="me-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
351 className="me-1 fw-bold"
352 aria-label={I18NextService.i18n.t("number_of_points", {
353 count: Number(this.commentView.counts.score),
354 formattedCount: numToSI(this.commentView.counts.score),
357 {numToSI(this.commentView.counts.score)}
359 <span className="me-1">•</span>
364 published={cv.comment.published}
365 updated={cv.comment.updated}
369 {/* end of user row */}
370 {this.state.showEdit && (
374 onReplyCancel={this.handleReplyCancel}
375 disabled={this.props.locked}
376 finished={this.props.finished.get(
377 this.props.node.comment_view.comment.id
380 allLanguages={this.props.allLanguages}
381 siteLanguages={this.props.siteLanguages}
382 containerClass="comment-comment-container"
383 onUpsertComment={this.props.onEditComment}
386 {!this.state.showEdit && !this.state.collapsed && (
388 {this.state.viewSource ? (
389 <pre>{this.commentUnlessRemoved}</pre>
393 dangerouslySetInnerHTML={
394 this.props.hideImages
395 ? mdToHtmlNoImages(this.commentUnlessRemoved)
396 : mdToHtml(this.commentUnlessRemoved)
400 <div className="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted fw-bold">
401 {this.props.showContext && this.getLinkButton()}
402 {this.props.markable && (
404 className="btn btn-link btn-animate text-muted"
405 onClick={linkEvent(this, this.handleMarkAsRead)}
407 this.commentReplyOrMentionRead
408 ? I18NextService.i18n.t("mark_as_unread")
409 : I18NextService.i18n.t("mark_as_read")
412 this.commentReplyOrMentionRead
413 ? I18NextService.i18n.t("mark_as_unread")
414 : I18NextService.i18n.t("mark_as_read")
417 {this.state.readLoading ? (
422 classes={`icon-inline ${
423 this.commentReplyOrMentionRead && "text-success"
429 {UserService.Instance.myUserInfo && !this.props.viewOnly && (
432 voteContentType={VoteContentType.Comment}
433 id={this.commentView.comment.id}
434 onVote={this.props.onCommentVote}
435 enableDownvotes={this.props.enableDownvotes}
436 counts={this.commentView.counts}
437 my_vote={this.commentView.my_vote}
440 className="btn btn-link btn-animate text-muted"
441 onClick={linkEvent(this, this.handleReplyClick)}
442 data-tippy-content={I18NextService.i18n.t("reply")}
443 aria-label={I18NextService.i18n.t("reply")}
445 <Icon icon="reply1" classes="icon-inline" />
447 {!this.state.showAdvanced ? (
449 className="btn btn-link btn-animate text-muted btn-more"
450 onClick={linkEvent(this, this.handleShowAdvanced)}
451 data-tippy-content={I18NextService.i18n.t("more")}
452 aria-label={I18NextService.i18n.t("more")}
454 <Icon icon="more-vertical" classes="icon-inline" />
458 {!this.myComment && (
461 className="btn btn-link btn-animate text-muted"
462 to={`/create_private_message/${cv.creator.id}`}
463 title={I18NextService.i18n
470 className="btn btn-link btn-animate text-muted"
473 this.handleShowReportDialog
475 data-tippy-content={I18NextService.i18n.t(
478 aria-label={I18NextService.i18n.t(
485 className="btn btn-link btn-animate text-muted"
488 this.handleBlockPerson
490 data-tippy-content={I18NextService.i18n.t(
493 aria-label={I18NextService.i18n.t("block_user")}
495 {this.state.blockPersonLoading ? (
498 <Icon icon="slash" />
504 className="btn btn-link btn-animate text-muted"
505 onClick={linkEvent(this, this.handleSaveComment)}
508 ? I18NextService.i18n.t("unsave")
509 : I18NextService.i18n.t("save")
513 ? I18NextService.i18n.t("unsave")
514 : I18NextService.i18n.t("save")
517 {this.state.saveLoading ? (
522 classes={`icon-inline ${
523 cv.saved && "text-warning"
529 className="btn btn-link btn-animate text-muted"
530 onClick={linkEvent(this, this.handleViewSource)}
531 data-tippy-content={I18NextService.i18n.t(
534 aria-label={I18NextService.i18n.t("view_source")}
538 classes={`icon-inline ${
539 this.state.viewSource && "text-success"
546 className="btn btn-link btn-animate text-muted"
547 onClick={linkEvent(this, this.handleEditClick)}
548 data-tippy-content={I18NextService.i18n.t(
551 aria-label={I18NextService.i18n.t("edit")}
553 <Icon icon="edit" classes="icon-inline" />
556 className="btn btn-link btn-animate text-muted"
559 this.handleDeleteComment
563 ? I18NextService.i18n.t("delete")
564 : I18NextService.i18n.t("restore")
568 ? I18NextService.i18n.t("delete")
569 : I18NextService.i18n.t("restore")
572 {this.state.deleteLoading ? (
577 classes={`icon-inline ${
578 cv.comment.deleted && "text-danger"
584 {(canModOnSelf || canAdminOnSelf) && (
586 className="btn btn-link btn-animate text-muted"
589 this.handleDistinguishComment
592 !cv.comment.distinguished
593 ? I18NextService.i18n.t("distinguish")
594 : I18NextService.i18n.t("undistinguish")
597 !cv.comment.distinguished
598 ? I18NextService.i18n.t("distinguish")
599 : I18NextService.i18n.t("undistinguish")
604 classes={`icon-inline ${
605 cv.comment.distinguished && "text-danger"
612 {/* Admins and mods can remove comments */}
613 {(canMod_ || canAdmin_) && (
615 {!cv.comment.removed ? (
617 className="btn btn-link btn-animate text-muted"
620 this.handleModRemoveShow
622 aria-label={I18NextService.i18n.t("remove")}
624 {I18NextService.i18n.t("remove")}
628 className="btn btn-link btn-animate text-muted"
631 this.handleRemoveComment
633 aria-label={I18NextService.i18n.t("restore")}
635 {this.state.removeLoading ? (
638 I18NextService.i18n.t("restore")
644 {/* Mods can ban from community, and appoint as mods to community */}
648 (!cv.creator_banned_from_community ? (
650 className="btn btn-link btn-animate text-muted"
653 this.handleModBanFromCommunityShow
655 aria-label={I18NextService.i18n.t(
659 {I18NextService.i18n.t(
665 className="btn btn-link btn-animate text-muted"
668 this.handleBanPersonFromCommunity
670 aria-label={I18NextService.i18n.t("unban")}
672 {this.state.banLoading ? (
675 I18NextService.i18n.t("unban")
679 {!cv.creator_banned_from_community &&
680 (!this.state.showConfirmAppointAsMod ? (
682 className="btn btn-link btn-animate text-muted"
685 this.handleShowConfirmAppointAsMod
689 ? I18NextService.i18n.t("remove_as_mod")
690 : I18NextService.i18n.t(
696 ? I18NextService.i18n.t("remove_as_mod")
697 : I18NextService.i18n.t("appoint_as_mod")}
702 className="btn btn-link btn-animate text-muted"
703 aria-label={I18NextService.i18n.t(
707 {I18NextService.i18n.t("are_you_sure")}
710 className="btn btn-link btn-animate text-muted"
713 this.handleAddModToCommunity
715 aria-label={I18NextService.i18n.t("yes")}
717 {this.state.addModLoading ? (
720 I18NextService.i18n.t("yes")
724 className="btn btn-link btn-animate text-muted"
727 this.handleCancelConfirmAppointAsMod
729 aria-label={I18NextService.i18n.t("no")}
731 {I18NextService.i18n.t("no")}
737 {/* Community creators and admins can transfer community to another mod */}
738 {(amCommunityCreator_ || canAdmin_) &&
741 (!this.state.showConfirmTransferCommunity ? (
743 className="btn btn-link btn-animate text-muted"
746 this.handleShowConfirmTransferCommunity
748 aria-label={I18NextService.i18n.t(
752 {I18NextService.i18n.t("transfer_community")}
757 className="btn btn-link btn-animate text-muted"
758 aria-label={I18NextService.i18n.t(
762 {I18NextService.i18n.t("are_you_sure")}
765 className="btn btn-link btn-animate text-muted"
768 this.handleTransferCommunity
770 aria-label={I18NextService.i18n.t("yes")}
772 {this.state.transferCommunityLoading ? (
775 I18NextService.i18n.t("yes")
779 className="btn btn-link btn-animate text-muted"
783 .handleCancelShowConfirmTransferCommunity
785 aria-label={I18NextService.i18n.t("no")}
787 {I18NextService.i18n.t("no")}
791 {/* Admins can ban from all, and appoint other admins */}
797 className="btn btn-link btn-animate text-muted"
800 this.handlePurgePersonShow
802 aria-label={I18NextService.i18n.t(
806 {I18NextService.i18n.t("purge_user")}
809 className="btn btn-link btn-animate text-muted"
812 this.handlePurgeCommentShow
814 aria-label={I18NextService.i18n.t(
818 {I18NextService.i18n.t("purge_comment")}
821 {!isBanned(cv.creator) ? (
823 className="btn btn-link btn-animate text-muted"
826 this.handleModBanShow
828 aria-label={I18NextService.i18n.t(
832 {I18NextService.i18n.t("ban_from_site")}
836 className="btn btn-link btn-animate text-muted"
841 aria-label={I18NextService.i18n.t(
845 {this.state.banLoading ? (
848 I18NextService.i18n.t("unban_from_site")
854 {!isBanned(cv.creator) &&
856 (!this.state.showConfirmAppointAsAdmin ? (
858 className="btn btn-link btn-animate text-muted"
861 this.handleShowConfirmAppointAsAdmin
865 ? I18NextService.i18n.t(
868 : I18NextService.i18n.t(
874 ? I18NextService.i18n.t("remove_as_admin")
875 : I18NextService.i18n.t(
881 <button className="btn btn-link btn-animate text-muted">
882 {I18NextService.i18n.t("are_you_sure")}
885 className="btn btn-link btn-animate text-muted"
890 aria-label={I18NextService.i18n.t("yes")}
892 {this.state.addAdminLoading ? (
895 I18NextService.i18n.t("yes")
899 className="btn btn-link btn-animate text-muted"
902 this.handleCancelConfirmAppointAsAdmin
904 aria-label={I18NextService.i18n.t("no")}
906 {I18NextService.i18n.t("no")}
917 {/* end of button group */}
922 {showMoreChildren && (
924 className={classNames("details ms-1 comment-node py-2", {
925 "border-top border-light": !this.props.noBorder,
927 style={`border-left: 2px ${moreRepliesBorderColor} solid !important`}
930 className="btn btn-link text-muted"
931 onClick={linkEvent(this, this.handleFetchChildren)}
933 {this.state.fetchChildrenLoading ? (
937 {I18NextService.i18n.t("x_more_replies", {
938 count: node.comment_view.counts.child_count,
939 formattedCount: numToSI(
940 node.comment_view.counts.child_count
949 {/* end of details */}
950 {this.state.showRemoveDialog && (
952 className="form-inline"
953 onSubmit={linkEvent(this, this.handleRemoveComment)}
956 className="visually-hidden"
957 htmlFor={`mod-remove-reason-${cv.comment.id}`}
959 {I18NextService.i18n.t("reason")}
963 id={`mod-remove-reason-${cv.comment.id}`}
964 className="form-control me-2"
965 placeholder={I18NextService.i18n.t("reason")}
966 value={this.state.removeReason}
967 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
971 className="btn btn-secondary"
972 aria-label={I18NextService.i18n.t("remove_comment")}
974 {I18NextService.i18n.t("remove_comment")}
978 {this.state.showReportDialog && (
980 className="form-inline"
981 onSubmit={linkEvent(this, this.handleReportComment)}
984 className="visually-hidden"
985 htmlFor={`report-reason-${cv.comment.id}`}
987 {I18NextService.i18n.t("reason")}
992 id={`report-reason-${cv.comment.id}`}
993 className="form-control me-2"
994 placeholder={I18NextService.i18n.t("reason")}
995 value={this.state.reportReason}
996 onInput={linkEvent(this, this.handleReportReasonChange)}
1000 className="btn btn-secondary"
1001 aria-label={I18NextService.i18n.t("create_report")}
1003 {I18NextService.i18n.t("create_report")}
1007 {this.state.showBanDialog && (
1008 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1009 <div className="mb-3 row col-12">
1011 className="col-form-label"
1012 htmlFor={`mod-ban-reason-${cv.comment.id}`}
1014 {I18NextService.i18n.t("reason")}
1018 id={`mod-ban-reason-${cv.comment.id}`}
1019 className="form-control me-2"
1020 placeholder={I18NextService.i18n.t("reason")}
1021 value={this.state.banReason}
1022 onInput={linkEvent(this, this.handleModBanReasonChange)}
1025 className="col-form-label"
1026 htmlFor={`mod-ban-expires-${cv.comment.id}`}
1028 {I18NextService.i18n.t("expires")}
1032 id={`mod-ban-expires-${cv.comment.id}`}
1033 className="form-control me-2"
1034 placeholder={I18NextService.i18n.t("number_of_days")}
1035 value={this.state.banExpireDays}
1036 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1038 <div className="input-group mb-3">
1039 <div className="form-check">
1041 className="form-check-input"
1042 id="mod-ban-remove-data"
1044 checked={this.state.removeData}
1045 onChange={linkEvent(this, this.handleModRemoveDataChange)}
1048 className="form-check-label"
1049 htmlFor="mod-ban-remove-data"
1050 title={I18NextService.i18n.t("remove_content_more")}
1052 {I18NextService.i18n.t("remove_content")}
1057 {/* TODO hold off on expires until later */}
1058 {/* <div class="mb-3 row"> */}
1059 {/* <label class="col-form-label">Expires</label> */}
1060 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1062 <div className="mb-3 row">
1065 className="btn btn-secondary"
1066 aria-label={I18NextService.i18n.t("ban")}
1068 {this.state.banLoading ? (
1072 {I18NextService.i18n.t("ban")} {cv.creator.name}
1080 {this.state.showPurgeDialog && (
1081 <form onSubmit={linkEvent(this, this.handlePurgeBothSubmit)}>
1083 <label className="visually-hidden" htmlFor="purge-reason">
1084 {I18NextService.i18n.t("reason")}
1089 className="form-control my-3"
1090 placeholder={I18NextService.i18n.t("reason")}
1091 value={this.state.purgeReason}
1092 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1094 <div className="mb-3 row col-12">
1095 {this.state.purgeLoading ? (
1100 className="btn btn-secondary"
1101 aria-label={purgeTypeText}
1109 {this.state.showReply && (
1112 onReplyCancel={this.handleReplyCancel}
1113 disabled={this.props.locked}
1114 finished={this.props.finished.get(
1115 this.props.node.comment_view.comment.id
1118 allLanguages={this.props.allLanguages}
1119 siteLanguages={this.props.siteLanguages}
1120 containerClass="comment-comment-container"
1121 onUpsertComment={this.props.onCreateComment}
1124 {!this.state.collapsed && node.children.length > 0 && (
1126 nodes={node.children}
1127 locked={this.props.locked}
1128 moderators={this.props.moderators}
1129 admins={this.props.admins}
1130 enableDownvotes={this.props.enableDownvotes}
1131 viewType={this.props.viewType}
1132 allLanguages={this.props.allLanguages}
1133 siteLanguages={this.props.siteLanguages}
1134 hideImages={this.props.hideImages}
1135 isChild={!this.props.isTopLevel}
1136 depth={this.props.node.depth + 1}
1137 finished={this.props.finished}
1138 onCommentReplyRead={this.props.onCommentReplyRead}
1139 onPersonMentionRead={this.props.onPersonMentionRead}
1140 onCreateComment={this.props.onCreateComment}
1141 onEditComment={this.props.onEditComment}
1142 onCommentVote={this.props.onCommentVote}
1143 onBlockPerson={this.props.onBlockPerson}
1144 onSaveComment={this.props.onSaveComment}
1145 onDeleteComment={this.props.onDeleteComment}
1146 onRemoveComment={this.props.onRemoveComment}
1147 onDistinguishComment={this.props.onDistinguishComment}
1148 onAddModToCommunity={this.props.onAddModToCommunity}
1149 onAddAdmin={this.props.onAddAdmin}
1150 onBanPersonFromCommunity={this.props.onBanPersonFromCommunity}
1151 onBanPerson={this.props.onBanPerson}
1152 onTransferCommunity={this.props.onTransferCommunity}
1153 onFetchChildren={this.props.onFetchChildren}
1154 onCommentReport={this.props.onCommentReport}
1155 onPurgePerson={this.props.onPurgePerson}
1156 onPurgeComment={this.props.onPurgeComment}
1159 {/* A collapsed clearfix */}
1160 {this.state.collapsed && <div className="row col-12" />}
1165 get commentReplyOrMentionRead(): boolean {
1166 const cv = this.commentView;
1168 if (this.isPersonMentionType(cv)) {
1169 return cv.person_mention.read;
1170 } else if (this.isCommentReplyType(cv)) {
1171 return cv.comment_reply.read;
1177 getLinkButton(small = false) {
1178 const cv = this.commentView;
1180 const classnames = classNames("btn btn-link btn-animate text-muted", {
1184 const title = this.props.showContext
1185 ? I18NextService.i18n.t("show_context")
1186 : I18NextService.i18n.t("link");
1188 // The context button should show the parent comment by default
1189 const parentCommentId = getCommentParentId(cv.comment) ?? cv.comment.id;
1194 className={classnames}
1195 to={`/comment/${parentCommentId}`}
1198 <Icon icon="link" classes="icon-inline" />
1201 <a className={classnames} title={title} href={cv.comment.ap_id}>
1202 <Icon icon="fedilink" classes="icon-inline" />
1209 get myComment(): boolean {
1211 UserService.Instance.myUserInfo?.local_user_view.person.id ==
1212 this.commentView.creator.id
1216 get isPostCreator(): boolean {
1217 return this.commentView.creator.id == this.commentView.post.creator_id;
1221 if (this.commentView.my_vote == 1) {
1223 } else if (this.commentView.my_vote == -1) {
1224 return "text-danger";
1226 return "text-muted";
1230 get pointsTippy(): string {
1231 const points = I18NextService.i18n.t("number_of_points", {
1232 count: Number(this.commentView.counts.score),
1233 formattedCount: numToSI(this.commentView.counts.score),
1236 const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1237 count: Number(this.commentView.counts.upvotes),
1238 formattedCount: numToSI(this.commentView.counts.upvotes),
1241 const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1242 count: Number(this.commentView.counts.downvotes),
1243 formattedCount: numToSI(this.commentView.counts.downvotes),
1246 return `${points} • ${upvotes} • ${downvotes}`;
1249 get expandText(): string {
1250 return this.state.collapsed
1251 ? I18NextService.i18n.t("expand")
1252 : I18NextService.i18n.t("collapse");
1255 get commentUnlessRemoved(): string {
1256 const comment = this.commentView.comment;
1257 return comment.removed
1258 ? `*${I18NextService.i18n.t("removed")}*`
1260 ? `*${I18NextService.i18n.t("deleted")}*`
1264 handleReplyClick(i: CommentNode) {
1265 i.setState({ showReply: true });
1268 handleEditClick(i: CommentNode) {
1269 i.setState({ showEdit: true });
1272 handleReplyCancel() {
1273 this.setState({ showReply: false, showEdit: false });
1276 handleShowReportDialog(i: CommentNode) {
1277 i.setState({ showReportDialog: !i.state.showReportDialog });
1280 handleReportReasonChange(i: CommentNode, event: any) {
1281 i.setState({ reportReason: event.target.value });
1284 handleModRemoveShow(i: CommentNode) {
1286 showRemoveDialog: !i.state.showRemoveDialog,
1287 showBanDialog: false,
1291 handleModRemoveReasonChange(i: CommentNode, event: any) {
1292 i.setState({ removeReason: event.target.value });
1295 handleModRemoveDataChange(i: CommentNode, event: any) {
1296 i.setState({ removeData: event.target.checked });
1299 isPersonMentionType(
1300 item: CommentView | PersonMentionView | CommentReplyView
1301 ): item is PersonMentionView {
1302 return (item as PersonMentionView).person_mention?.id !== undefined;
1306 item: CommentView | PersonMentionView | CommentReplyView
1307 ): item is CommentReplyView {
1308 return (item as CommentReplyView).comment_reply?.id !== undefined;
1311 handleModBanFromCommunityShow(i: CommentNode) {
1313 showBanDialog: true,
1314 banType: BanType.Community,
1315 showRemoveDialog: false,
1319 handleModBanShow(i: CommentNode) {
1321 showBanDialog: true,
1322 banType: BanType.Site,
1323 showRemoveDialog: false,
1327 handleModBanReasonChange(i: CommentNode, event: any) {
1328 i.setState({ banReason: event.target.value });
1331 handleModBanExpireDaysChange(i: CommentNode, event: any) {
1332 i.setState({ banExpireDays: event.target.value });
1335 handlePurgePersonShow(i: CommentNode) {
1337 showPurgeDialog: true,
1338 purgeType: PurgeType.Person,
1339 showRemoveDialog: false,
1343 handlePurgeCommentShow(i: CommentNode) {
1345 showPurgeDialog: true,
1346 purgeType: PurgeType.Comment,
1347 showRemoveDialog: false,
1351 handlePurgeReasonChange(i: CommentNode, event: any) {
1352 i.setState({ purgeReason: event.target.value });
1355 handleShowConfirmAppointAsMod(i: CommentNode) {
1356 i.setState({ showConfirmAppointAsMod: true });
1359 handleCancelConfirmAppointAsMod(i: CommentNode) {
1360 i.setState({ showConfirmAppointAsMod: false });
1363 handleShowConfirmAppointAsAdmin(i: CommentNode) {
1364 i.setState({ showConfirmAppointAsAdmin: true });
1367 handleCancelConfirmAppointAsAdmin(i: CommentNode) {
1368 i.setState({ showConfirmAppointAsAdmin: false });
1371 handleShowConfirmTransferCommunity(i: CommentNode) {
1372 i.setState({ showConfirmTransferCommunity: true });
1375 handleCancelShowConfirmTransferCommunity(i: CommentNode) {
1376 i.setState({ showConfirmTransferCommunity: false });
1379 handleShowConfirmTransferSite(i: CommentNode) {
1380 i.setState({ showConfirmTransferSite: true });
1383 handleCancelShowConfirmTransferSite(i: CommentNode) {
1384 i.setState({ showConfirmTransferSite: false });
1387 get isCommentNew(): boolean {
1388 const now = subMinutes(new Date(), 10);
1389 const then = parseISO(this.commentView.comment.published);
1390 return isBefore(now, then);
1393 handleCommentCollapse(i: CommentNode) {
1394 i.setState({ collapsed: !i.state.collapsed });
1398 handleViewSource(i: CommentNode) {
1399 i.setState({ viewSource: !i.state.viewSource });
1402 handleShowAdvanced(i: CommentNode) {
1403 i.setState({ showAdvanced: !i.state.showAdvanced });
1407 handleSaveComment(i: CommentNode) {
1408 i.setState({ saveLoading: true });
1410 i.props.onSaveComment({
1411 comment_id: i.commentView.comment.id,
1412 save: !i.commentView.saved,
1413 auth: myAuthRequired(),
1417 handleBlockPerson(i: CommentNode) {
1418 i.setState({ blockPersonLoading: true });
1419 i.props.onBlockPerson({
1420 person_id: i.commentView.creator.id,
1422 auth: myAuthRequired(),
1426 handleMarkAsRead(i: CommentNode) {
1427 i.setState({ readLoading: true });
1428 const cv = i.commentView;
1429 if (i.isPersonMentionType(cv)) {
1430 i.props.onPersonMentionRead({
1431 person_mention_id: cv.person_mention.id,
1432 read: !cv.person_mention.read,
1433 auth: myAuthRequired(),
1435 } else if (i.isCommentReplyType(cv)) {
1436 i.props.onCommentReplyRead({
1437 comment_reply_id: cv.comment_reply.id,
1438 read: !cv.comment_reply.read,
1439 auth: myAuthRequired(),
1444 handleDeleteComment(i: CommentNode) {
1445 i.setState({ deleteLoading: true });
1446 i.props.onDeleteComment({
1447 comment_id: i.commentId,
1448 deleted: !i.commentView.comment.deleted,
1449 auth: myAuthRequired(),
1453 handleRemoveComment(i: CommentNode, event: any) {
1454 event.preventDefault();
1455 i.setState({ removeLoading: true });
1456 i.props.onRemoveComment({
1457 comment_id: i.commentId,
1458 removed: !i.commentView.comment.removed,
1459 auth: myAuthRequired(),
1460 reason: i.state.removeReason,
1464 handleDistinguishComment(i: CommentNode) {
1465 i.setState({ distinguishLoading: true });
1466 i.props.onDistinguishComment({
1467 comment_id: i.commentId,
1468 distinguished: !i.commentView.comment.distinguished,
1469 auth: myAuthRequired(),
1473 handleBanPersonFromCommunity(i: CommentNode) {
1474 i.setState({ banLoading: true });
1475 i.props.onBanPersonFromCommunity({
1476 community_id: i.commentView.community.id,
1477 person_id: i.commentView.creator.id,
1478 ban: !i.commentView.creator_banned_from_community,
1479 reason: i.state.banReason,
1480 remove_data: i.state.removeData,
1481 expires: futureDaysToUnixTime(i.state.banExpireDays),
1482 auth: myAuthRequired(),
1486 handleBanPerson(i: CommentNode) {
1487 i.setState({ banLoading: true });
1488 i.props.onBanPerson({
1489 person_id: i.commentView.creator.id,
1490 ban: !i.commentView.creator_banned_from_community,
1491 reason: i.state.banReason,
1492 remove_data: i.state.removeData,
1493 expires: futureDaysToUnixTime(i.state.banExpireDays),
1494 auth: myAuthRequired(),
1498 handleModBanBothSubmit(i: CommentNode, event: any) {
1499 event.preventDefault();
1500 if (i.state.banType == BanType.Community) {
1501 i.handleBanPersonFromCommunity(i);
1503 i.handleBanPerson(i);
1507 handleAddModToCommunity(i: CommentNode) {
1508 i.setState({ addModLoading: true });
1510 const added = !isMod(i.commentView.comment.creator_id, i.props.moderators);
1511 i.props.onAddModToCommunity({
1512 community_id: i.commentView.community.id,
1513 person_id: i.commentView.creator.id,
1515 auth: myAuthRequired(),
1519 handleAddAdmin(i: CommentNode) {
1520 i.setState({ addAdminLoading: true });
1522 const added = !isAdmin(i.commentView.comment.creator_id, i.props.admins);
1523 i.props.onAddAdmin({
1524 person_id: i.commentView.creator.id,
1526 auth: myAuthRequired(),
1530 handleTransferCommunity(i: CommentNode) {
1531 i.setState({ transferCommunityLoading: true });
1532 i.props.onTransferCommunity({
1533 community_id: i.commentView.community.id,
1534 person_id: i.commentView.creator.id,
1535 auth: myAuthRequired(),
1539 handleReportComment(i: CommentNode, event: any) {
1540 event.preventDefault();
1541 i.setState({ reportLoading: true });
1542 i.props.onCommentReport({
1543 comment_id: i.commentId,
1544 reason: i.state.reportReason ?? "",
1545 auth: myAuthRequired(),
1549 handlePurgeBothSubmit(i: CommentNode, event: any) {
1550 event.preventDefault();
1551 i.setState({ purgeLoading: true });
1553 if (i.state.purgeType == PurgeType.Person) {
1554 i.props.onPurgePerson({
1555 person_id: i.commentView.creator.id,
1556 reason: i.state.purgeReason,
1557 auth: myAuthRequired(),
1560 i.props.onPurgeComment({
1561 comment_id: i.commentId,
1562 reason: i.state.purgeReason,
1563 auth: myAuthRequired(),
1568 handleFetchChildren(i: CommentNode) {
1569 i.setState({ fetchChildrenLoading: true });
1570 i.props.onFetchChildren?.({
1571 parent_id: i.commentId,
1572 max_depth: commentTreeMaxDepth,