Explorar el Código

Merge pull request #18374 from overleaf/em-chat-resolved-thread-ids

Add resolved-thread-ids endpoint to chat

GitOrigin-RevId: 211dee88707f2d7fb1c0c8805a1f6ac28dca494d
Eric Mc Sween hace 2 años
padre
commit
814b085b44

+ 10 - 0
services/chat/app/js/Features/Messages/MessageHttpController.js

@@ -69,6 +69,10 @@ export async function deleteMessage(context) {
   return await callMessageHttpController(context, _deleteMessage)
   return await callMessageHttpController(context, _deleteMessage)
 }
 }
 
 
+export async function getResolvedThreadIds(context) {
+  return await callMessageHttpController(context, _getResolvedThreadIds)
+}
+
 export async function destroyProject(context) {
 export async function destroyProject(context) {
   return await callMessageHttpController(context, _destroyProject)
   return await callMessageHttpController(context, _destroyProject)
 }
 }
@@ -161,6 +165,12 @@ const _deleteMessage = async (req, res) => {
   res.status(204)
   res.status(204)
 }
 }
 
 
+const _getResolvedThreadIds = async (req, res) => {
+  const { projectId } = req.params
+  const resolvedThreadIds = await ThreadManager.getResolvedThreadIds(projectId)
+  res.json({ resolvedThreadIds })
+}
+
 const _destroyProject = async (req, res) => {
 const _destroyProject = async (req, res) => {
   const { projectId } = req.params
   const { projectId } = req.params
   logger.debug({ projectId }, 'destroying project')
   logger.debug({ projectId }, 'destroying project')

+ 15 - 0
services/chat/app/js/Features/Threads/ThreadManager.js

@@ -109,3 +109,18 @@ export async function deleteAllThreadsInProject(projectId) {
     project_id: new ObjectId(projectId.toString()),
     project_id: new ObjectId(projectId.toString()),
   })
   })
 }
 }
+
+export async function getResolvedThreadIds(projectId) {
+  const resolvedThreadIds = await db.rooms
+    .find(
+      {
+        project_id: new ObjectId(projectId),
+        thread_id: { $exists: true },
+        resolved: { $exists: true },
+      },
+      { projection: { thread_id: 1 } }
+    )
+    .map(record => record.thread_id.toString())
+    .toArray()
+  return resolvedThreadIds
+}

+ 16 - 3
services/chat/chat.yaml

@@ -82,7 +82,7 @@ paths:
               $ref: '#/components/schemas/Message'
               $ref: '#/components/schemas/Message'
         description: |-
         description: |-
           JSON object with :
           JSON object with :
-          - user_id: Id of the user 
+          - user_id: Id of the user
           - content: Content of the message
           - content: Content of the message
   '/project/{projectId}/threads':
   '/project/{projectId}/threads':
     parameters:
     parameters:
@@ -206,7 +206,7 @@ paths:
               required:
               required:
                 - user_id
                 - user_id
         description: |-
         description: |-
-          JSON object with : 
+          JSON object with :
           - user_id: Id of the user.
           - user_id: Id of the user.
       description: Mark Thread with ThreadID and ProjectID provided owned by the user with UserID provided as resolved.
       description: Mark Thread with ThreadID and ProjectID provided owned by the user with UserID provided as resolved.
   '/project/{projectId}/thread/{threadId}/reopen':
   '/project/{projectId}/thread/{threadId}/reopen':
@@ -228,7 +228,7 @@ paths:
         '204':
         '204':
           description: No Content
           description: No Content
       description: |-
       description: |-
-        Reopen Thread with ThreadID and ProjectID provided. 
+        Reopen Thread with ThreadID and ProjectID provided.
         i.e unmark it as resolved.
         i.e unmark it as resolved.
   '/project/{projectId}/thread/{threadId}':
   '/project/{projectId}/thread/{threadId}':
     parameters:
     parameters:
@@ -249,6 +249,19 @@ paths:
         '204':
         '204':
           description: No Content
           description: No Content
       description: Delete thread with ThreadID and ProjectID provided
       description: Delete thread with ThreadID and ProjectID provided
+  '/project/{projectId}/resolved-thread-ids':
+    parameters:
+      - schema:
+          type: string
+        name: projectId
+        in: path
+        required: true
+    get:
+      summary: Get resolved thread ids
+      operationId: getResolvedThreadIds
+      responses:
+        '200':
+          description: Resolved thread ids
   '/project/{projectId}':
   '/project/{projectId}':
     parameters:
     parameters:
       - schema:
       - schema:

+ 21 - 0
services/chat/test/acceptance/js/ResolvingAThreadTests.js

@@ -38,6 +38,13 @@ describe('Resolving a thread', async function () {
       const resolvedAt = new Date(threads[threadId].resolved_at)
       const resolvedAt = new Date(threads[threadId].resolved_at)
       expect(new Date() - resolvedAt).to.be.below(1000)
       expect(new Date() - resolvedAt).to.be.below(1000)
     })
     })
+
+    it('should list the thread id in the resolved thread ids endpoint', async function () {
+      const { response, body } =
+        await ChatClient.getResolvedThreadIds(projectId)
+      expect(response.statusCode).to.equal(200)
+      expect(body.resolvedThreadIds).to.include(threadId)
+    })
   })
   })
 
 
   describe('when a thread is not resolved', async function () {
   describe('when a thread is not resolved', async function () {
@@ -58,6 +65,13 @@ describe('Resolving a thread', async function () {
       expect(response.statusCode).to.equal(200)
       expect(response.statusCode).to.equal(200)
       expect(threads[threadId].resolved).to.be.undefined
       expect(threads[threadId].resolved).to.be.undefined
     })
     })
+
+    it('should not list the thread in the resolved thread ids endpoint', async function () {
+      const { response, body } =
+        await ChatClient.getResolvedThreadIds(projectId)
+      expect(response.statusCode).to.equal(200)
+      expect(body.resolvedThreadIds).not.to.include(threadId)
+    })
   })
   })
 
 
   describe('when a thread is resolved then reopened', async function () {
   describe('when a thread is resolved then reopened', async function () {
@@ -89,5 +103,12 @@ describe('Resolving a thread', async function () {
       expect(response.statusCode).to.equal(200)
       expect(response.statusCode).to.equal(200)
       expect(threads[threadId].resolved).to.be.undefined
       expect(threads[threadId].resolved).to.be.undefined
     })
     })
+
+    it('should not list the thread in the resolved thread ids endpoint', async function () {
+      const { response, body } =
+        await ChatClient.getResolvedThreadIds(projectId)
+      expect(response.statusCode).to.equal(200)
+      expect(body.resolvedThreadIds).not.to.include(threadId)
+    })
   })
   })
 })
 })

+ 8 - 0
services/chat/test/acceptance/js/helpers/ChatClient.js

@@ -64,6 +64,14 @@ export async function resolveThread(projectId, threadId, userId) {
   })
   })
 }
 }
 
 
+export async function getResolvedThreadIds(projectId) {
+  return asyncRequest({
+    method: 'get',
+    url: `/project/${projectId}/resolved-thread-ids`,
+    json: true,
+  })
+}
+
 export async function editMessage(projectId, threadId, messageId, content) {
 export async function editMessage(projectId, threadId, messageId, content) {
   return asyncRequest({
   return asyncRequest({
     method: 'post',
     method: 'post',