mirror of
https://github.com/wassname/talk.git
synced 2026-07-05 19:06:55 +08:00
BE Subscription for Featured Comments
This commit is contained in:
@@ -103,7 +103,21 @@ class ModerationContainer extends Component {
|
||||
},
|
||||
});
|
||||
|
||||
this.subscriptions.push(sub1, sub2, sub3, sub4);
|
||||
const sub5 = this.props.data.subscribeToMore({
|
||||
document: COMMENT_FEATURED_SUBSCRIPTION,
|
||||
variables,
|
||||
updateQuery: (prev, {subscriptionData: {data: {commentFeatured: comment}}}) => {
|
||||
const sort = this.props.moderation.sortOrder;
|
||||
const notify = {
|
||||
activeQueue: this.activeTab,
|
||||
text: 'New Featured Comment',
|
||||
anyQueue: true,
|
||||
};
|
||||
return handleCommentChange(prev, comment, sort, notify);
|
||||
},
|
||||
});
|
||||
|
||||
this.subscriptions.push(sub1, sub2, sub3, sub4, sub5);
|
||||
}
|
||||
|
||||
unsubscribe() {
|
||||
@@ -217,6 +231,15 @@ class ModerationContainer extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
const COMMENT_FEATURED_SUBSCRIPTION = gql`
|
||||
subscription CommentFeatured($asset_id: ID){
|
||||
commentFeatured(asset_id: $asset_id){
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
}
|
||||
}
|
||||
${Comment.fragments.comment}
|
||||
`;
|
||||
|
||||
const COMMENT_EDITED_SUBSCRIPTION = gql`
|
||||
subscription CommentEdited($asset_id: ID){
|
||||
commentEdited(asset_id: $asset_id){
|
||||
|
||||
@@ -5,7 +5,11 @@ const {ADD_COMMENT_TAG, REMOVE_COMMENT_TAG} = require('../../perms/constants');
|
||||
/**
|
||||
* Modifies the targeted model with the specified operation to add/remove a tag.
|
||||
*/
|
||||
const modify = async ({user, loaders: {Tags}}, operation, {name, id, item_type, asset_id}) => {
|
||||
const modify = async ({user, loaders: {Tags}, pubsub}, operation, {name, id, item_type, asset_id}) => {
|
||||
|
||||
if (operation.name === 'add') {
|
||||
pubsub.publish('commentFeatured', {});
|
||||
}
|
||||
|
||||
// Get the global list of tags from the dataloader.
|
||||
const tags = await Tags.getAll.load({id, item_type, asset_id});
|
||||
|
||||
@@ -14,6 +14,9 @@ const Subscription = {
|
||||
commentFlagged(comment) {
|
||||
return comment;
|
||||
},
|
||||
commentFeatured(comment) {
|
||||
return comment;
|
||||
},
|
||||
userBanned(user) {
|
||||
return user;
|
||||
},
|
||||
|
||||
@@ -24,6 +24,7 @@ const {
|
||||
SUBSCRIBE_ALL_USER_SUSPENDED,
|
||||
SUBSCRIBE_ALL_USER_BANNED,
|
||||
SUBSCRIBE_ALL_USERNAME_REJECTED,
|
||||
SUBSCRIBE_COMMENT_FEATURED
|
||||
} = require('../perms/constants');
|
||||
|
||||
/**
|
||||
@@ -86,6 +87,16 @@ const setupFunctions = plugins.get('server', 'setupFunctions').reduce((acc, {plu
|
||||
}
|
||||
},
|
||||
}),
|
||||
commentFeatured: (options, args) => ({
|
||||
commentFeatured: {
|
||||
filter: (comment, context) => {
|
||||
if (!args.asset_id && (!context.user || !context.user.can(SUBSCRIBE_COMMENT_FEATURED))) {
|
||||
return false;
|
||||
}
|
||||
return !args.asset_id || comment.asset_id === args.asset_id;
|
||||
}
|
||||
},
|
||||
}),
|
||||
userSuspended: (options, args) => ({
|
||||
userSuspended: {
|
||||
filter: (user, context) => {
|
||||
|
||||
@@ -1046,6 +1046,10 @@ type Subscription {
|
||||
# Requires the `ADMIN` or `MODERATOR` role.
|
||||
commentFlagged(asset_id: ID): Comment
|
||||
|
||||
# Get an update whenever a comment is featured.
|
||||
# Requires the `ADMIN` or `MODERATOR` role.
|
||||
commentFeatured(asset_id: ID): Comment
|
||||
|
||||
# Get an update whenever a comment has been accepted.
|
||||
# Requires the `ADMIN` or `MODERATOR` role.
|
||||
commentAccepted(asset_id: ID): Comment
|
||||
|
||||
@@ -37,4 +37,5 @@ module.exports = {
|
||||
SUBSCRIBE_ALL_USER_SUSPENDED: 'SUBSCRIBE_ALL_USER_SUSPENDED',
|
||||
SUBSCRIBE_ALL_USER_BANNED: 'SUBSCRIBE_ALL_USER_BANNED',
|
||||
SUBSCRIBE_ALL_USERNAME_REJECTED: 'SUBSCRIBE_ALL_USERNAME_REJECTED',
|
||||
SUBSCRIBE_COMMENT_FEATURED: 'SUBSCRIBE_COMMENT_FEATURED'
|
||||
};
|
||||
|
||||
@@ -19,6 +19,8 @@ module.exports = (user, perm) => {
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.SUBSCRIBE_ALL_USERNAME_REJECTED:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.SUBSCRIBE_COMMENT_FEATURED:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user