mirror of
https://github.com/wassname/talk.git
synced 2026-07-18 12:40:13 +08:00
Return flags when creating comment, restrict access to actions in comment resolver
This commit is contained in:
@@ -64,6 +64,10 @@ export default {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
flags {
|
||||
reason
|
||||
message
|
||||
}
|
||||
}
|
||||
|
||||
fragment CoralEmbedStream_CreateCommentResponse_Comment on Comment {
|
||||
@@ -77,14 +81,6 @@ export default {
|
||||
title
|
||||
url
|
||||
}
|
||||
actions {
|
||||
__typename
|
||||
id
|
||||
... on FlagAction {
|
||||
reason
|
||||
message
|
||||
}
|
||||
}
|
||||
tags {
|
||||
tag {
|
||||
name
|
||||
@@ -124,6 +120,7 @@ export default {
|
||||
createComment: {
|
||||
__typename: 'CreateCommentResponse',
|
||||
errors: null,
|
||||
flags: [],
|
||||
comment: {
|
||||
__typename: 'Comment',
|
||||
user: {
|
||||
@@ -133,7 +130,6 @@ export default {
|
||||
},
|
||||
created_at: new Date().toISOString(),
|
||||
body,
|
||||
actions: [],
|
||||
action_summaries: [],
|
||||
tags: tags.map((tag) => ({
|
||||
tag: {
|
||||
|
||||
@@ -13,18 +13,18 @@ export const name = 'talk-plugin-commentbox';
|
||||
|
||||
const notifyReasons = ['LINKS', 'TRUST'];
|
||||
|
||||
function shouldNotify(actions = []) {
|
||||
return actions.some(({reason}) => notifyReasons.includes(reason));
|
||||
function shouldNotify(flags = []) {
|
||||
return flags.some(({reason}) => notifyReasons.includes(reason));
|
||||
}
|
||||
|
||||
// Given a newly posted comment's status, show a notification to the user
|
||||
// if needed
|
||||
export const notifyForNewCommentStatus = (notify, comment) => {
|
||||
export const notifyForNewCommentStatus = (notify, comment, flags) => {
|
||||
if (comment.status === 'REJECTED') {
|
||||
notify('error', t('comment_box.comment_post_banned_word'));
|
||||
} else if (
|
||||
comment.status === 'PREMOD' ||
|
||||
comment.status === 'SYSTEM_WITHHELD' && shouldNotify(comment.actions)) {
|
||||
comment.status === 'SYSTEM_WITHHELD' && shouldNotify(flags)) {
|
||||
notify('success', t('comment_box.comment_post_notif_premod'));
|
||||
}
|
||||
};
|
||||
@@ -78,11 +78,12 @@ class CommentBox extends React.Component {
|
||||
.then(({data}) => {
|
||||
this.setState({loadingState: 'success', body: ''});
|
||||
const postedComment = data.createComment.comment;
|
||||
const flags = data.createComment.flags;
|
||||
|
||||
// Execute postSubmit Hooks
|
||||
this.state.hooks.postSubmit.forEach((hook) => hook(data));
|
||||
|
||||
notifyForNewCommentStatus(notify, postedComment);
|
||||
notifyForNewCommentStatus(notify, postedComment, flags);
|
||||
|
||||
if (commentPostedHandler) {
|
||||
commentPostedHandler();
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
const RootMutation = {
|
||||
createComment: async (_, {input}, {mutators: {Comment}}) => ({
|
||||
comment: await Comment.create(input),
|
||||
}),
|
||||
createComment: async (_, {input}, {mutators: {Comment}, loaders: {Actions}}) => {
|
||||
const comment = await Comment.create(input);
|
||||
|
||||
// Retrieve flags that was assigned to comment.
|
||||
const actions = await Actions.getByID.load(comment.id);
|
||||
const flags = actions.filter(({action_type}) => action_type === 'FLAG');
|
||||
|
||||
return {comment, flags};
|
||||
},
|
||||
editComment: async (_, {id, asset_id, edit: {body}}, {mutators: {Comment}}) => ({
|
||||
comment: await Comment.edit({id, asset_id, edit: {body}}),
|
||||
}),
|
||||
|
||||
@@ -23,8 +23,8 @@ export default class CheckToxicityHook extends React.Component {
|
||||
});
|
||||
|
||||
this.toxicityPostHook = this.props.registerHook('postSubmit', (result) => {
|
||||
const actions = result.createComment.comment && result.createComment.comment.actions;
|
||||
if (actions && actions.some(({reason}) => reason === 'TOXIC_COMMENT')) {
|
||||
const flags = result.createComment.flags;
|
||||
if (flags && flags.some(({reason}) => reason === 'TOXIC_COMMENT')) {
|
||||
this.props.notify('error', t('talk-plugin-toxic-comments.still_toxic'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user