mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #18374 from overleaf/em-chat-resolved-thread-ids
Add resolved-thread-ids endpoint to chat GitOrigin-RevId: 211dee88707f2d7fb1c0c8805a1f6ac28dca494d
This commit is contained in:
parent
5af6acde2b
commit
814b085b44
5 changed files with 70 additions and 3 deletions
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue