From ed8fb7fe0209b6180222969c336fac0faa40cfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=AA=E1=86=BC=E1=84=92?= =?UTF-8?q?=E1=85=AE=E1=86=AB?= Date: Sun, 10 Dec 2023 20:24:11 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[BE]=20Feat=20:=20=ED=98=84=EC=9E=AC=20?= =?UTF-8?q?=EC=95=88=20=EC=9D=BD=EC=9D=80=20=EC=B1=84=ED=8C=85=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/chat/chat.controller.ts | 6 ++++ BE/src/chat/chat.service.ts | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/BE/src/chat/chat.controller.ts b/BE/src/chat/chat.controller.ts index 6c0c546..dc5631e 100644 --- a/BE/src/chat/chat.controller.ts +++ b/BE/src/chat/chat.controller.ts @@ -49,6 +49,12 @@ export class ChatController { } } + @Get('unread') + @UseGuards(AuthGuard) + async unreadChat(@UserHash() userId: string) { + return await this.chatService.unreadChat(userId); + } + @Get() async testPush(@Body() body) { await this.fcmHandler.sendPush(body.user, { diff --git a/BE/src/chat/chat.service.ts b/BE/src/chat/chat.service.ts index 7f3f0ca..3c60664 100644 --- a/BE/src/chat/chat.service.ts +++ b/BE/src/chat/chat.service.ts @@ -151,6 +151,61 @@ export class ChatService { return chatListInfo; } + async unreadChat(userId: string) { + const subquery = this.chatRepository + .createQueryBuilder('chat') + .select('chat.id', 'id') + .addSelect('chat.chat_room', 'chat_room') + .addSelect('chat.message', 'message') + .addSelect('chat.create_date', 'create_date') + .addSelect('chat.is_read', 'is_read') + .addSelect('chat.sender', 'sender') + .where( + 'chat.id IN (SELECT MAX(chat.id) FROM chat GROUP BY chat.chat_room)', + ); + + const rooms = await this.chatRoomRepository + .createQueryBuilder('chat_room') + .innerJoin( + '(' + subquery.getQuery() + ')', + 'chat_info', + 'chat_room.id = chat_info.chat_room', + ) + .leftJoin( + 'chat_room.writerUser', + 'writer', + 'chat_room.writerUser = writer.user_hash', + ) + .leftJoin( + 'chat_room.userUser', + 'user', + 'chat_room.userUser = user.user_hash', + ) + .select([ + 'chat_room.id as room_id', + 'chat_room.writer as writer', + 'writer.nickname as writer_nickname', + 'writer.profile_img as writer_profile_img', + 'chat_room.user as user', + 'user.nickname as user_nickname', + 'user.profile_img as user_profile_img', + 'chat_room.post_id as post_id', + 'chat_info.create_date as last_chat_date', + 'chat_info.message as last_chat', + 'chat_info.is_read as is_read', + 'chat_info.sender as sender', + ]) + .getRawMany(); + + for (let room of rooms) { + if (room.sender !== userId && room.is_read === 0) { + return { all_read: false }; + } + } + + return { all_read: true }; + } + async findRoomById(roomId: number, userId: string) { await this.chatRepository .createQueryBuilder('chat') From 6d9159f02281c4fb68562c788143e52ec8d2e171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=AA=E1=86=BC=E1=84=92?= =?UTF-8?q?=E1=85=AE=E1=86=AB?= Date: Sun, 10 Dec 2023 21:06:29 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[BE]=20Fix=20:=20all=5Fread=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/chat/chat.service.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BE/src/chat/chat.service.ts b/BE/src/chat/chat.service.ts index 3c60664..6419957 100644 --- a/BE/src/chat/chat.service.ts +++ b/BE/src/chat/chat.service.ts @@ -114,7 +114,7 @@ export class ChatService { 'post.thumbnail as post_thumbnail', 'chat_info.create_date as last_chat_date', 'chat_info.message as last_chat', - 'chat_info.is_read as allread', + 'chat_info.is_read as all_read', 'chat_info.sender as sender', ]) .where('chat_room.writer = :userId', { userId: userId }) @@ -134,13 +134,13 @@ export class ChatService { : cur.user_profile_img; if (cur.sender === userId) { - cur.allread = true; + cur.all_read = true; } else { - if (cur.allread === 0) { + if (cur.all_read === 0) { chatListInfo.all_read = false; - cur.allread = false; + cur.all_read = false; } else { - cur.allread = true; + cur.all_read = true; } } delete cur.sender;