Skip to content

Commit

Permalink
fix: 채팅 추가할 경우 채팅이 보이지 않는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Curry4182 committed Apr 11, 2024
1 parent 55cc597 commit 6457c32
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void sendExitMessageToChatRoom(final Long chatRoomId) {
);
}

@Cacheable(value = "chat", key = "#chatRoomId + '_' + #parameters.cursorId + '_' + #parameters.size")
@Cacheable(value = "chat", key = "#chatRoomId + '_' + #parameters.cursorId + '_' + #parameters.size", condition = "#parameters.cursorId != null")
public ChatGetCursorServiceResponse getChatByCursor(
final Long chatRoomId,
final CursorPageParameters parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.stereotype.Component;

import com.programmers.lime.domains.chat.model.ChatInfoWithMember;
import com.programmers.lime.redis.chat.ChatCursorCacheAppender;
import com.programmers.lime.redis.chat.model.ChatCursorCache;
import com.programmers.lime.redis.chat.publisher.IChatPublisher;
import com.programmers.lime.redis.chat.model.ChatInfoWithMemberCache;

Expand All @@ -16,6 +18,8 @@ public class ChatSendMessageEventListener {

private final IChatPublisher chatPublisher;

private final ChatCursorCacheAppender chatCursorCacheAppender;

@Async
@EventListener
public void sendMessage(final ChatSendMessageEvent event) {
Expand All @@ -26,6 +30,10 @@ public void sendMessage(final ChatSendMessageEvent event) {
);

chatPublisher.sendMessage("sub-chat", chatInfoWithMemberCache);
chatCursorCacheAppender.appendHeadNext(
event.chatInfoWithMember().chatRoomId(),
chatCursorCache(event.chatInfoWithMember())
);
}

public ChatInfoWithMemberCache chatInfoWithMember(final ChatInfoWithMember chatInfoWithMember,
Expand All @@ -42,4 +50,20 @@ public ChatInfoWithMemberCache chatInfoWithMember(final ChatInfoWithMember chatI
.destination(destination)
.build();
}

public ChatCursorCache chatCursorCache(
final ChatInfoWithMember chatInfoWithMember
) {
return ChatCursorCache.builder()
.cursorId(chatInfoWithMember.chatId().toString())
.chatId(chatInfoWithMember.chatId())
.chatRoomId(chatInfoWithMember.chatRoomId())
.memberId(chatInfoWithMember.memberId())
.nickname(chatInfoWithMember.nickname())
.profileImage(chatInfoWithMember.profileImage())
.message(chatInfoWithMember.message())
.sendAt(chatInfoWithMember.sendAt().toString())
.chatType(chatInfoWithMember.chatType().name())
.build();
}
}

0 comments on commit 6457c32

Please sign in to comment.