1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
11 CommunityModeratorView,
16 MarkPersonMentionAsRead,
22 } from "lemmy-js-client";
23 import moment from "moment";
24 import { i18n } from "../../i18next";
25 import { BanType, CommentNode as CommentNodeI } from "../../interfaces";
26 import { UserService, WebSocketService } from "../../services";
40 import { Icon, Spinner } from "../common/icon";
41 import { MomentTime } from "../common/moment-time";
42 import { CommunityLink } from "../community/community-link";
43 import { PersonListing } from "../person/person-listing";
44 import { CommentForm } from "./comment-form";
45 import { CommentNodes } from "./comment-nodes";
47 interface CommentNodeState {
50 showRemoveDialog: boolean;
52 showBanDialog: boolean;
55 banExpireDays: number;
57 showConfirmTransferSite: boolean;
58 showConfirmTransferCommunity: boolean;
59 showConfirmAppointAsMod: boolean;
60 showConfirmAppointAsAdmin: boolean;
63 showAdvanced: boolean;
64 showReportDialog: boolean;
75 interface CommentNodeProps {
82 showContext?: boolean;
83 moderators: CommunityModeratorView[];
84 admins: PersonViewSafe[];
85 // TODO is this necessary, can't I get it from the node itself?
86 postCreatorId?: number;
87 showCommunity?: boolean;
88 enableDownvotes: boolean;
91 export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
92 private emptyState: CommentNodeState = {
95 showRemoveDialog: false,
101 banType: BanType.Community,
105 showConfirmTransferSite: false,
106 showConfirmTransferCommunity: false,
107 showConfirmAppointAsMod: false,
108 showConfirmAppointAsAdmin: false,
109 showReportDialog: false,
111 my_vote: this.props.node.comment_view.my_vote,
112 score: this.props.node.comment_view.counts.score,
113 upvotes: this.props.node.comment_view.counts.upvotes,
114 downvotes: this.props.node.comment_view.counts.downvotes,
115 borderColor: this.props.node.depth
116 ? colorList[this.props.node.depth % colorList.length]
122 constructor(props: any, context: any) {
123 super(props, context);
125 this.state = this.emptyState;
126 this.handleReplyCancel = this.handleReplyCancel.bind(this);
127 this.handleCommentUpvote = this.handleCommentUpvote.bind(this);
128 this.handleCommentDownvote = this.handleCommentDownvote.bind(this);
131 // TODO see if there's a better way to do this, and all willReceiveProps
132 componentWillReceiveProps(nextProps: CommentNodeProps) {
133 let cv = nextProps.node.comment_view;
134 this.state.my_vote = cv.my_vote;
135 this.state.upvotes = cv.counts.upvotes;
136 this.state.downvotes = cv.counts.downvotes;
137 this.state.score = cv.counts.score;
138 this.state.readLoading = false;
139 this.state.saveLoading = false;
140 this.setState(this.state);
144 let node = this.props.node;
145 let cv = this.props.node.comment_view;
148 className={`comment ${
149 cv.comment.parent_id && !this.props.noIndent ? "ml-1" : ""
153 id={`comment-${cv.comment.id}`}
154 className={`details comment-node py-2 ${
155 !this.props.noBorder ? "border-top border-light" : ""
156 } ${this.isCommentNew ? "mark" : ""}`}
158 !this.props.noIndent &&
159 cv.comment.parent_id &&
160 `border-left: 2px ${this.state.borderColor} solid !important`
164 class={`${!this.props.noIndent && cv.comment.parent_id && "ml-2"}`}
166 <div class="d-flex flex-wrap align-items-center text-muted small">
168 <PersonListing person={cv.creator} />
172 <div className="badge badge-light d-none d-sm-inline mr-2">
177 <div className="badge badge-light d-none d-sm-inline mr-2">
181 {this.isPostCreator && (
182 <div className="badge badge-light d-none d-sm-inline mr-2">
186 {cv.creator.bot_account && (
187 <div className="badge badge-light d-none d-sm-inline mr-2">
188 {i18n.t("bot_account").toLowerCase()}
191 {(cv.creator_banned_from_community || isBanned(cv.creator)) && (
192 <div className="badge badge-danger mr-2">
196 {this.props.showCommunity && (
198 <span class="mx-1">{i18n.t("to")}</span>
199 <CommunityLink community={cv.community} />
200 <span class="mx-2">•</span>
201 <Link className="mr-2" to={`/post/${cv.post.id}`}>
207 class="btn btn-sm text-muted"
208 onClick={linkEvent(this, this.handleCommentCollapse)}
209 aria-label={this.expandText}
210 data-tippy-content={this.expandText}
212 {this.state.collapsed ? (
213 <Icon icon="plus-square" classes="icon-inline" />
215 <Icon icon="minus-square" classes="icon-inline" />
219 {/* This is an expanding spacer for mobile */}
220 <div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2"></div>
224 className={`unselectable pointer ${this.scoreColor}`}
225 onClick={linkEvent(node, this.handleCommentUpvote)}
226 data-tippy-content={this.pointsTippy}
229 class="mr-1 font-weight-bold"
230 aria-label={i18n.t("number_of_points", {
231 count: this.state.score,
232 formattedCount: this.state.score,
235 {numToSI(this.state.score)}
238 <span className="mr-1">•</span>
242 <MomentTime data={cv.comment} />
245 {/* end of user row */}
246 {this.state.showEdit && (
250 onReplyCancel={this.handleReplyCancel}
251 disabled={this.props.locked}
255 {!this.state.showEdit && !this.state.collapsed && (
257 {this.state.viewSource ? (
258 <pre>{this.commentUnlessRemoved}</pre>
262 dangerouslySetInnerHTML={mdToHtml(
263 this.commentUnlessRemoved
267 <div class="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold">
268 {this.props.showContext && this.linkBtn()}
269 {this.props.markable && (
271 class="btn btn-link btn-animate text-muted"
272 onClick={linkEvent(this, this.handleMarkRead)}
274 this.commentOrMentionRead
275 ? i18n.t("mark_as_unread")
276 : i18n.t("mark_as_read")
279 this.commentOrMentionRead
280 ? i18n.t("mark_as_unread")
281 : i18n.t("mark_as_read")
284 {this.state.readLoading ? (
289 classes={`icon-inline ${
290 this.commentOrMentionRead && "text-success"
296 {UserService.Instance.myUserInfo && !this.props.viewOnly && (
299 className={`btn btn-link btn-animate ${
300 this.state.my_vote == 1 ? "text-info" : "text-muted"
302 onClick={linkEvent(node, this.handleCommentUpvote)}
303 data-tippy-content={i18n.t("upvote")}
304 aria-label={i18n.t("upvote")}
306 <Icon icon="arrow-up1" classes="icon-inline" />
308 this.state.upvotes !== this.state.score && (
310 {numToSI(this.state.upvotes)}
314 {this.props.enableDownvotes && (
316 className={`btn btn-link btn-animate ${
317 this.state.my_vote == -1
321 onClick={linkEvent(node, this.handleCommentDownvote)}
322 data-tippy-content={i18n.t("downvote")}
323 aria-label={i18n.t("downvote")}
325 <Icon icon="arrow-down1" classes="icon-inline" />
327 this.state.upvotes !== this.state.score && (
329 {numToSI(this.state.downvotes)}
335 class="btn btn-link btn-animate text-muted"
336 onClick={linkEvent(this, this.handleReplyClick)}
337 data-tippy-content={i18n.t("reply")}
338 aria-label={i18n.t("reply")}
340 <Icon icon="reply1" classes="icon-inline" />
342 {!this.state.showAdvanced ? (
344 className="btn btn-link btn-animate text-muted"
345 onClick={linkEvent(this, this.handleShowAdvanced)}
346 data-tippy-content={i18n.t("more")}
347 aria-label={i18n.t("more")}
349 <Icon icon="more-vertical" classes="icon-inline" />
353 {!this.myComment && (
355 <button class="btn btn-link btn-animate">
357 className="text-muted"
358 to={`/create_private_message/recipient/${cv.creator.id}`}
359 title={i18n.t("message").toLowerCase()}
365 class="btn btn-link btn-animate text-muted"
368 this.handleShowReportDialog
370 data-tippy-content={i18n.t(
373 aria-label={i18n.t("show_report_dialog")}
378 class="btn btn-link btn-animate text-muted"
381 this.handleBlockUserClick
383 data-tippy-content={i18n.t("block_user")}
384 aria-label={i18n.t("block_user")}
386 <Icon icon="slash" />
391 class="btn btn-link btn-animate text-muted"
394 this.handleSaveCommentClick
397 cv.saved ? i18n.t("unsave") : i18n.t("save")
400 cv.saved ? i18n.t("unsave") : i18n.t("save")
403 {this.state.saveLoading ? (
408 classes={`icon-inline ${
409 cv.saved && "text-warning"
415 className="btn btn-link btn-animate text-muted"
416 onClick={linkEvent(this, this.handleViewSource)}
417 data-tippy-content={i18n.t("view_source")}
418 aria-label={i18n.t("view_source")}
422 classes={`icon-inline ${
423 this.state.viewSource && "text-success"
430 class="btn btn-link btn-animate text-muted"
431 onClick={linkEvent(this, this.handleEditClick)}
432 data-tippy-content={i18n.t("edit")}
433 aria-label={i18n.t("edit")}
435 <Icon icon="edit" classes="icon-inline" />
438 class="btn btn-link btn-animate text-muted"
441 this.handleDeleteClick
456 classes={`icon-inline ${
457 cv.comment.deleted && "text-danger"
463 {/* Admins and mods can remove comments */}
464 {(this.canMod || this.canAdmin) && (
466 {!cv.comment.removed ? (
468 class="btn btn-link btn-animate text-muted"
471 this.handleModRemoveShow
473 aria-label={i18n.t("remove")}
479 class="btn btn-link btn-animate text-muted"
482 this.handleModRemoveSubmit
484 aria-label={i18n.t("restore")}
491 {/* Mods can ban from community, and appoint as mods to community */}
495 (!cv.creator_banned_from_community ? (
497 class="btn btn-link btn-animate text-muted"
500 this.handleModBanFromCommunityShow
502 aria-label={i18n.t("ban")}
508 class="btn btn-link btn-animate text-muted"
511 this.handleModBanFromCommunitySubmit
513 aria-label={i18n.t("unban")}
518 {!cv.creator_banned_from_community &&
519 (!this.state.showConfirmAppointAsMod ? (
521 class="btn btn-link btn-animate text-muted"
524 this.handleShowConfirmAppointAsMod
528 ? i18n.t("remove_as_mod")
529 : i18n.t("appoint_as_mod")
533 ? i18n.t("remove_as_mod")
534 : i18n.t("appoint_as_mod")}
539 class="btn btn-link btn-animate text-muted"
540 aria-label={i18n.t("are_you_sure")}
542 {i18n.t("are_you_sure")}
545 class="btn btn-link btn-animate text-muted"
548 this.handleAddModToCommunity
550 aria-label={i18n.t("yes")}
555 class="btn btn-link btn-animate text-muted"
558 this.handleCancelConfirmAppointAsMod
560 aria-label={i18n.t("no")}
568 {/* Community creators and admins can transfer community to another mod */}
569 {(this.amCommunityCreator || this.canAdmin) &&
572 (!this.state.showConfirmTransferCommunity ? (
574 class="btn btn-link btn-animate text-muted"
577 this.handleShowConfirmTransferCommunity
579 aria-label={i18n.t("transfer_community")}
581 {i18n.t("transfer_community")}
586 class="btn btn-link btn-animate text-muted"
587 aria-label={i18n.t("are_you_sure")}
589 {i18n.t("are_you_sure")}
592 class="btn btn-link btn-animate text-muted"
595 this.handleTransferCommunity
597 aria-label={i18n.t("yes")}
602 class="btn btn-link btn-animate text-muted"
606 .handleCancelShowConfirmTransferCommunity
608 aria-label={i18n.t("no")}
614 {/* Admins can ban from all, and appoint other admins */}
618 (!isBanned(cv.creator) ? (
620 class="btn btn-link btn-animate text-muted"
623 this.handleModBanShow
625 aria-label={i18n.t("ban_from_site")}
627 {i18n.t("ban_from_site")}
631 class="btn btn-link btn-animate text-muted"
634 this.handleModBanSubmit
636 aria-label={i18n.t("unban_from_site")}
638 {i18n.t("unban_from_site")}
641 {!isBanned(cv.creator) &&
643 (!this.state.showConfirmAppointAsAdmin ? (
645 class="btn btn-link btn-animate text-muted"
648 this.handleShowConfirmAppointAsAdmin
652 ? i18n.t("remove_as_admin")
653 : i18n.t("appoint_as_admin")
657 ? i18n.t("remove_as_admin")
658 : i18n.t("appoint_as_admin")}
662 <button class="btn btn-link btn-animate text-muted">
663 {i18n.t("are_you_sure")}
666 class="btn btn-link btn-animate text-muted"
671 aria-label={i18n.t("yes")}
676 class="btn btn-link btn-animate text-muted"
679 this.handleCancelConfirmAppointAsAdmin
681 aria-label={i18n.t("no")}
694 {/* end of button group */}
699 {/* end of details */}
700 {this.state.showRemoveDialog && (
703 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
707 htmlFor={`mod-remove-reason-${cv.comment.id}`}
713 id={`mod-remove-reason-${cv.comment.id}`}
714 class="form-control mr-2"
715 placeholder={i18n.t("reason")}
716 value={this.state.removeReason}
717 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
721 class="btn btn-secondary"
722 aria-label={i18n.t("remove_comment")}
724 {i18n.t("remove_comment")}
728 {this.state.showReportDialog && (
731 onSubmit={linkEvent(this, this.handleReportSubmit)}
733 <label class="sr-only" htmlFor={`report-reason-${cv.comment.id}`}>
739 id={`report-reason-${cv.comment.id}`}
740 class="form-control mr-2"
741 placeholder={i18n.t("reason")}
742 value={this.state.reportReason}
743 onInput={linkEvent(this, this.handleReportReasonChange)}
747 class="btn btn-secondary"
748 aria-label={i18n.t("create_report")}
750 {i18n.t("create_report")}
754 {this.state.showBanDialog && (
755 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
756 <div class="form-group row col-12">
758 class="col-form-label"
759 htmlFor={`mod-ban-reason-${cv.comment.id}`}
765 id={`mod-ban-reason-${cv.comment.id}`}
766 class="form-control mr-2"
767 placeholder={i18n.t("reason")}
768 value={this.state.banReason}
769 onInput={linkEvent(this, this.handleModBanReasonChange)}
772 class="col-form-label"
773 htmlFor={`mod-ban-expires-${cv.comment.id}`}
779 id={`mod-ban-expires-${cv.comment.id}`}
780 class="form-control mr-2"
781 placeholder={i18n.t("number_of_days")}
782 value={this.state.banExpireDays}
783 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
785 <div class="form-group">
786 <div class="form-check">
788 class="form-check-input"
789 id="mod-ban-remove-data"
791 checked={this.state.removeData}
792 onChange={linkEvent(this, this.handleModRemoveDataChange)}
795 class="form-check-label"
796 htmlFor="mod-ban-remove-data"
797 title={i18n.t("remove_content_more")}
799 {i18n.t("remove_content")}
804 {/* TODO hold off on expires until later */}
805 {/* <div class="form-group row"> */}
806 {/* <label class="col-form-label">Expires</label> */}
807 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
809 <div class="form-group row">
812 class="btn btn-secondary"
813 aria-label={i18n.t("ban")}
815 {i18n.t("ban")} {cv.creator.name}
820 {this.state.showReply && (
823 onReplyCancel={this.handleReplyCancel}
824 disabled={this.props.locked}
828 {node.children && !this.state.collapsed && (
830 nodes={node.children}
831 locked={this.props.locked}
832 moderators={this.props.moderators}
833 admins={this.props.admins}
834 postCreatorId={this.props.postCreatorId}
835 enableDownvotes={this.props.enableDownvotes}
838 {/* A collapsed clearfix */}
839 {this.state.collapsed && <div class="row col-12"></div>}
844 get commentOrMentionRead() {
845 let cv = this.props.node.comment_view;
846 return this.isPersonMentionType(cv)
847 ? cv.person_mention.read
851 linkBtn(small = false) {
852 let cv = this.props.node.comment_view;
853 let classnames = classNames("btn btn-link btn-animate text-muted", {
857 let title = this.props.showContext
858 ? i18n.t("show_context")
864 className={classnames}
865 to={`/post/${cv.post.id}/comment/${cv.comment.id}`}
868 <Icon icon="link" classes="icon-inline" />
871 <a className={classnames} title={title} href={cv.comment.ap_id}>
872 <Icon icon="fedilink" classes="icon-inline" />
883 get myComment(): boolean {
885 this.props.node.comment_view.creator.id ==
886 UserService.Instance.myUserInfo?.local_user_view.person.id
890 get isMod(): boolean {
892 this.props.moderators &&
894 this.props.moderators.map(m => m.moderator.id),
895 this.props.node.comment_view.creator.id
900 get isAdmin(): boolean {
904 this.props.admins.map(a => a.person.id),
905 this.props.node.comment_view.creator.id
910 get isPostCreator(): boolean {
911 return this.props.node.comment_view.creator.id == this.props.postCreatorId;
914 get canMod(): boolean {
915 if (this.props.admins && this.props.moderators) {
916 let adminsThenMods = this.props.admins
917 .map(a => a.person.id)
918 .concat(this.props.moderators.map(m => m.moderator.id));
921 UserService.Instance.myUserInfo,
923 this.props.node.comment_view.creator.id
930 get canAdmin(): boolean {
934 UserService.Instance.myUserInfo,
935 this.props.admins.map(a => a.person.id),
936 this.props.node.comment_view.creator.id
941 get amCommunityCreator(): boolean {
943 this.props.moderators &&
944 UserService.Instance.myUserInfo &&
945 this.props.node.comment_view.creator.id !=
946 UserService.Instance.myUserInfo.local_user_view.person.id &&
947 UserService.Instance.myUserInfo.local_user_view.person.id ==
948 this.props.moderators[0].moderator.id
952 get amSiteCreator(): boolean {
955 UserService.Instance.myUserInfo &&
956 this.props.node.comment_view.creator.id !=
957 UserService.Instance.myUserInfo.local_user_view.person.id &&
958 UserService.Instance.myUserInfo.local_user_view.person.id ==
959 this.props.admins[0].person.id
963 get commentUnlessRemoved(): string {
964 let comment = this.props.node.comment_view.comment;
965 return comment.removed
966 ? `*${i18n.t("removed")}*`
968 ? `*${i18n.t("deleted")}*`
972 handleReplyClick(i: CommentNode) {
973 i.state.showReply = true;
977 handleEditClick(i: CommentNode) {
978 i.state.showEdit = true;
982 handleBlockUserClick(i: CommentNode) {
983 let blockUserForm: BlockPerson = {
984 person_id: i.props.node.comment_view.creator.id,
988 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
991 handleDeleteClick(i: CommentNode) {
992 let comment = i.props.node.comment_view.comment;
993 let deleteForm: DeleteComment = {
994 comment_id: comment.id,
995 deleted: !comment.deleted,
998 WebSocketService.Instance.send(wsClient.deleteComment(deleteForm));
1001 handleSaveCommentClick(i: CommentNode) {
1002 let cv = i.props.node.comment_view;
1003 let save = cv.saved == undefined ? true : !cv.saved;
1004 let form: SaveComment = {
1005 comment_id: cv.comment.id,
1010 WebSocketService.Instance.send(wsClient.saveComment(form));
1012 i.state.saveLoading = true;
1013 i.setState(this.state);
1016 handleReplyCancel() {
1017 this.state.showReply = false;
1018 this.state.showEdit = false;
1019 this.setState(this.state);
1022 handleCommentUpvote(i: CommentNodeI, event: any) {
1023 event.preventDefault();
1024 let new_vote = this.state.my_vote == 1 ? 0 : 1;
1026 if (this.state.my_vote == 1) {
1028 this.state.upvotes--;
1029 } else if (this.state.my_vote == -1) {
1030 this.state.downvotes--;
1031 this.state.upvotes++;
1032 this.state.score += 2;
1034 this.state.upvotes++;
1038 this.state.my_vote = new_vote;
1040 let form: CreateCommentLike = {
1041 comment_id: i.comment_view.comment.id,
1042 score: this.state.my_vote,
1046 WebSocketService.Instance.send(wsClient.likeComment(form));
1047 this.setState(this.state);
1051 handleCommentDownvote(i: CommentNodeI, event: any) {
1052 event.preventDefault();
1053 let new_vote = this.state.my_vote == -1 ? 0 : -1;
1055 if (this.state.my_vote == 1) {
1056 this.state.score -= 2;
1057 this.state.upvotes--;
1058 this.state.downvotes++;
1059 } else if (this.state.my_vote == -1) {
1060 this.state.downvotes--;
1063 this.state.downvotes++;
1067 this.state.my_vote = new_vote;
1069 let form: CreateCommentLike = {
1070 comment_id: i.comment_view.comment.id,
1071 score: this.state.my_vote,
1075 WebSocketService.Instance.send(wsClient.likeComment(form));
1076 this.setState(this.state);
1080 handleShowReportDialog(i: CommentNode) {
1081 i.state.showReportDialog = !i.state.showReportDialog;
1082 i.setState(i.state);
1085 handleReportReasonChange(i: CommentNode, event: any) {
1086 i.state.reportReason = event.target.value;
1087 i.setState(i.state);
1090 handleReportSubmit(i: CommentNode) {
1091 let comment = i.props.node.comment_view.comment;
1092 let form: CreateCommentReport = {
1093 comment_id: comment.id,
1094 reason: i.state.reportReason,
1097 WebSocketService.Instance.send(wsClient.createCommentReport(form));
1099 i.state.showReportDialog = false;
1100 i.setState(i.state);
1103 handleModRemoveShow(i: CommentNode) {
1104 i.state.showRemoveDialog = !i.state.showRemoveDialog;
1105 i.state.showBanDialog = false;
1106 i.setState(i.state);
1109 handleModRemoveReasonChange(i: CommentNode, event: any) {
1110 i.state.removeReason = event.target.value;
1111 i.setState(i.state);
1114 handleModRemoveDataChange(i: CommentNode, event: any) {
1115 i.state.removeData = event.target.checked;
1116 i.setState(i.state);
1119 handleModRemoveSubmit(i: CommentNode) {
1120 let comment = i.props.node.comment_view.comment;
1121 let form: RemoveComment = {
1122 comment_id: comment.id,
1123 removed: !comment.removed,
1124 reason: i.state.removeReason,
1127 WebSocketService.Instance.send(wsClient.removeComment(form));
1129 i.state.showRemoveDialog = false;
1130 i.setState(i.state);
1133 isPersonMentionType(
1134 item: CommentView | PersonMentionView
1135 ): item is PersonMentionView {
1136 return (item as PersonMentionView).person_mention?.id !== undefined;
1139 handleMarkRead(i: CommentNode) {
1140 if (i.isPersonMentionType(i.props.node.comment_view)) {
1141 let form: MarkPersonMentionAsRead = {
1142 person_mention_id: i.props.node.comment_view.person_mention.id,
1143 read: !i.props.node.comment_view.person_mention.read,
1146 WebSocketService.Instance.send(wsClient.markPersonMentionAsRead(form));
1148 let form: MarkCommentAsRead = {
1149 comment_id: i.props.node.comment_view.comment.id,
1150 read: !i.props.node.comment_view.comment.read,
1153 WebSocketService.Instance.send(wsClient.markCommentAsRead(form));
1156 i.state.readLoading = true;
1157 i.setState(this.state);
1160 handleModBanFromCommunityShow(i: CommentNode) {
1161 i.state.showBanDialog = true;
1162 i.state.banType = BanType.Community;
1163 i.state.showRemoveDialog = false;
1164 i.setState(i.state);
1167 handleModBanShow(i: CommentNode) {
1168 i.state.showBanDialog = true;
1169 i.state.banType = BanType.Site;
1170 i.state.showRemoveDialog = false;
1171 i.setState(i.state);
1174 handleModBanReasonChange(i: CommentNode, event: any) {
1175 i.state.banReason = event.target.value;
1176 i.setState(i.state);
1179 handleModBanExpireDaysChange(i: CommentNode, event: any) {
1180 i.state.banExpireDays = event.target.value;
1181 i.setState(i.state);
1184 handleModBanFromCommunitySubmit(i: CommentNode) {
1185 i.state.banType = BanType.Community;
1186 i.setState(i.state);
1187 i.handleModBanBothSubmit(i);
1190 handleModBanSubmit(i: CommentNode) {
1191 i.state.banType = BanType.Site;
1192 i.setState(i.state);
1193 i.handleModBanBothSubmit(i);
1196 handleModBanBothSubmit(i: CommentNode) {
1197 let cv = i.props.node.comment_view;
1199 if (i.state.banType == BanType.Community) {
1200 // If its an unban, restore all their data
1201 let ban = !cv.creator_banned_from_community;
1203 i.state.removeData = false;
1205 let form: BanFromCommunity = {
1206 person_id: cv.creator.id,
1207 community_id: cv.community.id,
1209 remove_data: i.state.removeData,
1210 reason: i.state.banReason,
1211 expires: futureDaysToUnixTime(i.state.banExpireDays),
1214 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1216 // If its an unban, restore all their data
1217 let ban = !cv.creator.banned;
1219 i.state.removeData = false;
1221 let form: BanPerson = {
1222 person_id: cv.creator.id,
1224 remove_data: i.state.removeData,
1225 reason: i.state.banReason,
1226 expires: futureDaysToUnixTime(i.state.banExpireDays),
1229 WebSocketService.Instance.send(wsClient.banPerson(form));
1232 i.state.showBanDialog = false;
1233 i.setState(i.state);
1236 handleShowConfirmAppointAsMod(i: CommentNode) {
1237 i.state.showConfirmAppointAsMod = true;
1238 i.setState(i.state);
1241 handleCancelConfirmAppointAsMod(i: CommentNode) {
1242 i.state.showConfirmAppointAsMod = false;
1243 i.setState(i.state);
1246 handleAddModToCommunity(i: CommentNode) {
1247 let cv = i.props.node.comment_view;
1248 let form: AddModToCommunity = {
1249 person_id: cv.creator.id,
1250 community_id: cv.community.id,
1254 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1255 i.state.showConfirmAppointAsMod = false;
1256 i.setState(i.state);
1259 handleShowConfirmAppointAsAdmin(i: CommentNode) {
1260 i.state.showConfirmAppointAsAdmin = true;
1261 i.setState(i.state);
1264 handleCancelConfirmAppointAsAdmin(i: CommentNode) {
1265 i.state.showConfirmAppointAsAdmin = false;
1266 i.setState(i.state);
1269 handleAddAdmin(i: CommentNode) {
1270 let form: AddAdmin = {
1271 person_id: i.props.node.comment_view.creator.id,
1275 WebSocketService.Instance.send(wsClient.addAdmin(form));
1276 i.state.showConfirmAppointAsAdmin = false;
1277 i.setState(i.state);
1280 handleShowConfirmTransferCommunity(i: CommentNode) {
1281 i.state.showConfirmTransferCommunity = true;
1282 i.setState(i.state);
1285 handleCancelShowConfirmTransferCommunity(i: CommentNode) {
1286 i.state.showConfirmTransferCommunity = false;
1287 i.setState(i.state);
1290 handleTransferCommunity(i: CommentNode) {
1291 let cv = i.props.node.comment_view;
1292 let form: TransferCommunity = {
1293 community_id: cv.community.id,
1294 person_id: cv.creator.id,
1297 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1298 i.state.showConfirmTransferCommunity = false;
1299 i.setState(i.state);
1302 handleShowConfirmTransferSite(i: CommentNode) {
1303 i.state.showConfirmTransferSite = true;
1304 i.setState(i.state);
1307 handleCancelShowConfirmTransferSite(i: CommentNode) {
1308 i.state.showConfirmTransferSite = false;
1309 i.setState(i.state);
1312 get isCommentNew(): boolean {
1313 let now = moment.utc().subtract(10, "minutes");
1314 let then = moment.utc(this.props.node.comment_view.comment.published);
1315 return now.isBefore(then);
1318 handleCommentCollapse(i: CommentNode) {
1319 i.state.collapsed = !i.state.collapsed;
1320 i.setState(i.state);
1324 handleViewSource(i: CommentNode) {
1325 i.state.viewSource = !i.state.viewSource;
1326 i.setState(i.state);
1329 handleShowAdvanced(i: CommentNode) {
1330 i.state.showAdvanced = !i.state.showAdvanced;
1331 i.setState(i.state);
1336 if (this.state.my_vote == 1) {
1338 } else if (this.state.my_vote == -1) {
1339 return "text-danger";
1341 return "text-muted";
1345 get pointsTippy(): string {
1346 let points = i18n.t("number_of_points", {
1347 count: this.state.score,
1348 formattedCount: this.state.score,
1351 let upvotes = i18n.t("number_of_upvotes", {
1352 count: this.state.upvotes,
1353 formattedCount: this.state.upvotes,
1356 let downvotes = i18n.t("number_of_downvotes", {
1357 count: this.state.downvotes,
1358 formattedCount: this.state.downvotes,
1361 return `${points} • ${upvotes} • ${downvotes}`;
1364 get expandText(): string {
1365 return this.state.collapsed ? i18n.t("expand") : i18n.t("collapse");