diff --git a/services/chat/app/js/Features/Messages/MessageHttpController.js b/services/chat/app/js/Features/Messages/MessageHttpController.js index 0d65a4a360..6c88b4ea3f 100644 --- a/services/chat/app/js/Features/Messages/MessageHttpController.js +++ b/services/chat/app/js/Features/Messages/MessageHttpController.js @@ -69,6 +69,10 @@ export async function deleteMessage(context) { return await callMessageHttpController(context, _deleteMessage) } +export async function getResolvedThreadIds(context) { + return await callMessageHttpController(context, _getResolvedThreadIds) +} + export async function destroyProject(context) { return await callMessageHttpController(context, _destroyProject) } @@ -161,6 +165,12 @@ const _deleteMessage = async (req, res) => { 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 { projectId } = req.params logger.debug({ projectId }, 'destroying project') diff --git a/services/chat/app/js/Features/Threads/ThreadManager.js b/services/chat/app/js/Features/Threads/ThreadManager.js index b55f564ae0..1844999a97 100644 --- a/services/chat/app/js/Features/Threads/ThreadManager.js +++ b/services/chat/app/js/Features/Threads/ThreadManager.js @@ -109,3 +109,18 @@ export async function deleteAllThreadsInProject(projectId) { 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 +} diff --git a/services/chat/chat.yaml b/services/chat/chat.yaml index a2568b0afc..b328baeced 100644 --- a/services/chat/chat.yaml +++ b/services/chat/chat.yaml @@ -82,7 +82,7 @@ paths: $ref: '#/components/schemas/Message' description: |- JSON object with : - - user_id: Id of the user + - user_id: Id of the user - content: Content of the message '/project/{projectId}/threads': parameters: @@ -206,7 +206,7 @@ paths: required: - user_id description: |- - JSON object with : + JSON object with : - user_id: Id of the user. description: Mark Thread with ThreadID and ProjectID provided owned by the user with UserID provided as resolved. '/project/{projectId}/thread/{threadId}/reopen': @@ -228,7 +228,7 @@ paths: '204': description: No Content description: |- - Reopen Thread with ThreadID and ProjectID provided. + Reopen Thread with ThreadID and ProjectID provided. i.e unmark it as resolved. '/project/{projectId}/thread/{threadId}': parameters: @@ -249,6 +249,19 @@ paths: '204': description: No Content 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}': parameters: - schema: diff --git a/services/chat/test/acceptance/js/ResolvingAThreadTests.js b/services/chat/test/acceptance/js/ResolvingAThreadTests.js index 129e362680..208d2324fd 100644 --- a/services/chat/test/acceptance/js/ResolvingAThreadTests.js +++ b/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) 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 () { @@ -58,6 +65,13 @@ describe('Resolving a thread', async function () { expect(response.statusCode).to.equal(200) 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 () { @@ -89,5 +103,12 @@ describe('Resolving a thread', async function () { expect(response.statusCode).to.equal(200) 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) + }) }) }) diff --git a/services/chat/test/acceptance/js/helpers/ChatClient.js b/services/chat/test/acceptance/js/helpers/ChatClient.js index 97c711f784..d6fc2c0997 100644 --- a/services/chat/test/acceptance/js/helpers/ChatClient.js +++ b/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) { return asyncRequest({ method: 'post',