mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
d07a7ce4a2
Migrate chat service to OpenAPI GitOrigin-RevId: dc49c52e5e23aa6650e9a3fbe57ae6ac9be1c1da
128 lines
2.6 KiB
JavaScript
128 lines
2.6 KiB
JavaScript
import Request from 'request'
|
|
|
|
const request = Request.defaults({
|
|
baseUrl: 'http://localhost:3010',
|
|
})
|
|
|
|
async function asyncRequest(options) {
|
|
return new Promise((resolve, reject) => {
|
|
request(options, (err, response, body) => {
|
|
if (err) {
|
|
reject(err)
|
|
} else {
|
|
resolve({ response, body })
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
export async function sendGlobalMessage(projectId, userId, content) {
|
|
return asyncRequest({
|
|
method: 'post',
|
|
url: `/project/${projectId}/messages`,
|
|
json: {
|
|
user_id: userId,
|
|
content,
|
|
},
|
|
})
|
|
}
|
|
|
|
export async function getGlobalMessages(projectId) {
|
|
return asyncRequest({
|
|
method: 'get',
|
|
url: `/project/${projectId}/messages`,
|
|
json: true,
|
|
})
|
|
}
|
|
|
|
export async function sendMessage(projectId, threadId, userId, content) {
|
|
return asyncRequest({
|
|
method: 'post',
|
|
url: `/project/${projectId}/thread/${threadId}/messages`,
|
|
json: {
|
|
user_id: userId,
|
|
content,
|
|
},
|
|
})
|
|
}
|
|
|
|
export async function getThreads(projectId) {
|
|
return asyncRequest({
|
|
method: 'get',
|
|
url: `/project/${projectId}/threads`,
|
|
json: true,
|
|
})
|
|
}
|
|
|
|
export async function resolveThread(projectId, threadId, userId) {
|
|
return asyncRequest({
|
|
method: 'post',
|
|
url: `/project/${projectId}/thread/${threadId}/resolve`,
|
|
json: {
|
|
user_id: userId,
|
|
},
|
|
})
|
|
}
|
|
|
|
export async function editMessage(projectId, threadId, messageId, content) {
|
|
return asyncRequest({
|
|
method: 'post',
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
json: {
|
|
content,
|
|
},
|
|
})
|
|
}
|
|
|
|
export async function editMessageWithUser(
|
|
projectId,
|
|
threadId,
|
|
messageId,
|
|
userId,
|
|
content
|
|
) {
|
|
return asyncRequest({
|
|
method: 'post',
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
json: {
|
|
content,
|
|
userId,
|
|
},
|
|
})
|
|
}
|
|
|
|
export async function checkStatus() {
|
|
return asyncRequest({
|
|
method: 'get',
|
|
url: `/status`,
|
|
json: true,
|
|
})
|
|
}
|
|
|
|
export async function reopenThread(projectId, threadId) {
|
|
return asyncRequest({
|
|
method: 'post',
|
|
url: `/project/${projectId}/thread/${threadId}/reopen`,
|
|
})
|
|
}
|
|
|
|
export async function deleteThread(projectId, threadId) {
|
|
return asyncRequest({
|
|
method: 'delete',
|
|
url: `/project/${projectId}/thread/${threadId}`,
|
|
})
|
|
}
|
|
|
|
export async function deleteMessage(projectId, threadId, messageId) {
|
|
return asyncRequest({
|
|
method: 'delete',
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}`,
|
|
})
|
|
}
|
|
|
|
export async function destroyProject(projectId) {
|
|
return asyncRequest({
|
|
method: 'delete',
|
|
url: `/project/${projectId}`,
|
|
})
|
|
}
|