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, 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!] diff --git a/services/comments.js b/services/comments.js index a71afd92b..68f991324 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, }); await events.emitAsync(COMMENTS_EDIT, originalComment, editedComment);