mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 11:59:10 +08:00
Return all actions in CreateCommentResponse
This commit is contained in:
@@ -64,9 +64,12 @@ export default {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
flags {
|
||||
reason
|
||||
message
|
||||
actions {
|
||||
__typename
|
||||
... on FlagAction {
|
||||
reason
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +123,7 @@ export default {
|
||||
createComment: {
|
||||
__typename: 'CreateCommentResponse',
|
||||
errors: null,
|
||||
flags: [],
|
||||
actions: [],
|
||||
comment: {
|
||||
__typename: 'Comment',
|
||||
user: {
|
||||
|
||||
@@ -13,18 +13,18 @@ export const name = 'talk-plugin-commentbox';
|
||||
|
||||
const notifyReasons = ['LINKS', 'TRUST'];
|
||||
|
||||
function shouldNotify(flags = []) {
|
||||
return flags.some(({reason}) => notifyReasons.includes(reason));
|
||||
function shouldNotify(actions = []) {
|
||||
return actions.some(({__typename, reason}) => __typename === 'FlagAction' && notifyReasons.includes(reason));
|
||||
}
|
||||
|
||||
// Given a newly posted comment's status, show a notification to the user
|
||||
// if needed
|
||||
export const notifyForNewCommentStatus = (notify, comment, flags) => {
|
||||
export const notifyForNewCommentStatus = (notify, comment, actions) => {
|
||||
if (comment.status === 'REJECTED') {
|
||||
notify('error', t('comment_box.comment_post_banned_word'));
|
||||
} else if (
|
||||
comment.status === 'PREMOD' ||
|
||||
comment.status === 'SYSTEM_WITHHELD' && shouldNotify(flags)) {
|
||||
comment.status === 'SYSTEM_WITHHELD' && shouldNotify(actions)) {
|
||||
notify('success', t('comment_box.comment_post_notif_premod'));
|
||||
}
|
||||
};
|
||||
@@ -78,12 +78,12 @@ class CommentBox extends React.Component {
|
||||
.then(({data}) => {
|
||||
this.setState({loadingState: 'success', body: ''});
|
||||
const postedComment = data.createComment.comment;
|
||||
const flags = data.createComment.flags;
|
||||
const actions = data.createComment.actions;
|
||||
|
||||
// Execute postSubmit Hooks
|
||||
this.state.hooks.postSubmit.forEach((hook) => hook(data));
|
||||
|
||||
notifyForNewCommentStatus(notify, postedComment, flags);
|
||||
notifyForNewCommentStatus(notify, postedComment, actions);
|
||||
|
||||
if (commentPostedHandler) {
|
||||
commentPostedHandler();
|
||||
|
||||
@@ -2,11 +2,10 @@ const RootMutation = {
|
||||
createComment: async (_, {input}, {mutators: {Comment}, loaders: {Actions}}) => {
|
||||
const comment = await Comment.create(input);
|
||||
|
||||
// Retrieve flags that was assigned to comment.
|
||||
// Retrieve actions 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};
|
||||
return {comment, actions};
|
||||
},
|
||||
editComment: async (_, {id, asset_id, edit: {body}}, {mutators: {Comment}}) => ({
|
||||
comment: await Comment.edit({id, asset_id, edit: {body}}),
|
||||
|
||||
@@ -261,7 +261,7 @@ enum ACTION_TYPE {
|
||||
# CommentsQuery allows the ability to query comments by a specific methods.
|
||||
input CommentsQuery {
|
||||
|
||||
# Author of the comments
|
||||
# Author of the commente
|
||||
author_id: ID
|
||||
|
||||
# Current status of a comment.
|
||||
@@ -877,8 +877,8 @@ type CreateCommentResponse implements Response {
|
||||
# The comment that was created.
|
||||
comment: Comment
|
||||
|
||||
# Flags that was assigned during creation of the comment.
|
||||
flags: [FlagAction]
|
||||
# Actions that was assigned during creation of the comment.
|
||||
actions: [Action]
|
||||
|
||||
# An array of errors relating to the mutation that occurred.
|
||||
errors: [UserError!]
|
||||
|
||||
@@ -23,8 +23,8 @@ export default class CheckToxicityHook extends React.Component {
|
||||
});
|
||||
|
||||
this.toxicityPostHook = this.props.registerHook('postSubmit', (result) => {
|
||||
const flags = result.createComment.flags;
|
||||
if (flags && flags.some(({reason}) => reason === 'TOXIC_COMMENT')) {
|
||||
const actions = result.createComment.actions;
|
||||
if (actions && actions.some(({__typename, reason}) => __typename === 'FlagAction' && reason === 'TOXIC_COMMENT')) {
|
||||
this.props.notify('error', t('talk-plugin-toxic-comments.still_toxic'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user