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 -5
View File
@@ -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
}
}
}
}