mirror of
https://github.com/wassname/talk.git
synced 2026-09-12 13:01:11 +08:00
Simplify subscription
This commit is contained in:
@@ -346,6 +346,12 @@ const setStatus = async ({user, loaders: {Comments}, pubsub}, {id, status}) => {
|
||||
// adjust the affected user's karma in the next tick.
|
||||
process.nextTick(adjustKarma(Comments, id, status));
|
||||
|
||||
if (pubsub) {
|
||||
|
||||
// Publish the comment status change via the subscription.
|
||||
pubsub.publish('commentStatusChanged', comment);
|
||||
}
|
||||
|
||||
return comment;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
const {SEARCH_OTHER_USERS} = require('../../perms/constants');
|
||||
|
||||
const CommentStatusHistory = {
|
||||
assigned_by({assigned_by}, _, {user, loaders: {Users}}) {
|
||||
if (user && user.can(SEARCH_OTHER_USERS) && assigned_by != null) {
|
||||
return Users.getByID.load(assigned_by);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = CommentStatusHistory;
|
||||
@@ -6,6 +6,7 @@ const Action = require('./action');
|
||||
const AssetActionSummary = require('./asset_action_summary');
|
||||
const Asset = require('./asset');
|
||||
const Comment = require('./comment');
|
||||
const CommentStatusHistory = require('./comment_status_history');
|
||||
const Date = require('./date');
|
||||
const FlagActionSummary = require('./flag_action_summary');
|
||||
const FlagAction = require('./flag_action');
|
||||
@@ -31,6 +32,7 @@ let resolvers = {
|
||||
AssetActionSummary,
|
||||
Asset,
|
||||
Comment,
|
||||
CommentStatusHistory,
|
||||
Date,
|
||||
FlagActionSummary,
|
||||
FlagAction,
|
||||
|
||||
@@ -31,18 +31,8 @@ const RootMutation = {
|
||||
stopIgnoringUser(_, {id}, {mutators: {User}}) {
|
||||
return wrapResponse(null)(User.stopIgnoringUser({id}));
|
||||
},
|
||||
setCommentStatus(_, {id, status}, {mutators: {Comment}, user, pubsub}) {
|
||||
const response = Comment.setStatus({id, status})
|
||||
.then((comment) => {
|
||||
if (pubsub) {
|
||||
|
||||
// Publish the comment status change via the subscription.
|
||||
pubsub.publish('commentStatusChanged', {user, comment});
|
||||
}
|
||||
return Promise.resolve(comment);
|
||||
});
|
||||
|
||||
return wrapResponse(null)(response);
|
||||
setCommentStatus(_, {id, status}, {mutators: {Comment}}) {
|
||||
return wrapResponse(null)(Comment.setStatus({id, status}));
|
||||
},
|
||||
addTag(_, {tag}, {mutators: {Tag}}) {
|
||||
return wrapResponse(null)(Tag.add(tag));
|
||||
|
||||
@@ -5,8 +5,8 @@ const Subscription = {
|
||||
commentEdited(comment) {
|
||||
return comment;
|
||||
},
|
||||
commentStatusChanged(data) {
|
||||
return data;
|
||||
commentStatusChanged(comment) {
|
||||
return comment;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
+16
-7
@@ -247,6 +247,12 @@ type EditInfo {
|
||||
editableUntil: Date
|
||||
}
|
||||
|
||||
type CommentStatusHistory {
|
||||
type: COMMENT_STATUS!
|
||||
created_at: Date!
|
||||
assigned_by: User
|
||||
}
|
||||
|
||||
# Comment is the base representation of user interaction in Talk.
|
||||
type Comment {
|
||||
|
||||
@@ -286,6 +292,9 @@ type Comment {
|
||||
# The current status of a comment.
|
||||
status: COMMENT_STATUS!
|
||||
|
||||
# The status history of the comment. Requires the `ADMIN` or `MODERATOR` role.
|
||||
status_history: [CommentStatusHistory!]
|
||||
|
||||
# The time when the comment was created
|
||||
created_at: Date!
|
||||
|
||||
@@ -936,16 +945,16 @@ type RootMutation {
|
||||
## Subscriptions
|
||||
################################################################################
|
||||
|
||||
# Response to ignoreUser mutation
|
||||
type CommentStatusChangedUpdate {
|
||||
user: User
|
||||
comment: Comment
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
|
||||
# Get an update whenever a comment was added.
|
||||
commentAdded(asset_id: ID!): Comment
|
||||
|
||||
# Get an update whenever a comment was edited.
|
||||
commentEdited(asset_id: ID): Comment
|
||||
commentStatusChanged(asset_id: ID): CommentStatusChangedUpdate
|
||||
|
||||
# Get an update whenever the status of a comment changed due to a moderator action.
|
||||
commentStatusChanged(asset_id: ID): Comment
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
Reference in New Issue
Block a user