diff --git a/client/coral-admin/src/graphql/utils.js b/client/coral-admin/src/graphql/utils.js index 62126f1af..9d85c6bb1 100644 --- a/client/coral-admin/src/graphql/utils.js +++ b/client/coral-admin/src/graphql/utils.js @@ -2,6 +2,7 @@ import update from 'immutability-helper'; import * as notification from 'coral-admin/src/services/notification'; const queues = ['all', 'premod', 'flagged', 'accepted', 'rejected']; +const limit = 10; const ascending = (a, b) => { const dateA = new Date(a.created_at); @@ -25,7 +26,6 @@ function removeCommentFromQueue(root, queue, id) { if (!queueHasComment(root, queue, id)) { return root; } - return update(root, { [`${queue}Count`]: {$set: root[`${queue}Count`] - 1}, [queue]: { @@ -34,7 +34,12 @@ function removeCommentFromQueue(root, queue, id) { }); } -function isCommentInCursor(root, queue, comment, sort) { +function shouldCommentBeAdded(root, queue, comment, sort) { + if (root[`${queue}Count`] < limit) { + + // Adding all comments until first limit has reached. + return true; + } const cursor = new Date(root[queue].endCursor); return sort === 'CHRONOLOGICAL' ? new Date(comment.created_at) <= cursor @@ -51,9 +56,12 @@ function addCommentToQueue(root, queue, comment, sort) { [`${queue}Count`]: {$set: root[`${queue}Count`] + 1}, }; - if (isCommentInCursor(root, queue, comment, sort)) { + if (shouldCommentBeAdded(root, queue, comment, sort)) { + const nodes = root[queue].nodes.concat(comment).sort(sortAlgo); changes[queue] = { - nodes: {$apply: (nodes) => nodes.concat(comment).sort(sortAlgo)}, + nodes: {$set: nodes}, + startCursor: {$set: nodes[0].created_at}, + endCursor: {$set: nodes[nodes.length - 1].created_at}, }; } @@ -93,7 +101,7 @@ export function handleCommentStatusChange(root, comment, {sort, notify, user, ac if (nextQueues.indexOf(queue) >= 0) { if (!queueHasComment(next, queue, comment.id)) { next = addCommentToQueue(next, queue, comment, sort); - if (notify && activeQueue === queue && isCommentInCursor(next, queue, comment, sort)) { + if (notify && activeQueue === queue && shouldCommentBeAdded(next, queue, comment, sort)) { showNotification(queue, comment, user); } } @@ -114,7 +122,6 @@ export function handleCommentStatusChange(root, comment, {sort, notify, user, ac } // TODO: Flagged notification - // TODO: Edited notification }); return next; } @@ -122,6 +129,7 @@ export function handleCommentStatusChange(root, comment, {sort, notify, user, ac export function handleCommentEdit(root, comment, {sort, activeQueue}) { if ( queueHasComment(root, activeQueue, comment.id) + || comment.status === 'PREMOD' && root[`${activeQueue}Count`] < limit ) { const text = `${comment.user.username} edited comment to "${truncate(comment.body, 50)}"`; notification.info(text); diff --git a/client/coral-admin/src/routes/Moderation/components/ModerationQueue.js b/client/coral-admin/src/routes/Moderation/components/ModerationQueue.js index 2e039c635..a0a11ab45 100644 --- a/client/coral-admin/src/routes/Moderation/components/ModerationQueue.js +++ b/client/coral-admin/src/routes/Moderation/components/ModerationQueue.js @@ -28,10 +28,6 @@ class ModerationQueue extends React.Component { constructor(props) { super(props); - - if (props.comments.length === 0 && props.commentCount > 0) { - this.loadMore(); - } } componentDidUpdate (prev) { diff --git a/client/coral-admin/src/routes/Moderation/containers/Moderation.js b/client/coral-admin/src/routes/Moderation/containers/Moderation.js index 706f7a5ee..d693863e0 100644 --- a/client/coral-admin/src/routes/Moderation/containers/Moderation.js +++ b/client/coral-admin/src/routes/Moderation/containers/Moderation.js @@ -231,28 +231,11 @@ const STATUS_CHANGED_SUBSCRIPTION = gql` username } comment { - id - status - body - created_at - action_summaries { - count - ... on FlagActionSummary { - reason - } - } - actions { - ... on FlagAction { - reason - message - user { - username - } - } - } + ...${getDefinitionName(Comment.fragments.comment)} } } } + ${Comment.fragments.comment} `; const LOAD_MORE_QUERY = gql` @@ -260,12 +243,6 @@ const LOAD_MORE_QUERY = gql` comments(query: {limit: $limit, cursor: $cursor, asset_id: $asset_id, statuses: $statuses, sort: $sort, action_type: $action_type}) { nodes { ...${getDefinitionName(Comment.fragments.comment)} - action_summaries { - count - ... on FlagActionSummary { - reason - } - } } hasNextPage startCursor diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 83886f0d1..ac2fd729d 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -31,16 +31,18 @@ const RootMutation = { stopIgnoringUser(_, {id}, {mutators: {User}}) { return wrapResponse(null)(User.stopIgnoringUser({id})); }, - setCommentStatus: async (_, {id, status}, {mutators: {Comment}, user, pubsub}) => { - const comment = await Comment.setStatus({id, status}); + setCommentStatus(_, {id, status}, {mutators: {Comment}, user, pubsub}) { + const response = Comment.setStatus({id, status}) + .then((comment) => { + if (pubsub) { - if (pubsub) { + // Publish the comment status change via the subscription. + pubsub.publish('commentStatusChanged', {user, comment}); + } + return Promise.resolve(comment); + }); - // Publish the comment status change via the subscription. - pubsub.publish('commentStatusChanged', {user, comment}); - } - - return wrapResponse(null)(comment); + return wrapResponse(null)(response); }, addTag(_, {tag}, {mutators: {Tag}}) { return wrapResponse(null)(Tag.add(tag));