Skip to content

Commit

Permalink
fix: socket readtime, socket nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed Nov 18, 2023
1 parent 5a0192d commit 873da6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
15 changes: 11 additions & 4 deletions src/chat/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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')
Expand Down
13 changes: 13 additions & 0 deletions src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 873da6f

Please sign in to comment.