From 42954fb84ab4b9e7651e66eeafe0da76a369fa07 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Wed, 20 Sep 2017 04:17:15 +0700 Subject: [PATCH] Return all actions in CreateCommentResponse --- client/coral-embed-stream/src/graphql/index.js | 11 +++++++---- client/talk-plugin-commentbox/CommentBox.js | 12 ++++++------ graph/resolvers/root_mutation.js | 5 ++--- graph/typeDefs.graphql | 6 +++--- .../client/components/CheckToxicityHook.js | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/client/coral-embed-stream/src/graphql/index.js b/client/coral-embed-stream/src/graphql/index.js index d7af76d82..20ed8a1d6 100644 --- a/client/coral-embed-stream/src/graphql/index.js +++ b/client/coral-embed-stream/src/graphql/index.js @@ -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: { diff --git a/client/talk-plugin-commentbox/CommentBox.js b/client/talk-plugin-commentbox/CommentBox.js index 49c4df0eb..b210f4e79 100644 --- a/client/talk-plugin-commentbox/CommentBox.js +++ b/client/talk-plugin-commentbox/CommentBox.js @@ -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(); diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index c7794303b..17235a59e 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -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}}), diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 5b3fe7ef9..71928f49e 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -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!] diff --git a/plugins/talk-plugin-toxic-comments/client/components/CheckToxicityHook.js b/plugins/talk-plugin-toxic-comments/client/components/CheckToxicityHook.js index 44e2e89a7..e4bd68097 100644 --- a/plugins/talk-plugin-toxic-comments/client/components/CheckToxicityHook.js +++ b/plugins/talk-plugin-toxic-comments/client/components/CheckToxicityHook.js @@ -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')); }