Skip to content

Commit

Permalink
fix: read_all push error in socket
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed Dec 10, 2023
1 parent ac06c30 commit 04597cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/chat/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ export class ChatGateway
this.chatService.updateReadTime(inRoomDto.roomId, client.data.userId);
}

console.log(
new Date(new Date().getTime() + 9 * 9 * 60 * 1000),
' ',
inRoomDto.inRoom,
);

if (inRoomDto.inRoom) {
client.leave(`${inRoomDto.roomId}_list`);
client.join(inRoomDto.roomId);
this.server.to(inRoomDto.roomId).emit('read_all');
client.to(inRoomDto.roomId).emit('read_all');
} else {
this.server.to(inRoomDto.roomId).emit('out_room', inRoomDto.roomId);
client.leave(inRoomDto.roomId);
Expand Down Expand Up @@ -147,7 +153,7 @@ export class ChatGateway
this.server
.to(`${chatData.roomId}_list`)
.emit('new_chat', { ...addChat, read: read });
await this.chatService.pushNewChat(chatData.roomId, client.data.id);
await this.chatService.pushNewChat(chatData.roomId, client.data.userId);
}
this.server
.to(chatData.roomId)
Expand Down
7 changes: 6 additions & 1 deletion src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class ChatService {
);
}

async getOtherProfile(roomId: string, userId: number) {
async findOtherUser(roomId: string, userId: number) {
const room = await this.roomModel.findOne({
id: roomId,
'users.userId': userId,
Expand All @@ -253,6 +253,11 @@ export class ChatService {
}

const otherUser = room.users.find((user) => user.userId != userId);
return otherUser;
}

async getOtherProfile(roomId: string, userId: number) {
const otherUser = await this.findOtherUser(roomId, userId);
const userImages = await this.userService.getUserImages(otherUser.userId);
return {
...(await this.userService.getUserProfile(otherUser.userId, userImages)),
Expand Down

0 comments on commit 04597cf

Please sign in to comment.