Skip to content

Commit

Permalink
feat(chat): enable review and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanChain authored and HolgerHuo committed Oct 16, 2024
1 parent a2184fa commit 5dc6e29
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 1 deletion.
134 changes: 134 additions & 0 deletions services/web/app/src/Features/Chat/ChatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,138 @@ module.exports = ChatController = {
}
)
},

sendComment(req, res, next) {
const { project_id: projectId, thread_id: threadId } = req.params
const { content, client_id: clientId } = req.body
const userId = SessionManager.getLoggedInUserId(req.session)
if (userId == null) {
const err = new Error('no logged-in user')
return next(err)
}
return ChatApiHandler.sendComment(
projectId,
threadId,
userId,
content,
function (err, message) {
if (err != null) {
return next(err)
}
return UserInfoManager.getPersonalInfo(
message.user_id,
function (err, user) {
if (err != null) {
return next(err)
}
message.user = UserInfoController.formatPersonalInfo(user)
message.clientId = clientId
EditorRealTimeController.emitToRoom(
projectId,
'new-comment',
threadId,
message
)
return res.sendStatus(204)
}
)
}
)
},

editMessage(req, res, next) {
const { project_id: projectId, thread_id: threadId, message_id: messageId } = req.params
const { content, client_id: clientId } = req.body
const userId = SessionManager.getLoggedInUserId(req.session)
if (userId == null) {
const err = new Error('no logged-in user')
return next(err)
}
return ChatApiHandler.editMessage(
projectId,
threadId,
messageId,
userId,
content,
function (err) {
if (err != null) {
return next(err)
}
EditorRealTimeController.emitToRoom(
projectId,
'edit-message',
threadId,
messageId,
content
)
return res.sendStatus(204)
}
)
},

deleteMessage(req, res, next) {
const { project_id: projectId, thread_id: threadId, message_id: messageId } = req.params
const { content, client_id: clientId } = req.body
const userId = SessionManager.getLoggedInUserId(req.session)
if (userId == null) {
const err = new Error('no logged-in user')
return next(err)
}
return ChatApiHandler.deleteMessage(
projectId,
threadId,
messageId,
function (err) {
if (err != null) {
return next(err)
}
return res.sendStatus(204)
}
)
},

getThreads(req, res, next) {
const { project_id: projectId } = req.params
const { query } = req
return ChatApiHandler.getThreads(
projectId,
query.limit,
query.before,
function (err, threads) {
if (err != null) {
return next(err)
}
return ChatManager.injectUserInfoIntoThreads(
threads,
function (err) {
if (err != null) {
return next(err)
}
return res.json(threads)
}
)
}
)
},

resolveThread(req, res, next) {
const { project_id: projectId, thread_id: threadId } = req.params
const { client_id: clientId } = req.body
const userId = SessionManager.getLoggedInUserId(req.session)
if (userId == null) {
const err = new Error('no logged-in user')
return next(err)
}
return ChatApiHandler.resolveThread(
projectId,
threadId,
userId,
function (err) {
if (err != null) {
return next(err)
}
return res.sendStatus(204)
}
)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function mergeDeletedDocs(a, b) {
}

module.exports = ProjectEditorHandler = {
trackChangesAvailable: false,
trackChangesAvailable: true,

buildProjectModelView(project, members, invites, deletedDocsFromDocstore) {
let owner, ownerFeatures
Expand Down
34 changes: 34 additions & 0 deletions services/web/app/src/router.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,40 @@ async function initialize(webRouter, privateApiRouter, publicApiRouter) {
RateLimiterMiddleware.rateLimit(rateLimiters.sendChatMessage),
ChatController.sendMessage
)
webRouter.get(
'/project/:project_id/threads',
AuthorizationMiddleware.blockRestrictedUserFromProject,
AuthorizationMiddleware.ensureUserCanReadProject,
ChatController.getThreads
)
webRouter.post(
'/project/:project_id/thread/:thread_id/messages',
AuthorizationMiddleware.blockRestrictedUserFromProject,
AuthorizationMiddleware.ensureUserCanReadProject,
RateLimiterMiddleware.rateLimit(rateLimiters.sendChatMessage),
ChatController.sendComment
)
webRouter.delete(
'/project/:project_id/thread/:thread_id/messages/:message_id',
AuthorizationMiddleware.blockRestrictedUserFromProject,
AuthorizationMiddleware.ensureUserCanReadProject,
RateLimiterMiddleware.rateLimit(rateLimiters.sendChatMessage),
ChatController.deleteMessage
)
webRouter.post(
'/project/:project_id/thread/:thread_id/messages/:message_id/edit',
AuthorizationMiddleware.blockRestrictedUserFromProject,
AuthorizationMiddleware.ensureUserCanReadProject,
RateLimiterMiddleware.rateLimit(rateLimiters.sendChatMessage),
ChatController.editMessage
)
webRouter.post(
'/project/:project_id/doc/:doc_id/thread/:thread_id/resolve',
AuthorizationMiddleware.blockRestrictedUserFromProject,
AuthorizationMiddleware.ensureUserCanReadProject,
RateLimiterMiddleware.rateLimit(rateLimiters.sendChatMessage),
ChatController.resolveThread
)
}

webRouter.post(
Expand Down

0 comments on commit 5dc6e29

Please sign in to comment.