-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE/#603] 채팅방 나갔다가 들어오면 이전 채팅 안보이게 구현 #604
Changes from all commits
ca8b194
ddd94c0
474e43f
9e3755a
a57e2b6
fafefd4
de92ad7
c10de5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,9 +123,9 @@ export class ChatService { | |
'chat_info.sender as sender', | ||
]) | ||
.where('chat_room.writer = :userId', { userId: userId }) | ||
.andWhere('chat_room.writer_left IS false') | ||
.andWhere('chat_room.writer_hide IS false') | ||
.orWhere('chat_room.user = :userId', { userId: userId }) | ||
.andWhere('chat_room.user_left IS false') | ||
.andWhere('chat_room.user_hide IS false') | ||
.orderBy('chat_info.create_date', 'DESC') | ||
.getRawMany(); | ||
|
||
|
@@ -206,7 +206,7 @@ export class ChatService { | |
return { all_read: true }; | ||
} | ||
|
||
async findRoomById(roomId: number, userId: string) { | ||
async makeAllRead(roomId: number, userId: string) { | ||
await this.chatRepository | ||
.createQueryBuilder('chat') | ||
.update() | ||
|
@@ -215,15 +215,57 @@ export class ChatService { | |
.andWhere('chat.is_read = :isRead', { isRead: false }) | ||
.andWhere('chat.sender != :userId', { userId: userId }) | ||
.execute(); | ||
} | ||
|
||
const room = await this.chatRoomRepository.findOne({ | ||
/*async getRoomAndChatInfoPagination(roomId: number, chatId: number) { | ||
return await this.chatRoomRepository | ||
.createQueryBuilder('chat_room') | ||
.innerJoinAndSelect('chat_room.chats', 'chat_info') | ||
.innerJoinAndSelect('chat_room.writerUser', 'writer') | ||
.innerJoinAndSelect('chat_room.userUser', 'user') | ||
.where('chat_room.id = :roomId', { roomId: roomId }) | ||
.andWhere('chat_info.id < :chatId', { chatId: chatId }) | ||
.orderBy('chat_info.id', 'DESC') | ||
.limit(30) | ||
.getOne(); | ||
}*/ | ||
|
||
async getRoomAndChatInfo(roomId: number, userId: string) { | ||
return await this.chatRoomRepository.findOne({ | ||
where: { | ||
id: roomId, | ||
}, | ||
relations: ['chats', 'userUser', 'writerUser'], | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일단 room이 찾아 지지 않을 때의 예외처리가 없어서 삭제되거나 존재하지 않는 roomId로 접근하면 에러가 발생 할 것 같네요.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 마찬가지로 위에 update 문도 없는 방을 업데이트 하려면 예외처리가 필요할 것 같고 유저의 권한을 확인 하는 로직이 밑에 있어서 본인의 방이 아닌 경우에도 채팅 읽음 처리를 하는 문제가 생길 수도 있을 것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그러면 checkAuth 를 맨 처음으로 옮겨서 처음에 해당 방이 존재하는지와 해당 방에 존재하는 사람이 맞는지 확인 후에 아래 로직들을 실행하는 방식으로 바꾸겠습니당~ |
||
} | ||
|
||
async findRoomById(roomId: number, userId: string) { | ||
await this.makeAllRead(roomId, userId); | ||
|
||
const room = await this.getRoomAndChatInfo(roomId, userId); | ||
|
||
this.checkAuth(room, userId); | ||
|
||
let chats = room.chats; | ||
|
||
if ( | ||
room.writer === userId && | ||
room.writer_hide === false && | ||
room.writer_left_time !== null | ||
) { | ||
Comment on lines
+251
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. url 로 접근하는 부분때문인가요? 자신이 숨긴 채팅방을 url 을 통해 400 혹은 409 로 던지면 될 것 같은데 어케 생각하시나요? |
||
chats = chats.filter((chat) => { | ||
return chat.create_date > room.writer_left_time; | ||
}); | ||
} else if ( | ||
room.user === userId && | ||
room.user_hide === false && | ||
room.user_left_time !== null | ||
) { | ||
chats = chats.filter((chat) => { | ||
return chat.create_date > room.user_left_time; | ||
}); | ||
} | ||
|
||
return { | ||
writer: room.writer, | ||
writer_profile_img: | ||
|
@@ -236,7 +278,7 @@ export class ChatService { | |
? this.configService.get('DEFAULT_PROFILE_IMAGE') | ||
: room.userUser.profile_img, | ||
post_id: room.post_id, | ||
chat_log: room.chats, | ||
chat_log: chats, | ||
}; | ||
} | ||
|
||
|
@@ -245,6 +287,10 @@ export class ChatService { | |
throw new HttpException('존재하지 않는 채팅방입니다.', 404); | ||
} else if (room.writer !== userId && room.user !== userId) { | ||
throw new HttpException('권한이 없습니다.', 403); | ||
} else if (room.writer === userId && room.writer_hide === true) { | ||
throw new HttpException('숨긴 채팅방입니다.', 403); | ||
} else if (room.user === userId && room.user_hide === true) { | ||
throw new HttpException('숨긴 채팅방입니다.', 403); | ||
} | ||
} | ||
|
||
|
@@ -275,10 +321,10 @@ export class ChatService { | |
where: { id: roomId }, | ||
}); | ||
|
||
if (room.writer === userId && room.user_left !== false) { | ||
room.user_left = false; | ||
} else if (room.user === userId && room.writer_left !== false) { | ||
room.writer_left = false; | ||
if (room.writer === userId && room.user_hide !== false) { | ||
room.user_hide = false; | ||
} else if (room.user === userId && room.writer_hide !== false) { | ||
room.writer_hide = false; | ||
} | ||
await this.chatRoomRepository.save(room); | ||
} | ||
|
@@ -302,9 +348,11 @@ export class ChatService { | |
}); | ||
|
||
if (room.writer === userId) { | ||
room.writer_left = true; | ||
room.writer_hide = true; | ||
room.writer_left_time = new Date(); | ||
} else if (room.user === userId) { | ||
room.user_left = true; | ||
room.user_hide = true; | ||
room.user_left_time = new Date(); | ||
} | ||
|
||
await this.chatRoomRepository.save(room); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분 채팅 페이지네이션 미리 적용해본건데 나중에 이걸로 바꾸겠습니다