feat(comment): add emoji reaction support for comments (#405)

* feat(comment): add emoji reaction support for comments

* fix(webui): adjust emoji picker trigger icon size to match mark-done icon

* fix(webui): prevent search icon and placeholder overlap in emoji picker

* fix(webui): use normal text color for reaction count

* feat(db): limit comment reaction code column to VarChar(32)
This commit is contained in:
Yiling-J
2026-09-14 15:01:36 +08:00
committed by GitHub
parent ede52e5009
commit def42cd000
29 changed files with 3084 additions and 41 deletions
+58
View File
@@ -36,6 +36,7 @@ vi.mock('@shumai/core/src/authz/authz', () => ({
Asset: 'asset',
Team: 'team',
Project: 'project',
Comment: 'comment',
},
}))
@@ -65,6 +66,8 @@ describe('file api', () => {
vi.spyOn(assetService, 'createComment').mockImplementation(vi.fn())
vi.spyOn(assetService, 'completeComment').mockImplementation(vi.fn())
vi.spyOn(assetService, 'deleteComment').mockImplementation(vi.fn())
vi.spyOn(assetService, 'addCommentReaction').mockImplementation(vi.fn())
vi.spyOn(assetService, 'removeCommentReaction').mockImplementation(vi.fn())
vi.spyOn(assetService, 'getComment').mockResolvedValue({
id: 'comment1',
assetId: 'file1',
@@ -215,6 +218,7 @@ describe('file api', () => {
sessionId: null,
isCompleted: false,
completionLastChangedBy: null,
reactionCounts: [],
})
// Mock assetService.getAsset to return teamId for notification
@@ -274,6 +278,7 @@ describe('file api', () => {
sessionId: null,
isCompleted: false,
completionLastChangedBy: null,
reactionCounts: [],
})
// Mock assetService.getAsset to return teamId for notification
@@ -330,6 +335,7 @@ describe('file api', () => {
sessionId: null,
isCompleted: false,
completionLastChangedBy: null,
reactionCounts: [],
},
],
pageInfo: { cursor: 'cursor', total: 1 },
@@ -349,6 +355,7 @@ describe('file api', () => {
type: ResourceType.Asset,
id: 'test-id',
})
expect(assetService.listComments).toHaveBeenCalledWith('test-id', expect.anything(), 'user1')
})
it('POST /files/:fileId/comments/export - success', async () => {
@@ -472,6 +479,7 @@ describe('file api', () => {
sessionId: null,
isCompleted: true,
completionLastChangedBy: { id: 'user1', name: 'Test User' },
reactionCounts: [],
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
@@ -520,6 +528,56 @@ describe('file api', () => {
})
})
it('POST /comments/:commentId/reactions', async () => {
vi.mocked(assetService.addCommentReaction).mockResolvedValue(undefined)
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/comments/comment-id/reactions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ code: '👍' }),
})
expect(res.status).toBe(200)
const json = await res.json()
expect(json.success).toBe(true)
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: { id: 'user1', name: 'Test User' },
permission: Permission.Read,
type: ResourceType.Comment,
id: 'comment-id',
})
expect(assetService.addCommentReaction).toHaveBeenCalledWith('comment-id', 'user1', '👍')
})
it('DELETE /comments/:commentId/reactions', async () => {
vi.mocked(assetService.removeCommentReaction).mockResolvedValue(undefined)
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/comments/comment-id/reactions', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ code: '👍' }),
})
expect(res.status).toBe(200)
const json = await res.json()
expect(json.success).toBe(true)
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: { id: 'user1', name: 'Test User' },
permission: Permission.Read,
type: ResourceType.Comment,
id: 'comment-id',
})
expect(assetService.removeCommentReaction).toHaveBeenCalledWith('comment-id', 'user1', '👍')
})
it('POST /teams/:teamId/files - image with compression', async () => {
vi.mocked(s3Service.putObject).mockResolvedValue(undefined)
+43 -1
View File
@@ -18,6 +18,8 @@ import {
getDownloadLinksRequestSchema,
completeCommentRequestSchema,
exportCommentsRequestSchema,
addCommentReactionRequestSchema,
removeCommentReactionRequestSchema,
AuditAction,
} from '@shumai/dtos'
import { transcodeService, buildContentDisposition } from '@shumai/core'
@@ -225,7 +227,7 @@ const route = new Hono<{ Variables: { user: User } }>()
id: fileId,
})
const comments = await assetService.listComments(fileId, req)
const comments = await assetService.listComments(fileId, req, user.id)
return c.json(comments)
})
.post(
@@ -250,6 +252,46 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.body(result.content)
},
)
.post(
'/comments/:commentId/reactions',
zValidator('json', addCommentReactionRequestSchema),
async (c) => {
const commentId = c.req.param('commentId')
const user = c.get('user')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Comment,
id: commentId,
})
await assetService.addCommentReaction(commentId, user.id, req.code)
return c.json({ success: true })
},
)
.delete(
'/comments/:commentId/reactions',
zValidator('json', removeCommentReactionRequestSchema),
async (c) => {
const commentId = c.req.param('commentId')
const user = c.get('user')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Comment,
id: commentId,
})
await assetService.removeCommentReaction(commentId, user.id, req.code)
return c.json({ success: true })
},
)
.post(
'/comments/:commentId/complete',
zValidator('json', completeCommentRequestSchema),
+8 -1
View File
@@ -282,7 +282,14 @@ const route = app
await shareService.verifyPublicAccess(fileId, password)
const targetFileId = await assetService.resolveTargetAssetId(fileId)
const res = await assetService.listComments(targetFileId, req)
let userId: string | undefined
const session = await auth.api.getSession({
headers: c.req.raw.headers,
})
if (session?.user) {
userId = session.user.id
}
const res = await assetService.listComments(targetFileId, req, userId)
return c.json(res)
} catch (err) {
return handlePublicShareError(c, err)