mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
Live update modqueue on new comments
This commit is contained in:
@@ -182,11 +182,11 @@ const createComment = async (context, {tags = [], body, asset_id, parent_id = nu
|
||||
Comments.parentCountByAssetID.incr(asset_id);
|
||||
}
|
||||
Comments.countByAssetID.incr(asset_id);
|
||||
|
||||
// Publish the newly added comment via the subscription.
|
||||
pubsub.publish('commentAdded', comment);
|
||||
}
|
||||
|
||||
// Publish the newly added comment via the subscription.
|
||||
pubsub.publish('commentAdded', comment);
|
||||
|
||||
return comment;
|
||||
};
|
||||
|
||||
|
||||
+21
-1
@@ -26,10 +26,30 @@ const setupFunctions = plugins.get('server', 'setupFunctions').reduce((acc, {plu
|
||||
commentAdded: (options, args) => ({
|
||||
commentAdded: {
|
||||
filter: (comment, context) => {
|
||||
|
||||
// Only priviledged users can subscribe to all assets.
|
||||
if (!args.asset_id && (!context.user || !context.user.can(SUBSCRIBE_ALL_COMMENT_ADDED))) {
|
||||
return false;
|
||||
}
|
||||
return !args.asset_id || comment.asset_id === args.asset_id;
|
||||
|
||||
// If user scubsscribes for statuses other than NONE and/or ACCEPTED statuses, it needs
|
||||
// special priviledges.
|
||||
if (
|
||||
(!args.statuses || args.statuses.some((status) => !['NONE', 'ACCEPTED'].includes(status))) &&
|
||||
(!context.user || !context.user.can(SUBSCRIBE_ALL_COMMENT_ADDED))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.asset_id && comment.asset_id !== args.asset_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.statuses && !args.statuses.includes(comment.status)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -1356,7 +1356,8 @@ type Subscription {
|
||||
|
||||
# Get an update whenever a comment was added.
|
||||
# `asset_id` is required except for users with the `ADMIN` or `MODERATOR` role.
|
||||
commentAdded(asset_id: ID): Comment
|
||||
# Non privileged user can only subscribe to 'NONE' and/or 'ACCEPTED' statuses.
|
||||
commentAdded(asset_id: ID, statuses: [COMMENT_STATUS!] = [NONE, ACCEPTED]): Comment
|
||||
|
||||
# Get an update whenever a comment was edited.
|
||||
# `asset_id` is required except for users with the `ADMIN` or `MODERATOR` role.
|
||||
|
||||
Reference in New Issue
Block a user