Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sungjiwoon committed Feb 7, 2024
2 parents 1374360 + b179a94 commit c7f92ef
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public class ChatRoomController {
private final ChatRoomService chatRoomService;

//TODO ๊ฐ™์€๊ฒŒ 2๊ฐœ..? getChatRoomList์— ๋ชจ๋“  ์ •๋ณด๊ฐ€ ๋‹ค ๋‹ด๊ธฐ๋Š”๋ฐ ์™œ??

@GetMapping("/list")
public List<ChatRoomListGetResponse> getChatRoomList(
@RequestHeader("Authorization") String accessToken,
Expand All @@ -31,6 +33,4 @@ public ChatRoomListGetResponse getChatRoom(
return chatRoomService.getChatRoomInfo(accessToken, roomId);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,23 @@ public List<ChatRoomListGetResponse> getChatRoomListByHttp(Long userId, String a
List<ChatRoomListGetResponse> chatRoomListGetResponseList = mainFeignClient.getChatRoomList(accessToken);
chatRoomListGetResponseList.forEach(this::setListChatLastMessage);
chatRoomRedisRepository.initChatRoomList(userId, chatRoomListGetResponseList);
chatRoomListGetResponseList = sortChatRoomListLatest(chatRoomListGetResponseList);
return chatRoomListGetResponseList;
return sortChatRoomListLatest(chatRoomListGetResponseList);
}

public List<ChatRoomListGetResponse> getChatRoomListByUserId(Long userId) {
List<ChatRoomListGetResponse> chatRoomListGetResponseList = new ArrayList<>();

if (chatRoomRedisRepository.existChatRoomList(userId)) {
chatRoomListGetResponseList = chatRoomRedisRepository.getChatRoomList(userId);
chatRoomListGetResponseList.forEach(this::setListChatLastMessage);
}

return chatRoomListGetResponseList;
}


public List<ChatRoomListGetResponse> getChatRoomList(Long userId, String accessToken) {
Long beforeTime = System.currentTimeMillis();

List<ChatRoomListGetResponse> chatRoomListGetResponseList = null;
if (chatRoomRedisRepository.existChatRoomList(userId)) {
chatRoomListGetResponseList = chatRoomRedisRepository.getChatRoomList(userId);

// log.info("YES ChatRoom!!!!! time : {}", System.currentTimeMillis() - beforeTime);

} else {
// ์ฑ„ํŒ…๋ฐฉ์ด ๋ ˆ๋””์Šค์— ์—†์œผ๋ฉด ํŽ˜์ธ ์‚ฌ์šฉํ•ด์„œ ๋ถˆ๋Ÿฌ์˜จ๋‹ค!
chatRoomListGetResponseList = mainFeignClient.getChatRoomList(accessToken);
chatRoomRedisRepository.initChatRoomList(userId, chatRoomListGetResponseList);
// log.info("NOT ChatRoom!!!!! time : {}", System.currentTimeMillis() - beforeTime);
}

chatRoomListGetResponseList.forEach(this::setListChatLastMessage);
Expand All @@ -74,25 +61,23 @@ public List<ChatRoomListGetResponse> getChatRoomList(Long userId, String accessT
* ๋ชฝ๊ณ  ๋””๋น„์—์„œ ๋งˆ์ง€๋ง‰ ๋ฉ”์‹œ์ง€ ๊ฐ€์ ธ์™€์„œ ์ €์žฅํ•˜๋Š” ๋กœ์ง
* @param chatRoomListGetResponse
*/
private void setListChatLastMessage(ChatRoomListGetResponse chatRoomListGetResponse) {
public void setListChatLastMessage(ChatRoomListGetResponse chatRoomListGetResponse) {

// ๋ชฝ๊ณ  ๋””๋น„์—์„œ ๋งˆ์ง€๋ง‰ ๋ฉ”์‹œ์ง€ ๊ฐ€์ ธ์™€์„œ ์ €์žฅ.
String chatRoomNumber = chatRoomListGetResponse.getChatRoomNumber();

//TODO ๋ ˆ๋””์Šค์— ๋งˆ์ง€๋ง‰ ๋ฉ”์„ธ์ง€๊ฐ€ ์—†์œผ๋ฉด??
if (chatRoomRedisRepository.getLastMessage(chatRoomNumber) != null) {
chatRoomListGetResponse.updateChatMessageDto(
chatRoomRedisRepository.getLastMessage(chatRoomNumber)
chatRoomRedisRepository.getLastMessage(chatRoomNumber)
);
return;
}

ChatMessage chatMessage = chatMongoService.findLatestMessageByRoomId(chatRoomNumber);
if (chatMessage != null) {
chatRoomListGetResponse.updateChatMessageDto(
} else {
ChatMessage chatMessage = chatMongoService.findLatestMessageByRoomId(chatRoomNumber);
if (chatMessage != null) {
chatRoomListGetResponse.updateChatMessageDto(
ChatMessageDto.fromEntity(chatMessage)
);
);
}
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
public class CorsConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@Configuration
public class RedisConfig {

// yml ํŒŒ์ผ redis ์„ค์ • ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
private final RedisProperties redisProperties;
/**
* ๋‹จ์ผ Topic ์‚ฌ์šฉ์„ ์œ„ํ•œ Bean ์„ค์ •
Expand Down
41 changes: 26 additions & 15 deletions src/main/java/com/catchroom/chat/message/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.catchroom.chat.message.type.MessageType;
import com.catchroom.chat.message.type.UserIdentity;

import java.util.ArrayList;
import java.util.List;

import lombok.RequiredArgsConstructor;
Expand All @@ -26,6 +27,7 @@ public class ChatService {

/**
* destination ์ •๋ณด์—์„œ roomId ์ถ”์ถœ
* TODO ์ด๊ฑฐ ํ•„์š”??
*/
public String getRoomId(String destination) {
int lastIndex = destination.lastIndexOf('/');
Expand All @@ -44,35 +46,33 @@ public void sendChatMessage(ChatMessageDto chatMessage, String accessToken) {
Long userId = chatMessage.getUserId();
Long partnerId;

Long before = System.currentTimeMillis();

// 1. ์ฑ„ํŒ…๋ฐฉ์ด ์‚ญ์ œ๋˜๋Š” ๊ฒƒ์ด๋ผ๋ฉด delete ๋ฅผ ํ•ด์ค€๋‹ค.
if (chatMessage.getType().equals(MessageType.DELETE)) {
chatRoomService.deleteChatRoom(accessToken, chatMessage.getRoomId(), userId);
//TODO ๋ ˆ๋””์Šค์—์„œ๋„ ์‚ญ์ œ ํ•„์š”??
chatRoomRedisRepository.deleteChatRoom(userId,chatMessage.getRoomId());
}

ChatRoomListGetResponse newChatRoomListResponse = null;
if (!chatRoomRedisRepository.existChatRoom(userId, chatMessage.getRoomId())) {
newChatRoomListResponse = chatRoomService.getChatRoomInfo(accessToken, chatMessage.getRoomId());
ChatRoomListGetResponse newChatRoomList = null;
if (chatRoomRedisRepository.existChatRoom(userId, chatMessage.getRoomId())) {
newChatRoomList = chatRoomRedisRepository.getChatRoom(userId, chatMessage.getRoomId());
} else {
newChatRoomListResponse = chatRoomRedisRepository.getChatRoom(userId, chatMessage.getRoomId());
newChatRoomList = chatRoomService.getChatRoomInfo(accessToken, chatMessage.getRoomId());
}

partnerId = getPartnerId(chatMessage, newChatRoomListResponse);
partnerId = getPartnerId(chatMessage, newChatRoomList);

// 2. ์ฑ„ํŒ…๋ฐฉ ๋ฆฌ์ŠคํŠธ์— ์ƒˆ๋กœ์šด ์ฑ„ํŒ…๋ฐฉ ์ •๋ณด๊ฐ€ ์—†๋‹ค๋ฉด, ๋„ฃ์–ด์ค€๋‹ค. ๋งˆ์ง€๋ง‰ ๋ฉ”์‹œ์ง€๋„ ๊ฐ™์ด ๋‹ด๋Š”๋‹ค. ์ƒ๋Œ€๋ฐฉ ๋ ˆ๋””์Šค์—๋„ ์—…๋ฐ์ดํŠธ ํ•ด์ค€๋‹ค.
setNewChatRoomInfo(chatMessage, newChatRoomListResponse);
setNewChatRoomInfo(chatMessage, newChatRoomList);

// 3. ๋งˆ์ง€๋ง‰ ๋ฉ”์‹œ์ง€๋“ค์ด ๋‹ด๊ธด ์ฑ„ํŒ…๋ฐฉ ๋ฆฌ์ŠคํŠธ๋“ค์„ ๊ฐ€์ ธ์˜จ๋‹ค. // 4. ํŒŒํŠธ๋„ˆ ์ฑ„ํŒ…๋ฐฉ ๋ฆฌ์ŠคํŠธ๋„ ๊ฐ€์ ธ์˜จ๋‹ค. (ํŒŒํŠธ๋„ˆ๋Š” userId ๋กœ๋งŒ)
List<ChatRoomListGetResponse> chatRoomListGetResponseList = chatRoomService.getChatRoomList(userId, accessToken);
List<ChatRoomListGetResponse> partnerChatRoomGetResponseList = chatRoomService.getChatRoomListByUserId(partnerId);

List<ChatRoomListGetResponse> partnerChatRoomGetResponseList = getChatRoomListByUserId(partnerId);

// 5. ๋งˆ์ง€๋ง‰ ๋ฉ”์„ธ์ง€ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ ์ฑ„ํŒ…๋ฐฉ ๋ฆฌ์ŠคํŠธ ์ •๋ ฌ
chatRoomListGetResponseList = chatRoomService.sortChatRoomListLatest(chatRoomListGetResponseList);
partnerChatRoomGetResponseList = chatRoomService.sortChatRoomListLatest(partnerChatRoomGetResponseList);


MessageSubDto messageSubDto = MessageSubDto.builder()
.userId(userId)
.partnerId(partnerId)
Expand All @@ -81,9 +81,6 @@ public void sendChatMessage(ChatMessageDto chatMessage, String accessToken) {
.partnerList(partnerChatRoomGetResponseList)
.build();

Long after = System.currentTimeMillis() - before;
log.info("message Time : {}", after);

redisPublisher.publish(messageSubDto);
}

Expand All @@ -107,7 +104,6 @@ private void setNewChatRoomInfo(ChatMessageDto chatMessage, ChatRoomListGetRespo

newChatRoomListResponse.updateChatMessageDto(chatMessage);


/** ์ƒ๋Œ€๋ฐฉ ์ฑ„ํŒ… ๋ฆฌ์ŠคํŠธ์™€ ๋‚ด ๋ฆฌ์ŠคํŠธ ๋‘˜๋‹ค ์ฑ„ํŒ…๋ฐฉ์„ ์ €์žฅํ•œ๋‹ค. */

if (newChatRoomListResponse.getLoginUserIdentity().equals(UserIdentity.SELLER)) {
Expand All @@ -133,6 +129,21 @@ private void setNewChatRoomInfo(ChatMessageDto chatMessage, ChatRoomListGetRespo

}

// redis์—์„œ ์ฑ„ํŒ…๋ฐฉ ๋ฆฌ์ŠคํŠธ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋กœ์ง
private List<ChatRoomListGetResponse> getChatRoomListByUserId(Long userId) {
List<ChatRoomListGetResponse> chatRoomListGetResponseList = new ArrayList<>();

if (chatRoomRedisRepository.existChatRoomList(userId)) {
chatRoomListGetResponseList = chatRoomRedisRepository.getChatRoomList(userId);
for (ChatRoomListGetResponse chatRoomListGetResponse : chatRoomListGetResponseList) {
chatRoomService.setListChatLastMessage(chatRoomListGetResponse);
}
}


return chatRoomListGetResponseList;
}




Expand Down

0 comments on commit c7f92ef

Please sign in to comment.