Simplify subscription

This commit is contained in:
Chi Vinh Le
2017-06-16 19:19:59 +07:00
parent ecf63ffb55
commit 5f450adbaf
10 changed files with 59 additions and 34 deletions
+6
View File
@@ -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;
};
+11
View File
@@ -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;
+2
View File
@@ -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,
+2 -12
View File
@@ -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));
+2 -2
View File
@@ -5,8 +5,8 @@ const Subscription = {
commentEdited(comment) {
return comment;
},
commentStatusChanged(data) {
return data;
commentStatusChanged(comment) {
return comment;
},
};
+16 -7
View File
@@ -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
}
################################################################################