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,
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentReplyView,
|
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,
|
2023-05-11 18:32:32 +00:00
|
|
|
DistinguishComment,
|
2022-07-30 13:28:08 +00:00
|
|
|
GetComments,
|
2022-09-22 15:14:58 +00:00
|
|
|
Language,
|
2022-07-30 13:28:08 +00:00
|
|
|
MarkCommentReplyAsRead,
|
2021-03-15 18:09:31 +00:00
|
|
|
MarkPersonMentionAsRead,
|
2021-07-17 20:42:55 +00:00
|
|
|
PersonMentionView,
|
2023-05-11 18:32:32 +00:00
|
|
|
PersonView,
|
2022-06-23 19:44:05 +00:00
|
|
|
PurgeComment,
|
|
|
|
PurgePerson,
|
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";
|
2023-05-11 18:32:32 +00:00
|
|
|
import {
|
|
|
|
BanType,
|
|
|
|
CommentNodeI,
|
|
|
|
CommentViewType,
|
|
|
|
PurgeType,
|
|
|
|
} from "../../interfaces";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
amCommunityCreator,
|
|
|
|
canAdmin,
|
2020-09-06 16:15:25 +00:00
|
|
|
canMod,
|
2021-07-17 20:42:55 +00:00
|
|
|
colorList,
|
2022-07-30 13:28:08 +00:00
|
|
|
commentTreeMaxDepth,
|
2022-01-09 17:53:11 +00:00
|
|
|
futureDaysToUnixTime,
|
2022-06-21 21:42:29 +00:00
|
|
|
isAdmin,
|
2022-01-09 17:53:11 +00:00
|
|
|
isBanned,
|
2020-09-06 16:15:25 +00:00
|
|
|
isMod,
|
2021-07-17 20:42:55 +00:00
|
|
|
mdToHtml,
|
2022-11-19 02:02:38 +00:00
|
|
|
mdToHtmlNoImages,
|
2023-01-04 16:56:24 +00:00
|
|
|
myAuth,
|
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";
|
2022-06-23 19:44:05 +00:00
|
|
|
import { Icon, PurgeWarning, Spinner } from "../common/icon";
|
2021-07-17 20:42:55 +00:00
|
|
|
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;
|
2023-01-04 16:56:24 +00:00
|
|
|
removeReason?: string;
|
2020-09-06 16:15:25 +00:00
|
|
|
showBanDialog: boolean;
|
|
|
|
removeData: boolean;
|
2023-01-04 16:56:24 +00:00
|
|
|
banReason?: string;
|
|
|
|
banExpireDays?: number;
|
2020-09-06 16:15:25 +00:00
|
|
|
banType: BanType;
|
2022-06-23 19:44:05 +00:00
|
|
|
showPurgeDialog: boolean;
|
2023-01-04 16:56:24 +00:00
|
|
|
purgeReason?: string;
|
2022-06-23 19:44:05 +00:00
|
|
|
purgeType: PurgeType;
|
|
|
|
purgeLoading: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
showConfirmTransferSite: boolean;
|
|
|
|
showConfirmTransferCommunity: boolean;
|
|
|
|
showConfirmAppointAsMod: boolean;
|
|
|
|
showConfirmAppointAsAdmin: boolean;
|
|
|
|
collapsed: boolean;
|
|
|
|
viewSource: boolean;
|
|
|
|
showAdvanced: boolean;
|
2021-09-28 10:38:59 +00:00
|
|
|
showReportDialog: boolean;
|
2023-01-04 16:56:24 +00:00
|
|
|
reportReason?: string;
|
|
|
|
my_vote?: number;
|
2023-05-15 19:53:29 +00:00
|
|
|
score: number;
|
|
|
|
upvotes: number;
|
|
|
|
downvotes: number;
|
2020-09-06 16:15:25 +00:00
|
|
|
readLoading: boolean;
|
|
|
|
saveLoading: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CommentNodeProps {
|
|
|
|
node: CommentNodeI;
|
2023-01-04 16:56:24 +00:00
|
|
|
moderators?: CommunityModeratorView[];
|
2023-05-11 18:32:32 +00:00
|
|
|
admins?: PersonView[];
|
2020-09-06 16:15:25 +00:00
|
|
|
noBorder?: boolean;
|
|
|
|
noIndent?: boolean;
|
|
|
|
viewOnly?: boolean;
|
|
|
|
locked?: boolean;
|
|
|
|
markable?: boolean;
|
|
|
|
showContext?: boolean;
|
|
|
|
showCommunity?: boolean;
|
2023-01-04 16:56:24 +00:00
|
|
|
enableDownvotes?: boolean;
|
2022-07-30 13:28:08 +00:00
|
|
|
viewType: CommentViewType;
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages: Language[];
|
2022-12-19 15:57:29 +00:00
|
|
|
siteLanguages: number[];
|
2022-11-19 02:02:38 +00:00
|
|
|
hideImages?: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
2023-01-04 16:56:24 +00:00
|
|
|
state: CommentNodeState = {
|
2020-09-06 16:15:25 +00:00
|
|
|
showReply: false,
|
|
|
|
showEdit: false,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
showBanDialog: false,
|
2021-01-26 17:21:10 +00:00
|
|
|
removeData: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
banType: BanType.Community,
|
2022-06-23 19:44:05 +00:00
|
|
|
showPurgeDialog: false,
|
|
|
|
purgeLoading: false,
|
|
|
|
purgeType: PurgeType.Person,
|
2020-09-06 16:15:25 +00:00
|
|
|
collapsed: false,
|
|
|
|
viewSource: false,
|
|
|
|
showAdvanced: false,
|
|
|
|
showConfirmTransferSite: false,
|
|
|
|
showConfirmTransferCommunity: false,
|
|
|
|
showConfirmAppointAsMod: false,
|
|
|
|
showConfirmAppointAsAdmin: false,
|
2021-09-28 10:38:59 +00:00
|
|
|
showReportDialog: false,
|
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,
|
2020-09-06 16:15:25 +00:00
|
|
|
readLoading: false,
|
|
|
|
saveLoading: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
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;
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
my_vote: cv.my_vote,
|
|
|
|
upvotes: cv.counts.upvotes,
|
|
|
|
downvotes: cv.counts.downvotes,
|
|
|
|
score: cv.counts.score,
|
|
|
|
readLoading: false,
|
|
|
|
saveLoading: false,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let node = this.props.node;
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = this.props.node.comment_view;
|
2022-06-21 21:42:29 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
let purgeTypeText =
|
|
|
|
this.state.purgeType == PurgeType.Comment
|
|
|
|
? i18n.t("purge_comment")
|
|
|
|
: `${i18n.t("purge")} ${cv.creator.name}`;
|
2022-06-23 19:44:05 +00:00
|
|
|
|
2023-02-21 20:52:57 +00:00
|
|
|
let canMod_ =
|
|
|
|
canMod(cv.creator.id, this.props.moderators, this.props.admins) &&
|
|
|
|
cv.community.local;
|
|
|
|
let canModOnSelf =
|
|
|
|
canMod(
|
|
|
|
cv.creator.id,
|
|
|
|
this.props.moderators,
|
|
|
|
this.props.admins,
|
|
|
|
UserService.Instance.myUserInfo,
|
|
|
|
true
|
|
|
|
) && cv.community.local;
|
|
|
|
let canAdmin_ =
|
|
|
|
canAdmin(cv.creator.id, this.props.admins) && cv.community.local;
|
|
|
|
let canAdminOnSelf =
|
|
|
|
canAdmin(
|
|
|
|
cv.creator.id,
|
|
|
|
this.props.admins,
|
|
|
|
UserService.Instance.myUserInfo,
|
|
|
|
true
|
|
|
|
) && cv.community.local;
|
2023-01-04 16:56:24 +00:00
|
|
|
let isMod_ = isMod(cv.creator.id, this.props.moderators);
|
2023-02-21 20:52:57 +00:00
|
|
|
let isAdmin_ =
|
|
|
|
isAdmin(cv.creator.id, this.props.admins) && cv.community.local;
|
2022-06-21 21:42:29 +00:00
|
|
|
let amCommunityCreator_ = amCommunityCreator(
|
2023-01-04 16:56:24 +00:00
|
|
|
cv.creator.id,
|
|
|
|
this.props.moderators
|
2022-06-21 21:42:29 +00:00
|
|
|
);
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
let borderColor = this.props.node.depth
|
|
|
|
? colorList[(this.props.node.depth - 1) % colorList.length]
|
|
|
|
: colorList[0];
|
|
|
|
let moreRepliesBorderColor = this.props.node.depth
|
|
|
|
? colorList[this.props.node.depth % colorList.length]
|
|
|
|
: colorList[0];
|
|
|
|
|
|
|
|
let showMoreChildren =
|
|
|
|
this.props.viewType == CommentViewType.Tree &&
|
|
|
|
!this.state.collapsed &&
|
|
|
|
node.children.length == 0 &&
|
|
|
|
node.comment_view.counts.child_count > 0;
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`comment ${
|
2022-07-30 13:28:08 +00:00
|
|
|
this.props.node.depth && !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}`}
|
2022-08-17 23:26:50 +00:00
|
|
|
className={classNames(`details comment-node py-2`, {
|
|
|
|
"border-top border-light": !this.props.noBorder,
|
|
|
|
mark:
|
|
|
|
this.isCommentNew ||
|
|
|
|
this.props.node.comment_view.comment.distinguished,
|
|
|
|
})}
|
2020-09-06 16:15:25 +00:00
|
|
|
style={
|
2023-01-04 16:56:24 +00:00
|
|
|
!this.props.noIndent && this.props.node.depth
|
|
|
|
? `border-left: 2px ${borderColor} solid !important`
|
|
|
|
: ""
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<div
|
2023-01-04 16:56:24 +00:00
|
|
|
className={classNames({
|
|
|
|
"ml-2": !this.props.noIndent && this.props.node.depth,
|
|
|
|
})}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="d-flex flex-wrap align-items-center text-muted small">
|
|
|
|
<span className="mr-2">
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={cv.creator} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
2022-08-17 23:26:50 +00:00
|
|
|
{cv.comment.distinguished && (
|
|
|
|
<Icon icon="shield" inline classes={`text-danger mr-2`} />
|
|
|
|
)}
|
2022-06-21 21:42:29 +00:00
|
|
|
{isMod_ && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<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>
|
|
|
|
)}
|
2022-06-21 21:42:29 +00:00
|
|
|
{isAdmin_ && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<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>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.props.showCommunity && (
|
|
|
|
<>
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="mx-1">{i18n.t("to")}</span>
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={cv.community} />
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="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
|
2022-09-22 15:03:35 +00:00
|
|
|
className="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)}
|
2023-05-21 18:13:25 +00:00
|
|
|
<span className="mx-1 badge badge-secondary">
|
|
|
|
{
|
|
|
|
this.props.allLanguages.find(
|
|
|
|
lang => lang.id === cv.comment.language_id
|
|
|
|
)?.name
|
|
|
|
}
|
|
|
|
</span>
|
2020-09-06 16:15:25 +00:00
|
|
|
{/* This is an expanding spacer for mobile */}
|
2023-05-21 18:13:25 +00:00
|
|
|
<div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
|
2021-04-09 16:23:30 +00:00
|
|
|
{showScores() && (
|
|
|
|
<>
|
|
|
|
<a
|
|
|
|
className={`unselectable pointer ${this.scoreColor}`}
|
2022-07-30 13:28:08 +00:00
|
|
|
onClick={this.handleCommentUpvote}
|
2021-04-09 16:23:30 +00:00
|
|
|
data-tippy-content={this.pointsTippy}
|
|
|
|
>
|
|
|
|
<span
|
2022-09-22 15:03:35 +00:00
|
|
|
className="mr-1 font-weight-bold"
|
2021-04-09 16:23:30 +00:00
|
|
|
aria-label={i18n.t("number_of_points", {
|
2023-05-11 18:32:32 +00:00
|
|
|
count: Number(this.state.score),
|
|
|
|
formattedCount: numToSI(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>
|
2022-06-21 21:42:29 +00:00
|
|
|
<MomentTime
|
|
|
|
published={cv.comment.published}
|
|
|
|
updated={cv.comment.updated}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{/* end of user row */}
|
|
|
|
{this.state.showEdit && (
|
|
|
|
<CommentForm
|
2023-01-04 16:56:24 +00:00
|
|
|
node={node}
|
2020-09-06 16:15:25 +00:00
|
|
|
edit
|
|
|
|
onReplyCancel={this.handleReplyCancel}
|
|
|
|
disabled={this.props.locked}
|
|
|
|
focus
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2022-12-19 15:57:29 +00:00
|
|
|
siteLanguages={this.props.siteLanguages}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{!this.state.showEdit && !this.state.collapsed && (
|
|
|
|
<div>
|
|
|
|
{this.state.viewSource ? (
|
|
|
|
<pre>{this.commentUnlessRemoved}</pre>
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className="md-div"
|
2022-11-19 02:02:38 +00:00
|
|
|
dangerouslySetInnerHTML={
|
|
|
|
this.props.hideImages
|
|
|
|
? mdToHtmlNoImages(this.commentUnlessRemoved)
|
|
|
|
: mdToHtml(this.commentUnlessRemoved)
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
)}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="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
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleMarkRead)}
|
|
|
|
data-tippy-content={
|
2022-07-30 13:28:08 +00:00
|
|
|
this.commentReplyOrMentionRead
|
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={
|
2022-07-30 13:28:08 +00:00
|
|
|
this.commentReplyOrMentionRead
|
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 ${
|
2022-07-30 13:28:08 +00:00
|
|
|
this.commentReplyOrMentionRead && "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>
|
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
{UserService.Instance.myUserInfo && !this.props.viewOnly && (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
className={`btn btn-link btn-animate ${
|
|
|
|
this.state.my_vote == 1 ? "text-info" : "text-muted"
|
|
|
|
}`}
|
|
|
|
onClick={this.handleCommentUpvote}
|
|
|
|
data-tippy-content={i18n.t("upvote")}
|
|
|
|
aria-label={i18n.t("upvote")}
|
|
|
|
>
|
|
|
|
<Icon icon="arrow-up1" classes="icon-inline" />
|
|
|
|
{showScores() &&
|
|
|
|
this.state.upvotes !== this.state.score && (
|
|
|
|
<span className="ml-1">
|
|
|
|
{numToSI(this.state.upvotes)}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
{this.props.enableDownvotes && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
|
|
|
className={`btn btn-link btn-animate ${
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.my_vote == -1
|
|
|
|
? "text-danger"
|
2021-02-22 02:39:04 +00:00
|
|
|
: "text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2023-01-04 16:56:24 +00:00
|
|
|
onClick={this.handleCommentDownvote}
|
|
|
|
data-tippy-content={i18n.t("downvote")}
|
|
|
|
aria-label={i18n.t("downvote")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
<Icon icon="arrow-down1" classes="icon-inline" />
|
2021-04-09 16:23:30 +00:00
|
|
|
{showScores() &&
|
|
|
|
this.state.upvotes !== this.state.score && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="ml-1">
|
2023-01-04 16:56:24 +00:00
|
|
|
{numToSI(this.state.downvotes)}
|
2021-09-18 16:35:49 +00:00
|
|
|
</span>
|
2021-04-09 16:23:30 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
)}
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleReplyClick)}
|
|
|
|
data-tippy-content={i18n.t("reply")}
|
|
|
|
aria-label={i18n.t("reply")}
|
|
|
|
>
|
|
|
|
<Icon icon="reply1" classes="icon-inline" />
|
|
|
|
</button>
|
|
|
|
{!this.state.showAdvanced ? (
|
2022-06-21 21:42:29 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2023-01-04 16:56:24 +00:00
|
|
|
onClick={linkEvent(this, this.handleShowAdvanced)}
|
|
|
|
data-tippy-content={i18n.t("more")}
|
|
|
|
aria-label={i18n.t("more")}
|
2022-06-21 21:42:29 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
<Icon icon="more-vertical" classes="icon-inline" />
|
2022-06-21 21:42:29 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{!this.myComment && (
|
|
|
|
<>
|
|
|
|
<button className="btn btn-link btn-animate">
|
|
|
|
<Link
|
|
|
|
className="text-muted"
|
2023-04-15 14:47:10 +00:00
|
|
|
to={`/create_private_message/${cv.creator.id}`}
|
2023-01-04 16:56:24 +00:00
|
|
|
title={i18n.t("message").toLowerCase()}
|
|
|
|
>
|
|
|
|
<Icon icon="mail" />
|
|
|
|
</Link>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
className="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>
|
|
|
|
<button
|
|
|
|
className="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")}
|
|
|
|
>
|
|
|
|
<Icon icon="slash" />
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
2023-01-04 16:56:24 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleSaveCommentClick
|
|
|
|
)}
|
|
|
|
data-tippy-content={
|
|
|
|
cv.saved ? i18n.t("unsave") : i18n.t("save")
|
|
|
|
}
|
|
|
|
aria-label={
|
|
|
|
cv.saved ? i18n.t("unsave") : i18n.t("save")
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{this.state.saveLoading ? (
|
|
|
|
this.loadingIcon
|
|
|
|
) : (
|
|
|
|
<Icon
|
|
|
|
icon="star"
|
|
|
|
classes={`icon-inline ${
|
|
|
|
cv.saved && "text-warning"
|
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleViewSource)}
|
|
|
|
data-tippy-content={i18n.t("view_source")}
|
|
|
|
aria-label={i18n.t("view_source")}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="file-text"
|
|
|
|
classes={`icon-inline ${
|
|
|
|
this.state.viewSource && "text-success"
|
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
{this.myComment && (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleEditClick)}
|
|
|
|
data-tippy-content={i18n.t("edit")}
|
|
|
|
aria-label={i18n.t("edit")}
|
|
|
|
>
|
|
|
|
<Icon icon="edit" classes="icon-inline" />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteClick
|
|
|
|
)}
|
|
|
|
data-tippy-content={
|
|
|
|
!cv.comment.deleted
|
|
|
|
? i18n.t("delete")
|
|
|
|
: i18n.t("restore")
|
|
|
|
}
|
|
|
|
aria-label={
|
|
|
|
!cv.comment.deleted
|
|
|
|
? i18n.t("delete")
|
|
|
|
: i18n.t("restore")
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="trash"
|
|
|
|
classes={`icon-inline ${
|
|
|
|
cv.comment.deleted && "text-danger"
|
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
{(canModOnSelf || canAdminOnSelf) && (
|
2022-06-21 21:42:29 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2022-06-21 21:42:29 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleDistinguishClick
|
2022-06-21 21:42:29 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
data-tippy-content={
|
|
|
|
!cv.comment.distinguished
|
|
|
|
? i18n.t("distinguish")
|
|
|
|
: i18n.t("undistinguish")
|
|
|
|
}
|
|
|
|
aria-label={
|
|
|
|
!cv.comment.distinguished
|
|
|
|
? i18n.t("distinguish")
|
|
|
|
: i18n.t("undistinguish")
|
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
<Icon
|
|
|
|
icon="shield"
|
|
|
|
classes={`icon-inline ${
|
|
|
|
cv.comment.distinguished && "text-danger"
|
|
|
|
}`}
|
|
|
|
/>
|
2022-06-21 21:42:29 +00:00
|
|
|
</button>
|
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Admins and mods can remove comments */}
|
|
|
|
{(canMod_ || canAdmin_) && (
|
|
|
|
<>
|
|
|
|
{!cv.comment.removed ? (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleModRemoveShow
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("remove")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("remove")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
) : (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleModRemoveSubmit
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("restore")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("restore")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Mods can ban from community, and appoint as mods to community */}
|
|
|
|
{canMod_ && (
|
|
|
|
<>
|
|
|
|
{!isMod_ &&
|
|
|
|
(!cv.creator_banned_from_community ? (
|
2022-08-17 23:26:50 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2022-08-17 23:26:50 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleModBanFromCommunityShow
|
2022-08-17 23:26:50 +00:00
|
|
|
)}
|
2023-02-21 21:12:00 +00:00
|
|
|
aria-label={i18n.t("ban_from_community")}
|
2022-08-17 23:26:50 +00:00
|
|
|
>
|
2023-02-21 21:12:00 +00:00
|
|
|
{i18n.t("ban_from_community")}
|
2022-08-17 23:26:50 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
) : (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleModBanFromCommunitySubmit
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("unban")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("unban")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
))}
|
|
|
|
{!cv.creator_banned_from_community &&
|
|
|
|
(!this.state.showConfirmAppointAsMod ? (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleShowConfirmAppointAsMod
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={
|
|
|
|
isMod_
|
|
|
|
? i18n.t("remove_as_mod")
|
|
|
|
: i18n.t("appoint_as_mod")
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{isMod_
|
|
|
|
? i18n.t("remove_as_mod")
|
|
|
|
: i18n.t("appoint_as_mod")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
) : (
|
|
|
|
<>
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("are_you_sure")}
|
2021-02-09 16:21:24 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("are_you_sure")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleAddModToCommunity
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleCancelConfirmAppointAsMod
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("no")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("no")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Community creators and admins can transfer community to another mod */}
|
|
|
|
{(amCommunityCreator_ || canAdmin_) &&
|
|
|
|
isMod_ &&
|
|
|
|
cv.creator.local &&
|
|
|
|
(!this.state.showConfirmTransferCommunity ? (
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmTransferCommunity
|
|
|
|
)}
|
|
|
|
aria-label={i18n.t("transfer_community")}
|
|
|
|
>
|
|
|
|
{i18n.t("transfer_community")}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
aria-label={i18n.t("are_you_sure")}
|
|
|
|
>
|
|
|
|
{i18n.t("are_you_sure")}
|
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleTransferCommunity
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this
|
|
|
|
.handleCancelShowConfirmTransferCommunity
|
|
|
|
)}
|
|
|
|
aria-label={i18n.t("no")}
|
|
|
|
>
|
|
|
|
{i18n.t("no")}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
{/* Admins can ban from all, and appoint other admins */}
|
|
|
|
{canAdmin_ && (
|
|
|
|
<>
|
|
|
|
{!isAdmin_ && (
|
2022-06-21 21:42:29 +00:00
|
|
|
<>
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handlePurgePersonShow
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("purge_user")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("purge_user")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handlePurgeCommentShow
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("purge_comment")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("purge_comment")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
|
|
|
|
{!isBanned(cv.creator) ? (
|
2022-06-21 21:42:29 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2022-06-21 21:42:29 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleModBanShow
|
2022-06-21 21:42:29 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("ban_from_site")}
|
2022-06-21 21:42:29 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("ban_from_site")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
) : (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleModBanSubmit
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("unban_from_site")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("unban_from_site")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{!isBanned(cv.creator) &&
|
|
|
|
cv.creator.local &&
|
|
|
|
(!this.state.showConfirmAppointAsAdmin ? (
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmAppointAsAdmin
|
2022-06-23 19:44:05 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={
|
|
|
|
isAdmin_
|
|
|
|
? i18n.t("remove_as_admin")
|
|
|
|
: i18n.t("appoint_as_admin")
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{isAdmin_
|
|
|
|
? i18n.t("remove_as_admin")
|
|
|
|
: i18n.t("appoint_as_admin")}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<button className="btn btn-link btn-animate text-muted">
|
|
|
|
{i18n.t("are_you_sure")}
|
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.handleAddAdmin
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2023-01-04 16:56:24 +00:00
|
|
|
aria-label={i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2023-01-04 16:56:24 +00:00
|
|
|
{i18n.t("yes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2023-01-04 16:56:24 +00:00
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleCancelConfirmAppointAsAdmin
|
|
|
|
)}
|
|
|
|
aria-label={i18n.t("no")}
|
|
|
|
>
|
|
|
|
{i18n.t("no")}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
{/* end of button group */}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-30 13:28:08 +00:00
|
|
|
{showMoreChildren && (
|
|
|
|
<div
|
|
|
|
className={`details ml-1 comment-node py-2 ${
|
|
|
|
!this.props.noBorder ? "border-top border-light" : ""
|
|
|
|
}`}
|
|
|
|
style={`border-left: 2px ${moreRepliesBorderColor} solid !important`}
|
|
|
|
>
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted"
|
2022-07-30 13:28:08 +00:00
|
|
|
onClick={linkEvent(this, this.handleFetchChildren)}
|
|
|
|
>
|
|
|
|
{i18n.t("x_more_replies", {
|
|
|
|
count: node.comment_view.counts.child_count,
|
2023-05-15 19:53:29 +00:00
|
|
|
formattedCount: numToSI(node.comment_view.counts.child_count),
|
2022-07-30 13:28:08 +00:00
|
|
|
})}{" "}
|
|
|
|
➔
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{/* end of details */}
|
|
|
|
{this.state.showRemoveDialog && (
|
|
|
|
<form
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-inline"
|
2020-09-06 16:15:25 +00:00
|
|
|
onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
|
|
|
|
>
|
2021-02-09 16:21:24 +00:00
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="sr-only"
|
2021-02-09 16:21:24 +00:00
|
|
|
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}`}
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.removeReason}
|
2020-09-06 16:15:25 +00:00
|
|
|
onInput={linkEvent(this, this.handleModRemoveReasonChange)}
|
|
|
|
/>
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="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
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-inline"
|
2021-09-28 10:38:59 +00:00
|
|
|
onSubmit={linkEvent(this, this.handleReportSubmit)}
|
|
|
|
>
|
2022-09-22 15:03:35 +00:00
|
|
|
<label
|
|
|
|
className="sr-only"
|
|
|
|
htmlFor={`report-reason-${cv.comment.id}`}
|
|
|
|
>
|
2021-09-28 10:38:59 +00:00
|
|
|
{i18n.t("reason")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
required
|
|
|
|
id={`report-reason-${cv.comment.id}`}
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2021-09-28 10:38:59 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
|
|
|
value={this.state.reportReason}
|
|
|
|
onInput={linkEvent(this, this.handleReportReasonChange)}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary"
|
2021-09-28 10:38:59 +00:00
|
|
|
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-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row col-12">
|
2021-02-06 20:20:41 +00:00
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="col-form-label"
|
2021-02-06 20:20:41 +00:00
|
|
|
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}`}
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.banReason}
|
2020-09-06 16:15:25 +00:00
|
|
|
onInput={linkEvent(this, this.handleModBanReasonChange)}
|
|
|
|
/>
|
2022-01-09 17:53:11 +00:00
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="col-form-label"
|
2022-01-09 17:53:11 +00:00
|
|
|
htmlFor={`mod-ban-expires-${cv.comment.id}`}
|
|
|
|
>
|
|
|
|
{i18n.t("expires")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
id={`mod-ban-expires-${cv.comment.id}`}
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2022-01-09 17:53:11 +00:00
|
|
|
placeholder={i18n.t("number_of_days")}
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.banExpireDays}
|
2022-01-09 17:53:11 +00:00
|
|
|
onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
|
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
|
|
|
<div className="form-check">
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2020-09-06 16:15:25 +00:00
|
|
|
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
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2021-08-17 21:46:27 +00:00
|
|
|
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> */}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="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>
|
|
|
|
)}
|
2022-06-23 19:44:05 +00:00
|
|
|
|
|
|
|
{this.state.showPurgeDialog && (
|
|
|
|
<form onSubmit={linkEvent(this, this.handlePurgeSubmit)}>
|
|
|
|
<PurgeWarning />
|
2022-09-22 15:03:35 +00:00
|
|
|
<label className="sr-only" htmlFor="purge-reason">
|
2022-06-23 19:44:05 +00:00
|
|
|
{i18n.t("reason")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="purge-reason"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control my-3"
|
2022-06-23 19:44:05 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.purgeReason}
|
2022-06-23 19:44:05 +00:00
|
|
|
onInput={linkEvent(this, this.handlePurgeReasonChange)}
|
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row col-12">
|
2022-06-23 19:44:05 +00:00
|
|
|
{this.state.purgeLoading ? (
|
|
|
|
<Spinner />
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary"
|
2022-06-23 19:44:05 +00:00
|
|
|
aria-label={purgeTypeText}
|
|
|
|
>
|
|
|
|
{purgeTypeText}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.state.showReply && (
|
|
|
|
<CommentForm
|
2023-01-04 16:56:24 +00:00
|
|
|
node={node}
|
2020-09-06 16:15:25 +00:00
|
|
|
onReplyCancel={this.handleReplyCancel}
|
|
|
|
disabled={this.props.locked}
|
|
|
|
focus
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2022-12-19 15:57:29 +00:00
|
|
|
siteLanguages={this.props.siteLanguages}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
)}
|
2022-07-30 13:28:08 +00:00
|
|
|
{!this.state.collapsed && node.children.length > 0 && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<CommentNodes
|
|
|
|
nodes={node.children}
|
|
|
|
locked={this.props.locked}
|
|
|
|
moderators={this.props.moderators}
|
|
|
|
admins={this.props.admins}
|
|
|
|
enableDownvotes={this.props.enableDownvotes}
|
2022-07-30 13:28:08 +00:00
|
|
|
viewType={this.props.viewType}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2022-12-19 15:57:29 +00:00
|
|
|
siteLanguages={this.props.siteLanguages}
|
2022-11-19 02:02:38 +00:00
|
|
|
hideImages={this.props.hideImages}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{/* A collapsed clearfix */}
|
2022-09-22 15:03:35 +00:00
|
|
|
{this.state.collapsed && <div className="row col-12"></div>}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
get commentReplyOrMentionRead(): boolean {
|
2021-01-06 21:05:42 +00:00
|
|
|
let cv = this.props.node.comment_view;
|
2022-07-30 13:28:08 +00:00
|
|
|
|
|
|
|
if (this.isPersonMentionType(cv)) {
|
|
|
|
return cv.person_mention.read;
|
|
|
|
} else if (this.isCommentReplyType(cv)) {
|
|
|
|
return cv.comment_reply.read;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
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}
|
2022-07-30 13:28:08 +00:00
|
|
|
to={`/comment/${cv.comment.id}`}
|
2022-02-14 18:49:57 +00:00
|
|
|
title={title}
|
|
|
|
>
|
|
|
|
<Icon icon="link" classes="icon-inline" />
|
|
|
|
</Link>
|
2022-03-14 18:33:59 +00:00
|
|
|
{
|
|
|
|
<a className={classnames} title={title} href={cv.comment.ap_id}>
|
2022-02-14 18:49:57 +00:00
|
|
|
<Icon icon="fedilink" classes="icon-inline" />
|
|
|
|
</a>
|
2022-03-14 18:33:59 +00:00
|
|
|
}
|
2022-02-14 18:49:57 +00:00
|
|
|
</>
|
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 {
|
2023-01-04 16:56:24 +00:00
|
|
|
return (
|
|
|
|
UserService.Instance.myUserInfo?.local_user_view.person.id ==
|
|
|
|
this.props.node.comment_view.creator.id
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get isPostCreator(): boolean {
|
|
|
|
return (
|
2022-06-21 21:42:29 +00:00
|
|
|
this.props.node.comment_view.creator.id ==
|
|
|
|
this.props.node.comment_view.post.creator_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) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showReply: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleEditClick(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showEdit: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 02:56:18 +00:00
|
|
|
handleBlockUserClick(i: CommentNode) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let blockUserForm: BlockPerson = {
|
|
|
|
person_id: i.props.node.comment_view.creator.id,
|
|
|
|
block: true,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
|
|
|
|
}
|
2021-08-20 02:56:18 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let deleteForm: DeleteComment = {
|
|
|
|
comment_id: comment.id,
|
|
|
|
deleted: !comment.deleted,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
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;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: SaveComment = {
|
|
|
|
comment_id: cv.comment.id,
|
|
|
|
save,
|
|
|
|
auth,
|
|
|
|
};
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.saveComment(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ saveLoading: true });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleReplyCancel() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ showReply: false, showEdit: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
handleCommentUpvote(event: any) {
|
2021-02-02 16:52:44 +00:00
|
|
|
event.preventDefault();
|
2023-01-04 16:56:24 +00:00
|
|
|
let myVote = this.state.my_vote;
|
2022-06-21 21:42:29 +00:00
|
|
|
let newVote = myVote == 1 ? 0 : 1;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
if (myVote == 1) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
2023-05-15 19:53:29 +00:00
|
|
|
score: this.state.score - 1,
|
|
|
|
upvotes: this.state.upvotes - 1,
|
2022-09-22 15:03:35 +00:00
|
|
|
});
|
2022-06-21 21:42:29 +00:00
|
|
|
} else if (myVote == -1) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
2023-05-15 19:53:29 +00:00
|
|
|
downvotes: this.state.downvotes - 1,
|
|
|
|
upvotes: this.state.upvotes + 1,
|
|
|
|
score: this.state.score + 2,
|
2022-09-22 15:03:35 +00:00
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
2023-05-15 19:53:29 +00:00
|
|
|
score: this.state.score + 1,
|
|
|
|
upvotes: this.state.upvotes + 1,
|
2022-09-22 15:03:35 +00:00
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState({ my_vote: newVote });
|
|
|
|
|
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: CreateCommentLike = {
|
|
|
|
comment_id: this.props.node.comment_view.comment.id,
|
|
|
|
score: newVote,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.likeComment(form));
|
|
|
|
setupTippy();
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
handleCommentDownvote(event: any) {
|
2021-02-02 16:52:44 +00:00
|
|
|
event.preventDefault();
|
2023-01-04 16:56:24 +00:00
|
|
|
let myVote = this.state.my_vote;
|
2022-06-21 21:42:29 +00:00
|
|
|
let newVote = myVote == -1 ? 0 : -1;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
if (myVote == 1) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
2023-05-15 19:53:29 +00:00
|
|
|
downvotes: this.state.downvotes + 1,
|
|
|
|
upvotes: this.state.upvotes - 1,
|
|
|
|
score: this.state.score - 2,
|
2022-09-22 15:03:35 +00:00
|
|
|
});
|
2022-06-21 21:42:29 +00:00
|
|
|
} else if (myVote == -1) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
2023-05-15 19:53:29 +00:00
|
|
|
downvotes: this.state.downvotes - 1,
|
|
|
|
score: this.state.score + 1,
|
2022-09-22 15:03:35 +00:00
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
2023-05-15 19:53:29 +00:00
|
|
|
downvotes: this.state.downvotes + 1,
|
|
|
|
score: this.state.score - 1,
|
2022-09-22 15:03:35 +00:00
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState({ my_vote: newVote });
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: CreateCommentLike = {
|
|
|
|
comment_id: this.props.node.comment_view.comment.id,
|
|
|
|
score: newVote,
|
|
|
|
auth,
|
|
|
|
};
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.likeComment(form));
|
|
|
|
setupTippy();
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:59 +00:00
|
|
|
handleShowReportDialog(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showReportDialog: !i.state.showReportDialog });
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleReportReasonChange(i: CommentNode, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ reportReason: event.target.value });
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleReportSubmit(i: CommentNode) {
|
|
|
|
let comment = i.props.node.comment_view.comment;
|
2023-01-04 16:56:24 +00:00
|
|
|
let reason = i.state.reportReason;
|
|
|
|
let auth = myAuth();
|
|
|
|
if (reason && auth) {
|
|
|
|
let form: CreateCommentReport = {
|
|
|
|
comment_id: comment.id,
|
|
|
|
reason,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.createCommentReport(form));
|
|
|
|
i.setState({ showReportDialog: false });
|
|
|
|
}
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleModRemoveShow(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showRemoveDialog: !i.state.showRemoveDialog,
|
|
|
|
showBanDialog: false,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveReasonChange(i: CommentNode, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ removeReason: event.target.value });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveDataChange(i: CommentNode, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ removeData: event.target.checked });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveSubmit(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let comment = i.props.node.comment_view.comment;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: RemoveComment = {
|
|
|
|
comment_id: comment.id,
|
|
|
|
removed: !comment.removed,
|
|
|
|
reason: i.state.removeReason,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.removeComment(form));
|
|
|
|
|
|
|
|
i.setState({ showRemoveDialog: false });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-08-17 23:26:50 +00:00
|
|
|
handleDistinguishClick(i: CommentNode) {
|
|
|
|
let comment = i.props.node.comment_view.comment;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
2023-05-11 18:32:32 +00:00
|
|
|
let form: DistinguishComment = {
|
2023-01-04 16:56:24 +00:00
|
|
|
comment_id: comment.id,
|
|
|
|
distinguished: !comment.distinguished,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.editComment(form));
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2022-08-17 23:26:50 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
isPersonMentionType(
|
2022-07-30 13:28:08 +00:00
|
|
|
item: CommentView | PersonMentionView | CommentReplyView
|
2021-03-15 18:09:31 +00:00
|
|
|
): item is PersonMentionView {
|
|
|
|
return (item as PersonMentionView).person_mention?.id !== undefined;
|
2020-12-24 01:58:27 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
isCommentReplyType(
|
|
|
|
item: CommentView | PersonMentionView | CommentReplyView
|
|
|
|
): item is CommentReplyView {
|
|
|
|
return (item as CommentReplyView).comment_reply?.id !== undefined;
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleMarkRead(i: CommentNode) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
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,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.markPersonMentionAsRead(form));
|
|
|
|
} else if (i.isCommentReplyType(i.props.node.comment_view)) {
|
|
|
|
let form: MarkCommentReplyAsRead = {
|
|
|
|
comment_reply_id: i.props.node.comment_view.comment_reply.id,
|
|
|
|
read: !i.props.node.comment_view.comment_reply.read,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.markCommentReplyAsRead(form));
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ readLoading: true });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanFromCommunityShow(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showBanDialog: true,
|
|
|
|
banType: BanType.Community,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanShow(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showBanDialog: true,
|
|
|
|
banType: BanType.Site,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanReasonChange(i: CommentNode, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ banReason: event.target.value });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 17:53:11 +00:00
|
|
|
handleModBanExpireDaysChange(i: CommentNode, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ banExpireDays: event.target.value });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanFromCommunitySubmit(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ banType: BanType.Community });
|
2020-09-06 16:15:25 +00:00
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanSubmit(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ banType: BanType.Site });
|
2020-09-06 16:15:25 +00:00
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanBothSubmit(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = i.props.node.comment_view;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
if (i.state.banType == BanType.Community) {
|
|
|
|
// If its an unban, restore all their data
|
|
|
|
let ban = !cv.creator_banned_from_community;
|
|
|
|
if (ban == false) {
|
|
|
|
i.setState({ removeData: false });
|
|
|
|
}
|
|
|
|
let form: BanFromCommunity = {
|
|
|
|
person_id: cv.creator.id,
|
|
|
|
community_id: cv.community.id,
|
|
|
|
ban,
|
|
|
|
remove_data: i.state.removeData,
|
|
|
|
reason: i.state.banReason,
|
|
|
|
expires: futureDaysToUnixTime(i.state.banExpireDays),
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.banFromCommunity(form));
|
|
|
|
} else {
|
|
|
|
// If its an unban, restore all their data
|
|
|
|
let ban = !cv.creator.banned;
|
|
|
|
if (ban == false) {
|
|
|
|
i.setState({ removeData: false });
|
|
|
|
}
|
|
|
|
let form: BanPerson = {
|
|
|
|
person_id: cv.creator.id,
|
|
|
|
ban,
|
|
|
|
remove_data: i.state.removeData,
|
|
|
|
reason: i.state.banReason,
|
|
|
|
expires: futureDaysToUnixTime(i.state.banExpireDays),
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.banPerson(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ showBanDialog: false });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 19:44:05 +00:00
|
|
|
handlePurgePersonShow(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showPurgeDialog: true,
|
|
|
|
purgeType: PurgeType.Person,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
});
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePurgeCommentShow(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showPurgeDialog: true,
|
|
|
|
purgeType: PurgeType.Comment,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
});
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePurgeReasonChange(i: CommentNode, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ purgeReason: event.target.value });
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePurgeSubmit(i: CommentNode, event: any) {
|
|
|
|
event.preventDefault();
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
if (i.state.purgeType == PurgeType.Person) {
|
|
|
|
let form: PurgePerson = {
|
|
|
|
person_id: i.props.node.comment_view.creator.id,
|
|
|
|
reason: i.state.purgeReason,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.purgePerson(form));
|
|
|
|
} else if (i.state.purgeType == PurgeType.Comment) {
|
|
|
|
let form: PurgeComment = {
|
|
|
|
comment_id: i.props.node.comment_view.comment.id,
|
|
|
|
reason: i.state.purgeReason,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.purgeComment(form));
|
|
|
|
}
|
2022-06-23 19:44:05 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ purgeLoading: true });
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleShowConfirmAppointAsMod(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmAppointAsMod: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelConfirmAppointAsMod(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmAppointAsMod: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleAddModToCommunity(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = i.props.node.comment_view;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: AddModToCommunity = {
|
|
|
|
person_id: cv.creator.id,
|
|
|
|
community_id: cv.community.id,
|
|
|
|
added: !isMod(cv.creator.id, i.props.moderators),
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.addModToCommunity(form));
|
|
|
|
i.setState({ showConfirmAppointAsMod: false });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmAppointAsAdmin(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmAppointAsAdmin: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelConfirmAppointAsAdmin(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmAppointAsAdmin: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleAddAdmin(i: CommentNode) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let creatorId = i.props.node.comment_view.creator.id;
|
|
|
|
let form: AddAdmin = {
|
|
|
|
person_id: creatorId,
|
|
|
|
added: !isAdmin(creatorId, i.props.admins),
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.addAdmin(form));
|
|
|
|
i.setState({ showConfirmAppointAsAdmin: false });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmTransferCommunity(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferCommunity: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelShowConfirmTransferCommunity(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferCommunity: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleTransferCommunity(i: CommentNode) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let cv = i.props.node.comment_view;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: TransferCommunity = {
|
|
|
|
community_id: cv.community.id,
|
|
|
|
person_id: cv.creator.id,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.transferCommunity(form));
|
|
|
|
i.setState({ showConfirmTransferCommunity: false });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmTransferSite(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferSite: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelShowConfirmTransferSite(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferSite: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ collapsed: !i.state.collapsed });
|
2021-07-16 17:04:35 +00:00
|
|
|
setupTippy();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleViewSource(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ viewSource: !i.state.viewSource });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleShowAdvanced(i: CommentNode) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showAdvanced: !i.state.showAdvanced });
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
handleFetchChildren(i: CommentNode) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let form: GetComments = {
|
|
|
|
post_id: i.props.node.comment_view.post.id,
|
|
|
|
parent_id: i.props.node.comment_view.comment.id,
|
|
|
|
max_depth: commentTreeMaxDepth,
|
2023-05-15 19:53:29 +00:00
|
|
|
limit: 999, // TODO
|
2023-05-11 18:32:32 +00:00
|
|
|
type_: "All",
|
2023-01-04 16:56:24 +00:00
|
|
|
saved_only: false,
|
|
|
|
auth: myAuth(false),
|
|
|
|
};
|
2022-07-30 13:28:08 +00:00
|
|
|
|
|
|
|
WebSocketService.Instance.send(wsClient.getComments(form));
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
get scoreColor() {
|
2023-01-04 16:56:24 +00:00
|
|
|
if (this.state.my_vote == 1) {
|
2021-02-22 02:39:04 +00:00
|
|
|
return "text-info";
|
2023-01-04 16:56:24 +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", {
|
2023-05-11 18:32:32 +00:00
|
|
|
count: Number(this.state.score),
|
|
|
|
formattedCount: numToSI(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", {
|
2023-05-11 18:32:32 +00:00
|
|
|
count: Number(this.state.upvotes),
|
|
|
|
formattedCount: numToSI(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", {
|
2023-05-11 18:32:32 +00:00
|
|
|
count: Number(this.state.downvotes),
|
|
|
|
formattedCount: numToSI(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
|
|
|
}
|