From 78019396e2d53ec178ac39d68f0cbcc1bcb89638 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 29 Jan 2018 13:47:46 +0100 Subject: [PATCH 1/3] Use same created_at --- services/comments.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/services/comments.js b/services/comments.js index e18e04970..fd986ae3f 100644 --- a/services/comments.js +++ b/services/comments.js @@ -19,6 +19,7 @@ module.exports = class CommentsService { static async publicCreate(input) { // Extract the parent_id from the comment, if there is one. const { status = 'NONE', parent_id = null } = input; + const created_at = new Date(); // Check to see if we are replying to a comment, and if that comment is // visible. @@ -37,14 +38,14 @@ module.exports = class CommentsService { ? [ { type: status, - created_at: new Date(), + created_at, }, ] : [], body_history: [ { body: input.body, - created_at: new Date(), + created_at, }, ], }, @@ -85,6 +86,7 @@ module.exports = class CommentsService { */ static async edit({ id, author_id, body, status }) { const EDITABLE_STATUSES = ['NONE', 'PREMOD', 'ACCEPTED']; + const created_at = new Date(); const query = { id, @@ -112,11 +114,11 @@ module.exports = class CommentsService { $push: { body_history: { body, - created_at: new Date(), + created_at, }, status_history: { type: status, - created_at: new Date(), + created_at, }, }, }); @@ -160,11 +162,11 @@ module.exports = class CommentsService { editedComment.body = body; editedComment.body_history.push({ body, - created_at: new Date(), + created_at, }); editedComment.status_history.push({ type: status, - created_at: new Date(), + created_at, }); // We should adjust the comment's status such that if it was approved @@ -192,7 +194,7 @@ module.exports = class CommentsService { $push: { status_history: { type: lastUnmoderatedStatus, - created_at: new Date(), + created_at, }, }, } @@ -202,7 +204,7 @@ module.exports = class CommentsService { editedComment.status = lastUnmoderatedStatus; editedComment.status_history.push({ type: lastUnmoderatedStatus, - created_at: new Date(), + created_at, }); } } From c12fe526b824778a7aa1e23b666c38b48b4c7f17 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 29 Jan 2018 14:52:09 +0100 Subject: [PATCH 2/3] Better detect edits --- .../src/routes/Moderation/graphql.js | 20 +++++++++++++++++-- graph/typeDefs.graphql | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/routes/Moderation/graphql.js b/client/coral-admin/src/routes/Moderation/graphql.js index c542b8f84..aa6267880 100644 --- a/client/coral-admin/src/routes/Moderation/graphql.js +++ b/client/coral-admin/src/routes/Moderation/graphql.js @@ -112,6 +112,10 @@ function getOlderDate(a, b) { function determineLatestChange(comment) { let lc = null; + comment.body_history.forEach(item => { + lc = getOlderDate(lc, item.created_at); + }); + comment.status_history.forEach(item => { lc = getOlderDate(lc, item.created_at); }); @@ -124,12 +128,16 @@ function determineLatestChange(comment) { } function reconstructPreviousCommentState(comment) { - const history = comment.status_history; + const statusHistory = comment.status_history; + const bodyHistory = comment.body_history; const actions = comment.actions; const lastChangeDate = determineLatestChange(comment); const previousComment = { ...comment, - status_history: history.filter( + body_history: bodyHistory.filter( + item => new Date(item.created_at) < lastChangeDate + ), + status_history: statusHistory.filter( item => new Date(item.created_at) < lastChangeDate ), actions: actions.filter(item => new Date(item.created_at) < lastChangeDate), @@ -145,6 +153,9 @@ function reconstructPreviousCommentState(comment) { previousComment.status_history.length - 1 ].type; + previousComment.body = + previousComment.body_history[previousComment.body_history.length - 1].body; + return previousComment; } @@ -383,6 +394,11 @@ export function handleIndicatorChange(root, comment, queueConfig) { export const subscriptionFields = ` status + body + body_history { + body + created_at + } actions { __typename created_at diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 550856082..cec8e0015 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -453,6 +453,11 @@ type EditInfo { editableUntil: Date } +type CommentBodyHistory { + body: String! + created_at: Date! +} + type CommentStatusHistory { type: COMMENT_STATUS! created_at: Date! @@ -471,6 +476,9 @@ type Comment { # The actual comment data. body: String! + # The body history of the comment. + body_history: [CommentBodyHistory!]! + # the tags on the comment tags: [TagLink!] From 2bfa99fa1a9ad73da822b7f2cbd1644e3217927f Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 29 Jan 2018 14:52:26 +0100 Subject: [PATCH 3/3] Remove unused proptype --- client/coral-admin/src/routes/Configure/components/Configure.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/coral-admin/src/routes/Configure/components/Configure.js b/client/coral-admin/src/routes/Configure/components/Configure.js index 2b3e44f1e..f81bf7735 100644 --- a/client/coral-admin/src/routes/Configure/components/Configure.js +++ b/client/coral-admin/src/routes/Configure/components/Configure.js @@ -86,7 +86,6 @@ export default class Configure extends Component { } Configure.propTypes = { - notify: PropTypes.func.isRequired, savePending: PropTypes.func.isRequired, auth: PropTypes.object.isRequired, data: PropTypes.object.isRequired,