Skip to content

Commit

Permalink
fix: 채팅 및 채팅방 생성과 알림 순서 수정(#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
acceptor-gyu committed May 18, 2024
1 parent 15251c6 commit 33d51cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ChatRoomRepositoryImpl implements ChatRoomRepositoryCustom {
public List<ChatRoom> findAllByUserAndActiveIsTrue(User user) {

return queryFactory.selectFrom(chatRoom)
.where((chatRoom.sentUser.eq(user)
.or(chatRoom.receivedUser.eq(user))
.where((chatRoom.sender.eq(user)
.or(chatRoom.receiver.eq(user))
.and(chatRoom.active.eq(true)))
)
.fetch();
Expand Down
22 changes: 11 additions & 11 deletions be/src/main/java/yeonba/be/chatting/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private ChatRoomResponse toChatRoomResponseBy(ChatRoom chatRoom, User user) {
ChatMessage lastMessage = chatMessageQuery.findLastMessageByChatRoomId(chatRoom.getId());

return new ChatRoomResponse(chatRoom.getId(), partner.getNickname(),
partner.getProfilePhotos().get(0).getPhotoUrl(),
partner.getRepresentativeProfilePhoto(),
chatMessageQuery.countUnreadMessagesByChatRoomId(chatRoom.getId()),
lastMessage.getContent(),
lastMessage.getSentAt());
Expand All @@ -79,14 +79,14 @@ public void requestChat(long senderId, long receiverId) {
throw new GeneralException(BlockException.ALREADY_BLOCKED_USER);
}

// 비활성화된 채팅방 생성
chatRoomCommand.createChatRoom(new ChatRoom(sender, receiver));

NotificationSendEvent notificationSendEvent = new NotificationSendEvent(
NotificationType.CHATTING_REQUESTED, sender, receiver,
LocalDateTime.now());

eventPublisher.publishEvent(notificationSendEvent);

// 비활성화된 채팅방 생성
chatRoomCommand.createChatRoom(new ChatRoom(sender, receiver));
}

public void acceptRequestedChat(long userId, long notificationId) {
Expand All @@ -108,17 +108,17 @@ public void acceptRequestedChat(long userId, long notificationId) {
throw new GeneralException(NotificationException.NOT_YOUR_CHATTING_REQUEST_NOTIFICATION);
}

NotificationSendEvent notificationSendEvent = new NotificationSendEvent(
NotificationType.CHATTING_REQUEST_ACCEPTED, receiver, sender,
LocalDateTime.now());

eventPublisher.publishEvent(notificationSendEvent);

// 채팅방 활성화
ChatRoom chatRoom = chatRoomQuery.findBy(sender, receiver);
chatRoom.activeRoom();

String activeRoom = "채팅방이 활상화되었습니다.";
String activeRoom = "채팅방이 활성화되었습니다.";
chatMessageCommand.createChatMessage(new ChatMessage(chatRoom, sender, receiver, activeRoom));

NotificationSendEvent notificationSendEvent = new NotificationSendEvent(
NotificationType.CHATTING_REQUEST_ACCEPTED, receiver, sender,
LocalDateTime.now());

eventPublisher.publishEvent(notificationSendEvent);
}
}

0 comments on commit 33d51cf

Please sign in to comment.