Просмотр исходного кода

Merge pull request #18506 from overleaf/em-revert-web-resolved-comment-ids

Revert #18398 - return resolved commentIds with getDocument()

GitOrigin-RevId: c5d2dd91d02d88029eb2702d73ac37cb8dbca32c
Eric Mc Sween 2 лет назад
Родитель
Сommit
ea8f8d0651

+ 6 - 6
libraries/fetch-utils/index.js

@@ -9,8 +9,8 @@ const https = require('https')
  * Make a request and return the parsed JSON response.
  *
  * @param {string | URL} url - request URL
- * @param {any} [opts] - fetch options
- * @return {Promise<any>} the parsed JSON response
+ * @param {object} opts - fetch options
+ * @return {Promise<object>} the parsed JSON response
  * @throws {RequestFailedError} if the response has a failure status code
  */
 async function fetchJson(url, opts = {}) {
@@ -39,7 +39,7 @@ async function fetchJsonWithResponse(url, opts = {}) {
  * If the response body is destroyed, the request is aborted.
  *
  * @param {string | URL} url - request URL
- * @param {any} [opts] - fetch options
+ * @param {object} opts - fetch options
  * @return {Promise<Readable>}
  * @throws {RequestFailedError} if the response has a failure status code
  */
@@ -67,7 +67,7 @@ async function fetchStreamWithResponse(url, opts = {}) {
  * Make a request and discard the response.
  *
  * @param {string | URL} url - request URL
- * @param {any} [opts] - fetch options
+ * @param {object} opts - fetch options
  * @return {Promise<Response>}
  * @throws {RequestFailedError} if the response has a failure status code
  */
@@ -86,7 +86,7 @@ async function fetchNothing(url, opts = {}) {
  * Make a request and extract the redirect from the response.
  *
  * @param {string | URL} url - request URL
- * @param {any} [opts] - fetch options
+ * @param {object} opts - fetch options
  * @return {Promise<string>}
  * @throws {RequestFailedError} if the response has a non redirect status code or missing Location header
  */
@@ -115,7 +115,7 @@ async function fetchRedirect(url, opts = {}) {
  * Make a request and return a string.
  *
  * @param {string | URL} url - request URL
- * @param {any} [opts] - fetch options
+ * @param {object} opts - fetch options
  * @return {Promise<string>}
  * @throws {RequestFailedError} if the response has a failure status code
  */

+ 0 - 9
services/web/app/src/Features/Chat/ChatApiHandler.js

@@ -90,13 +90,6 @@ async function deleteMessage(projectId, threadId, messageId) {
   )
 }
 
-async function getResolvedThreadIds(projectId) {
-  const body = await fetchJson(
-    chatApiUrl(`/project/${projectId}/resolved-thread-ids`)
-  )
-  return body.resolvedThreadIds
-}
-
 function chatApiUrl(path) {
   return new URL(path, settings.apis.chat.internal_url)
 }
@@ -112,7 +105,6 @@ module.exports = {
   deleteThread: callbackify(deleteThread),
   editMessage: callbackify(editMessage),
   deleteMessage: callbackify(deleteMessage),
-  getResolvedThreadIds: callbackify(getResolvedThreadIds),
   promises: {
     getThreads,
     destroyProject,
@@ -124,6 +116,5 @@ module.exports = {
     deleteThread,
     editMessage,
     deleteMessage,
-    getResolvedThreadIds,
   },
 }

+ 0 - 13
services/web/app/src/Features/Documents/DocumentController.js

@@ -1,4 +1,3 @@
-const ChatApiHandler = require('../Chat/ChatApiHandler')
 const ProjectGetter = require('../Project/ProjectGetter')
 const ProjectLocator = require('../Project/ProjectLocator')
 const ProjectEntityHandler = require('../Project/ProjectEntityHandler')
@@ -32,17 +31,6 @@ async function getDocument(req, res) {
     { peek }
   )
 
-  const resolvedCommentIdsInProject =
-    await ChatApiHandler.promises.getResolvedThreadIds(projectId)
-
-  const commentIdsInDoc = new Set(
-    ranges.comments?.map(comment => comment.id) ?? []
-  )
-
-  const resolvedCommentIds = resolvedCommentIdsInProject.filter(commentId =>
-    commentIdsInDoc.has(commentId)
-  )
-
   if (plain) {
     plainTextResponse(res, lines.join('\n'))
   } else {
@@ -65,7 +53,6 @@ async function getDocument(req, res) {
       projectHistoryId,
       projectHistoryType,
       historyRangesSupport,
-      resolvedCommentIds,
     })
   }
 }

+ 12 - 41
services/web/test/unit/src/Documents/DocumentControllerTests.js

@@ -15,26 +15,7 @@ describe('DocumentController', function () {
     this.doc = { _id: 'doc-id-123' }
     this.doc_lines = ['one', 'two', 'three']
     this.version = 42
-    this.ranges = {
-      comments: [
-        {
-          id: 'comment1',
-          op: {
-            c: 'foo',
-            p: 123,
-            t: 'comment1',
-          },
-        },
-        {
-          id: 'comment2',
-          op: {
-            c: 'bar',
-            p: 456,
-            t: 'comment2',
-          },
-        },
-      ],
-    }
+    this.ranges = { mock: 'ranges' }
     this.pathname = '/a/b/c/file.tex'
     this.lastUpdatedAt = new Date().getTime()
     this.lastUpdatedBy = 'fake-last-updater-id'
@@ -48,10 +29,6 @@ describe('DocumentController', function () {
         },
       },
     }
-    this.resolvedThreadIds = [
-      'comment2',
-      'comment4', // Comment in project but not in doc
-    ]
 
     this.ProjectGetter = {
       promises: {
@@ -81,12 +58,6 @@ describe('DocumentController', function () {
       },
     }
 
-    this.ChatApiHandler = {
-      promises: {
-        getResolvedThreadIds: sinon.stub().resolves(this.resolvedThreadIds),
-      },
-    }
-
     this.DocumentController = SandboxedModule.require(MODULE_PATH, {
       requires: {
         '../Project/ProjectGetter': this.ProjectGetter,
@@ -94,7 +65,6 @@ describe('DocumentController', function () {
         '../Project/ProjectEntityHandler': this.ProjectEntityHandler,
         '../Project/ProjectEntityUpdateHandler':
           this.ProjectEntityUpdateHandler,
-        '../Chat/ChatApiHandler': this.ChatApiHandler,
       },
     })
   })
@@ -117,16 +87,17 @@ describe('DocumentController', function () {
 
       it('should return the history id and display setting to the client as JSON', function () {
         this.res.type.should.equal('application/json')
-        JSON.parse(this.res.body).should.deep.equal({
-          lines: this.doc_lines,
-          version: this.version,
-          ranges: this.ranges,
-          pathname: this.pathname,
-          projectHistoryId: this.project.overleaf.history.id,
-          projectHistoryType: 'project-history',
-          resolvedCommentIds: ['comment2'],
-          historyRangesSupport: false,
-        })
+        this.res.body.should.equal(
+          JSON.stringify({
+            lines: this.doc_lines,
+            version: this.version,
+            ranges: this.ranges,
+            pathname: this.pathname,
+            projectHistoryId: this.project.overleaf.history.id,
+            projectHistoryType: 'project-history',
+            historyRangesSupport: false,
+          })
+        )
       })
     })