1 import classNames from "classnames";
2 import { Component, InfernoNode, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
13 CommunityModeratorView,
22 MarkCommentReplyAsRead,
23 MarkPersonMentionAsRead,
31 } from "lemmy-js-client";
32 import moment from "moment";
33 import { i18n } from "../../i18next";
40 } from "../../interfaces";
41 import { UserService } from "../../services";
62 import { Icon, PurgeWarning, Spinner } from "../common/icon";
63 import { MomentTime } from "../common/moment-time";
64 import { CommunityLink } from "../community/community-link";
65 import { PersonListing } from "../person/person-listing";
66 import { CommentForm } from "./comment-form";
67 import { CommentNodes } from "./comment-nodes";
69 interface CommentNodeState {
72 showRemoveDialog: boolean;
73 removeReason?: string;
74 showBanDialog: boolean;
77 banExpireDays?: number;
79 showPurgeDialog: boolean;
82 showConfirmTransferSite: boolean;
83 showConfirmTransferCommunity: boolean;
84 showConfirmAppointAsMod: boolean;
85 showConfirmAppointAsAdmin: boolean;
88 showAdvanced: boolean;
89 showReportDialog: boolean;
90 reportReason?: string;
91 createOrEditCommentLoading: boolean;
92 upvoteLoading: boolean;
93 downvoteLoading: boolean;
96 blockPersonLoading: boolean;
97 deleteLoading: boolean;
98 removeLoading: boolean;
99 distinguishLoading: boolean;
101 addModLoading: boolean;
102 addAdminLoading: boolean;
103 transferCommunityLoading: boolean;
104 fetchChildrenLoading: boolean;
105 reportLoading: boolean;
106 purgeLoading: boolean;
109 interface CommentNodeProps {
111 moderators?: CommunityModeratorView[];
112 admins?: PersonView[];
118 showContext?: boolean;
119 showCommunity?: boolean;
120 enableDownvotes?: boolean;
121 viewType: CommentViewType;
122 allLanguages: Language[];
123 siteLanguages: number[];
124 hideImages?: boolean;
125 finished: Map<CommentId, boolean | undefined>;
126 onSaveComment(form: SaveComment): void;
127 onCommentReplyRead(form: MarkCommentReplyAsRead): void;
128 onPersonMentionRead(form: MarkPersonMentionAsRead): void;
129 onCreateComment(form: EditComment | CreateComment): void;
130 onEditComment(form: EditComment | CreateComment): void;
131 onCommentVote(form: CreateCommentLike): void;
132 onBlockPerson(form: BlockPerson): void;
133 onDeleteComment(form: DeleteComment): void;
134 onRemoveComment(form: RemoveComment): void;
135 onDistinguishComment(form: DistinguishComment): void;
136 onAddModToCommunity(form: AddModToCommunity): void;
137 onAddAdmin(form: AddAdmin): void;
138 onBanPersonFromCommunity(form: BanFromCommunity): void;
139 onBanPerson(form: BanPerson): void;
140 onTransferCommunity(form: TransferCommunity): void;
141 onFetchChildren?(form: GetComments): void;
142 onCommentReport(form: CreateCommentReport): void;
143 onPurgePerson(form: PurgePerson): void;
144 onPurgeComment(form: PurgeComment): void;
147 export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
148 state: CommentNodeState = {
151 showRemoveDialog: false,
152 showBanDialog: false,
154 banType: BanType.Community,
155 showPurgeDialog: false,
156 purgeType: PurgeType.Person,
160 showConfirmTransferSite: false,
161 showConfirmTransferCommunity: false,
162 showConfirmAppointAsMod: false,
163 showConfirmAppointAsAdmin: false,
164 showReportDialog: false,
165 createOrEditCommentLoading: false,
166 upvoteLoading: false,
167 downvoteLoading: false,
170 blockPersonLoading: false,
171 deleteLoading: false,
172 removeLoading: false,
173 distinguishLoading: false,
175 addModLoading: false,
176 addAdminLoading: false,
177 transferCommunityLoading: false,
178 fetchChildrenLoading: false,
179 reportLoading: false,
183 constructor(props: any, context: any) {
184 super(props, context);
186 this.handleReplyCancel = this.handleReplyCancel.bind(this);
189 get commentView(): CommentView {
190 return this.props.node.comment_view;
193 get commentId(): CommentId {
194 return this.commentView.comment.id;
197 componentWillReceiveProps(
198 nextProps: Readonly<{ children?: InfernoNode } & CommentNodeProps>
200 if (this.props != nextProps) {
204 showRemoveDialog: false,
205 showBanDialog: false,
207 banType: BanType.Community,
208 showPurgeDialog: false,
209 purgeType: PurgeType.Person,
213 showConfirmTransferSite: false,
214 showConfirmTransferCommunity: false,
215 showConfirmAppointAsMod: false,
216 showConfirmAppointAsAdmin: false,
217 showReportDialog: false,
218 createOrEditCommentLoading: false,
219 upvoteLoading: false,
220 downvoteLoading: false,
223 blockPersonLoading: false,
224 deleteLoading: false,
225 removeLoading: false,
226 distinguishLoading: false,
228 addModLoading: false,
229 addAdminLoading: false,
230 transferCommunityLoading: false,
231 fetchChildrenLoading: false,
232 reportLoading: false,
239 const node = this.props.node;
240 const cv = this.commentView;
242 const purgeTypeText =
243 this.state.purgeType == PurgeType.Comment
244 ? i18n.t("purge_comment")
245 : `${i18n.t("purge")} ${cv.creator.name}`;
247 const canMod_ = canMod(
249 this.props.moderators,
252 const canModOnSelf = canMod(
254 this.props.moderators,
256 UserService.Instance.myUserInfo,
259 const canAdmin_ = canAdmin(cv.creator.id, this.props.admins);
260 const canAdminOnSelf = canAdmin(
263 UserService.Instance.myUserInfo,
266 const isMod_ = isMod(cv.creator.id, this.props.moderators);
267 const isAdmin_ = isAdmin(cv.creator.id, this.props.admins);
268 const amCommunityCreator_ = amCommunityCreator(
270 this.props.moderators
273 const moreRepliesBorderColor = this.props.node.depth
274 ? colorList[this.props.node.depth % colorList.length]
277 const showMoreChildren =
278 this.props.viewType == CommentViewType.Tree &&
279 !this.state.collapsed &&
280 node.children.length == 0 &&
281 node.comment_view.counts.child_count > 0;
284 <li className="comment" role="comment">
286 id={`comment-${cv.comment.id}`}
287 className={classNames(`details comment-node py-2`, {
288 "border-top border-light": !this.props.noBorder,
289 mark: this.isCommentNew || this.commentView.comment.distinguished,
293 className={classNames({
294 "ml-2": !this.props.noIndent,
297 <div className="d-flex flex-wrap align-items-center text-muted small">
299 className="btn btn-sm text-muted mr-2"
300 onClick={linkEvent(this, this.handleCommentCollapse)}
301 aria-label={this.expandText}
302 data-tippy-content={this.expandText}
305 icon={`${this.state.collapsed ? "plus" : "minus"}-square`}
306 classes="icon-inline"
309 <span className="mr-2">
310 <PersonListing person={cv.creator} />
312 {cv.comment.distinguished && (
313 <Icon icon="shield" inline classes={`text-danger mr-2`} />
315 {this.isPostCreator && (
316 <div className="badge badge-light d-none d-sm-inline mr-2">
321 <div className="badge d-none d-sm-inline mr-2">
326 <div className="badge d-none d-sm-inline mr-2">
330 {cv.creator.bot_account && (
331 <div className="badge d-none d-sm-inline mr-2">
332 {i18n.t("bot_account").toLowerCase()}
335 {this.props.showCommunity && (
337 <span className="mx-1">{i18n.t("to")}</span>
338 <CommunityLink community={cv.community} />
339 <span className="mx-2">•</span>
340 <Link className="mr-2" to={`/post/${cv.post.id}`}>
346 {cv.comment.language_id !== 0 && (
347 <span className="badge d-none d-sm-inline mr-2">
349 this.props.allLanguages.find(
350 lang => lang.id === cv.comment.language_id
355 {/* This is an expanding spacer for mobile */}
356 <div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
360 className={`unselectable pointer ${this.scoreColor}`}
361 onClick={linkEvent(this, this.handleUpvote)}
362 data-tippy-content={this.pointsTippy}
364 {this.state.upvoteLoading ? (
368 className="mr-1 font-weight-bold"
369 aria-label={i18n.t("number_of_points", {
370 count: Number(this.commentView.counts.score),
371 formattedCount: numToSI(
372 this.commentView.counts.score
376 {numToSI(this.commentView.counts.score)}
380 <span className="mr-1">•</span>
385 published={cv.comment.published}
386 updated={cv.comment.updated}
390 {/* end of user row */}
391 {this.state.showEdit && (
395 onReplyCancel={this.handleReplyCancel}
396 disabled={this.props.locked}
397 finished={this.props.finished.get(
398 this.props.node.comment_view.comment.id
401 allLanguages={this.props.allLanguages}
402 siteLanguages={this.props.siteLanguages}
403 onUpsertComment={this.props.onEditComment}
406 {!this.state.showEdit && !this.state.collapsed && (
408 {this.state.viewSource ? (
409 <pre>{this.commentUnlessRemoved}</pre>
413 dangerouslySetInnerHTML={
414 this.props.hideImages
415 ? mdToHtmlNoImages(this.commentUnlessRemoved)
416 : mdToHtml(this.commentUnlessRemoved)
420 <div className="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold">
421 {this.props.showContext && this.linkBtn()}
422 {this.props.markable && (
424 className="btn btn-link btn-animate text-muted"
425 onClick={linkEvent(this, this.handleMarkAsRead)}
427 this.commentReplyOrMentionRead
428 ? i18n.t("mark_as_unread")
429 : i18n.t("mark_as_read")
432 this.commentReplyOrMentionRead
433 ? i18n.t("mark_as_unread")
434 : i18n.t("mark_as_read")
437 {this.state.readLoading ? (
442 classes={`icon-inline ${
443 this.commentReplyOrMentionRead && "text-success"
449 {UserService.Instance.myUserInfo && !this.props.viewOnly && (
452 className={`btn btn-link btn-animate ${
453 this.commentView.my_vote === 1
457 onClick={linkEvent(this, this.handleUpvote)}
458 data-tippy-content={i18n.t("upvote")}
459 aria-label={i18n.t("upvote")}
460 aria-pressed={this.commentView.my_vote === 1}
462 {this.state.upvoteLoading ? (
466 <Icon icon="arrow-up1" classes="icon-inline" />
468 this.commentView.counts.upvotes !==
469 this.commentView.counts.score && (
470 <span className="ml-1">
471 {numToSI(this.commentView.counts.upvotes)}
477 {this.props.enableDownvotes && (
479 className={`btn btn-link btn-animate ${
480 this.commentView.my_vote === -1
484 onClick={linkEvent(this, this.handleDownvote)}
485 data-tippy-content={i18n.t("downvote")}
486 aria-label={i18n.t("downvote")}
487 aria-pressed={this.commentView.my_vote === -1}
489 {this.state.downvoteLoading ? (
493 <Icon icon="arrow-down1" classes="icon-inline" />
495 this.commentView.counts.upvotes !==
496 this.commentView.counts.score && (
497 <span className="ml-1">
498 {numToSI(this.commentView.counts.downvotes)}
506 className="btn btn-link btn-animate text-muted"
507 onClick={linkEvent(this, this.handleReplyClick)}
508 data-tippy-content={i18n.t("reply")}
509 aria-label={i18n.t("reply")}
511 <Icon icon="reply1" classes="icon-inline" />
513 {!this.state.showAdvanced ? (
515 className="btn btn-link btn-animate text-muted"
516 onClick={linkEvent(this, this.handleShowAdvanced)}
517 data-tippy-content={i18n.t("more")}
518 aria-label={i18n.t("more")}
520 <Icon icon="more-vertical" classes="icon-inline" />
524 {!this.myComment && (
527 className="btn btn-link btn-animate text-muted"
528 to={`/create_private_message/${cv.creator.id}`}
529 title={i18n.t("message").toLowerCase()}
534 className="btn btn-link btn-animate text-muted"
537 this.handleShowReportDialog
539 data-tippy-content={i18n.t(
542 aria-label={i18n.t("show_report_dialog")}
547 className="btn btn-link btn-animate text-muted"
550 this.handleBlockPerson
552 data-tippy-content={i18n.t("block_user")}
553 aria-label={i18n.t("block_user")}
555 {this.state.blockPersonLoading ? (
558 <Icon icon="slash" />
564 className="btn btn-link btn-animate text-muted"
565 onClick={linkEvent(this, this.handleSaveComment)}
567 cv.saved ? i18n.t("unsave") : i18n.t("save")
570 cv.saved ? i18n.t("unsave") : i18n.t("save")
573 {this.state.saveLoading ? (
578 classes={`icon-inline ${
579 cv.saved && "text-warning"
585 className="btn btn-link btn-animate text-muted"
586 onClick={linkEvent(this, this.handleViewSource)}
587 data-tippy-content={i18n.t("view_source")}
588 aria-label={i18n.t("view_source")}
592 classes={`icon-inline ${
593 this.state.viewSource && "text-success"
600 className="btn btn-link btn-animate text-muted"
601 onClick={linkEvent(this, this.handleEditClick)}
602 data-tippy-content={i18n.t("edit")}
603 aria-label={i18n.t("edit")}
605 <Icon icon="edit" classes="icon-inline" />
608 className="btn btn-link btn-animate text-muted"
611 this.handleDeleteComment
624 {this.state.deleteLoading ? (
629 classes={`icon-inline ${
630 cv.comment.deleted && "text-danger"
636 {(canModOnSelf || canAdminOnSelf) && (
638 className="btn btn-link btn-animate text-muted"
641 this.handleDistinguishComment
644 !cv.comment.distinguished
645 ? i18n.t("distinguish")
646 : i18n.t("undistinguish")
649 !cv.comment.distinguished
650 ? i18n.t("distinguish")
651 : i18n.t("undistinguish")
656 classes={`icon-inline ${
657 cv.comment.distinguished && "text-danger"
664 {/* Admins and mods can remove comments */}
665 {(canMod_ || canAdmin_) && (
667 {!cv.comment.removed ? (
669 className="btn btn-link btn-animate text-muted"
672 this.handleModRemoveShow
674 aria-label={i18n.t("remove")}
680 className="btn btn-link btn-animate text-muted"
683 this.handleRemoveComment
685 aria-label={i18n.t("restore")}
687 {this.state.removeLoading ? (
696 {/* Mods can ban from community, and appoint as mods to community */}
700 (!cv.creator_banned_from_community ? (
702 className="btn btn-link btn-animate text-muted"
705 this.handleModBanFromCommunityShow
707 aria-label={i18n.t("ban_from_community")}
709 {i18n.t("ban_from_community")}
713 className="btn btn-link btn-animate text-muted"
716 this.handleBanPersonFromCommunity
718 aria-label={i18n.t("unban")}
720 {this.state.banLoading ? (
727 {!cv.creator_banned_from_community &&
728 (!this.state.showConfirmAppointAsMod ? (
730 className="btn btn-link btn-animate text-muted"
733 this.handleShowConfirmAppointAsMod
737 ? i18n.t("remove_as_mod")
738 : i18n.t("appoint_as_mod")
742 ? i18n.t("remove_as_mod")
743 : i18n.t("appoint_as_mod")}
748 className="btn btn-link btn-animate text-muted"
749 aria-label={i18n.t("are_you_sure")}
751 {i18n.t("are_you_sure")}
754 className="btn btn-link btn-animate text-muted"
757 this.handleAddModToCommunity
759 aria-label={i18n.t("yes")}
761 {this.state.addModLoading ? (
768 className="btn btn-link btn-animate text-muted"
771 this.handleCancelConfirmAppointAsMod
773 aria-label={i18n.t("no")}
781 {/* Community creators and admins can transfer community to another mod */}
782 {(amCommunityCreator_ || canAdmin_) &&
785 (!this.state.showConfirmTransferCommunity ? (
787 className="btn btn-link btn-animate text-muted"
790 this.handleShowConfirmTransferCommunity
792 aria-label={i18n.t("transfer_community")}
794 {i18n.t("transfer_community")}
799 className="btn btn-link btn-animate text-muted"
800 aria-label={i18n.t("are_you_sure")}
802 {i18n.t("are_you_sure")}
805 className="btn btn-link btn-animate text-muted"
808 this.handleTransferCommunity
810 aria-label={i18n.t("yes")}
812 {this.state.transferCommunityLoading ? (
819 className="btn btn-link btn-animate text-muted"
823 .handleCancelShowConfirmTransferCommunity
825 aria-label={i18n.t("no")}
831 {/* Admins can ban from all, and appoint other admins */}
837 className="btn btn-link btn-animate text-muted"
840 this.handlePurgePersonShow
842 aria-label={i18n.t("purge_user")}
844 {i18n.t("purge_user")}
847 className="btn btn-link btn-animate text-muted"
850 this.handlePurgeCommentShow
852 aria-label={i18n.t("purge_comment")}
854 {i18n.t("purge_comment")}
857 {!isBanned(cv.creator) ? (
859 className="btn btn-link btn-animate text-muted"
862 this.handleModBanShow
864 aria-label={i18n.t("ban_from_site")}
866 {i18n.t("ban_from_site")}
870 className="btn btn-link btn-animate text-muted"
875 aria-label={i18n.t("unban_from_site")}
877 {this.state.banLoading ? (
880 i18n.t("unban_from_site")
886 {!isBanned(cv.creator) &&
888 (!this.state.showConfirmAppointAsAdmin ? (
890 className="btn btn-link btn-animate text-muted"
893 this.handleShowConfirmAppointAsAdmin
897 ? i18n.t("remove_as_admin")
898 : i18n.t("appoint_as_admin")
902 ? i18n.t("remove_as_admin")
903 : i18n.t("appoint_as_admin")}
907 <button className="btn btn-link btn-animate text-muted">
908 {i18n.t("are_you_sure")}
911 className="btn btn-link btn-animate text-muted"
916 aria-label={i18n.t("yes")}
918 {this.state.addAdminLoading ? (
925 className="btn btn-link btn-animate text-muted"
928 this.handleCancelConfirmAppointAsAdmin
930 aria-label={i18n.t("no")}
943 {/* end of button group */}
948 {showMoreChildren && (
950 className={classNames("details ml-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 {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)}
983 htmlFor={`mod-remove-reason-${cv.comment.id}`}
989 id={`mod-remove-reason-${cv.comment.id}`}
990 className="form-control mr-2"
991 placeholder={i18n.t("reason")}
992 value={this.state.removeReason}
993 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
997 className="btn btn-secondary"
998 aria-label={i18n.t("remove_comment")}
1000 {i18n.t("remove_comment")}
1004 {this.state.showReportDialog && (
1006 className="form-inline"
1007 onSubmit={linkEvent(this, this.handleReportComment)}
1011 htmlFor={`report-reason-${cv.comment.id}`}
1018 id={`report-reason-${cv.comment.id}`}
1019 className="form-control mr-2"
1020 placeholder={i18n.t("reason")}
1021 value={this.state.reportReason}
1022 onInput={linkEvent(this, this.handleReportReasonChange)}
1026 className="btn btn-secondary"
1027 aria-label={i18n.t("create_report")}
1029 {i18n.t("create_report")}
1033 {this.state.showBanDialog && (
1034 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1035 <div className="form-group row col-12">
1037 className="col-form-label"
1038 htmlFor={`mod-ban-reason-${cv.comment.id}`}
1044 id={`mod-ban-reason-${cv.comment.id}`}
1045 className="form-control mr-2"
1046 placeholder={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}`}
1058 id={`mod-ban-expires-${cv.comment.id}`}
1059 className="form-control mr-2"
1060 placeholder={i18n.t("number_of_days")}
1061 value={this.state.banExpireDays}
1062 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1064 <div className="form-group">
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={i18n.t("remove_content_more")}
1078 {i18n.t("remove_content")}
1083 {/* TODO hold off on expires until later */}
1084 {/* <div class="form-group row"> */}
1085 {/* <label class="col-form-label">Expires</label> */}
1086 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1088 <div className="form-group row">
1091 className="btn btn-secondary"
1092 aria-label={i18n.t("ban")}
1094 {this.state.banLoading ? (
1098 {i18n.t("ban")} {cv.creator.name}
1106 {this.state.showPurgeDialog && (
1107 <form onSubmit={linkEvent(this, this.handlePurgeBothSubmit)}>
1109 <label className="sr-only" htmlFor="purge-reason">
1115 className="form-control my-3"
1116 placeholder={i18n.t("reason")}
1117 value={this.state.purgeReason}
1118 onInput={linkEvent(this, this.handlePurgeReasonChange)}
1120 <div className="form-group 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 onUpsertComment={this.props.onCreateComment}
1149 {!this.state.collapsed && node.children.length > 0 && (
1151 nodes={node.children}
1152 locked={this.props.locked}
1153 moderators={this.props.moderators}
1154 admins={this.props.admins}
1155 enableDownvotes={this.props.enableDownvotes}
1156 viewType={this.props.viewType}
1157 allLanguages={this.props.allLanguages}
1158 siteLanguages={this.props.siteLanguages}
1159 hideImages={this.props.hideImages}
1160 isChild={!this.props.noIndent}
1161 depth={this.props.node.depth + 1}
1162 finished={this.props.finished}
1163 onCommentReplyRead={this.props.onCommentReplyRead}
1164 onPersonMentionRead={this.props.onPersonMentionRead}
1165 onCreateComment={this.props.onCreateComment}
1166 onEditComment={this.props.onEditComment}
1167 onCommentVote={this.props.onCommentVote}
1168 onBlockPerson={this.props.onBlockPerson}
1169 onSaveComment={this.props.onSaveComment}
1170 onDeleteComment={this.props.onDeleteComment}
1171 onRemoveComment={this.props.onRemoveComment}
1172 onDistinguishComment={this.props.onDistinguishComment}
1173 onAddModToCommunity={this.props.onAddModToCommunity}
1174 onAddAdmin={this.props.onAddAdmin}
1175 onBanPersonFromCommunity={this.props.onBanPersonFromCommunity}
1176 onBanPerson={this.props.onBanPerson}
1177 onTransferCommunity={this.props.onTransferCommunity}
1178 onFetchChildren={this.props.onFetchChildren}
1179 onCommentReport={this.props.onCommentReport}
1180 onPurgePerson={this.props.onPurgePerson}
1181 onPurgeComment={this.props.onPurgeComment}
1184 {/* A collapsed clearfix */}
1185 {this.state.collapsed && <div className="row col-12" />}
1190 get commentReplyOrMentionRead(): boolean {
1191 const cv = this.commentView;
1193 if (this.isPersonMentionType(cv)) {
1194 return cv.person_mention.read;
1195 } else if (this.isCommentReplyType(cv)) {
1196 return cv.comment_reply.read;
1202 linkBtn(small = false) {
1203 const cv = this.commentView;
1205 const classnames = classNames("btn btn-link btn-animate text-muted", {
1209 const title = this.props.showContext
1210 ? i18n.t("show_context")
1213 // The context button should show the parent comment by default
1214 const parentCommentId = getCommentParentId(cv.comment) ?? cv.comment.id;
1219 className={classnames}
1220 to={`/comment/${parentCommentId}`}
1223 <Icon icon="link" classes="icon-inline" />
1226 <a className={classnames} title={title} href={cv.comment.ap_id}>
1227 <Icon icon="fedilink" classes="icon-inline" />
1234 get myComment(): boolean {
1236 UserService.Instance.myUserInfo?.local_user_view.person.id ==
1237 this.commentView.creator.id
1241 get isPostCreator(): boolean {
1242 return this.commentView.creator.id == this.commentView.post.creator_id;
1246 if (this.commentView.my_vote == 1) {
1248 } else if (this.commentView.my_vote == -1) {
1249 return "text-danger";
1251 return "text-muted";
1255 get pointsTippy(): string {
1256 const points = i18n.t("number_of_points", {
1257 count: Number(this.commentView.counts.score),
1258 formattedCount: numToSI(this.commentView.counts.score),
1261 const upvotes = i18n.t("number_of_upvotes", {
1262 count: Number(this.commentView.counts.upvotes),
1263 formattedCount: numToSI(this.commentView.counts.upvotes),
1266 const downvotes = i18n.t("number_of_downvotes", {
1267 count: Number(this.commentView.counts.downvotes),
1268 formattedCount: numToSI(this.commentView.counts.downvotes),
1271 return `${points} • ${upvotes} • ${downvotes}`;
1274 get expandText(): string {
1275 return this.state.collapsed ? i18n.t("expand") : i18n.t("collapse");
1278 get commentUnlessRemoved(): string {
1279 const comment = this.commentView.comment;
1280 return comment.removed
1281 ? `*${i18n.t("removed")}*`
1283 ? `*${i18n.t("deleted")}*`
1287 handleReplyClick(i: CommentNode) {
1288 i.setState({ showReply: true });
1291 handleEditClick(i: CommentNode) {
1292 i.setState({ showEdit: true });
1295 handleReplyCancel() {
1296 this.setState({ showReply: false, showEdit: false });
1299 handleShowReportDialog(i: CommentNode) {
1300 i.setState({ showReportDialog: !i.state.showReportDialog });
1303 handleReportReasonChange(i: CommentNode, event: any) {
1304 i.setState({ reportReason: event.target.value });
1307 handleModRemoveShow(i: CommentNode) {
1309 showRemoveDialog: !i.state.showRemoveDialog,
1310 showBanDialog: false,
1314 handleModRemoveReasonChange(i: CommentNode, event: any) {
1315 i.setState({ removeReason: event.target.value });
1318 handleModRemoveDataChange(i: CommentNode, event: any) {
1319 i.setState({ removeData: event.target.checked });
1322 isPersonMentionType(
1323 item: CommentView | PersonMentionView | CommentReplyView
1324 ): item is PersonMentionView {
1325 return (item as PersonMentionView).person_mention?.id !== undefined;
1329 item: CommentView | PersonMentionView | CommentReplyView
1330 ): item is CommentReplyView {
1331 return (item as CommentReplyView).comment_reply?.id !== undefined;
1334 handleModBanFromCommunityShow(i: CommentNode) {
1336 showBanDialog: true,
1337 banType: BanType.Community,
1338 showRemoveDialog: false,
1342 handleModBanShow(i: CommentNode) {
1344 showBanDialog: true,
1345 banType: BanType.Site,
1346 showRemoveDialog: false,
1350 handleModBanReasonChange(i: CommentNode, event: any) {
1351 i.setState({ banReason: event.target.value });
1354 handleModBanExpireDaysChange(i: CommentNode, event: any) {
1355 i.setState({ banExpireDays: event.target.value });
1358 handlePurgePersonShow(i: CommentNode) {
1360 showPurgeDialog: true,
1361 purgeType: PurgeType.Person,
1362 showRemoveDialog: false,
1366 handlePurgeCommentShow(i: CommentNode) {
1368 showPurgeDialog: true,
1369 purgeType: PurgeType.Comment,
1370 showRemoveDialog: false,
1374 handlePurgeReasonChange(i: CommentNode, event: any) {
1375 i.setState({ purgeReason: event.target.value });
1378 handleShowConfirmAppointAsMod(i: CommentNode) {
1379 i.setState({ showConfirmAppointAsMod: true });
1382 handleCancelConfirmAppointAsMod(i: CommentNode) {
1383 i.setState({ showConfirmAppointAsMod: false });
1386 handleShowConfirmAppointAsAdmin(i: CommentNode) {
1387 i.setState({ showConfirmAppointAsAdmin: true });
1390 handleCancelConfirmAppointAsAdmin(i: CommentNode) {
1391 i.setState({ showConfirmAppointAsAdmin: false });
1394 handleShowConfirmTransferCommunity(i: CommentNode) {
1395 i.setState({ showConfirmTransferCommunity: true });
1398 handleCancelShowConfirmTransferCommunity(i: CommentNode) {
1399 i.setState({ showConfirmTransferCommunity: false });
1402 handleShowConfirmTransferSite(i: CommentNode) {
1403 i.setState({ showConfirmTransferSite: true });
1406 handleCancelShowConfirmTransferSite(i: CommentNode) {
1407 i.setState({ showConfirmTransferSite: false });
1410 get isCommentNew(): boolean {
1411 const now = moment.utc().subtract(10, "minutes");
1412 const then = moment.utc(this.commentView.comment.published);
1413 return now.isBefore(then);
1416 handleCommentCollapse(i: CommentNode) {
1417 i.setState({ collapsed: !i.state.collapsed });
1421 handleViewSource(i: CommentNode) {
1422 i.setState({ viewSource: !i.state.viewSource });
1425 handleShowAdvanced(i: CommentNode) {
1426 i.setState({ showAdvanced: !i.state.showAdvanced });
1430 handleSaveComment(i: CommentNode) {
1431 i.setState({ saveLoading: true });
1433 i.props.onSaveComment({
1434 comment_id: i.commentView.comment.id,
1435 save: !i.commentView.saved,
1436 auth: myAuthRequired(),
1440 handleUpvote(i: CommentNode) {
1441 i.setState({ upvoteLoading: true });
1442 i.props.onCommentVote({
1443 comment_id: i.commentId,
1444 score: newVote(VoteType.Upvote, i.commentView.my_vote),
1445 auth: myAuthRequired(),
1449 handleDownvote(i: CommentNode) {
1450 i.setState({ downvoteLoading: true });
1451 i.props.onCommentVote({
1452 comment_id: i.commentId,
1453 score: newVote(VoteType.Downvote, i.commentView.my_vote),
1454 auth: myAuthRequired(),
1458 handleBlockPerson(i: CommentNode) {
1459 i.setState({ blockPersonLoading: true });
1460 i.props.onBlockPerson({
1461 person_id: i.commentView.creator.id,
1463 auth: myAuthRequired(),
1467 handleMarkAsRead(i: CommentNode) {
1468 i.setState({ readLoading: true });
1469 const cv = i.commentView;
1470 if (i.isPersonMentionType(cv)) {
1471 i.props.onPersonMentionRead({
1472 person_mention_id: cv.person_mention.id,
1473 read: !cv.person_mention.read,
1474 auth: myAuthRequired(),
1476 } else if (i.isCommentReplyType(cv)) {
1477 i.props.onCommentReplyRead({
1478 comment_reply_id: cv.comment_reply.id,
1479 read: !cv.comment_reply.read,
1480 auth: myAuthRequired(),
1485 handleDeleteComment(i: CommentNode) {
1486 i.setState({ deleteLoading: true });
1487 i.props.onDeleteComment({
1488 comment_id: i.commentId,
1489 deleted: !i.commentView.comment.deleted,
1490 auth: myAuthRequired(),
1494 handleRemoveComment(i: CommentNode, event: any) {
1495 event.preventDefault();
1496 i.setState({ removeLoading: true });
1497 i.props.onRemoveComment({
1498 comment_id: i.commentId,
1499 removed: !i.commentView.comment.removed,
1500 auth: myAuthRequired(),
1504 handleDistinguishComment(i: CommentNode) {
1505 i.setState({ distinguishLoading: true });
1506 i.props.onDistinguishComment({
1507 comment_id: i.commentId,
1508 distinguished: !i.commentView.comment.distinguished,
1509 auth: myAuthRequired(),
1513 handleBanPersonFromCommunity(i: CommentNode) {
1514 i.setState({ banLoading: true });
1515 i.props.onBanPersonFromCommunity({
1516 community_id: i.commentView.community.id,
1517 person_id: i.commentView.creator.id,
1518 ban: !i.commentView.creator_banned_from_community,
1519 reason: i.state.banReason,
1520 remove_data: i.state.removeData,
1521 expires: futureDaysToUnixTime(i.state.banExpireDays),
1522 auth: myAuthRequired(),
1526 handleBanPerson(i: CommentNode) {
1527 i.setState({ banLoading: true });
1528 i.props.onBanPerson({
1529 person_id: i.commentView.creator.id,
1530 ban: !i.commentView.creator_banned_from_community,
1531 reason: i.state.banReason,
1532 remove_data: i.state.removeData,
1533 expires: futureDaysToUnixTime(i.state.banExpireDays),
1534 auth: myAuthRequired(),
1538 handleModBanBothSubmit(i: CommentNode, event: any) {
1539 event.preventDefault();
1540 if (i.state.banType == BanType.Community) {
1541 i.handleBanPersonFromCommunity(i);
1543 i.handleBanPerson(i);
1547 handleAddModToCommunity(i: CommentNode) {
1548 i.setState({ addModLoading: true });
1550 const added = !isMod(i.commentView.comment.creator_id, i.props.moderators);
1551 i.props.onAddModToCommunity({
1552 community_id: i.commentView.community.id,
1553 person_id: i.commentView.creator.id,
1555 auth: myAuthRequired(),
1559 handleAddAdmin(i: CommentNode) {
1560 i.setState({ addAdminLoading: true });
1562 const added = !isAdmin(i.commentView.comment.creator_id, i.props.admins);
1563 i.props.onAddAdmin({
1564 person_id: i.commentView.creator.id,
1566 auth: myAuthRequired(),
1570 handleTransferCommunity(i: CommentNode) {
1571 i.setState({ transferCommunityLoading: true });
1572 i.props.onTransferCommunity({
1573 community_id: i.commentView.community.id,
1574 person_id: i.commentView.creator.id,
1575 auth: myAuthRequired(),
1579 handleReportComment(i: CommentNode, event: any) {
1580 event.preventDefault();
1581 i.setState({ reportLoading: true });
1582 i.props.onCommentReport({
1583 comment_id: i.commentId,
1584 reason: i.state.reportReason ?? "",
1585 auth: myAuthRequired(),
1589 handlePurgeBothSubmit(i: CommentNode, event: any) {
1590 event.preventDefault();
1591 i.setState({ purgeLoading: true });
1593 if (i.state.purgeType == PurgeType.Person) {
1594 i.props.onPurgePerson({
1595 person_id: i.commentView.creator.id,
1596 reason: i.state.purgeReason,
1597 auth: myAuthRequired(),
1600 i.props.onPurgeComment({
1601 comment_id: i.commentId,
1602 reason: i.state.purgeReason,
1603 auth: myAuthRequired(),
1608 handleFetchChildren(i: CommentNode) {
1609 i.setState({ fetchChildrenLoading: true });
1610 i.props.onFetchChildren?.({
1611 parent_id: i.commentId,
1612 max_depth: commentTreeMaxDepth,