Return flags when creating comment, restrict access to actions in comment resolver

This commit is contained in:
Chi Vinh Le
2017-09-20 02:50:43 +07:00
parent b482976c58
commit 5f7c4f82e7
4 changed files with 22 additions and 19 deletions
+6 -5
View File
@@ -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();