mirror of
https://github.com/wassname/talk.git
synced 2026-07-14 11:18:50 +08:00
Simplify subscription
This commit is contained in:
@@ -93,7 +93,7 @@ function showNotification(queue, comment, user) {
|
||||
notification.info(text);
|
||||
}
|
||||
|
||||
export function handleCommentStatusChange(root, comment, {sort, notify, user, activeQueue}) {
|
||||
export function handleCommentStatusChange(root, comment, {sort, notify, activeQueue}) {
|
||||
let next = root;
|
||||
const nextQueues = getCommentQueues(comment);
|
||||
|
||||
@@ -102,7 +102,8 @@ export function handleCommentStatusChange(root, comment, {sort, notify, user, ac
|
||||
if (notificationShown) {
|
||||
return;
|
||||
}
|
||||
showNotification(...args);
|
||||
const user = comment.status_history[comment.status_history.length - 1].assigned_by;
|
||||
showNotification(...[...args, user]);
|
||||
notificationShown = true;
|
||||
};
|
||||
|
||||
@@ -111,13 +112,13 @@ export function handleCommentStatusChange(root, comment, {sort, notify, user, ac
|
||||
if (!queueHasComment(next, queue, comment.id)) {
|
||||
next = addCommentToQueue(next, queue, comment, sort);
|
||||
if (notify && activeQueue === queue && shouldCommentBeAdded(next, queue, comment, sort)) {
|
||||
showNotificationOnce(queue, comment, user);
|
||||
showNotificationOnce(queue, comment);
|
||||
}
|
||||
}
|
||||
} else if(queueHasComment(next, queue, comment.id)){
|
||||
next = removeCommentFromQueue(next, queue, comment.id);
|
||||
if (notify && activeQueue === queue) {
|
||||
showNotificationOnce(queue, comment, user);
|
||||
showNotificationOnce(queue, comment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +128,7 @@ export function handleCommentStatusChange(root, comment, {sort, notify, user, ac
|
||||
&& notify
|
||||
&& activeQueue === queue
|
||||
) {
|
||||
showNotificationOnce(queue, comment, user);
|
||||
showNotificationOnce(queue, comment);
|
||||
}
|
||||
|
||||
// TODO: Flagged notification
|
||||
|
||||
@@ -42,12 +42,13 @@ class ModerationContainer extends Component {
|
||||
variables: {
|
||||
asset_id: this.props.data.variables.asset_id,
|
||||
},
|
||||
updateQuery: (prev, {subscriptionData: {data: {commentStatusChanged: {user, comment}}}}) => {
|
||||
updateQuery: (prev, {subscriptionData: {data: {commentStatusChanged: comment}}}) => {
|
||||
const user = comment.status_history[comment.status_history.length - 1].assigned_by;
|
||||
|
||||
const extraParams = this.props.auth.user.id === user.id
|
||||
? {}
|
||||
: {
|
||||
notify: true,
|
||||
user,
|
||||
activeQueue: this.activeTab,
|
||||
};
|
||||
return handleCommentStatusChange(prev, comment, {
|
||||
@@ -218,12 +219,14 @@ const COMMENTS_EDITED_SUBSCRIPTION = gql`
|
||||
const STATUS_CHANGED_SUBSCRIPTION = gql`
|
||||
subscription CommentStatusChanged($asset_id: ID){
|
||||
commentStatusChanged(asset_id: $asset_id){
|
||||
user {
|
||||
id
|
||||
username
|
||||
}
|
||||
comment {
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
status_history {
|
||||
type
|
||||
created_at
|
||||
assigned_by {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -22,6 +22,7 @@ module.exports = {
|
||||
SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS: 'SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS',
|
||||
SEARCH_OTHERS_COMMENTS: 'SEARCH_OTHERS_COMMENTS',
|
||||
SEARCH_COMMENT_METRICS: 'SEARCH_COMMENT_METRICS',
|
||||
SEARCH_COMMENT_STATUS_HISTORY: 'SEARCH_COMMENT_STATUS_HISTORY',
|
||||
|
||||
// subscriptions
|
||||
SUBSCRIBE_COMMENT_STATUS: 'SUBSCRIBE_COMMENT_STATUS',
|
||||
|
||||
@@ -15,6 +15,8 @@ module.exports = (user, perm) => {
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.SEARCH_COMMENT_METRICS:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.SEARCH_COMMENT_STATUS_HISTORY:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user