2022-02-14 18:49:57 +00:00
|
|
|
import classNames from "classnames";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import { Link } from "inferno-router";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
AddAdmin,
|
|
|
|
AddModToCommunity,
|
|
|
|
BanFromCommunity,
|
|
|
|
BanPerson,
|
2021-08-20 02:56:18 +00:00
|
|
|
BlockPerson,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommentView,
|
|
|
|
CommunityModeratorView,
|
2020-12-24 01:58:27 +00:00
|
|
|
CreateCommentLike,
|
2021-09-28 10:38:59 +00:00
|
|
|
CreateCommentReport,
|
2020-12-24 01:58:27 +00:00
|
|
|
DeleteComment,
|
|
|
|
MarkCommentAsRead,
|
2021-03-15 18:09:31 +00:00
|
|
|
MarkPersonMentionAsRead,
|
2021-07-17 20:42:55 +00:00
|
|
|
PersonMentionView,
|
2021-03-15 18:09:31 +00:00
|
|
|
PersonViewSafe,
|
2021-07-17 20:42:55 +00:00
|
|
|
RemoveComment,
|
|
|
|
SaveComment,
|
2020-12-24 01:58:27 +00:00
|
|
|
TransferCommunity,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import moment from "moment";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { BanType, CommentNode as CommentNodeI } from "../../interfaces";
|
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
authField,
|
2020-09-06 16:15:25 +00:00
|
|
|
canMod,
|
2021-07-17 20:42:55 +00:00
|
|
|
colorList,
|
2022-01-09 17:53:11 +00:00
|
|
|
futureDaysToUnixTime,
|
|
|
|
isBanned,
|
2020-09-06 16:15:25 +00:00
|
|
|
isMod,
|
2021-07-17 20:42:55 +00:00
|
|
|
mdToHtml,
|
2021-09-18 16:35:49 +00:00
|
|
|
numToSI,
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy,
|
2021-04-09 16:23:30 +00:00
|
|
|
showScores,
|
2021-07-17 20:42:55 +00:00
|
|
|
wsClient,
|
|
|
|
} from "../../utils";
|
|
|
|
import { Icon, Spinner } from "../common/icon";
|
|
|
|
import { MomentTime } from "../common/moment-time";
|
|
|
|
import { CommunityLink } from "../community/community-link";
|
|
|
|
import { PersonListing } from "../person/person-listing";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { CommentForm } from "./comment-form";
|
|
|
|
import { CommentNodes } from "./comment-nodes";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface CommentNodeState {
|
|
|
|
showReply: boolean;
|
|
|
|
showEdit: boolean;
|
|
|
|
showRemoveDialog: boolean;
|
|
|
|
removeReason: string;
|
|
|
|
showBanDialog: boolean;
|
|
|
|
removeData: boolean;
|
|
|
|
banReason: string;
|
2022-01-09 17:53:11 +00:00
|
|
|
banExpireDays: number;
|
2020-09-06 16:15:25 +00:00
|
|
|
banType: BanType;
|
|
|
|
showConfirmTransferSite: boolean;
|
|
|
|
showConfirmTransferCommunity: boolean;
|
|
|
|
showConfirmAppointAsMod: boolean;
|
|
|
|
showConfirmAppointAsAdmin: boolean;
|
|
|
|
collapsed: boolean;
|
|
|
|
viewSource: boolean;
|
|
|
|
showAdvanced: boolean;
|
2021-09-28 10:38:59 +00:00
|
|
|
showReportDialog: boolean;
|
|
|
|
reportReason: string;
|
2020-09-06 16:15:25 +00:00
|
|
|
my_vote: number;
|
|
|
|
score: number;
|
|
|
|
upvotes: number;
|
|
|
|
downvotes: number;
|
|
|
|
borderColor: string;
|
|
|
|
readLoading: boolean;
|
|
|
|
saveLoading: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CommentNodeProps {
|
|
|
|
node: CommentNodeI;
|
|
|
|
noBorder?: boolean;
|
|
|
|
noIndent?: boolean;
|
|
|
|
viewOnly?: boolean;
|
|
|
|
locked?: boolean;
|
|
|
|
markable?: boolean;
|
|
|
|
showContext?: boolean;
|
2020-12-24 01:58:27 +00:00
|
|
|
moderators: CommunityModeratorView[];
|
2021-03-15 18:09:31 +00:00
|
|
|
admins: PersonViewSafe[];
|
2020-09-06 16:15:25 +00:00
|
|
|
// TODO is this necessary, can't I get it from the node itself?
|
|
|
|
postCreatorId?: number;
|
|
|
|
showCommunity?: boolean;
|
|
|
|
enableDownvotes: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
|
|
|
private emptyState: CommentNodeState = {
|
|
|
|
showReply: false,
|
|
|
|
showEdit: false,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
removeReason: null,
|
|
|
|
showBanDialog: false,
|
2021-01-26 17:21:10 +00:00
|
|
|
removeData: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
banReason: null,
|
2022-01-09 17:53:11 +00:00
|
|
|
banExpireDays: null,
|
2020-09-06 16:15:25 +00:00
|
|
|
banType: BanType.Community,
|
|
|
|
collapsed: false,
|
|
|
|
viewSource: false,
|
|
|
|
showAdvanced: false,
|
|
|
|
showConfirmTransferSite: false,
|
|
|
|
showConfirmTransferCommunity: false,
|
|
|
|
showConfirmAppointAsMod: false,
|
|
|
|
showConfirmAppointAsAdmin: false,
|
2021-09-28 10:38:59 +00:00
|
|
|
showReportDialog: false,
|
|
|
|
reportReason: null,
|
2020-12-24 01:58:27 +00:00
|
|
|
my_vote: this.props.node.comment_view.my_vote,
|
|
|
|
score: this.props.node.comment_view.counts.score,
|
|
|
|
upvotes: this.props.node.comment_view.counts.upvotes,
|
|
|
|
downvotes: this.props.node.comment_view.counts.downvotes,
|
|
|
|
borderColor: this.props.node.depth
|
|
|
|
? colorList[this.props.node.depth % colorList.length]
|
2020-09-06 16:15:25 +00:00
|
|
|
: colorList[0],
|
|
|
|
readLoading: false,
|
|
|
|
saveLoading: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handleReplyCancel = this.handleReplyCancel.bind(this);
|
|
|
|
this.handleCommentUpvote = this.handleCommentUpvote.bind(this);
|
|
|
|
this.handleCommentDownvote = this.handleCommentDownvote.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
// TODO see if there's a better way to do this, and all willReceiveProps
|
2020-09-06 16:15:25 +00:00
|
|
|
componentWillReceiveProps(nextProps: CommentNodeProps) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = nextProps.node.comment_view;
|
|
|
|
this.state.my_vote = cv.my_vote;
|
|
|
|
this.state.upvotes = cv.counts.upvotes;
|
|
|
|
this.state.downvotes = cv.counts.downvotes;
|
|
|
|
this.state.score = cv.counts.score;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.readLoading = false;
|
|
|
|
this.state.saveLoading = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let node = this.props.node;
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = this.props.node.comment_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`comment ${
|
2021-02-22 02:39:04 +00:00
|
|
|
cv.comment.parent_id && !this.props.noIndent ? "ml-1" : ""
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<div
|
2020-12-24 01:58:27 +00:00
|
|
|
id={`comment-${cv.comment.id}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
className={`details comment-node py-2 ${
|
2021-02-22 02:39:04 +00:00
|
|
|
!this.props.noBorder ? "border-top border-light" : ""
|
|
|
|
} ${this.isCommentNew ? "mark" : ""}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
style={
|
|
|
|
!this.props.noIndent &&
|
2020-12-24 01:58:27 +00:00
|
|
|
cv.comment.parent_id &&
|
2020-09-06 16:15:25 +00:00
|
|
|
`border-left: 2px ${this.state.borderColor} solid !important`
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div
|
2021-02-22 02:39:04 +00:00
|
|
|
class={`${!this.props.noIndent && cv.comment.parent_id && "ml-2"}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
|
|
|
<div class="d-flex flex-wrap align-items-center text-muted small">
|
|
|
|
<span class="mr-2">
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={cv.creator} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
|
|
|
|
|
|
|
{this.isMod && (
|
|
|
|
<div className="badge badge-light d-none d-sm-inline mr-2">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("mod")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{this.isAdmin && (
|
|
|
|
<div className="badge badge-light d-none d-sm-inline mr-2">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("admin")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{this.isPostCreator && (
|
|
|
|
<div className="badge badge-light d-none d-sm-inline mr-2">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("creator")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2021-10-18 01:44:02 +00:00
|
|
|
{cv.creator.bot_account && (
|
|
|
|
<div className="badge badge-light d-none d-sm-inline mr-2">
|
|
|
|
{i18n.t("bot_account").toLowerCase()}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-01-09 17:53:11 +00:00
|
|
|
{(cv.creator_banned_from_community || isBanned(cv.creator)) && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<div className="badge badge-danger mr-2">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("banned")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{this.props.showCommunity && (
|
|
|
|
<>
|
2021-02-22 02:39:04 +00:00
|
|
|
<span class="mx-1">{i18n.t("to")}</span>
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={cv.community} />
|
2020-09-06 16:15:25 +00:00
|
|
|
<span class="mx-2">•</span>
|
2020-12-24 01:58:27 +00:00
|
|
|
<Link className="mr-2" to={`/post/${cv.post.id}`}>
|
|
|
|
{cv.post.name}
|
2020-09-06 16:15:25 +00:00
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<button
|
2020-09-25 21:16:41 +00:00
|
|
|
class="btn btn-sm text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleCommentCollapse)}
|
2021-07-16 17:04:35 +00:00
|
|
|
aria-label={this.expandText}
|
|
|
|
data-tippy-content={this.expandText}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-07-16 17:04:35 +00:00
|
|
|
{this.state.collapsed ? (
|
|
|
|
<Icon icon="plus-square" classes="icon-inline" />
|
|
|
|
) : (
|
|
|
|
<Icon icon="minus-square" classes="icon-inline" />
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2021-07-17 16:59:00 +00:00
|
|
|
{this.linkBtn(true)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{/* This is an expanding spacer for mobile */}
|
2021-07-17 16:59:00 +00:00
|
|
|
<div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2"></div>
|
2021-04-09 16:23:30 +00:00
|
|
|
{showScores() && (
|
|
|
|
<>
|
|
|
|
<a
|
|
|
|
className={`unselectable pointer ${this.scoreColor}`}
|
|
|
|
onClick={linkEvent(node, this.handleCommentUpvote)}
|
|
|
|
data-tippy-content={this.pointsTippy}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
class="mr-1 font-weight-bold"
|
|
|
|
aria-label={i18n.t("number_of_points", {
|
|
|
|
count: this.state.score,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: this.state.score,
|
2021-04-09 16:23:30 +00:00
|
|
|
})}
|
|
|
|
>
|
2021-09-18 16:35:49 +00:00
|
|
|
{numToSI(this.state.score)}
|
2021-04-09 16:23:30 +00:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
<span className="mr-1">•</span>
|
|
|
|
</>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
<span>
|
2020-12-24 01:58:27 +00:00
|
|
|
<MomentTime data={cv.comment} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{/* end of user row */}
|
|
|
|
{this.state.showEdit && (
|
|
|
|
<CommentForm
|
|
|
|
node={node}
|
|
|
|
edit
|
|
|
|
onReplyCancel={this.handleReplyCancel}
|
|
|
|
disabled={this.props.locked}
|
|
|
|
focus
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{!this.state.showEdit && !this.state.collapsed && (
|
|
|
|
<div>
|
|
|
|
{this.state.viewSource ? (
|
|
|
|
<pre>{this.commentUnlessRemoved}</pre>
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className="md-div"
|
|
|
|
dangerouslySetInnerHTML={mdToHtml(
|
|
|
|
this.commentUnlessRemoved
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<div class="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold">
|
2021-07-17 16:59:00 +00:00
|
|
|
{this.props.showContext && this.linkBtn()}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.props.markable && (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleMarkRead)}
|
|
|
|
data-tippy-content={
|
2021-01-06 21:05:42 +00:00
|
|
|
this.commentOrMentionRead
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("mark_as_unread")
|
|
|
|
: i18n.t("mark_as_read")
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2021-02-06 20:20:41 +00:00
|
|
|
aria-label={
|
|
|
|
this.commentOrMentionRead
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("mark_as_unread")
|
|
|
|
: i18n.t("mark_as_read")
|
2021-02-06 20:20:41 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
|
|
|
{this.state.readLoading ? (
|
|
|
|
this.loadingIcon
|
|
|
|
) : (
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon
|
|
|
|
icon="check"
|
|
|
|
classes={`icon-inline ${
|
2021-02-22 02:39:04 +00:00
|
|
|
this.commentOrMentionRead && "text-success"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2021-02-11 20:35:27 +00:00
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
)}
|
2021-08-20 02:56:18 +00:00
|
|
|
{UserService.Instance.myUserInfo && !this.props.viewOnly && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<>
|
|
|
|
<button
|
|
|
|
className={`btn btn-link btn-animate ${
|
2021-02-22 02:39:04 +00:00
|
|
|
this.state.my_vote == 1 ? "text-info" : "text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
onClick={linkEvent(node, this.handleCommentUpvote)}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("upvote")}
|
|
|
|
aria-label={i18n.t("upvote")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="arrow-up1" classes="icon-inline" />
|
2021-04-09 16:23:30 +00:00
|
|
|
{showScores() &&
|
|
|
|
this.state.upvotes !== this.state.score && (
|
2021-09-18 16:35:49 +00:00
|
|
|
<span class="ml-1">
|
|
|
|
{numToSI(this.state.upvotes)}
|
|
|
|
</span>
|
2021-04-09 16:23:30 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
{this.props.enableDownvotes && (
|
|
|
|
<button
|
|
|
|
className={`btn btn-link btn-animate ${
|
|
|
|
this.state.my_vote == -1
|
2021-02-22 02:39:04 +00:00
|
|
|
? "text-danger"
|
|
|
|
: "text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
onClick={linkEvent(node, this.handleCommentDownvote)}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("downvote")}
|
|
|
|
aria-label={i18n.t("downvote")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="arrow-down1" classes="icon-inline" />
|
2021-04-09 16:23:30 +00:00
|
|
|
{showScores() &&
|
|
|
|
this.state.upvotes !== this.state.score && (
|
2021-09-18 16:35:49 +00:00
|
|
|
<span class="ml-1">
|
|
|
|
{numToSI(this.state.downvotes)}
|
|
|
|
</span>
|
2021-04-09 16:23:30 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleReplyClick)}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("reply")}
|
|
|
|
aria-label={i18n.t("reply")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="reply1" classes="icon-inline" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
{!this.state.showAdvanced ? (
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleShowAdvanced)}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("more")}
|
|
|
|
aria-label={i18n.t("more")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="more-vertical" classes="icon-inline" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{!this.myComment && (
|
2021-08-20 02:56:18 +00:00
|
|
|
<>
|
|
|
|
<button class="btn btn-link btn-animate">
|
|
|
|
<Link
|
|
|
|
className="text-muted"
|
|
|
|
to={`/create_private_message/recipient/${cv.creator.id}`}
|
|
|
|
title={i18n.t("message").toLowerCase()}
|
|
|
|
>
|
|
|
|
<Icon icon="mail" />
|
|
|
|
</Link>
|
|
|
|
</button>
|
2021-09-28 10:38:59 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowReportDialog
|
|
|
|
)}
|
|
|
|
data-tippy-content={i18n.t(
|
|
|
|
"show_report_dialog"
|
|
|
|
)}
|
|
|
|
aria-label={i18n.t("show_report_dialog")}
|
|
|
|
>
|
|
|
|
<Icon icon="flag" />
|
|
|
|
</button>
|
2021-08-20 02:56:18 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleBlockUserClick
|
|
|
|
)}
|
|
|
|
data-tippy-content={i18n.t("block_user")}
|
|
|
|
aria-label={i18n.t("block_user")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-08-20 02:56:18 +00:00
|
|
|
<Icon icon="slash" />
|
|
|
|
</button>
|
|
|
|
</>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleSaveCommentClick
|
|
|
|
)}
|
|
|
|
data-tippy-content={
|
2021-02-22 02:39:04 +00:00
|
|
|
cv.saved ? i18n.t("unsave") : i18n.t("save")
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2021-02-06 20:20:41 +00:00
|
|
|
aria-label={
|
2021-02-22 02:39:04 +00:00
|
|
|
cv.saved ? i18n.t("unsave") : i18n.t("save")
|
2021-02-06 20:20:41 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
|
|
|
{this.state.saveLoading ? (
|
|
|
|
this.loadingIcon
|
|
|
|
) : (
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon
|
|
|
|
icon="star"
|
|
|
|
classes={`icon-inline ${
|
2021-02-22 02:39:04 +00:00
|
|
|
cv.saved && "text-warning"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2021-02-11 20:35:27 +00:00
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleViewSource)}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("view_source")}
|
|
|
|
aria-label={i18n.t("view_source")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon
|
|
|
|
icon="file-text"
|
|
|
|
classes={`icon-inline ${
|
2021-02-22 02:39:04 +00:00
|
|
|
this.state.viewSource && "text-success"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2021-02-11 20:35:27 +00:00
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
{this.myComment && (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleEditClick)}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("edit")}
|
|
|
|
aria-label={i18n.t("edit")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="edit" classes="icon-inline" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteClick
|
|
|
|
)}
|
|
|
|
data-tippy-content={
|
2020-12-24 01:58:27 +00:00
|
|
|
!cv.comment.deleted
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("delete")
|
|
|
|
: i18n.t("restore")
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2021-02-06 20:20:41 +00:00
|
|
|
aria-label={
|
|
|
|
!cv.comment.deleted
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("delete")
|
|
|
|
: i18n.t("restore")
|
2021-02-06 20:20:41 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon
|
|
|
|
icon="trash"
|
|
|
|
classes={`icon-inline ${
|
2021-02-22 02:39:04 +00:00
|
|
|
cv.comment.deleted && "text-danger"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2021-02-11 20:35:27 +00:00
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Admins and mods can remove comments */}
|
|
|
|
{(this.canMod || this.canAdmin) && (
|
|
|
|
<>
|
2020-12-24 01:58:27 +00:00
|
|
|
{!cv.comment.removed ? (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModRemoveShow
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("remove")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("remove")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModRemoveSubmit
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("restore")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("restore")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Mods can ban from community, and appoint as mods to community */}
|
|
|
|
{this.canMod && (
|
|
|
|
<>
|
|
|
|
{!this.isMod &&
|
2020-12-24 01:58:27 +00:00
|
|
|
(!cv.creator_banned_from_community ? (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanFromCommunityShow
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("ban")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("ban")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanFromCommunitySubmit
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("unban")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("unban")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
))}
|
2020-12-24 01:58:27 +00:00
|
|
|
{!cv.creator_banned_from_community &&
|
2020-09-06 16:15:25 +00:00
|
|
|
(!this.state.showConfirmAppointAsMod ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmAppointAsMod
|
|
|
|
)}
|
2021-02-09 16:21:24 +00:00
|
|
|
aria-label={
|
|
|
|
this.isMod
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("remove_as_mod")
|
|
|
|
: i18n.t("appoint_as_mod")
|
2021-02-09 16:21:24 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
|
|
|
{this.isMod
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("remove_as_mod")
|
|
|
|
: i18n.t("appoint_as_mod")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("are_you_sure")}
|
2021-02-09 16:21:24 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("are_you_sure")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleAddModToCommunity
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleCancelConfirmAppointAsMod
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("no")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("no")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Community creators and admins can transfer community to another mod */}
|
|
|
|
{(this.amCommunityCreator || this.canAdmin) &&
|
|
|
|
this.isMod &&
|
2020-12-24 01:58:27 +00:00
|
|
|
cv.creator.local &&
|
2020-09-06 16:15:25 +00:00
|
|
|
(!this.state.showConfirmTransferCommunity ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmTransferCommunity
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("transfer_community")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("transfer_community")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("are_you_sure")}
|
2021-02-09 16:21:24 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("are_you_sure")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleTransferCommunity
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this
|
|
|
|
.handleCancelShowConfirmTransferCommunity
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("no")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("no")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
{/* Admins can ban from all, and appoint other admins */}
|
|
|
|
{this.canAdmin && (
|
|
|
|
<>
|
|
|
|
{!this.isAdmin &&
|
2022-01-09 17:53:11 +00:00
|
|
|
(!isBanned(cv.creator) ? (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanShow
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("ban_from_site")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("ban_from_site")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanSubmit
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("unban_from_site")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("unban_from_site")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
))}
|
2022-01-09 17:53:11 +00:00
|
|
|
{!isBanned(cv.creator) &&
|
2020-12-24 01:58:27 +00:00
|
|
|
cv.creator.local &&
|
2020-09-06 16:15:25 +00:00
|
|
|
(!this.state.showConfirmAppointAsAdmin ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmAppointAsAdmin
|
|
|
|
)}
|
2021-02-09 16:21:24 +00:00
|
|
|
aria-label={
|
|
|
|
this.isAdmin
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("remove_as_admin")
|
|
|
|
: i18n.t("appoint_as_admin")
|
2021-02-09 16:21:24 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
|
|
|
{this.isAdmin
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("remove_as_admin")
|
|
|
|
: i18n.t("appoint_as_admin")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<button class="btn btn-link btn-animate text-muted">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("are_you_sure")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleAddAdmin
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleCancelConfirmAppointAsAdmin
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("no")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("no")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{/* end of button group */}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* end of details */}
|
|
|
|
{this.state.showRemoveDialog && (
|
|
|
|
<form
|
|
|
|
class="form-inline"
|
|
|
|
onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
|
|
|
|
>
|
2021-02-09 16:21:24 +00:00
|
|
|
<label
|
|
|
|
class="sr-only"
|
|
|
|
htmlFor={`mod-remove-reason-${cv.comment.id}`}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("reason")}
|
2021-02-09 16:21:24 +00:00
|
|
|
</label>
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
2021-02-09 16:21:24 +00:00
|
|
|
id={`mod-remove-reason-${cv.comment.id}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
class="form-control mr-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
2020-09-06 16:15:25 +00:00
|
|
|
value={this.state.removeReason}
|
|
|
|
onInput={linkEvent(this, this.handleModRemoveReasonChange)}
|
|
|
|
/>
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-secondary"
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("remove_comment")}
|
2021-02-09 16:21:24 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("remove_comment")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
)}
|
2021-09-28 10:38:59 +00:00
|
|
|
{this.state.showReportDialog && (
|
|
|
|
<form
|
|
|
|
class="form-inline"
|
|
|
|
onSubmit={linkEvent(this, this.handleReportSubmit)}
|
|
|
|
>
|
|
|
|
<label class="sr-only" htmlFor={`report-reason-${cv.comment.id}`}>
|
|
|
|
{i18n.t("reason")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
required
|
|
|
|
id={`report-reason-${cv.comment.id}`}
|
|
|
|
class="form-control mr-2"
|
|
|
|
placeholder={i18n.t("reason")}
|
|
|
|
value={this.state.reportReason}
|
|
|
|
onInput={linkEvent(this, this.handleReportReasonChange)}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-secondary"
|
|
|
|
aria-label={i18n.t("create_report")}
|
|
|
|
>
|
|
|
|
{i18n.t("create_report")}
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.state.showBanDialog && (
|
|
|
|
<form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
|
2022-01-09 17:53:11 +00:00
|
|
|
<div class="form-group row col-12">
|
2021-02-06 20:20:41 +00:00
|
|
|
<label
|
|
|
|
class="col-form-label"
|
|
|
|
htmlFor={`mod-ban-reason-${cv.comment.id}`}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("reason")}
|
2021-02-06 20:20:41 +00:00
|
|
|
</label>
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
2021-02-06 20:20:41 +00:00
|
|
|
id={`mod-ban-reason-${cv.comment.id}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
class="form-control mr-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
2020-09-06 16:15:25 +00:00
|
|
|
value={this.state.banReason}
|
|
|
|
onInput={linkEvent(this, this.handleModBanReasonChange)}
|
|
|
|
/>
|
2022-01-09 17:53:11 +00:00
|
|
|
<label
|
|
|
|
class="col-form-label"
|
|
|
|
htmlFor={`mod-ban-expires-${cv.comment.id}`}
|
|
|
|
>
|
|
|
|
{i18n.t("expires")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
id={`mod-ban-expires-${cv.comment.id}`}
|
|
|
|
class="form-control mr-2"
|
|
|
|
placeholder={i18n.t("number_of_days")}
|
|
|
|
value={this.state.banExpireDays}
|
|
|
|
onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
id="mod-ban-remove-data"
|
|
|
|
type="checkbox"
|
|
|
|
checked={this.state.removeData}
|
|
|
|
onChange={linkEvent(this, this.handleModRemoveDataChange)}
|
|
|
|
/>
|
2021-08-17 21:46:27 +00:00
|
|
|
<label
|
|
|
|
class="form-check-label"
|
|
|
|
htmlFor="mod-ban-remove-data"
|
|
|
|
title={i18n.t("remove_content_more")}
|
|
|
|
>
|
|
|
|
{i18n.t("remove_content")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* TODO hold off on expires until later */}
|
|
|
|
{/* <div class="form-group row"> */}
|
|
|
|
{/* <label class="col-form-label">Expires</label> */}
|
|
|
|
{/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
|
|
|
|
{/* </div> */}
|
|
|
|
<div class="form-group row">
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-secondary"
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("ban")}
|
2021-02-09 16:21:24 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("ban")} {cv.creator.name}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)}
|
|
|
|
{this.state.showReply && (
|
|
|
|
<CommentForm
|
|
|
|
node={node}
|
|
|
|
onReplyCancel={this.handleReplyCancel}
|
|
|
|
disabled={this.props.locked}
|
|
|
|
focus
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{node.children && !this.state.collapsed && (
|
|
|
|
<CommentNodes
|
|
|
|
nodes={node.children}
|
|
|
|
locked={this.props.locked}
|
|
|
|
moderators={this.props.moderators}
|
|
|
|
admins={this.props.admins}
|
|
|
|
postCreatorId={this.props.postCreatorId}
|
|
|
|
enableDownvotes={this.props.enableDownvotes}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{/* A collapsed clearfix */}
|
|
|
|
{this.state.collapsed && <div class="row col-12"></div>}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-06 21:05:42 +00:00
|
|
|
get commentOrMentionRead() {
|
|
|
|
let cv = this.props.node.comment_view;
|
2021-03-15 18:09:31 +00:00
|
|
|
return this.isPersonMentionType(cv)
|
|
|
|
? cv.person_mention.read
|
|
|
|
: cv.comment.read;
|
2021-01-06 21:05:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 16:59:00 +00:00
|
|
|
linkBtn(small = false) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = this.props.node.comment_view;
|
2022-02-14 18:49:57 +00:00
|
|
|
let classnames = classNames("btn btn-link btn-animate text-muted", {
|
|
|
|
"btn-sm": small,
|
|
|
|
});
|
|
|
|
|
|
|
|
let title = this.props.showContext
|
|
|
|
? i18n.t("show_context")
|
|
|
|
: i18n.t("link");
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-02-14 18:49:57 +00:00
|
|
|
<>
|
|
|
|
<Link
|
|
|
|
className={classnames}
|
|
|
|
to={`/post/${cv.post.id}/comment/${cv.comment.id}`}
|
|
|
|
title={title}
|
|
|
|
>
|
|
|
|
<Icon icon="link" classes="icon-inline" />
|
|
|
|
</Link>
|
|
|
|
{/* TODO comment ap_ids are currently broken anyway, so use post.ap_id, and wait until comment tree / endpoint refactor */}
|
|
|
|
{!cv.comment.local && (
|
|
|
|
<a className={classnames} title={title} href={cv.post.ap_id}>
|
|
|
|
<Icon icon="fedilink" classes="icon-inline" />
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</>
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get loadingIcon() {
|
2021-02-11 20:35:27 +00:00
|
|
|
return <Spinner />;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get myComment(): boolean {
|
|
|
|
return (
|
2021-03-15 18:09:31 +00:00
|
|
|
this.props.node.comment_view.creator.id ==
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo?.local_user_view.person.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get isMod(): boolean {
|
|
|
|
return (
|
|
|
|
this.props.moderators &&
|
|
|
|
isMod(
|
2020-12-24 01:58:27 +00:00
|
|
|
this.props.moderators.map(m => m.moderator.id),
|
|
|
|
this.props.node.comment_view.creator.id
|
2020-09-06 16:15:25 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get isAdmin(): boolean {
|
|
|
|
return (
|
|
|
|
this.props.admins &&
|
|
|
|
isMod(
|
2021-03-15 18:09:31 +00:00
|
|
|
this.props.admins.map(a => a.person.id),
|
2020-12-24 01:58:27 +00:00
|
|
|
this.props.node.comment_view.creator.id
|
2020-09-06 16:15:25 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get isPostCreator(): boolean {
|
2020-12-24 01:58:27 +00:00
|
|
|
return this.props.node.comment_view.creator.id == this.props.postCreatorId;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get canMod(): boolean {
|
|
|
|
if (this.props.admins && this.props.moderators) {
|
|
|
|
let adminsThenMods = this.props.admins
|
2021-03-15 18:09:31 +00:00
|
|
|
.map(a => a.person.id)
|
2020-12-24 01:58:27 +00:00
|
|
|
.concat(this.props.moderators.map(m => m.moderator.id));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
return canMod(
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo,
|
2020-09-06 16:15:25 +00:00
|
|
|
adminsThenMods,
|
2020-12-24 01:58:27 +00:00
|
|
|
this.props.node.comment_view.creator.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get canAdmin(): boolean {
|
|
|
|
return (
|
|
|
|
this.props.admins &&
|
|
|
|
canMod(
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo,
|
2021-03-15 18:09:31 +00:00
|
|
|
this.props.admins.map(a => a.person.id),
|
2020-12-24 01:58:27 +00:00
|
|
|
this.props.node.comment_view.creator.id
|
2020-09-06 16:15:25 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get amCommunityCreator(): boolean {
|
|
|
|
return (
|
|
|
|
this.props.moderators &&
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo &&
|
2021-03-15 18:09:31 +00:00
|
|
|
this.props.node.comment_view.creator.id !=
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo.local_user_view.person.id &&
|
|
|
|
UserService.Instance.myUserInfo.local_user_view.person.id ==
|
2021-03-15 18:09:31 +00:00
|
|
|
this.props.moderators[0].moderator.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get amSiteCreator(): boolean {
|
|
|
|
return (
|
|
|
|
this.props.admins &&
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo &&
|
2021-03-15 18:09:31 +00:00
|
|
|
this.props.node.comment_view.creator.id !=
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo.local_user_view.person.id &&
|
|
|
|
UserService.Instance.myUserInfo.local_user_view.person.id ==
|
2021-03-15 18:09:31 +00:00
|
|
|
this.props.admins[0].person.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get commentUnlessRemoved(): string {
|
2020-12-24 01:58:27 +00:00
|
|
|
let comment = this.props.node.comment_view.comment;
|
|
|
|
return comment.removed
|
2021-02-22 02:39:04 +00:00
|
|
|
? `*${i18n.t("removed")}*`
|
2020-12-24 01:58:27 +00:00
|
|
|
: comment.deleted
|
2021-02-22 02:39:04 +00:00
|
|
|
? `*${i18n.t("deleted")}*`
|
2020-12-24 01:58:27 +00:00
|
|
|
: comment.content;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleReplyClick(i: CommentNode) {
|
|
|
|
i.state.showReply = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditClick(i: CommentNode) {
|
|
|
|
i.state.showEdit = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-08-20 02:56:18 +00:00
|
|
|
handleBlockUserClick(i: CommentNode) {
|
|
|
|
let blockUserForm: BlockPerson = {
|
|
|
|
person_id: i.props.node.comment_view.creator.id,
|
|
|
|
block: true,
|
|
|
|
auth: authField(),
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleDeleteClick(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let comment = i.props.node.comment_view.comment;
|
|
|
|
let deleteForm: DeleteComment = {
|
2021-01-18 22:42:41 +00:00
|
|
|
comment_id: comment.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
deleted: !comment.deleted,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.deleteComment(deleteForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSaveCommentClick(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = i.props.node.comment_view;
|
|
|
|
let save = cv.saved == undefined ? true : !cv.saved;
|
|
|
|
let form: SaveComment = {
|
|
|
|
comment_id: cv.comment.id,
|
|
|
|
save,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.saveComment(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
i.state.saveLoading = true;
|
|
|
|
i.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleReplyCancel() {
|
|
|
|
this.state.showReply = false;
|
|
|
|
this.state.showEdit = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
2021-02-02 16:52:44 +00:00
|
|
|
handleCommentUpvote(i: CommentNodeI, event: any) {
|
|
|
|
event.preventDefault();
|
2020-09-06 16:15:25 +00:00
|
|
|
let new_vote = this.state.my_vote == 1 ? 0 : 1;
|
|
|
|
|
|
|
|
if (this.state.my_vote == 1) {
|
|
|
|
this.state.score--;
|
|
|
|
this.state.upvotes--;
|
|
|
|
} else if (this.state.my_vote == -1) {
|
|
|
|
this.state.downvotes--;
|
|
|
|
this.state.upvotes++;
|
|
|
|
this.state.score += 2;
|
|
|
|
} else {
|
|
|
|
this.state.upvotes++;
|
|
|
|
this.state.score++;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state.my_vote = new_vote;
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: CreateCommentLike = {
|
|
|
|
comment_id: i.comment_view.comment.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
score: this.state.my_vote,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.likeComment(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2021-02-02 16:52:44 +00:00
|
|
|
handleCommentDownvote(i: CommentNodeI, event: any) {
|
|
|
|
event.preventDefault();
|
2020-09-06 16:15:25 +00:00
|
|
|
let new_vote = this.state.my_vote == -1 ? 0 : -1;
|
|
|
|
|
|
|
|
if (this.state.my_vote == 1) {
|
|
|
|
this.state.score -= 2;
|
|
|
|
this.state.upvotes--;
|
|
|
|
this.state.downvotes++;
|
|
|
|
} else if (this.state.my_vote == -1) {
|
|
|
|
this.state.downvotes--;
|
|
|
|
this.state.score++;
|
|
|
|
} else {
|
|
|
|
this.state.downvotes++;
|
|
|
|
this.state.score--;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state.my_vote = new_vote;
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: CreateCommentLike = {
|
|
|
|
comment_id: i.comment_view.comment.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
score: this.state.my_vote,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.likeComment(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:59 +00:00
|
|
|
handleShowReportDialog(i: CommentNode) {
|
|
|
|
i.state.showReportDialog = !i.state.showReportDialog;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleReportReasonChange(i: CommentNode, event: any) {
|
|
|
|
i.state.reportReason = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleReportSubmit(i: CommentNode) {
|
|
|
|
let comment = i.props.node.comment_view.comment;
|
|
|
|
let form: CreateCommentReport = {
|
|
|
|
comment_id: comment.id,
|
|
|
|
reason: i.state.reportReason,
|
|
|
|
auth: authField(),
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.createCommentReport(form));
|
|
|
|
|
|
|
|
i.state.showReportDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleModRemoveShow(i: CommentNode) {
|
2021-10-03 16:18:10 +00:00
|
|
|
i.state.showRemoveDialog = !i.state.showRemoveDialog;
|
|
|
|
i.state.showBanDialog = false;
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveReasonChange(i: CommentNode, event: any) {
|
|
|
|
i.state.removeReason = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveDataChange(i: CommentNode, event: any) {
|
|
|
|
i.state.removeData = event.target.checked;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveSubmit(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let comment = i.props.node.comment_view.comment;
|
|
|
|
let form: RemoveComment = {
|
2021-01-18 22:42:41 +00:00
|
|
|
comment_id: comment.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
removed: !comment.removed,
|
2020-09-06 16:15:25 +00:00
|
|
|
reason: i.state.removeReason,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.removeComment(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
i.state.showRemoveDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
isPersonMentionType(
|
|
|
|
item: CommentView | PersonMentionView
|
|
|
|
): item is PersonMentionView {
|
|
|
|
return (item as PersonMentionView).person_mention?.id !== undefined;
|
2020-12-24 01:58:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleMarkRead(i: CommentNode) {
|
2021-03-15 18:09:31 +00:00
|
|
|
if (i.isPersonMentionType(i.props.node.comment_view)) {
|
|
|
|
let form: MarkPersonMentionAsRead = {
|
|
|
|
person_mention_id: i.props.node.comment_view.person_mention.id,
|
|
|
|
read: !i.props.node.comment_view.person_mention.read,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2021-03-15 18:09:31 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.markPersonMentionAsRead(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: MarkCommentAsRead = {
|
|
|
|
comment_id: i.props.node.comment_view.comment.id,
|
|
|
|
read: !i.props.node.comment_view.comment.read,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.markCommentAsRead(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i.state.readLoading = true;
|
|
|
|
i.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanFromCommunityShow(i: CommentNode) {
|
2021-10-03 16:18:10 +00:00
|
|
|
i.state.showBanDialog = true;
|
2020-09-06 16:15:25 +00:00
|
|
|
i.state.banType = BanType.Community;
|
2021-10-03 16:18:10 +00:00
|
|
|
i.state.showRemoveDialog = false;
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanShow(i: CommentNode) {
|
2021-10-03 16:18:10 +00:00
|
|
|
i.state.showBanDialog = true;
|
2020-09-06 16:15:25 +00:00
|
|
|
i.state.banType = BanType.Site;
|
2021-10-03 16:18:10 +00:00
|
|
|
i.state.showRemoveDialog = false;
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanReasonChange(i: CommentNode, event: any) {
|
|
|
|
i.state.banReason = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2022-01-09 17:53:11 +00:00
|
|
|
handleModBanExpireDaysChange(i: CommentNode, event: any) {
|
|
|
|
i.state.banExpireDays = event.target.value;
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanFromCommunitySubmit(i: CommentNode) {
|
|
|
|
i.state.banType = BanType.Community;
|
|
|
|
i.setState(i.state);
|
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanSubmit(i: CommentNode) {
|
|
|
|
i.state.banType = BanType.Site;
|
|
|
|
i.setState(i.state);
|
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanBothSubmit(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = i.props.node.comment_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
if (i.state.banType == BanType.Community) {
|
|
|
|
// If its an unban, restore all their data
|
2020-12-24 01:58:27 +00:00
|
|
|
let ban = !cv.creator_banned_from_community;
|
2020-09-06 16:15:25 +00:00
|
|
|
if (ban == false) {
|
|
|
|
i.state.removeData = false;
|
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: BanFromCommunity = {
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: cv.creator.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
community_id: cv.community.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
ban,
|
|
|
|
remove_data: i.state.removeData,
|
|
|
|
reason: i.state.banReason,
|
2022-01-09 17:53:11 +00:00
|
|
|
expires: futureDaysToUnixTime(i.state.banExpireDays),
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.banFromCommunity(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
|
|
|
// If its an unban, restore all their data
|
2020-12-24 01:58:27 +00:00
|
|
|
let ban = !cv.creator.banned;
|
2020-09-06 16:15:25 +00:00
|
|
|
if (ban == false) {
|
|
|
|
i.state.removeData = false;
|
|
|
|
}
|
2021-03-15 18:09:31 +00:00
|
|
|
let form: BanPerson = {
|
|
|
|
person_id: cv.creator.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
ban,
|
|
|
|
remove_data: i.state.removeData,
|
|
|
|
reason: i.state.banReason,
|
2022-01-09 17:53:11 +00:00
|
|
|
expires: futureDaysToUnixTime(i.state.banExpireDays),
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2021-03-15 18:09:31 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.banPerson(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i.state.showBanDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmAppointAsMod(i: CommentNode) {
|
|
|
|
i.state.showConfirmAppointAsMod = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelConfirmAppointAsMod(i: CommentNode) {
|
|
|
|
i.state.showConfirmAppointAsMod = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAddModToCommunity(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = i.props.node.comment_view;
|
|
|
|
let form: AddModToCommunity = {
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: cv.creator.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
community_id: cv.community.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
added: !i.isMod,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.addModToCommunity(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
i.state.showConfirmAppointAsMod = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmAppointAsAdmin(i: CommentNode) {
|
|
|
|
i.state.showConfirmAppointAsAdmin = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelConfirmAppointAsAdmin(i: CommentNode) {
|
|
|
|
i.state.showConfirmAppointAsAdmin = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAddAdmin(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: AddAdmin = {
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: i.props.node.comment_view.creator.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
added: !i.isAdmin,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.addAdmin(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
i.state.showConfirmAppointAsAdmin = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmTransferCommunity(i: CommentNode) {
|
|
|
|
i.state.showConfirmTransferCommunity = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelShowConfirmTransferCommunity(i: CommentNode) {
|
|
|
|
i.state.showConfirmTransferCommunity = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTransferCommunity(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = i.props.node.comment_view;
|
|
|
|
let form: TransferCommunity = {
|
|
|
|
community_id: cv.community.id,
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: cv.creator.id,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.transferCommunity(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
i.state.showConfirmTransferCommunity = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmTransferSite(i: CommentNode) {
|
|
|
|
i.state.showConfirmTransferSite = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelShowConfirmTransferSite(i: CommentNode) {
|
|
|
|
i.state.showConfirmTransferSite = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
get isCommentNew(): boolean {
|
2021-02-22 02:39:04 +00:00
|
|
|
let now = moment.utc().subtract(10, "minutes");
|
2020-12-24 01:58:27 +00:00
|
|
|
let then = moment.utc(this.props.node.comment_view.comment.published);
|
2020-09-06 16:15:25 +00:00
|
|
|
return now.isBefore(then);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCommentCollapse(i: CommentNode) {
|
|
|
|
i.state.collapsed = !i.state.collapsed;
|
|
|
|
i.setState(i.state);
|
2021-07-16 17:04:35 +00:00
|
|
|
setupTippy();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleViewSource(i: CommentNode) {
|
|
|
|
i.state.viewSource = !i.state.viewSource;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowAdvanced(i: CommentNode) {
|
|
|
|
i.state.showAdvanced = !i.state.showAdvanced;
|
|
|
|
i.setState(i.state);
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
|
|
|
get scoreColor() {
|
|
|
|
if (this.state.my_vote == 1) {
|
2021-02-22 02:39:04 +00:00
|
|
|
return "text-info";
|
2020-09-06 16:15:25 +00:00
|
|
|
} else if (this.state.my_vote == -1) {
|
2021-02-22 02:39:04 +00:00
|
|
|
return "text-danger";
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2021-02-22 02:39:04 +00:00
|
|
|
return "text-muted";
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get pointsTippy(): string {
|
2021-02-22 02:39:04 +00:00
|
|
|
let points = i18n.t("number_of_points", {
|
2020-09-06 16:15:25 +00:00
|
|
|
count: this.state.score,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: this.state.score,
|
2020-09-06 16:15:25 +00:00
|
|
|
});
|
|
|
|
|
2021-02-22 02:39:04 +00:00
|
|
|
let upvotes = i18n.t("number_of_upvotes", {
|
2020-09-06 16:15:25 +00:00
|
|
|
count: this.state.upvotes,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: this.state.upvotes,
|
2020-09-06 16:15:25 +00:00
|
|
|
});
|
|
|
|
|
2021-02-22 02:39:04 +00:00
|
|
|
let downvotes = i18n.t("number_of_downvotes", {
|
2020-09-06 16:15:25 +00:00
|
|
|
count: this.state.downvotes,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: this.state.downvotes,
|
2020-09-06 16:15:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return `${points} • ${upvotes} • ${downvotes}`;
|
|
|
|
}
|
2021-07-16 17:04:35 +00:00
|
|
|
|
|
|
|
get expandText(): string {
|
|
|
|
return this.state.collapsed ? i18n.t("expand") : i18n.t("collapse");
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|