diff --git a/services/project-history/app/js/UpdateTranslator.js b/services/project-history/app/js/UpdateTranslator.js index 1c6834d330..04841f848c 100644 --- a/services/project-history/app/js/UpdateTranslator.js +++ b/services/project-history/app/js/UpdateTranslator.js @@ -297,16 +297,19 @@ class OperationsBuilder { ts: new Date(update.meta.ts).toISOString(), }, }) - } else if (update.meta.tc != null) { - this.insert(op.i, { - tracking: { + } else { + const opts = {} + if (update.meta.tc != null) { + opts.tracking = { type: 'insert', userId: update.meta.user_id, ts: new Date(update.meta.ts).toISOString(), - }, - }) - } else { - this.insert(op.i) + } + } + if (op.commentIds != null) { + opts.commentIds = op.commentIds + } + this.insert(op.i, opts) } } @@ -395,9 +398,10 @@ class OperationsBuilder { * @param {string} str * @param {object} opts * @param {TrackingProps} [opts.tracking] + * @param {string[]} [opts.commentIds] */ insert(str, opts = {}) { - if (opts.tracking) { + if (opts.tracking || opts.commentIds) { this.textOperation.push({ i: str, ...opts }) } else { this.textOperation.push(str) diff --git a/services/project-history/app/js/types.ts b/services/project-history/app/js/types.ts index 5d3365251f..91d1ea6bcf 100644 --- a/services/project-history/app/js/types.ts +++ b/services/project-history/app/js/types.ts @@ -1,4 +1,9 @@ -export type Update = TextUpdate | AddDocUpdate | AddFileUpdate | RenameUpdate | DeleteCommentUpdate +export type Update = + | TextUpdate + | AddDocUpdate + | AddFileUpdate + | RenameUpdate + | DeleteCommentUpdate export type UpdateMeta = { user_id: string @@ -57,6 +62,7 @@ export type InsertOp = { u?: boolean hpos?: number trackedDeleteRejection?: boolean + commentIds?: string[] } export type DeleteOp = { diff --git a/services/project-history/test/unit/js/UpdateTranslator/UpdateTranslatorTests.js b/services/project-history/test/unit/js/UpdateTranslator/UpdateTranslatorTests.js index ba9a064320..2b994539d5 100644 --- a/services/project-history/test/unit/js/UpdateTranslator/UpdateTranslatorTests.js +++ b/services/project-history/test/unit/js/UpdateTranslator/UpdateTranslatorTests.js @@ -476,7 +476,7 @@ describe('UpdateTranslator', function () { doc: this.doc_id, op: [ { p: 3, i: 'foo' }, - { p: 15, i: 'bar' }, + { p: 15, i: 'bar', commentIds: ['comment1'] }, ], v: this.version, meta: { @@ -501,7 +501,13 @@ describe('UpdateTranslator', function () { operations: [ { pathname: 'main.tex', - textOperation: [3, 'foo', 9, 'bar', 8], + textOperation: [ + 3, + 'foo', + 9, + { i: 'bar', commentIds: ['comment1'] }, + 8, + ], }, ], v2Authors: [this.user_id],