mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 07:54:41 +08:00
Add userFlagged subscription
This commit is contained in:
@@ -73,10 +73,20 @@ const createAction = async (
|
||||
metadata,
|
||||
});
|
||||
|
||||
if (action_type === 'FLAG' && item_type === 'COMMENTS') {
|
||||
// The item is a comment, and this is a flag. Push that the comment was
|
||||
// flagged, don't wait for it to finish.
|
||||
pubsub.publish('commentFlagged', item);
|
||||
if (action_type === 'FLAG') {
|
||||
switch (item_type) {
|
||||
case 'COMMENTS':
|
||||
// The item is a comment, and this is a flag. Push that the comment was
|
||||
// flagged, don't wait for it to finish.
|
||||
pubsub.publish('commentFlagged', item);
|
||||
break;
|
||||
case 'USERS':
|
||||
// The item is a user, and this is a flag. Push that the user was
|
||||
// flagged, don't wait for it to finish.
|
||||
pubsub.publish('userFlagged', item);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
return action;
|
||||
|
||||
@@ -26,6 +26,9 @@ const Subscription = {
|
||||
usernameRejected(user) {
|
||||
return user;
|
||||
},
|
||||
usernameFlagged(user) {
|
||||
return user;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = Subscription;
|
||||
|
||||
@@ -9,6 +9,7 @@ const {
|
||||
SUBSCRIBE_ALL_USER_BANNED,
|
||||
SUBSCRIBE_ALL_USERNAME_REJECTED,
|
||||
SUBSCRIBE_ALL_USERNAME_APPROVED,
|
||||
SUBSCRIBE_ALL_USERNAME_FLAGGED,
|
||||
} = require('../perms/constants');
|
||||
|
||||
const merge = require('lodash/merge');
|
||||
@@ -97,6 +98,16 @@ const setupFunctions = {
|
||||
}
|
||||
return !args.user_id || user.id === args.user_id;
|
||||
},
|
||||
usernameFlagged: (options, args, user, context) => {
|
||||
if (
|
||||
!context.user ||
|
||||
(args.user_id !== user.id &&
|
||||
!context.user.can(SUBSCRIBE_ALL_USERNAME_FLAGGED))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return !args.user_id || user.id === args.user_id;
|
||||
},
|
||||
usernameRejected: (options, args, user, context) => {
|
||||
if (
|
||||
!context.user ||
|
||||
|
||||
@@ -1506,6 +1506,11 @@ type Subscription {
|
||||
# users with the `ADMIN` or `MODERATOR` role.
|
||||
userBanned(user_id: ID): User
|
||||
|
||||
# Get an update whenever a username was flagged.
|
||||
# `user_id` must match id of current user except for
|
||||
# users with the `ADMIN` or `MODERATOR` role.
|
||||
usernameFlagged(user_id: ID): User
|
||||
|
||||
# Get an update whenever a username has been rejected.
|
||||
# `user_id` must match id of current user except for
|
||||
# users with the `ADMIN` or `MODERATOR` role.
|
||||
|
||||
@@ -9,4 +9,5 @@ module.exports = {
|
||||
SUBSCRIBE_ALL_USER_BANNED: 'SUBSCRIBE_ALL_USER_BANNED',
|
||||
SUBSCRIBE_ALL_USERNAME_REJECTED: 'SUBSCRIBE_ALL_USERNAME_REJECTED',
|
||||
SUBSCRIBE_ALL_USERNAME_APPROVED: 'SUBSCRIBE_ALL_USERNAME_APPROVED',
|
||||
SUBSCRIBE_ALL_USERNAME_FLAGGED: 'SUBSCRIBE_ALL_USERNAME_FLAGGED',
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@ module.exports = (user, perm) => {
|
||||
case types.SUBSCRIBE_ALL_USER_BANNED:
|
||||
case types.SUBSCRIBE_ALL_USERNAME_REJECTED:
|
||||
case types.SUBSCRIBE_ALL_USERNAME_APPROVED:
|
||||
case types.SUBSCRIBE_ALL_USERNAME_FLAGGED:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user