diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 2f92de1..ac74b57 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -131,7 +131,6 @@ export class AuthController { try { const { id, infoId, page } = req.user as SignupPayload; if (page == 16) { - // email, phoneNumber 저장 const result = await this.authService.checkComplete(id); if (!result) throw new BadRequestException('invalid info'); return res.json({ diff --git a/src/chat/chat.gateway.ts b/src/chat/chat.gateway.ts index 7a8e11b..b90a4b3 100644 --- a/src/chat/chat.gateway.ts +++ b/src/chat/chat.gateway.ts @@ -53,13 +53,13 @@ export class ChatGateway client.emit('create_room', roomId); } else { const roomId = await this.chatService.newChatRoom(users); - + const createUser = await this.chatService.findUserSocket(user); const socketUser = await this.chatService.findUserSocket(user); if (socketUser) { this.server.to(socketUser.socketId).emit('invite_chat', { roomId: roomId, - nickname: socketUser.userNickname, - sex: socketUser.userSex, + nickname: createUser.userNickname, + sex: createUser.userSex, }); } else { this.chatService.pushCreateRoom(user); @@ -86,15 +86,22 @@ export class ChatGateway @ConnectedSocket() client: Socket, @MessageBody() inRoomDto: InRoomDto, ) { + const adapter = this.server.adapter as any; + if (!inRoomDto.inRoom && adapter.rooms.get(inRoomDto.roomId).size == 2) { + this.chatService.updateAllReadTime(inRoomDto.roomId); + } else { + this.chatService.updateReadTime(inRoomDto.roomId, client.data.userId); + } + if (inRoomDto.inRoom) { client.leave(`${inRoomDto.roomId}_list`); client.join(inRoomDto.roomId); + this.server.to(inRoomDto.roomId).emit('read_all'); } else { this.server.to(inRoomDto.roomId).emit('out_room', inRoomDto.roomId); client.leave(inRoomDto.roomId); client.join(`${inRoomDto.roomId}_list`); } - this.chatService.updateReadTime(inRoomDto.roomId, client.data.userId); } @SubscribeMessage('send_chat') diff --git a/src/chat/chat.service.ts b/src/chat/chat.service.ts index 955836b..a70806f 100644 --- a/src/chat/chat.service.ts +++ b/src/chat/chat.service.ts @@ -208,6 +208,19 @@ export class ChatService { ); } + async updateAllReadTime(roomId: string) { + await this.roomModel.findOneAndUpdate( + { id: roomId }, + { + $set: { + 'users.$[].hasRead': new Date( + new Date().getTime() + 9 * 60 * 60 * 1000, + ), + }, + }, + ); + } + pushCreateRoom(userId: number) { this.fcmService.sendPush( userId,