Handle comment flags

This commit is contained in:
Chi Vinh Le
2017-06-16 20:06:13 +07:00
parent 5f450adbaf
commit 2625b372e1
8 changed files with 101 additions and 48 deletions
+18 -1
View File
@@ -12,7 +12,9 @@ const {deserializeUser} = require('../services/subscriptions');
const {
SUBSCRIBE_COMMENT_STATUS,
SUBSCRIBE_COMMENT_FLAGS,
SUBSCRIBE_ALL_COMMENT_EDITS,
SUBSCRIBE_ALL_COMMENT_ADDITIONS,
} = require('../perms/constants');
/**
@@ -27,7 +29,12 @@ const setupFunctions = plugins.get('server', 'setupFunctions').reduce((acc, {plu
}, {
commentAdded: (options, args) => ({
commentAdded: {
filter: (comment) => comment.asset_id === args.asset_id
filter: (comment, context) => {
if (!args.asset_id && (!context.user || !context.user.can(SUBSCRIBE_ALL_COMMENT_ADDITIONS))) {
return false;
}
return !args.asset_id || comment.asset_id === args.asset_id;
}
},
}),
commentEdited: (options, args) => ({
@@ -40,6 +47,16 @@ const setupFunctions = plugins.get('server', 'setupFunctions').reduce((acc, {plu
}
},
}),
commentFlagged: (options, args) => ({
commentFlagged: {
filter: ({comment}, context) => {
if (!context.user || !context.user.can(SUBSCRIBE_COMMENT_FLAGS)) {
return false;
}
return !args.asset_id || comment.asset_id === args.asset_id;
}
},
}),
commentStatusChanged: (options, args) => ({
commentStatusChanged: {
filter: ({comment}, context) => {