mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
fix eslint violations
GitOrigin-RevId: c2ee81487ab2fd66890ac5fda60f396bb537e0e1
This commit is contained in:
parent
c72ec548bb
commit
d56b49d529
13 changed files with 175 additions and 249 deletions
|
@ -1,7 +1,3 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -38,16 +34,16 @@ module.exports = MessageFormatter = {
|
|||
|
||||
groupMessagesByThreads(rooms, messages) {
|
||||
let room, thread
|
||||
const rooms_by_id = {}
|
||||
const roomsById = {}
|
||||
for (room of Array.from(rooms)) {
|
||||
rooms_by_id[room._id.toString()] = room
|
||||
roomsById[room._id.toString()] = room
|
||||
}
|
||||
|
||||
const threads = {}
|
||||
const getThread = function (room) {
|
||||
const thread_id = room.thread_id.toString()
|
||||
if (threads[thread_id] != null) {
|
||||
return threads[thread_id]
|
||||
const threadId = room.thread_id.toString()
|
||||
if (threads[threadId] != null) {
|
||||
return threads[threadId]
|
||||
} else {
|
||||
const thread = { messages: [] }
|
||||
if (room.resolved != null) {
|
||||
|
@ -55,13 +51,13 @@ module.exports = MessageFormatter = {
|
|||
thread.resolved_at = room.resolved.ts
|
||||
thread.resolved_by_user_id = room.resolved.user_id
|
||||
}
|
||||
threads[thread_id] = thread
|
||||
threads[threadId] = thread
|
||||
return thread
|
||||
}
|
||||
}
|
||||
|
||||
for (const message of Array.from(messages)) {
|
||||
room = rooms_by_id[message.room_id.toString()]
|
||||
room = roomsById[message.room_id.toString()]
|
||||
if (room != null) {
|
||||
thread = getThread(room)
|
||||
thread.messages.push(
|
||||
|
@ -70,8 +66,8 @@ module.exports = MessageFormatter = {
|
|||
}
|
||||
}
|
||||
|
||||
for (const thread_id in threads) {
|
||||
thread = threads[thread_id]
|
||||
for (const threadId in threads) {
|
||||
thread = threads[threadId]
|
||||
thread.messages.sort((a, b) => a.timestamp - b.timestamp)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -13,7 +8,6 @@
|
|||
*/
|
||||
let MessageHttpController
|
||||
const logger = require('@overleaf/logger')
|
||||
const metrics = require('@overleaf/metrics')
|
||||
const MessageManager = require('./MessageManager')
|
||||
const MessageFormatter = require('./MessageFormatter')
|
||||
const ThreadManager = require('../Threads/ThreadManager')
|
||||
|
@ -43,7 +37,7 @@ module.exports = MessageHttpController = {
|
|||
|
||||
sendThreadMessage(req, res, next) {
|
||||
return MessageHttpController._sendMessage(
|
||||
req.params.thread_id,
|
||||
req.params.threadId,
|
||||
req,
|
||||
res,
|
||||
next
|
||||
|
@ -51,40 +45,37 @@ module.exports = MessageHttpController = {
|
|||
},
|
||||
|
||||
getAllThreads(req, res, next) {
|
||||
const { project_id } = req.params
|
||||
logger.log({ project_id }, 'getting all threads')
|
||||
return ThreadManager.findAllThreadRooms(
|
||||
project_id,
|
||||
function (error, rooms) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
const room_ids = rooms.map(r => r._id)
|
||||
return MessageManager.findAllMessagesInRooms(
|
||||
room_ids,
|
||||
function (error, messages) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
const threads = MessageFormatter.groupMessagesByThreads(
|
||||
rooms,
|
||||
messages
|
||||
)
|
||||
return res.json(threads)
|
||||
}
|
||||
)
|
||||
const { projectId } = req.params
|
||||
logger.log({ projectId }, 'getting all threads')
|
||||
return ThreadManager.findAllThreadRooms(projectId, function (error, rooms) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
)
|
||||
const roomIds = rooms.map(r => r._id)
|
||||
return MessageManager.findAllMessagesInRooms(
|
||||
roomIds,
|
||||
function (error, messages) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
const threads = MessageFormatter.groupMessagesByThreads(
|
||||
rooms,
|
||||
messages
|
||||
)
|
||||
return res.json(threads)
|
||||
}
|
||||
)
|
||||
})
|
||||
},
|
||||
|
||||
resolveThread(req, res, next) {
|
||||
const { project_id, thread_id } = req.params
|
||||
const { user_id } = req.body
|
||||
logger.log({ user_id, project_id, thread_id }, 'marking thread as resolved')
|
||||
const { projectId, threadId } = req.params
|
||||
const { user_id: userId } = req.body
|
||||
logger.log({ userId, projectId, threadId }, 'marking thread as resolved')
|
||||
return ThreadManager.resolveThread(
|
||||
project_id,
|
||||
thread_id,
|
||||
user_id,
|
||||
projectId,
|
||||
threadId,
|
||||
userId,
|
||||
function (error) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
|
@ -95,9 +86,9 @@ module.exports = MessageHttpController = {
|
|||
}, // No content
|
||||
|
||||
reopenThread(req, res, next) {
|
||||
const { project_id, thread_id } = req.params
|
||||
logger.log({ project_id, thread_id }, 'reopening thread')
|
||||
return ThreadManager.reopenThread(project_id, thread_id, function (error) {
|
||||
const { projectId, threadId } = req.params
|
||||
logger.log({ projectId, threadId }, 'reopening thread')
|
||||
return ThreadManager.reopenThread(projectId, threadId, function (error) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
|
@ -106,45 +97,39 @@ module.exports = MessageHttpController = {
|
|||
}, // No content
|
||||
|
||||
deleteThread(req, res, next) {
|
||||
const { project_id, thread_id } = req.params
|
||||
logger.log({ project_id, thread_id }, 'deleting thread')
|
||||
const { projectId, threadId } = req.params
|
||||
logger.log({ projectId, threadId }, 'deleting thread')
|
||||
return ThreadManager.deleteThread(
|
||||
project_id,
|
||||
thread_id,
|
||||
function (error, room_id) {
|
||||
projectId,
|
||||
threadId,
|
||||
function (error, roomId) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return MessageManager.deleteAllMessagesInRoom(
|
||||
room_id,
|
||||
function (error) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return res.sendStatus(204)
|
||||
return MessageManager.deleteAllMessagesInRoom(roomId, function (error) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
)
|
||||
return res.sendStatus(204)
|
||||
})
|
||||
}
|
||||
)
|
||||
}, // No content
|
||||
|
||||
editMessage(req, res, next) {
|
||||
const { content } = req != null ? req.body : undefined
|
||||
const { project_id, thread_id, message_id } = req.params
|
||||
logger.log(
|
||||
{ project_id, thread_id, message_id, content },
|
||||
'editing message'
|
||||
)
|
||||
const { projectId, threadId, messageId } = req.params
|
||||
logger.log({ projectId, threadId, messageId, content }, 'editing message')
|
||||
return ThreadManager.findOrCreateThread(
|
||||
project_id,
|
||||
thread_id,
|
||||
projectId,
|
||||
threadId,
|
||||
function (error, room) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return MessageManager.updateMessage(
|
||||
room._id,
|
||||
message_id,
|
||||
messageId,
|
||||
content,
|
||||
Date.now(),
|
||||
function (error) {
|
||||
|
@ -159,18 +144,18 @@ module.exports = MessageHttpController = {
|
|||
},
|
||||
|
||||
deleteMessage(req, res, next) {
|
||||
const { project_id, thread_id, message_id } = req.params
|
||||
logger.log({ project_id, thread_id, message_id }, 'deleting message')
|
||||
const { projectId, threadId, messageId } = req.params
|
||||
logger.log({ projectId, threadId, messageId }, 'deleting message')
|
||||
return ThreadManager.findOrCreateThread(
|
||||
project_id,
|
||||
thread_id,
|
||||
projectId,
|
||||
threadId,
|
||||
function (error, room) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return MessageManager.deleteMessage(
|
||||
room._id,
|
||||
message_id,
|
||||
messageId,
|
||||
function (error, message) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
|
@ -182,11 +167,11 @@ module.exports = MessageHttpController = {
|
|||
)
|
||||
},
|
||||
|
||||
_sendMessage(client_thread_id, req, res, next) {
|
||||
const { user_id, content } = req != null ? req.body : undefined
|
||||
const { project_id } = req.params
|
||||
if (!ObjectId.isValid(user_id)) {
|
||||
return res.status(400).send('Invalid user_id')
|
||||
_sendMessage(clientThreadId, req, res, next) {
|
||||
const { user_id: userId, content } = req != null ? req.body : undefined
|
||||
const { projectId } = req.params
|
||||
if (!ObjectId.isValid(userId)) {
|
||||
return res.status(400).send('Invalid userId')
|
||||
}
|
||||
if (content == null) {
|
||||
return res.status(400).send('No content provided')
|
||||
|
@ -197,19 +182,19 @@ module.exports = MessageHttpController = {
|
|||
.send(`Content too long (> ${this.MAX_MESSAGE_LENGTH} bytes)`)
|
||||
}
|
||||
logger.log(
|
||||
{ client_thread_id, project_id, user_id, content },
|
||||
{ clientThreadId, projectId, userId, content },
|
||||
'new message received'
|
||||
)
|
||||
return ThreadManager.findOrCreateThread(
|
||||
project_id,
|
||||
client_thread_id,
|
||||
projectId,
|
||||
clientThreadId,
|
||||
function (error, thread) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return MessageManager.createMessage(
|
||||
thread._id,
|
||||
user_id,
|
||||
userId,
|
||||
content,
|
||||
Date.now(),
|
||||
function (error, message) {
|
||||
|
@ -217,7 +202,7 @@ module.exports = MessageHttpController = {
|
|||
return next(error)
|
||||
}
|
||||
message = MessageFormatter.formatMessageForClientSide(message)
|
||||
message.room_id = project_id
|
||||
message.room_id = projectId
|
||||
return res.status(201).send(message)
|
||||
}
|
||||
)
|
||||
|
@ -225,9 +210,9 @@ module.exports = MessageHttpController = {
|
|||
)
|
||||
},
|
||||
|
||||
_getMessages(client_thread_id, req, res, next) {
|
||||
_getMessages(clientThreadId, req, res, next) {
|
||||
let before, limit
|
||||
const { project_id } = req.params
|
||||
const { projectId } = req.params
|
||||
if ((req.query != null ? req.query.before : undefined) != null) {
|
||||
before = parseInt(req.query.before, 10)
|
||||
} else {
|
||||
|
@ -239,23 +224,23 @@ module.exports = MessageHttpController = {
|
|||
limit = MessageHttpController.DEFAULT_MESSAGE_LIMIT
|
||||
}
|
||||
logger.log(
|
||||
{ limit, before, project_id, client_thread_id },
|
||||
{ limit, before, projectId, clientThreadId },
|
||||
'get message request received'
|
||||
)
|
||||
return ThreadManager.findOrCreateThread(
|
||||
project_id,
|
||||
client_thread_id,
|
||||
projectId,
|
||||
clientThreadId,
|
||||
function (error, thread) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
const thread_object_id = thread._id
|
||||
const threadObjectId = thread._id
|
||||
logger.log(
|
||||
{ limit, before, project_id, client_thread_id, thread_object_id },
|
||||
{ limit, before, projectId, clientThreadId, threadObjectId },
|
||||
'found or created thread'
|
||||
)
|
||||
return MessageManager.getMessages(
|
||||
thread_object_id,
|
||||
threadObjectId,
|
||||
limit,
|
||||
before,
|
||||
function (error, messages) {
|
||||
|
@ -263,7 +248,7 @@ module.exports = MessageHttpController = {
|
|||
return next(error)
|
||||
}
|
||||
messages = MessageFormatter.formatMessagesForClientSide(messages)
|
||||
logger.log({ project_id, messages }, 'got messages')
|
||||
logger.log({ projectId, messages }, 'got messages')
|
||||
return res.status(200).send(messages)
|
||||
}
|
||||
)
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -17,14 +12,14 @@ const metrics = require('@overleaf/metrics')
|
|||
const logger = require('@overleaf/logger')
|
||||
|
||||
module.exports = MessageManager = {
|
||||
createMessage(room_id, user_id, content, timestamp, callback) {
|
||||
createMessage(roomId, userId, content, timestamp, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
let newMessageOpts = {
|
||||
content,
|
||||
room_id,
|
||||
user_id,
|
||||
room_id: roomId,
|
||||
user_id: userId,
|
||||
timestamp,
|
||||
}
|
||||
newMessageOpts = this._ensureIdsAreObjectIds(newMessageOpts)
|
||||
|
@ -37,11 +32,11 @@ module.exports = MessageManager = {
|
|||
})
|
||||
},
|
||||
|
||||
getMessages(room_id, limit, before, callback) {
|
||||
getMessages(roomId, limit, before, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
let query = { room_id }
|
||||
let query = { room_id: roomId }
|
||||
if (before != null) {
|
||||
query.timestamp = { $lt: before }
|
||||
}
|
||||
|
@ -53,36 +48,36 @@ module.exports = MessageManager = {
|
|||
.toArray(callback)
|
||||
},
|
||||
|
||||
findAllMessagesInRooms(room_ids, callback) {
|
||||
findAllMessagesInRooms(roomIds, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
db.messages
|
||||
.find({
|
||||
room_id: { $in: room_ids },
|
||||
room_id: { $in: roomIds },
|
||||
})
|
||||
.toArray(callback)
|
||||
},
|
||||
|
||||
deleteAllMessagesInRoom(room_id, callback) {
|
||||
deleteAllMessagesInRoom(roomId, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
db.messages.deleteMany(
|
||||
{
|
||||
room_id,
|
||||
room_id: roomId,
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
updateMessage(room_id, message_id, content, timestamp, callback) {
|
||||
updateMessage(roomId, messageId, content, timestamp, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
const query = this._ensureIdsAreObjectIds({
|
||||
_id: message_id,
|
||||
room_id,
|
||||
_id: messageId,
|
||||
room_id: roomId,
|
||||
})
|
||||
db.messages.updateOne(
|
||||
query,
|
||||
|
@ -96,13 +91,13 @@ module.exports = MessageManager = {
|
|||
)
|
||||
},
|
||||
|
||||
deleteMessage(room_id, message_id, callback) {
|
||||
deleteMessage(roomId, messageId, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
const query = this._ensureIdsAreObjectIds({
|
||||
_id: message_id,
|
||||
room_id,
|
||||
_id: messageId,
|
||||
room_id: roomId,
|
||||
})
|
||||
db.messages.deleteOne(query, callback)
|
||||
},
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -18,32 +14,32 @@ const metrics = require('@overleaf/metrics')
|
|||
module.exports = ThreadManager = {
|
||||
GLOBAL_THREAD: 'GLOBAL',
|
||||
|
||||
findOrCreateThread(project_id, thread_id, callback) {
|
||||
findOrCreateThread(projectId, threadId, callback) {
|
||||
let query, update
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
project_id = ObjectId(project_id.toString())
|
||||
if (thread_id !== ThreadManager.GLOBAL_THREAD) {
|
||||
thread_id = ObjectId(thread_id.toString())
|
||||
projectId = ObjectId(projectId.toString())
|
||||
if (threadId !== ThreadManager.GLOBAL_THREAD) {
|
||||
threadId = ObjectId(threadId.toString())
|
||||
}
|
||||
|
||||
if (thread_id === ThreadManager.GLOBAL_THREAD) {
|
||||
if (threadId === ThreadManager.GLOBAL_THREAD) {
|
||||
query = {
|
||||
project_id,
|
||||
project_id: projectId,
|
||||
thread_id: { $exists: false },
|
||||
}
|
||||
update = {
|
||||
project_id,
|
||||
project_id: projectId,
|
||||
}
|
||||
} else {
|
||||
query = {
|
||||
project_id,
|
||||
thread_id,
|
||||
project_id: projectId,
|
||||
thread_id: threadId,
|
||||
}
|
||||
update = {
|
||||
project_id,
|
||||
thread_id,
|
||||
project_id: projectId,
|
||||
thread_id: threadId,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,14 +56,14 @@ module.exports = ThreadManager = {
|
|||
)
|
||||
},
|
||||
|
||||
findAllThreadRooms(project_id, callback) {
|
||||
findAllThreadRooms(projectId, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
db.rooms
|
||||
.find(
|
||||
{
|
||||
project_id: ObjectId(project_id.toString()),
|
||||
project_id: ObjectId(projectId.toString()),
|
||||
thread_id: { $exists: true },
|
||||
},
|
||||
{
|
||||
|
@ -78,19 +74,19 @@ module.exports = ThreadManager = {
|
|||
.toArray(callback)
|
||||
},
|
||||
|
||||
resolveThread(project_id, thread_id, user_id, callback) {
|
||||
resolveThread(projectId, threadId, userId, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
db.rooms.updateOne(
|
||||
{
|
||||
project_id: ObjectId(project_id.toString()),
|
||||
thread_id: ObjectId(thread_id.toString()),
|
||||
project_id: ObjectId(projectId.toString()),
|
||||
thread_id: ObjectId(threadId.toString()),
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
resolved: {
|
||||
user_id,
|
||||
user_id: userId,
|
||||
ts: new Date(),
|
||||
},
|
||||
},
|
||||
|
@ -99,14 +95,14 @@ module.exports = ThreadManager = {
|
|||
)
|
||||
},
|
||||
|
||||
reopenThread(project_id, thread_id, callback) {
|
||||
reopenThread(projectId, threadId, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
db.rooms.updateOne(
|
||||
{
|
||||
project_id: ObjectId(project_id.toString()),
|
||||
thread_id: ObjectId(thread_id.toString()),
|
||||
project_id: ObjectId(projectId.toString()),
|
||||
thread_id: ObjectId(threadId.toString()),
|
||||
},
|
||||
{
|
||||
$unset: {
|
||||
|
@ -117,30 +113,26 @@ module.exports = ThreadManager = {
|
|||
)
|
||||
},
|
||||
|
||||
deleteThread(project_id, thread_id, callback) {
|
||||
deleteThread(projectId, threadId, callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
return this.findOrCreateThread(
|
||||
project_id,
|
||||
thread_id,
|
||||
function (error, room) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
db.rooms.deleteOne(
|
||||
{
|
||||
_id: room._id,
|
||||
},
|
||||
function (error) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
return callback(null, room._id)
|
||||
}
|
||||
)
|
||||
return this.findOrCreateThread(projectId, threadId, function (error, room) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
)
|
||||
db.rooms.deleteOne(
|
||||
{
|
||||
_id: room._id,
|
||||
},
|
||||
function (error) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
return callback(null, room._id)
|
||||
}
|
||||
)
|
||||
})
|
||||
},
|
||||
}
|
||||
;[
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -10,72 +5,71 @@
|
|||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let Router
|
||||
const MessageHttpController = require('./Features/Messages/MessageHttpController')
|
||||
const { ObjectId } = require('./mongodb')
|
||||
|
||||
module.exports = Router = {
|
||||
module.exports = {
|
||||
route(app) {
|
||||
app.param('project_id', function (req, res, next, project_id) {
|
||||
if (ObjectId.isValid(project_id)) {
|
||||
app.param('projectId', function (req, res, next, projectId) {
|
||||
if (ObjectId.isValid(projectId)) {
|
||||
return next()
|
||||
} else {
|
||||
return res.status(400).send('Invalid project_id')
|
||||
return res.status(400).send('Invalid projectId')
|
||||
}
|
||||
})
|
||||
|
||||
app.param('thread_id', function (req, res, next, thread_id) {
|
||||
if (ObjectId.isValid(thread_id)) {
|
||||
app.param('threadId', function (req, res, next, threadId) {
|
||||
if (ObjectId.isValid(threadId)) {
|
||||
return next()
|
||||
} else {
|
||||
return res.status(400).send('Invalid thread_id')
|
||||
return res.status(400).send('Invalid threadId')
|
||||
}
|
||||
})
|
||||
|
||||
// These are for backwards compatibility
|
||||
app.get(
|
||||
'/room/:project_id/messages',
|
||||
'/room/:projectId/messages',
|
||||
MessageHttpController.getGlobalMessages
|
||||
)
|
||||
app.post(
|
||||
'/room/:project_id/messages',
|
||||
'/room/:projectId/messages',
|
||||
MessageHttpController.sendGlobalMessage
|
||||
)
|
||||
|
||||
app.get(
|
||||
'/project/:project_id/messages',
|
||||
'/project/:projectId/messages',
|
||||
MessageHttpController.getGlobalMessages
|
||||
)
|
||||
app.post(
|
||||
'/project/:project_id/messages',
|
||||
'/project/:projectId/messages',
|
||||
MessageHttpController.sendGlobalMessage
|
||||
)
|
||||
|
||||
app.post(
|
||||
'/project/:project_id/thread/:thread_id/messages',
|
||||
'/project/:projectId/thread/:threadId/messages',
|
||||
MessageHttpController.sendThreadMessage
|
||||
)
|
||||
app.get('/project/:project_id/threads', MessageHttpController.getAllThreads)
|
||||
app.get('/project/:projectId/threads', MessageHttpController.getAllThreads)
|
||||
|
||||
app.post(
|
||||
'/project/:project_id/thread/:thread_id/messages/:message_id/edit',
|
||||
'/project/:projectId/thread/:threadId/messages/:messageId/edit',
|
||||
MessageHttpController.editMessage
|
||||
)
|
||||
app.delete(
|
||||
'/project/:project_id/thread/:thread_id/messages/:message_id',
|
||||
'/project/:projectId/thread/:threadId/messages/:messageId',
|
||||
MessageHttpController.deleteMessage
|
||||
)
|
||||
|
||||
app.post(
|
||||
'/project/:project_id/thread/:thread_id/resolve',
|
||||
'/project/:projectId/thread/:threadId/resolve',
|
||||
MessageHttpController.resolveThread
|
||||
)
|
||||
app.post(
|
||||
'/project/:project_id/thread/:thread_id/reopen',
|
||||
'/project/:projectId/thread/:threadId/reopen',
|
||||
MessageHttpController.reopenThread
|
||||
)
|
||||
app.delete(
|
||||
'/project/:project_id/thread/:thread_id',
|
||||
'/project/:projectId/thread/:threadId',
|
||||
MessageHttpController.deleteThread
|
||||
)
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
/* eslint-disable
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -12,7 +9,6 @@ const metrics = require('@overleaf/metrics')
|
|||
metrics.initialize('chat')
|
||||
const logger = require('@overleaf/logger')
|
||||
logger.initialize('chat')
|
||||
const Path = require('path')
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const app = express()
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -11,7 +7,6 @@
|
|||
*/
|
||||
const { ObjectId } = require('../../../app/js/mongodb')
|
||||
const { expect } = require('chai')
|
||||
const crypto = require('crypto')
|
||||
|
||||
const ChatClient = require('./helpers/ChatClient')
|
||||
const ChatApp = require('./helpers/ChatApp')
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -43,8 +39,8 @@ describe('Editing a message', function () {
|
|||
this.thread_id,
|
||||
this.message.id,
|
||||
this.new_content,
|
||||
(error, response, new_message) => {
|
||||
this.new_message = new_message
|
||||
(error, response, newMessage) => {
|
||||
this.new_message = newMessage
|
||||
expect(error).to.be.null
|
||||
expect(response.statusCode).to.equal(204)
|
||||
return done()
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -12,7 +8,6 @@
|
|||
const { ObjectId } = require('../../../app/js/mongodb')
|
||||
const { expect } = require('chai')
|
||||
const async = require('async')
|
||||
const crypto = require('crypto')
|
||||
|
||||
const ChatClient = require('./helpers/ChatClient')
|
||||
const ChatApp = require('./helpers/ChatApp')
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -12,7 +7,6 @@
|
|||
*/
|
||||
const { ObjectId } = require('../../../app/js/mongodb')
|
||||
const { expect } = require('chai')
|
||||
const crypto = require('crypto')
|
||||
|
||||
const ChatClient = require('./helpers/ChatClient')
|
||||
const ChatApp = require('./helpers/ChatApp')
|
||||
|
@ -60,8 +54,8 @@ describe('Resolving a thread', function () {
|
|||
expect(threads[this.thread_id].resolved_by_user_id).to.equal(
|
||||
this.user_id
|
||||
)
|
||||
const resolved_at = new Date(threads[this.thread_id].resolved_at)
|
||||
expect(new Date() - resolved_at).to.be.below(1000)
|
||||
const resolvedAt = new Date(threads[this.thread_id].resolved_at)
|
||||
expect(new Date() - resolvedAt).to.be.below(1000)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
no-return-assign,
|
||||
node/no-deprecated-api,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -122,7 +117,7 @@ describe('Sending a message', function () {
|
|||
(error, response, body) => {
|
||||
if (error) return done(error)
|
||||
expect(response.statusCode).to.equal(400)
|
||||
expect(body).to.equal('Invalid user_id')
|
||||
expect(body).to.equal('Invalid userId')
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
@ -139,7 +134,7 @@ describe('Sending a message', function () {
|
|||
(error, response, body) => {
|
||||
if (error) return done(error)
|
||||
expect(response.statusCode).to.equal(400)
|
||||
expect(body).to.equal('Invalid project_id')
|
||||
expect(body).to.equal('Invalid projectId')
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
@ -156,7 +151,7 @@ describe('Sending a message', function () {
|
|||
(error, response, body) => {
|
||||
if (error) return done(error)
|
||||
expect(response.statusCode).to.equal(400)
|
||||
expect(body).to.equal('Invalid thread_id')
|
||||
expect(body).to.equal('Invalid threadId')
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
|
@ -14,12 +10,12 @@ const request = require('request').defaults({
|
|||
})
|
||||
|
||||
module.exports = {
|
||||
sendGlobalMessage(project_id, user_id, content, callback) {
|
||||
sendGlobalMessage(projectId, userId, content, callback) {
|
||||
return request.post(
|
||||
{
|
||||
url: `/project/${project_id}/messages`,
|
||||
url: `/project/${projectId}/messages`,
|
||||
json: {
|
||||
user_id,
|
||||
user_id: userId,
|
||||
content,
|
||||
},
|
||||
},
|
||||
|
@ -27,22 +23,22 @@ module.exports = {
|
|||
)
|
||||
},
|
||||
|
||||
getGlobalMessages(project_id, callback) {
|
||||
getGlobalMessages(projectId, callback) {
|
||||
return request.get(
|
||||
{
|
||||
url: `/project/${project_id}/messages`,
|
||||
url: `/project/${projectId}/messages`,
|
||||
json: true,
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
sendMessage(project_id, thread_id, user_id, content, callback) {
|
||||
sendMessage(projectId, threadId, userId, content, callback) {
|
||||
return request.post(
|
||||
{
|
||||
url: `/project/${project_id}/thread/${thread_id}/messages`,
|
||||
url: `/project/${projectId}/thread/${threadId}/messages`,
|
||||
json: {
|
||||
user_id,
|
||||
user_id: userId,
|
||||
content,
|
||||
},
|
||||
},
|
||||
|
@ -50,50 +46,50 @@ module.exports = {
|
|||
)
|
||||
},
|
||||
|
||||
getThreads(project_id, callback) {
|
||||
getThreads(projectId, callback) {
|
||||
return request.get(
|
||||
{
|
||||
url: `/project/${project_id}/threads`,
|
||||
url: `/project/${projectId}/threads`,
|
||||
json: true,
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
resolveThread(project_id, thread_id, user_id, callback) {
|
||||
resolveThread(projectId, threadId, userId, callback) {
|
||||
return request.post(
|
||||
{
|
||||
url: `/project/${project_id}/thread/${thread_id}/resolve`,
|
||||
url: `/project/${projectId}/thread/${threadId}/resolve`,
|
||||
json: {
|
||||
user_id,
|
||||
user_id: userId,
|
||||
},
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
reopenThread(project_id, thread_id, callback) {
|
||||
reopenThread(projectId, threadId, callback) {
|
||||
return request.post(
|
||||
{
|
||||
url: `/project/${project_id}/thread/${thread_id}/reopen`,
|
||||
url: `/project/${projectId}/thread/${threadId}/reopen`,
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
deleteThread(project_id, thread_id, callback) {
|
||||
deleteThread(projectId, threadId, callback) {
|
||||
return request.del(
|
||||
{
|
||||
url: `/project/${project_id}/thread/${thread_id}`,
|
||||
url: `/project/${projectId}/thread/${threadId}`,
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
editMessage(project_id, thread_id, message_id, content, callback) {
|
||||
editMessage(projectId, threadId, messageId, content, callback) {
|
||||
return request.post(
|
||||
{
|
||||
url: `/project/${project_id}/thread/${thread_id}/messages/${message_id}/edit`,
|
||||
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
||||
json: {
|
||||
content,
|
||||
},
|
||||
|
@ -102,10 +98,10 @@ module.exports = {
|
|||
)
|
||||
},
|
||||
|
||||
deleteMessage(project_id, thread_id, message_id, callback) {
|
||||
deleteMessage(projectId, threadId, messageId, callback) {
|
||||
return request.del(
|
||||
{
|
||||
url: `/project/${project_id}/thread/${thread_id}/messages/${message_id}`,
|
||||
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}`,
|
||||
},
|
||||
callback
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue