2019-04-08 05:19:02 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
|
|
|
import { Link } from 'inferno-router';
|
2019-10-19 00:20:27 +00:00
|
|
|
import {
|
|
|
|
CommentNode as CommentNodeI,
|
|
|
|
CommentLikeForm,
|
|
|
|
CommentForm as CommentFormI,
|
2019-10-20 00:46:29 +00:00
|
|
|
EditUserMentionForm,
|
2019-10-19 00:20:27 +00:00
|
|
|
SaveCommentForm,
|
|
|
|
BanFromCommunityForm,
|
|
|
|
BanUserForm,
|
|
|
|
CommunityUser,
|
|
|
|
UserView,
|
|
|
|
AddModToCommunityForm,
|
|
|
|
AddAdminForm,
|
|
|
|
TransferCommunityForm,
|
|
|
|
TransferSiteForm,
|
|
|
|
BanType,
|
2020-02-09 16:44:24 +00:00
|
|
|
CommentSortType,
|
|
|
|
SortType,
|
2019-10-19 00:20:27 +00:00
|
|
|
} from '../interfaces';
|
2019-04-08 05:19:02 +00:00
|
|
|
import { WebSocketService, UserService } from '../services';
|
2019-12-29 20:39:48 +00:00
|
|
|
import {
|
|
|
|
mdToHtml,
|
|
|
|
getUnixTime,
|
|
|
|
canMod,
|
|
|
|
isMod,
|
2020-03-03 07:29:45 +00:00
|
|
|
setupTippy,
|
2020-03-05 20:10:46 +00:00
|
|
|
colorList,
|
2019-12-29 20:39:48 +00:00
|
|
|
} from '../utils';
|
2020-01-06 16:22:51 +00:00
|
|
|
import moment from 'moment';
|
2019-04-08 05:19:02 +00:00
|
|
|
import { MomentTime } from './moment-time';
|
|
|
|
import { CommentForm } from './comment-form';
|
|
|
|
import { CommentNodes } from './comment-nodes';
|
2020-04-10 20:55:57 +00:00
|
|
|
import { UserListing } from './user-listing';
|
2019-08-10 00:14:43 +00:00
|
|
|
import { i18n } from '../i18next';
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
interface CommentNodeState {
|
|
|
|
showReply: boolean;
|
|
|
|
showEdit: boolean;
|
2019-04-15 23:12:06 +00:00
|
|
|
showRemoveDialog: boolean;
|
|
|
|
removeReason: string;
|
|
|
|
showBanDialog: boolean;
|
|
|
|
banReason: string;
|
|
|
|
banExpires: string;
|
2019-04-20 04:06:25 +00:00
|
|
|
banType: BanType;
|
2019-08-29 02:22:50 +00:00
|
|
|
showConfirmTransferSite: boolean;
|
|
|
|
showConfirmTransferCommunity: boolean;
|
2020-01-02 03:09:07 +00:00
|
|
|
showConfirmAppointAsMod: boolean;
|
|
|
|
showConfirmAppointAsAdmin: boolean;
|
2019-09-06 00:18:48 +00:00
|
|
|
collapsed: boolean;
|
2019-09-08 18:00:08 +00:00
|
|
|
viewSource: boolean;
|
2020-03-01 03:06:42 +00:00
|
|
|
showAdvanced: boolean;
|
2020-02-09 20:04:41 +00:00
|
|
|
my_vote: number;
|
|
|
|
score: number;
|
|
|
|
upvotes: number;
|
|
|
|
downvotes: number;
|
2020-03-05 04:36:42 +00:00
|
|
|
borderColor: string;
|
2020-03-19 15:45:23 +00:00
|
|
|
readLoading: boolean;
|
|
|
|
saveLoading: boolean;
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface CommentNodeProps {
|
|
|
|
node: CommentNodeI;
|
|
|
|
noIndent?: boolean;
|
|
|
|
viewOnly?: boolean;
|
2019-04-15 23:12:06 +00:00
|
|
|
locked?: boolean;
|
2019-04-20 18:17:00 +00:00
|
|
|
markable?: boolean;
|
2020-03-20 20:53:54 +00:00
|
|
|
showContext?: boolean;
|
2019-04-15 23:12:06 +00:00
|
|
|
moderators: Array<CommunityUser>;
|
2019-04-20 04:06:25 +00:00
|
|
|
admins: Array<UserView>;
|
2020-02-08 04:05:15 +00:00
|
|
|
// TODO is this necessary, can't I get it from the node itself?
|
2019-09-13 15:37:12 +00:00
|
|
|
postCreatorId?: number;
|
2020-02-08 04:05:15 +00:00
|
|
|
showCommunity?: boolean;
|
2020-02-09 16:44:24 +00:00
|
|
|
sort?: CommentSortType;
|
|
|
|
sortType?: SortType;
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
|
|
|
private emptyState: CommentNodeState = {
|
|
|
|
showReply: false,
|
2019-04-15 23:12:06 +00:00
|
|
|
showEdit: false,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
removeReason: null,
|
|
|
|
showBanDialog: false,
|
|
|
|
banReason: null,
|
|
|
|
banExpires: null,
|
2019-07-16 05:56:46 +00:00
|
|
|
banType: BanType.Community,
|
|
|
|
collapsed: false,
|
2019-09-08 18:00:08 +00:00
|
|
|
viewSource: false,
|
2020-03-01 03:06:42 +00:00
|
|
|
showAdvanced: false,
|
2019-08-29 02:22:50 +00:00
|
|
|
showConfirmTransferSite: false,
|
|
|
|
showConfirmTransferCommunity: false,
|
2020-01-02 03:09:07 +00:00
|
|
|
showConfirmAppointAsMod: false,
|
|
|
|
showConfirmAppointAsAdmin: false,
|
2020-02-09 20:04:41 +00:00
|
|
|
my_vote: this.props.node.comment.my_vote,
|
|
|
|
score: this.props.node.comment.score,
|
|
|
|
upvotes: this.props.node.comment.upvotes,
|
|
|
|
downvotes: this.props.node.comment.downvotes,
|
2020-03-05 20:10:46 +00:00
|
|
|
borderColor: this.props.node.comment.depth
|
|
|
|
? colorList[this.props.node.comment.depth % colorList.length]
|
|
|
|
: colorList[0],
|
2020-03-19 15:45:23 +00:00
|
|
|
readLoading: false,
|
|
|
|
saveLoading: false,
|
2019-10-19 00:20:27 +00:00
|
|
|
};
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handleReplyCancel = this.handleReplyCancel.bind(this);
|
2020-01-20 15:11:50 +00:00
|
|
|
this.handleCommentUpvote = this.handleCommentUpvote.bind(this);
|
|
|
|
this.handleCommentDownvote = this.handleCommentDownvote.bind(this);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 15:11:50 +00:00
|
|
|
componentWillReceiveProps(nextProps: CommentNodeProps) {
|
2020-02-09 20:04:41 +00:00
|
|
|
this.state.my_vote = nextProps.node.comment.my_vote;
|
|
|
|
this.state.upvotes = nextProps.node.comment.upvotes;
|
|
|
|
this.state.downvotes = nextProps.node.comment.downvotes;
|
|
|
|
this.state.score = nextProps.node.comment.score;
|
2020-03-19 15:45:23 +00:00
|
|
|
this.state.readLoading = false;
|
|
|
|
this.state.saveLoading = false;
|
2020-02-09 20:04:41 +00:00
|
|
|
this.setState(this.state);
|
2020-01-20 00:48:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
render() {
|
|
|
|
let node = this.props.node;
|
|
|
|
return (
|
2019-10-19 00:20:27 +00:00
|
|
|
<div
|
|
|
|
className={`comment ${
|
2020-03-19 04:52:08 +00:00
|
|
|
node.comment.parent_id && !this.props.noIndent ? 'ml-1' : ''
|
2019-10-19 00:20:27 +00:00
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
id={`comment-${node.comment.id}`}
|
2020-03-19 04:52:08 +00:00
|
|
|
className={`details comment-node border-top border-light ${
|
2019-10-19 00:20:27 +00:00
|
|
|
this.isCommentNew ? 'mark' : ''
|
|
|
|
}`}
|
2020-03-05 04:36:42 +00:00
|
|
|
style={
|
|
|
|
!this.props.noIndent &&
|
2020-03-05 05:02:08 +00:00
|
|
|
this.props.node.comment.parent_id &&
|
2020-03-06 14:55:32 +00:00
|
|
|
`border-left: 2px ${this.state.borderColor} solid !important`
|
2020-03-05 04:36:42 +00:00
|
|
|
}
|
2019-10-19 00:20:27 +00:00
|
|
|
>
|
2020-03-05 05:02:08 +00:00
|
|
|
<div
|
|
|
|
class={`${!this.props.noIndent &&
|
|
|
|
this.props.node.comment.parent_id &&
|
|
|
|
'ml-2'}`}
|
|
|
|
>
|
2020-03-21 14:20:03 +00:00
|
|
|
<div class="d-flex flex-wrap align-items-center mb-1 mt-1 text-muted small">
|
2020-04-10 20:55:57 +00:00
|
|
|
<span class="mr-2">
|
|
|
|
<UserListing
|
|
|
|
user={{
|
|
|
|
name: node.comment.creator_name,
|
|
|
|
avatar: node.comment.creator_avatar,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</span>
|
2020-03-05 04:36:42 +00:00
|
|
|
{this.isMod && (
|
2020-03-21 04:15:45 +00:00
|
|
|
<div className="badge badge-light d-none d-sm-inline mr-2">
|
2020-03-05 04:36:42 +00:00
|
|
|
{i18n.t('mod')}
|
2020-03-21 04:15:45 +00:00
|
|
|
</div>
|
2020-03-05 04:36:42 +00:00
|
|
|
)}
|
|
|
|
{this.isAdmin && (
|
2020-03-21 04:15:45 +00:00
|
|
|
<div className="badge badge-light d-none d-sm-inline mr-2">
|
2020-03-05 04:36:42 +00:00
|
|
|
{i18n.t('admin')}
|
2020-03-21 04:15:45 +00:00
|
|
|
</div>
|
2020-03-05 04:36:42 +00:00
|
|
|
)}
|
|
|
|
{this.isPostCreator && (
|
2020-03-21 04:15:45 +00:00
|
|
|
<div className="badge badge-light d-none d-sm-inline mr-2">
|
2020-03-05 04:36:42 +00:00
|
|
|
{i18n.t('creator')}
|
2020-03-21 04:15:45 +00:00
|
|
|
</div>
|
2020-03-05 04:36:42 +00:00
|
|
|
)}
|
|
|
|
{(node.comment.banned_from_community || node.comment.banned) && (
|
2020-03-21 04:15:45 +00:00
|
|
|
<div className="badge badge-danger mr-2">
|
2020-03-05 04:36:42 +00:00
|
|
|
{i18n.t('banned')}
|
2020-03-19 04:52:08 +00:00
|
|
|
</div>
|
2020-03-21 04:15:45 +00:00
|
|
|
)}
|
2020-03-05 04:36:42 +00:00
|
|
|
{this.props.showCommunity && (
|
2020-03-21 04:15:45 +00:00
|
|
|
<>
|
|
|
|
<span class="mx-1">{i18n.t('to')}</span>
|
|
|
|
<Link class="mr-2" to={`/c/${node.comment.community_name}`}>
|
2020-03-05 04:36:42 +00:00
|
|
|
{node.comment.community_name}
|
|
|
|
</Link>
|
2020-03-21 04:15:45 +00:00
|
|
|
</>
|
2020-03-05 04:36:42 +00:00
|
|
|
)}
|
2020-03-21 04:15:45 +00:00
|
|
|
<div
|
2020-04-10 20:55:57 +00:00
|
|
|
className="mr-lg-4 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2"
|
2020-03-21 04:15:45 +00:00
|
|
|
onClick={linkEvent(this, this.handleCommentCollapse)}
|
|
|
|
>
|
|
|
|
{this.state.collapsed ? (
|
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-plus-square"></use>
|
|
|
|
</svg>
|
|
|
|
) : (
|
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-minus-square"></use>
|
2020-03-06 14:55:32 +00:00
|
|
|
</svg>
|
2020-03-21 04:15:45 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<span
|
|
|
|
className={`unselectable pointer ${this.scoreColor}`}
|
|
|
|
onClick={linkEvent(node, this.handleCommentUpvote)}
|
|
|
|
data-tippy-content={this.pointsTippy}
|
|
|
|
>
|
|
|
|
<svg class="icon icon-inline mr-1">
|
|
|
|
<use xlinkHref="#icon-zap"></use>
|
|
|
|
</svg>
|
|
|
|
<span class="mr-1">{this.state.score}</span>
|
|
|
|
</span>
|
|
|
|
<span className="mr-1">•</span>
|
|
|
|
<span>
|
|
|
|
<MomentTime data={node.comment} />
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{/* end of user row */}
|
2020-03-05 04:36:42 +00:00
|
|
|
{this.state.showEdit && (
|
|
|
|
<CommentForm
|
|
|
|
node={node}
|
|
|
|
edit
|
|
|
|
onReplyCancel={this.handleReplyCancel}
|
|
|
|
disabled={this.props.locked}
|
|
|
|
/>
|
2020-02-08 04:05:15 +00:00
|
|
|
)}
|
2020-03-05 04:36:42 +00:00
|
|
|
{!this.state.showEdit && !this.state.collapsed && (
|
|
|
|
<div>
|
|
|
|
{this.state.viewSource ? (
|
|
|
|
<pre>{this.commentUnlessRemoved}</pre>
|
2020-03-04 00:14:36 +00:00
|
|
|
) : (
|
2020-03-05 04:36:42 +00:00
|
|
|
<div
|
|
|
|
className="md-div"
|
|
|
|
dangerouslySetInnerHTML={mdToHtml(
|
|
|
|
this.commentUnlessRemoved
|
|
|
|
)}
|
|
|
|
/>
|
2020-01-02 03:09:07 +00:00
|
|
|
)}
|
2020-03-21 04:15:45 +00:00
|
|
|
<div class="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold">
|
2020-03-20 20:53:54 +00:00
|
|
|
{this.props.showContext && this.linkBtn}
|
2020-03-05 04:36:42 +00:00
|
|
|
{this.props.markable && (
|
2020-03-21 04:15:45 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleMarkRead)}
|
|
|
|
data-tippy-content={
|
|
|
|
node.comment.read
|
|
|
|
? i18n.t('mark_as_unread')
|
|
|
|
: i18n.t('mark_as_read')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{this.state.readLoading ? (
|
|
|
|
this.loadingIcon
|
|
|
|
) : (
|
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${node.comment.read &&
|
|
|
|
'text-success'}`}
|
|
|
|
>
|
|
|
|
<use xlinkHref="#icon-check"></use>
|
|
|
|
</svg>
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{UserService.Instance.user && !this.props.viewOnly && (
|
|
|
|
<>
|
2020-03-19 04:52:08 +00:00
|
|
|
<button
|
2020-03-21 04:15:45 +00:00
|
|
|
className={`btn btn-link btn-animate ${
|
|
|
|
this.state.my_vote == 1 ? 'text-info' : 'text-muted'
|
|
|
|
}`}
|
|
|
|
onClick={linkEvent(node, this.handleCommentUpvote)}
|
|
|
|
data-tippy-content={i18n.t('upvote')}
|
2019-10-19 00:20:27 +00:00
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-arrow-up"></use>
|
|
|
|
</svg>
|
|
|
|
{this.state.upvotes !== this.state.score && (
|
|
|
|
<span class="ml-1">{this.state.upvotes}</span>
|
2020-03-19 15:45:23 +00:00
|
|
|
)}
|
2020-03-19 04:52:08 +00:00
|
|
|
</button>
|
2020-03-21 04:15:45 +00:00
|
|
|
{WebSocketService.Instance.site.enable_downvotes && (
|
2020-03-04 18:52:11 +00:00
|
|
|
<button
|
2020-03-21 04:15:45 +00:00
|
|
|
className={`btn btn-link btn-animate ${
|
|
|
|
this.state.my_vote == -1
|
|
|
|
? 'text-danger'
|
|
|
|
: 'text-muted'
|
2020-03-04 18:52:11 +00:00
|
|
|
}`}
|
2020-03-21 04:15:45 +00:00
|
|
|
onClick={linkEvent(node, this.handleCommentDownvote)}
|
|
|
|
data-tippy-content={i18n.t('downvote')}
|
2020-03-04 18:52:11 +00:00
|
|
|
>
|
2020-03-06 14:55:32 +00:00
|
|
|
<svg class="icon icon-inline">
|
2020-03-21 04:15:45 +00:00
|
|
|
<use xlinkHref="#icon-arrow-down"></use>
|
2020-03-04 18:52:11 +00:00
|
|
|
</svg>
|
2020-03-06 14:55:32 +00:00
|
|
|
{this.state.upvotes !== this.state.score && (
|
2020-03-21 04:15:45 +00:00
|
|
|
<span class="ml-1">{this.state.downvotes}</span>
|
2020-03-06 14:55:32 +00:00
|
|
|
)}
|
2020-03-04 18:52:11 +00:00
|
|
|
</button>
|
2020-03-05 04:36:42 +00:00
|
|
|
)}
|
2020-03-21 04:15:45 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleSaveCommentClick)}
|
|
|
|
data-tippy-content={
|
|
|
|
node.comment.saved ? i18n.t('unsave') : i18n.t('save')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{this.state.saveLoading ? (
|
|
|
|
this.loadingIcon
|
|
|
|
) : (
|
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${node.comment.saved &&
|
|
|
|
'text-warning'}`}
|
|
|
|
>
|
|
|
|
<use xlinkHref="#icon-star"></use>
|
|
|
|
</svg>
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleReplyClick)}
|
|
|
|
data-tippy-content={i18n.t('reply')}
|
|
|
|
>
|
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-reply1"></use>
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
{!this.state.showAdvanced ? (
|
2020-03-19 15:45:23 +00:00
|
|
|
<button
|
2020-03-21 04:15:45 +00:00
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleShowAdvanced)}
|
|
|
|
data-tippy-content={i18n.t('more')}
|
2020-03-05 04:36:42 +00:00
|
|
|
>
|
|
|
|
<svg class="icon icon-inline">
|
2020-03-21 04:15:45 +00:00
|
|
|
<use xlinkHref="#icon-more-vertical"></use>
|
2020-03-05 04:36:42 +00:00
|
|
|
</svg>
|
2020-03-19 15:45:23 +00:00
|
|
|
</button>
|
2020-03-05 04:36:42 +00:00
|
|
|
) : (
|
|
|
|
<>
|
2020-03-06 14:55:32 +00:00
|
|
|
{!this.myComment && (
|
2020-03-21 04:15:45 +00:00
|
|
|
<button class="btn btn-link btn-animate">
|
2020-03-06 14:55:32 +00:00
|
|
|
<Link
|
2020-03-21 04:15:45 +00:00
|
|
|
class="text-muted"
|
2020-03-06 14:55:32 +00:00
|
|
|
to={`/create_private_message?recipient_id=${node.comment.creator_id}`}
|
|
|
|
title={i18n.t('message').toLowerCase()}
|
|
|
|
>
|
|
|
|
<svg class="icon">
|
|
|
|
<use xlinkHref="#icon-mail"></use>
|
|
|
|
</svg>
|
|
|
|
</Link>
|
2020-03-21 04:15:45 +00:00
|
|
|
</button>
|
2020-03-06 14:55:32 +00:00
|
|
|
)}
|
2020-03-20 20:53:54 +00:00
|
|
|
{!this.props.showContext && this.linkBtn}
|
2020-03-21 04:15:45 +00:00
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleViewSource)}
|
|
|
|
data-tippy-content={i18n.t('view_source')}
|
|
|
|
>
|
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${this.state
|
|
|
|
.viewSource && 'text-success'}`}
|
2020-03-05 04:36:42 +00:00
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
<use xlinkHref="#icon-file-text"></use>
|
|
|
|
</svg>
|
|
|
|
</button>
|
2020-03-05 04:36:42 +00:00
|
|
|
{this.myComment && (
|
|
|
|
<>
|
2020-03-21 04:15:45 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleEditClick)}
|
|
|
|
data-tippy-content={i18n.t('edit')}
|
|
|
|
>
|
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-edit"></use>
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteClick
|
|
|
|
)}
|
|
|
|
data-tippy-content={
|
|
|
|
!node.comment.deleted
|
|
|
|
? i18n.t('delete')
|
|
|
|
: i18n.t('restore')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${node.comment
|
|
|
|
.deleted && 'text-danger'}`}
|
|
|
|
>
|
|
|
|
<use xlinkHref="#icon-trash"></use>
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Admins and mods can remove comments */}
|
|
|
|
{(this.canMod || this.canAdmin) && (
|
|
|
|
<>
|
|
|
|
{!node.comment.removed ? (
|
2020-03-19 04:52:08 +00:00
|
|
|
<button
|
2020-03-21 04:15:45 +00:00
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-01-02 03:09:07 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleModRemoveShow
|
2020-01-02 03:09:07 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
{i18n.t('remove')}
|
2020-03-19 04:52:08 +00:00
|
|
|
</button>
|
2020-03-21 04:15:45 +00:00
|
|
|
) : (
|
2020-03-19 04:52:08 +00:00
|
|
|
<button
|
2020-03-21 04:15:45 +00:00
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-01-02 03:09:07 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleModRemoveSubmit
|
2020-01-02 03:09:07 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
{i18n.t('restore')}
|
2020-03-19 04:52:08 +00:00
|
|
|
</button>
|
2020-03-21 04:15:45 +00:00
|
|
|
)}
|
2020-03-05 04:36:42 +00:00
|
|
|
</>
|
|
|
|
)}
|
2020-03-21 04:15:45 +00:00
|
|
|
{/* Mods can ban from community, and appoint as mods to community */}
|
|
|
|
{this.canMod && (
|
2020-03-05 04:36:42 +00:00
|
|
|
<>
|
2020-03-21 04:15:45 +00:00
|
|
|
{!this.isMod &&
|
|
|
|
(!node.comment.banned_from_community ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-03-01 03:06:42 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleModBanFromCommunityShow
|
2020-03-01 03:06:42 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
{i18n.t('ban')}
|
|
|
|
</button>
|
2020-03-01 03:06:42 +00:00
|
|
|
) : (
|
2020-03-21 04:15:45 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-03-01 03:06:42 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleModBanFromCommunitySubmit
|
2020-03-01 03:06:42 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
{i18n.t('unban')}
|
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
{!node.comment.banned_from_community &&
|
|
|
|
(!this.state.showConfirmAppointAsMod ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-03-01 03:06:42 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleShowConfirmAppointAsMod
|
2020-03-01 03:06:42 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
{this.isMod
|
|
|
|
? i18n.t('remove_as_mod')
|
|
|
|
: i18n.t('appoint_as_mod')}
|
|
|
|
</button>
|
2020-03-01 03:06:42 +00:00
|
|
|
) : (
|
|
|
|
<>
|
2020-03-21 04:15:45 +00:00
|
|
|
<button class="btn btn-link btn-animate text-muted">
|
2020-03-01 03:06:42 +00:00
|
|
|
{i18n.t('are_you_sure')}
|
2020-03-21 04:15:45 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-03-01 03:06:42 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleAddModToCommunity
|
2020-03-01 03:06:42 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('yes')}
|
2020-03-21 04:15:45 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-03-01 03:06:42 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleCancelConfirmAppointAsMod
|
2020-03-01 03:06:42 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('no')}
|
2020-03-21 04:15:45 +00:00
|
|
|
</button>
|
2020-03-01 03:06:42 +00:00
|
|
|
</>
|
2020-03-21 04:15:45 +00:00
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Community creators and admins can transfer community to another mod */}
|
|
|
|
{(this.amCommunityCreator || this.canAdmin) &&
|
|
|
|
this.isMod &&
|
|
|
|
(!this.state.showConfirmTransferCommunity ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmTransferCommunity
|
2020-03-01 03:06:42 +00:00
|
|
|
)}
|
2020-03-21 04:15:45 +00:00
|
|
|
>
|
|
|
|
{i18n.t('transfer_community')}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<button class="btn btn-link btn-animate text-muted">
|
|
|
|
{i18n.t('are_you_sure')}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleTransferCommunity
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('yes')}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this
|
|
|
|
.handleCancelShowConfirmTransferCommunity
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('no')}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
2020-03-05 04:36:42 +00:00
|
|
|
{/* Admins can ban from all, and appoint other admins */}
|
|
|
|
{this.canAdmin && (
|
|
|
|
<>
|
2020-03-21 04:15:45 +00:00
|
|
|
{!this.isAdmin &&
|
|
|
|
(!node.comment.banned ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanShow
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('ban_from_site')}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanSubmit
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('unban_from_site')}
|
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
{!node.comment.banned &&
|
|
|
|
(!this.state.showConfirmAppointAsAdmin ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmAppointAsAdmin
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{this.isAdmin
|
|
|
|
? i18n.t('remove_as_admin')
|
|
|
|
: i18n.t('appoint_as_admin')}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<button class="btn btn-link btn-animate text-muted">
|
|
|
|
{i18n.t('are_you_sure')}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-03-05 04:36:42 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleAddAdmin
|
2020-03-05 04:36:42 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
{i18n.t('yes')}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-03-05 04:36:42 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleCancelConfirmAppointAsAdmin
|
2020-03-05 04:36:42 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
{i18n.t('no')}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
2020-03-05 04:36:42 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Site Creator can transfer to another admin */}
|
2020-03-21 04:15:45 +00:00
|
|
|
{this.amSiteCreator &&
|
|
|
|
this.isAdmin &&
|
|
|
|
(!this.state.showConfirmTransferSite ? (
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmTransferSite
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('transfer_site')}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<button class="btn btn-link btn-animate text-muted">
|
|
|
|
{i18n.t('are_you_sure')}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
2020-03-01 03:06:42 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-21 04:15:45 +00:00
|
|
|
this.handleTransferSite
|
2020-03-01 03:06:42 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-21 04:15:45 +00:00
|
|
|
{i18n.t('yes')}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleCancelShowConfirmTransferSite
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('no')}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
2020-03-05 04:36:42 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2020-03-21 04:15:45 +00:00
|
|
|
</div>
|
|
|
|
{/* end of button group */}
|
2020-03-05 04:36:42 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2020-03-05 15:02:23 +00:00
|
|
|
{/* end of details */}
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.showRemoveDialog && (
|
|
|
|
<form
|
|
|
|
class="form-inline"
|
|
|
|
onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control mr-2"
|
|
|
|
placeholder={i18n.t('reason')}
|
|
|
|
value={this.state.removeReason}
|
|
|
|
onInput={linkEvent(this, this.handleModRemoveReasonChange)}
|
|
|
|
/>
|
|
|
|
<button type="submit" class="btn btn-secondary">
|
2020-02-02 19:22:35 +00:00
|
|
|
{i18n.t('remove_comment')}
|
2019-10-19 00:20:27 +00:00
|
|
|
</button>
|
2019-04-15 23:12:06 +00:00
|
|
|
</form>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{this.state.showBanDialog && (
|
2019-04-20 04:06:25 +00:00
|
|
|
<form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
|
|
|
|
<div class="form-group row">
|
2020-02-02 19:22:35 +00:00
|
|
|
<label class="col-form-label">{i18n.t('reason')}</label>
|
2019-10-19 00:20:27 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control mr-2"
|
|
|
|
placeholder={i18n.t('reason')}
|
|
|
|
value={this.state.banReason}
|
|
|
|
onInput={linkEvent(this, this.handleModBanReasonChange)}
|
|
|
|
/>
|
2019-04-20 04:06:25 +00:00
|
|
|
</div>
|
2019-04-22 17:45:50 +00:00
|
|
|
{/* TODO hold off on expires until later */}
|
|
|
|
{/* <div class="form-group row"> */}
|
|
|
|
{/* <label class="col-form-label">Expires</label> */}
|
2019-08-10 00:14:43 +00:00
|
|
|
{/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
|
2019-04-22 17:45:50 +00:00
|
|
|
{/* </div> */}
|
2019-04-20 04:06:25 +00:00
|
|
|
<div class="form-group row">
|
2019-10-19 00:20:27 +00:00
|
|
|
<button type="submit" class="btn btn-secondary">
|
|
|
|
{i18n.t('ban')} {node.comment.creator_name}
|
|
|
|
</button>
|
2019-04-20 04:06:25 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{this.state.showReply && (
|
|
|
|
<CommentForm
|
|
|
|
node={node}
|
|
|
|
onReplyCancel={this.handleReplyCancel}
|
|
|
|
disabled={this.props.locked}
|
2019-04-20 04:06:25 +00:00
|
|
|
/>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{node.children && !this.state.collapsed && (
|
|
|
|
<CommentNodes
|
|
|
|
nodes={node.children}
|
|
|
|
locked={this.props.locked}
|
2019-04-20 04:06:25 +00:00
|
|
|
moderators={this.props.moderators}
|
|
|
|
admins={this.props.admins}
|
2019-09-13 15:37:12 +00:00
|
|
|
postCreatorId={this.props.postCreatorId}
|
2020-02-09 16:44:24 +00:00
|
|
|
sort={this.props.sort}
|
|
|
|
sortType={this.props.sortType}
|
2019-04-20 04:06:25 +00:00
|
|
|
/>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-07-16 05:56:46 +00:00
|
|
|
{/* A collapsed clearfix */}
|
|
|
|
{this.state.collapsed && <div class="row col-12"></div>}
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 15:45:23 +00:00
|
|
|
get linkBtn() {
|
|
|
|
let node = this.props.node;
|
|
|
|
return (
|
2020-03-21 04:15:45 +00:00
|
|
|
<button className="btn btn-link btn-animate">
|
2020-03-19 15:45:23 +00:00
|
|
|
<Link
|
2020-03-21 04:15:45 +00:00
|
|
|
class="text-muted"
|
2020-03-19 15:45:23 +00:00
|
|
|
to={`/post/${node.comment.post_id}/comment/${node.comment.id}`}
|
2020-03-20 20:53:54 +00:00
|
|
|
title={
|
|
|
|
this.props.showContext ? i18n.t('show_context') : i18n.t('link')
|
|
|
|
}
|
2020-03-19 15:45:23 +00:00
|
|
|
>
|
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-link"></use>
|
|
|
|
</svg>
|
|
|
|
</Link>
|
2020-03-21 04:15:45 +00:00
|
|
|
</button>
|
2020-03-19 15:45:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get loadingIcon() {
|
|
|
|
return (
|
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
get myComment(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
UserService.Instance.user &&
|
|
|
|
this.props.node.comment.creator_id == UserService.Instance.user.id
|
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
get isMod(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.moderators &&
|
|
|
|
isMod(
|
|
|
|
this.props.moderators.map(m => m.user_id),
|
|
|
|
this.props.node.comment.creator_id
|
|
|
|
)
|
|
|
|
);
|
2019-04-20 04:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get isAdmin(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.admins &&
|
|
|
|
isMod(
|
|
|
|
this.props.admins.map(a => a.id),
|
|
|
|
this.props.node.comment.creator_id
|
|
|
|
)
|
|
|
|
);
|
2019-04-20 04:06:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 15:37:12 +00:00
|
|
|
get isPostCreator(): boolean {
|
|
|
|
return this.props.node.comment.creator_id == this.props.postCreatorId;
|
|
|
|
}
|
|
|
|
|
2019-04-21 20:52:55 +00:00
|
|
|
get canMod(): boolean {
|
2019-04-22 18:32:50 +00:00
|
|
|
if (this.props.admins && this.props.moderators) {
|
2019-10-19 00:20:27 +00:00
|
|
|
let adminsThenMods = this.props.admins
|
|
|
|
.map(a => a.id)
|
|
|
|
.concat(this.props.moderators.map(m => m.user_id));
|
|
|
|
|
|
|
|
return canMod(
|
|
|
|
UserService.Instance.user,
|
|
|
|
adminsThenMods,
|
|
|
|
this.props.node.comment.creator_id
|
|
|
|
);
|
|
|
|
} else {
|
2019-04-22 18:32:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-21 20:52:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
get canAdmin(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.admins &&
|
|
|
|
canMod(
|
|
|
|
UserService.Instance.user,
|
|
|
|
this.props.admins.map(a => a.id),
|
|
|
|
this.props.node.comment.creator_id
|
|
|
|
)
|
|
|
|
);
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 02:40:41 +00:00
|
|
|
get amCommunityCreator(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.moderators &&
|
|
|
|
UserService.Instance.user &&
|
|
|
|
this.props.node.comment.creator_id != UserService.Instance.user.id &&
|
|
|
|
UserService.Instance.user.id == this.props.moderators[0].user_id
|
|
|
|
);
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get amSiteCreator(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.admins &&
|
|
|
|
UserService.Instance.user &&
|
|
|
|
this.props.node.comment.creator_id != UserService.Instance.user.id &&
|
|
|
|
UserService.Instance.user.id == this.props.admins[0].id
|
|
|
|
);
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
2019-10-19 00:20:27 +00:00
|
|
|
|
|
|
|
get commentUnlessRemoved(): string {
|
2019-09-08 18:00:08 +00:00
|
|
|
let node = this.props.node;
|
2019-10-19 00:20:27 +00:00
|
|
|
return node.comment.removed
|
|
|
|
? `*${i18n.t('removed')}*`
|
|
|
|
: node.comment.deleted
|
|
|
|
? `*${i18n.t('deleted')}*`
|
|
|
|
: node.comment.content;
|
2019-09-08 18:00:08 +00:00
|
|
|
}
|
2019-08-24 02:40:41 +00:00
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handleReplyClick(i: CommentNode) {
|
|
|
|
i.state.showReply = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditClick(i: CommentNode) {
|
|
|
|
i.state.showEdit = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDeleteClick(i: CommentNode) {
|
|
|
|
let deleteForm: CommentFormI = {
|
2019-04-29 19:14:54 +00:00
|
|
|
content: i.props.node.comment.content,
|
2019-04-08 05:19:02 +00:00
|
|
|
edit_id: i.props.node.comment.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
creator_id: i.props.node.comment.creator_id,
|
2019-04-08 05:19:02 +00:00
|
|
|
post_id: i.props.node.comment.post_id,
|
|
|
|
parent_id: i.props.node.comment.parent_id,
|
2019-04-29 19:14:54 +00:00
|
|
|
deleted: !i.props.node.comment.deleted,
|
2019-10-19 00:20:27 +00:00
|
|
|
auth: null,
|
2019-04-08 05:19:02 +00:00
|
|
|
};
|
|
|
|
WebSocketService.Instance.editComment(deleteForm);
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
handleSaveCommentClick(i: CommentNode) {
|
2019-10-19 00:20:27 +00:00
|
|
|
let saved =
|
|
|
|
i.props.node.comment.saved == undefined
|
|
|
|
? true
|
|
|
|
: !i.props.node.comment.saved;
|
2019-04-20 04:06:25 +00:00
|
|
|
let form: SaveCommentForm = {
|
|
|
|
comment_id: i.props.node.comment.id,
|
2019-10-19 00:20:27 +00:00
|
|
|
save: saved,
|
2019-04-20 04:06:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WebSocketService.Instance.saveComment(form);
|
2020-03-19 15:45:23 +00:00
|
|
|
|
|
|
|
i.state.saveLoading = true;
|
|
|
|
i.setState(this.state);
|
2019-04-20 04:06:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handleReplyCancel() {
|
|
|
|
this.state.showReply = false;
|
|
|
|
this.state.showEdit = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
2020-01-20 15:11:50 +00:00
|
|
|
handleCommentUpvote(i: CommentNodeI) {
|
2020-02-09 20:04:41 +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++;
|
2020-01-25 18:39:22 +00:00
|
|
|
}
|
2020-02-09 20:04:41 +00:00
|
|
|
|
|
|
|
this.state.my_vote = new_vote;
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
let form: CommentLikeForm = {
|
|
|
|
comment_id: i.comment.id,
|
|
|
|
post_id: i.comment.post_id,
|
2020-02-09 20:04:41 +00:00
|
|
|
score: this.state.my_vote,
|
2019-04-08 05:19:02 +00:00
|
|
|
};
|
2020-02-09 20:04:41 +00:00
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
WebSocketService.Instance.likeComment(form);
|
2020-02-09 20:04:41 +00:00
|
|
|
this.setState(this.state);
|
2020-03-11 23:10:10 +00:00
|
|
|
setupTippy();
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 15:11:50 +00:00
|
|
|
handleCommentDownvote(i: CommentNodeI) {
|
2020-02-09 20:04:41 +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--;
|
2020-01-25 18:39:22 +00:00
|
|
|
}
|
2020-02-09 20:04:41 +00:00
|
|
|
|
|
|
|
this.state.my_vote = new_vote;
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
let form: CommentLikeForm = {
|
|
|
|
comment_id: i.comment.id,
|
|
|
|
post_id: i.comment.post_id,
|
2020-02-09 20:04:41 +00:00
|
|
|
score: this.state.my_vote,
|
2019-04-08 05:19:02 +00:00
|
|
|
};
|
2020-02-09 20:04:41 +00:00
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
WebSocketService.Instance.likeComment(form);
|
2020-02-09 20:04:41 +00:00
|
|
|
this.setState(this.state);
|
2020-03-11 23:10:10 +00:00
|
|
|
setupTippy();
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
2019-04-15 23:12:06 +00:00
|
|
|
|
|
|
|
handleModRemoveShow(i: CommentNode) {
|
|
|
|
i.state.showRemoveDialog = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveReasonChange(i: CommentNode, event: any) {
|
|
|
|
i.state.removeReason = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveSubmit(i: CommentNode) {
|
2019-04-16 23:04:23 +00:00
|
|
|
event.preventDefault();
|
2019-04-15 23:12:06 +00:00
|
|
|
let form: CommentFormI = {
|
|
|
|
content: i.props.node.comment.content,
|
|
|
|
edit_id: i.props.node.comment.id,
|
|
|
|
creator_id: i.props.node.comment.creator_id,
|
|
|
|
post_id: i.props.node.comment.post_id,
|
|
|
|
parent_id: i.props.node.comment.parent_id,
|
|
|
|
removed: !i.props.node.comment.removed,
|
|
|
|
reason: i.state.removeReason,
|
2019-10-19 00:20:27 +00:00
|
|
|
auth: null,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
WebSocketService.Instance.editComment(form);
|
|
|
|
|
|
|
|
i.state.showRemoveDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-20 18:17:00 +00:00
|
|
|
handleMarkRead(i: CommentNode) {
|
2019-10-20 00:46:29 +00:00
|
|
|
// if it has a user_mention_id field, then its a mention
|
|
|
|
if (i.props.node.comment.user_mention_id) {
|
|
|
|
let form: EditUserMentionForm = {
|
|
|
|
user_mention_id: i.props.node.comment.user_mention_id,
|
|
|
|
read: !i.props.node.comment.read,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.editUserMention(form);
|
|
|
|
} else {
|
|
|
|
let form: CommentFormI = {
|
|
|
|
content: i.props.node.comment.content,
|
|
|
|
edit_id: i.props.node.comment.id,
|
|
|
|
creator_id: i.props.node.comment.creator_id,
|
|
|
|
post_id: i.props.node.comment.post_id,
|
|
|
|
parent_id: i.props.node.comment.parent_id,
|
|
|
|
read: !i.props.node.comment.read,
|
|
|
|
auth: null,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.editComment(form);
|
|
|
|
}
|
2020-03-19 15:45:23 +00:00
|
|
|
|
|
|
|
i.state.readLoading = true;
|
|
|
|
i.setState(this.state);
|
2019-04-20 18:17:00 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
handleModBanFromCommunityShow(i: CommentNode) {
|
2020-01-02 03:09:07 +00:00
|
|
|
i.state.showBanDialog = !i.state.showBanDialog;
|
2019-04-20 04:06:25 +00:00
|
|
|
i.state.banType = BanType.Community;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
handleModBanShow(i: CommentNode) {
|
2020-01-02 03:09:07 +00:00
|
|
|
i.state.showBanDialog = !i.state.showBanDialog;
|
2019-04-20 04:06:25 +00:00
|
|
|
i.state.banType = BanType.Site;
|
2019-04-15 23:12:06 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanReasonChange(i: CommentNode, event: any) {
|
|
|
|
i.state.banReason = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanExpiresChange(i: CommentNode, event: any) {
|
|
|
|
i.state.banExpires = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
handleModBanFromCommunitySubmit(i: CommentNode) {
|
|
|
|
i.state.banType = BanType.Community;
|
|
|
|
i.setState(i.state);
|
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
handleModBanSubmit(i: CommentNode) {
|
2019-04-20 04:06:25 +00:00
|
|
|
i.state.banType = BanType.Site;
|
|
|
|
i.setState(i.state);
|
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanBothSubmit(i: CommentNode) {
|
2019-04-16 23:04:23 +00:00
|
|
|
event.preventDefault();
|
2019-04-20 04:06:25 +00:00
|
|
|
|
|
|
|
if (i.state.banType == BanType.Community) {
|
|
|
|
let form: BanFromCommunityForm = {
|
|
|
|
user_id: i.props.node.comment.creator_id,
|
|
|
|
community_id: i.props.node.comment.community_id,
|
|
|
|
ban: !i.props.node.comment.banned_from_community,
|
|
|
|
reason: i.state.banReason,
|
|
|
|
expires: getUnixTime(i.state.banExpires),
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.banFromCommunity(form);
|
|
|
|
} else {
|
|
|
|
let form: BanUserForm = {
|
|
|
|
user_id: i.props.node.comment.creator_id,
|
|
|
|
ban: !i.props.node.comment.banned,
|
|
|
|
reason: i.state.banReason,
|
|
|
|
expires: getUnixTime(i.state.banExpires),
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.banUser(form);
|
|
|
|
}
|
2019-04-15 23:12:06 +00:00
|
|
|
|
|
|
|
i.state.showBanDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2020-01-02 03:09:07 +00:00
|
|
|
handleShowConfirmAppointAsMod(i: CommentNode) {
|
|
|
|
i.state.showConfirmAppointAsMod = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelConfirmAppointAsMod(i: CommentNode) {
|
|
|
|
i.state.showConfirmAppointAsMod = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
handleAddModToCommunity(i: CommentNode) {
|
|
|
|
let form: AddModToCommunityForm = {
|
|
|
|
user_id: i.props.node.comment.creator_id,
|
|
|
|
community_id: i.props.node.comment.community_id,
|
|
|
|
added: !i.isMod,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.addModToCommunity(form);
|
2020-01-02 03:09:07 +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;
|
2019-04-15 23:12:06 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2019-04-20 04:06:25 +00:00
|
|
|
|
2019-04-20 18:17:00 +00:00
|
|
|
handleAddAdmin(i: CommentNode) {
|
2019-04-20 04:06:25 +00:00
|
|
|
let form: AddAdminForm = {
|
|
|
|
user_id: i.props.node.comment.creator_id,
|
|
|
|
added: !i.isAdmin,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.addAdmin(form);
|
2020-01-02 03:09:07 +00:00
|
|
|
i.state.showConfirmAppointAsAdmin = false;
|
2019-04-20 04:06:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2019-04-24 16:58:45 +00:00
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
handleShowConfirmTransferCommunity(i: CommentNode) {
|
2019-08-29 02:22:50 +00:00
|
|
|
i.state.showConfirmTransferCommunity = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
handleCancelShowConfirmTransferCommunity(i: CommentNode) {
|
2019-08-29 02:22:50 +00:00
|
|
|
i.state.showConfirmTransferCommunity = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-08-24 02:40:41 +00:00
|
|
|
handleTransferCommunity(i: CommentNode) {
|
|
|
|
let form: TransferCommunityForm = {
|
|
|
|
community_id: i.props.node.comment.community_id,
|
|
|
|
user_id: i.props.node.comment.creator_id,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.transferCommunity(form);
|
2019-08-29 22:18:50 +00:00
|
|
|
i.state.showConfirmTransferCommunity = false;
|
2019-08-24 02:40:41 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
handleShowConfirmTransferSite(i: CommentNode) {
|
2019-08-29 02:22:50 +00:00
|
|
|
i.state.showConfirmTransferSite = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
handleCancelShowConfirmTransferSite(i: CommentNode) {
|
2019-08-29 02:22:50 +00:00
|
|
|
i.state.showConfirmTransferSite = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-08-24 02:40:41 +00:00
|
|
|
handleTransferSite(i: CommentNode) {
|
|
|
|
let form: TransferSiteForm = {
|
|
|
|
user_id: i.props.node.comment.creator_id,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.transferSite(form);
|
2019-08-29 22:18:50 +00:00
|
|
|
i.state.showConfirmTransferSite = false;
|
2019-08-24 02:40:41 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-24 16:58:45 +00:00
|
|
|
get isCommentNew(): boolean {
|
|
|
|
let now = moment.utc().subtract(10, 'minutes');
|
|
|
|
let then = moment.utc(this.props.node.comment.published);
|
|
|
|
return now.isBefore(then);
|
|
|
|
}
|
2019-07-16 05:56:46 +00:00
|
|
|
|
|
|
|
handleCommentCollapse(i: CommentNode) {
|
|
|
|
i.state.collapsed = !i.state.collapsed;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2019-09-08 18:00:08 +00:00
|
|
|
|
|
|
|
handleViewSource(i: CommentNode) {
|
|
|
|
i.state.viewSource = !i.state.viewSource;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2020-03-01 03:06:42 +00:00
|
|
|
|
|
|
|
handleShowAdvanced(i: CommentNode) {
|
|
|
|
i.state.showAdvanced = !i.state.showAdvanced;
|
|
|
|
i.setState(i.state);
|
2020-03-03 16:07:07 +00:00
|
|
|
setupTippy();
|
2020-03-01 03:06:42 +00:00
|
|
|
}
|
2020-03-04 19:06:03 +00:00
|
|
|
|
|
|
|
get scoreColor() {
|
|
|
|
if (this.state.my_vote == 1) {
|
|
|
|
return 'text-info';
|
|
|
|
} else if (this.state.my_vote == -1) {
|
|
|
|
return 'text-danger';
|
|
|
|
} else {
|
|
|
|
return 'text-muted';
|
|
|
|
}
|
|
|
|
}
|
2020-03-11 23:10:10 +00:00
|
|
|
|
|
|
|
get pointsTippy(): string {
|
|
|
|
let points = i18n.t('number_of_points', {
|
|
|
|
count: this.state.score,
|
|
|
|
});
|
|
|
|
|
|
|
|
let upvotes = i18n.t('number_of_upvotes', {
|
|
|
|
count: this.state.upvotes,
|
|
|
|
});
|
|
|
|
|
|
|
|
let downvotes = i18n.t('number_of_downvotes', {
|
|
|
|
count: this.state.downvotes,
|
|
|
|
});
|
|
|
|
|
|
|
|
return `${points} • ${upvotes} • ${downvotes}`;
|
|
|
|
}
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|