2019-04-08 05:19:02 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
|
|
|
import { Link } from 'inferno-router';
|
2019-04-20 04:06:25 +00:00
|
|
|
import { CommentNode as CommentNodeI, CommentLikeForm, CommentForm as CommentFormI, SaveCommentForm, BanFromCommunityForm, BanUserForm, CommunityUser, UserView, AddModToCommunityForm, AddAdminForm } from '../interfaces';
|
2019-04-08 05:19:02 +00:00
|
|
|
import { WebSocketService, UserService } from '../services';
|
2019-04-20 04:06:25 +00:00
|
|
|
import { mdToHtml, getUnixTime, canMod, isMod } from '../utils';
|
2019-04-24 16:58:45 +00:00
|
|
|
import * as 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';
|
2019-08-10 00:14:43 +00:00
|
|
|
import { i18n } from '../i18next';
|
|
|
|
import { T } from 'inferno-i18next';
|
2019-04-08 05:19:02 +00:00
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
enum BanType {Community, Site};
|
|
|
|
|
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-07-16 05:56:46 +00:00
|
|
|
collapsed: 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;
|
2019-04-15 23:12:06 +00:00
|
|
|
moderators: Array<CommunityUser>;
|
2019-04-20 04:06:25 +00:00
|
|
|
admins: Array<UserView>;
|
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-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);
|
|
|
|
this.handleCommentLike = this.handleCommentLike.bind(this);
|
|
|
|
this.handleCommentDisLike = this.handleCommentDisLike.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let node = this.props.node;
|
|
|
|
return (
|
2019-04-17 03:23:52 +00:00
|
|
|
<div className={`comment ${node.comment.parent_id && !this.props.noIndent ? 'ml-4' : ''}`}>
|
2019-05-05 22:47:35 +00:00
|
|
|
<div className={`mr-1 float-left small text-center ${this.props.viewOnly && 'no-click'}`}>
|
2019-04-24 15:26:49 +00:00
|
|
|
<div className={`pointer ${node.comment.my_vote == 1 ? 'text-info' : 'text-muted'}`} onClick={linkEvent(node, this.handleCommentLike)}>
|
2019-07-23 03:15:00 +00:00
|
|
|
<svg class="pointer icon upvote"><use xlinkHref="#icon-arrow-up"></use></svg>
|
2019-04-24 15:26:49 +00:00
|
|
|
</div>
|
2019-05-05 22:47:35 +00:00
|
|
|
<div class={`font-weight-bold text-muted`}>{node.comment.score}</div>
|
2019-04-25 01:03:21 +00:00
|
|
|
<div className={`pointer ${node.comment.my_vote == -1 ? 'text-danger' : 'text-muted'}`} onClick={linkEvent(node, this.handleCommentDisLike)}>
|
2019-07-23 03:15:00 +00:00
|
|
|
<svg class="pointer icon downvote"><use xlinkHref="#icon-arrow-down"></use></svg>
|
2019-04-24 15:26:49 +00:00
|
|
|
</div>
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-04-24 16:58:45 +00:00
|
|
|
<div id={`comment-${node.comment.id}`} className={`details ml-4 ${this.isCommentNew ? 'mark' : ''}`}>
|
2019-04-08 05:19:02 +00:00
|
|
|
<ul class="list-inline mb-0 text-muted small">
|
|
|
|
<li className="list-inline-item">
|
2019-04-25 21:52:18 +00:00
|
|
|
<Link className="text-info" to={`/u/${node.comment.creator_name}`}>{node.comment.creator_name}</Link>
|
2019-04-08 05:19:02 +00:00
|
|
|
</li>
|
2019-04-20 04:06:25 +00:00
|
|
|
{this.isMod &&
|
2019-08-10 00:14:43 +00:00
|
|
|
<li className="list-inline-item badge badge-light"><T i18nKey="mod">#</T></li>
|
2019-04-20 04:06:25 +00:00
|
|
|
}
|
|
|
|
{this.isAdmin &&
|
2019-08-10 00:14:43 +00:00
|
|
|
<li className="list-inline-item badge badge-light"><T i18nKey="admin">#</T></li>
|
2019-04-20 04:06:25 +00:00
|
|
|
}
|
2019-04-08 05:19:02 +00:00
|
|
|
<li className="list-inline-item">
|
|
|
|
<span>(
|
|
|
|
<span className="text-info">+{node.comment.upvotes}</span>
|
|
|
|
<span> | </span>
|
|
|
|
<span className="text-danger">-{node.comment.downvotes}</span>
|
|
|
|
<span>) </span>
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<span><MomentTime data={node.comment} /></span>
|
|
|
|
</li>
|
2019-07-16 05:56:46 +00:00
|
|
|
<li className="list-inline-item">
|
|
|
|
<div className="pointer text-monospace" onClick={linkEvent(this, this.handleCommentCollapse)}>{this.state.collapsed ? '[+]' : '[-]'}</div>
|
|
|
|
</li>
|
2019-04-08 05:19:02 +00:00
|
|
|
</ul>
|
2019-04-15 23:12:06 +00:00
|
|
|
{this.state.showEdit && <CommentForm node={node} edit onReplyCancel={this.handleReplyCancel} disabled={this.props.locked} />}
|
2019-07-16 05:56:46 +00:00
|
|
|
{!this.state.showEdit && !this.state.collapsed &&
|
2019-04-08 05:19:02 +00:00
|
|
|
<div>
|
2019-08-10 00:14:43 +00:00
|
|
|
<div className="md-div" dangerouslySetInnerHTML={mdToHtml(node.comment.removed ? `*${i18n.t('removed')}*` : node.comment.deleted ? `*${i18n.t('deleted')}*` : node.comment.content)} />
|
2019-04-08 05:19:02 +00:00
|
|
|
<ul class="list-inline mb-1 text-muted small font-weight-bold">
|
2019-04-20 04:06:25 +00:00
|
|
|
{UserService.Instance.user && !this.props.viewOnly &&
|
|
|
|
<>
|
2019-04-08 05:19:02 +00:00
|
|
|
<li className="list-inline-item">
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleReplyClick)}><T i18nKey="reply">#</T></span>
|
2019-04-08 05:19:02 +00:00
|
|
|
</li>
|
2019-04-20 04:06:25 +00:00
|
|
|
<li className="list-inline-item mr-2">
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleSaveCommentClick)}>{node.comment.saved ? i18n.t('unsave') : i18n.t('save')}</span>
|
2019-04-20 04:06:25 +00:00
|
|
|
</li>
|
2019-04-08 05:19:02 +00:00
|
|
|
{this.myComment &&
|
2019-04-15 23:12:06 +00:00
|
|
|
<>
|
2019-04-20 04:06:25 +00:00
|
|
|
<li className="list-inline-item">
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleEditClick)}><T i18nKey="edit">#</T></span>
|
2019-04-20 04:06:25 +00:00
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
2019-04-29 19:14:54 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleDeleteClick)}>
|
2019-08-10 00:14:43 +00:00
|
|
|
{!this.props.node.comment.deleted ? i18n.t('delete') : i18n.t('restore')}
|
2019-04-29 19:14:54 +00:00
|
|
|
</span>
|
2019-04-20 04:06:25 +00:00
|
|
|
</li>
|
|
|
|
</>
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
2019-04-20 04:06:25 +00:00
|
|
|
{/* Admins and mods can remove comments */}
|
|
|
|
{this.canMod &&
|
2019-04-15 23:12:06 +00:00
|
|
|
<li className="list-inline-item">
|
|
|
|
{!this.props.node.comment.removed ?
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleModRemoveShow)}><T i18nKey="remove">#</T></span> :
|
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleModRemoveSubmit)}><T i18nKey="restore">#</T></span>
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
</li>
|
2019-04-20 04:06:25 +00:00
|
|
|
}
|
|
|
|
{/* Mods can ban from community, and appoint as mods to community */}
|
|
|
|
{this.canMod &&
|
|
|
|
<>
|
|
|
|
{!this.isMod &&
|
|
|
|
<li className="list-inline-item">
|
|
|
|
{!this.props.node.comment.banned_from_community ?
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleModBanFromCommunityShow)}><T i18nKey="ban">#</T></span> :
|
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}><T i18nKey="unban">#</T></span>
|
2019-04-20 04:06:25 +00:00
|
|
|
}
|
|
|
|
</li>
|
|
|
|
}
|
|
|
|
{!this.props.node.comment.banned_from_community &&
|
|
|
|
<li className="list-inline-item">
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleAddModToCommunity)}>{this.isMod ? i18n.t('remove_as_mod') : i18n.t('appoint_as_mod')}</span>
|
2019-04-20 04:06:25 +00:00
|
|
|
</li>
|
|
|
|
}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
{/* Admins can ban from all, and appoint other admins */}
|
|
|
|
{this.canAdmin &&
|
|
|
|
<>
|
|
|
|
{!this.isAdmin &&
|
2019-04-15 23:12:06 +00:00
|
|
|
<li className="list-inline-item">
|
|
|
|
{!this.props.node.comment.banned ?
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleModBanShow)}><T i18nKey="ban_from_site">#</T></span> :
|
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleModBanSubmit)}><T i18nKey="unban_from_site">#</T></span>
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
</li>
|
2019-04-20 04:06:25 +00:00
|
|
|
}
|
|
|
|
{!this.props.node.comment.banned &&
|
|
|
|
<li className="list-inline-item">
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleAddAdmin)}>{this.isAdmin ? i18n.t('remove_as_admin') : i18n.t('appoint_as_admin')}</span>
|
2019-04-20 04:06:25 +00:00
|
|
|
</li>
|
|
|
|
}
|
|
|
|
</>
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
2019-04-20 04:06:25 +00:00
|
|
|
</>
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
<li className="list-inline-item">
|
2019-08-10 00:14:43 +00:00
|
|
|
<Link className="text-muted" to={`/post/${node.comment.post_id}/comment/${node.comment.id}`}><T i18nKey="link">#</T></Link>
|
2019-04-08 05:19:02 +00:00
|
|
|
</li>
|
2019-04-20 18:17:00 +00:00
|
|
|
{this.props.markable &&
|
|
|
|
<li className="list-inline-item">
|
2019-08-10 00:14:43 +00:00
|
|
|
<span class="pointer" onClick={linkEvent(this, this.handleMarkRead)}>{node.comment.read ? i18n.t('mark_as_unread') : i18n.t('mark_as_read')}</span>
|
2019-04-20 18:17:00 +00:00
|
|
|
</li>
|
|
|
|
}
|
2019-04-08 05:19:02 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
2019-04-15 23:12:06 +00:00
|
|
|
{this.state.showRemoveDialog &&
|
|
|
|
<form class="form-inline" onSubmit={linkEvent(this, this.handleModRemoveSubmit)}>
|
2019-08-10 00:14:43 +00:00
|
|
|
<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"><T i18nKey="remove_comment">#</T></button>
|
2019-04-15 23:12:06 +00:00
|
|
|
</form>
|
|
|
|
}
|
|
|
|
{this.state.showBanDialog &&
|
2019-04-20 04:06:25 +00:00
|
|
|
<form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
|
|
|
|
<div class="form-group row">
|
2019-08-10 00:14:43 +00:00
|
|
|
<label class="col-form-label"><T i18nKey="reason">#</T></label>
|
|
|
|
<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-08-10 00:14:43 +00:00
|
|
|
<button type="submit" class="btn btn-secondary">{i18n.t('ban')} {this.props.node.comment.creator_name}</button>
|
2019-04-20 04:06:25 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
}
|
|
|
|
{this.state.showReply &&
|
|
|
|
<CommentForm
|
|
|
|
node={node}
|
|
|
|
onReplyCancel={this.handleReplyCancel}
|
|
|
|
disabled={this.props.locked}
|
|
|
|
/>
|
|
|
|
}
|
2019-07-16 05:56:46 +00:00
|
|
|
{this.props.node.children && !this.state.collapsed &&
|
2019-04-20 04:06:25 +00:00
|
|
|
<CommentNodes
|
|
|
|
nodes={this.props.node.children}
|
|
|
|
locked={this.props.locked}
|
|
|
|
moderators={this.props.moderators}
|
|
|
|
admins={this.props.admins}
|
|
|
|
/>
|
2019-04-15 23:12:06 +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-04-15 23:12:06 +00:00
|
|
|
get myComment(): boolean {
|
2019-04-16 23:04:23 +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-04-20 07:24:59 +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-04-20 07:24:59 +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-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) {
|
|
|
|
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 {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-21 20:52:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
get canAdmin(): boolean {
|
2019-04-20 07:24:59 +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-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-04-08 05:19:02 +00:00
|
|
|
auth: null
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.editComment(deleteForm);
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
handleSaveCommentClick(i: CommentNode) {
|
|
|
|
let saved = (i.props.node.comment.saved == undefined) ? true : !i.props.node.comment.saved;
|
|
|
|
let form: SaveCommentForm = {
|
|
|
|
comment_id: i.props.node.comment.id,
|
|
|
|
save: saved
|
|
|
|
};
|
|
|
|
|
|
|
|
WebSocketService.Instance.saveComment(form);
|
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handleReplyCancel() {
|
|
|
|
this.state.showReply = false;
|
|
|
|
this.state.showEdit = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleCommentLike(i: CommentNodeI) {
|
|
|
|
|
|
|
|
let form: CommentLikeForm = {
|
|
|
|
comment_id: i.comment.id,
|
|
|
|
post_id: i.comment.post_id,
|
|
|
|
score: (i.comment.my_vote == 1) ? 0 : 1
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.likeComment(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCommentDisLike(i: CommentNodeI) {
|
|
|
|
let form: CommentLikeForm = {
|
|
|
|
comment_id: i.comment.id,
|
|
|
|
post_id: i.comment.post_id,
|
|
|
|
score: (i.comment.my_vote == -1) ? 0 : -1
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.likeComment(form);
|
|
|
|
}
|
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,
|
|
|
|
auth: null
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.editComment(form);
|
|
|
|
|
|
|
|
i.state.showRemoveDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-20 18:17:00 +00:00
|
|
|
handleMarkRead(i: CommentNode) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
handleModBanFromCommunityShow(i: CommentNode) {
|
|
|
|
i.state.showBanDialog = true;
|
|
|
|
i.state.banType = BanType.Community;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
handleModBanShow(i: CommentNode) {
|
|
|
|
i.state.showBanDialog = true;
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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-04-08 05:19:02 +00:00
|
|
|
}
|