feat: chat — group settings (rename, photo, add/remove members), fix mention underline style

This commit is contained in:
2026-04-15 11:32:52 +03:00
parent 2cdc44b495
commit e6caf10a98
4 changed files with 229 additions and 17 deletions

View File

@@ -0,0 +1,2 @@
-- Group room avatar
ALTER TABLE chat_rooms ADD COLUMN IF NOT EXISTS avatar_url TEXT;

View File

@@ -79,7 +79,7 @@ const chatRoutes: FastifyPluginAsync = async (fastify) => {
const userId = request.user.sub
const { rows } = await db.query(
`SELECT r.id, r.type, r.name,
`SELECT r.id, r.type, r.name, r.avatar_url,
(SELECT COUNT(*) FROM chat_messages m
WHERE m.room_id = r.id AND m.deleted_at IS NULL
AND m.created_at > COALESCE(
@@ -367,7 +367,7 @@ const chatRoutes: FastifyPluginAsync = async (fastify) => {
// ── PATCH group room (rename / add/remove members) ────────────────────────
fastify.patch<RoomParam & { Body: { name?: string; addMemberIds?: string[]; removeMemberIds?: string[] } }>(
fastify.patch<RoomParam & { Body: { name?: string; avatarUrl?: string; avatar_url?: string; addMemberIds?: string[]; add_member_ids?: string[]; removeMemberIds?: string[]; remove_member_ids?: string[] } }>(
'/api/hotels/:slug/chat/rooms/:roomId/group',
{ onRequest: [fastify.authenticate] },
async (request, reply) => {
@@ -375,10 +375,20 @@ const chatRoutes: FastifyPluginAsync = async (fastify) => {
if (!canAccess(request.user.hotelSlug, request.user.role, slug))
return reply.code(403).send({ error: 'Forbidden' })
const { name, addMemberIds = [], removeMemberIds = [] } = request.body
const b = request.body as Record<string, unknown>
const name = b.name as string | undefined
const avatarUrl = (b.avatar_url ?? b.avatarUrl) as string | undefined
const addMemberIds: string[] = Array.isArray(b.add_member_ids) ? b.add_member_ids as string[]
: Array.isArray(b.addMemberIds) ? b.addMemberIds as string[] : []
const removeMemberIds: string[] = Array.isArray(b.remove_member_ids) ? b.remove_member_ids as string[]
: Array.isArray(b.removeMemberIds) ? b.removeMemberIds as string[] : []
if (name) {
await db.query('UPDATE chat_rooms SET name = $1 WHERE id = $2', [name.trim(), roomId])
}
if (avatarUrl !== undefined) {
await db.query('UPDATE chat_rooms SET avatar_url = $1 WHERE id = $2', [avatarUrl || null, roomId])
}
if (addMemberIds.length > 0) {
const vals = addMemberIds.map((_, i) => `($1, $${i + 2})`).join(', ')
await db.query(