Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
94b4cd7
chore: FRONTEND_PROD_URL, BACKEND_URL, BACKEND_PROD_URL Value 추가
chuuminggg Jan 21, 2026
1284857
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Jan 23, 2026
fc5ff71
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Jan 26, 2026
2d51667
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Jan 28, 2026
b963c9f
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Feb 5, 2026
77bdf45
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Feb 5, 2026
96d87fc
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Feb 12, 2026
031791a
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Feb 13, 2026
ae81b27
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Mar 3, 2026
14350bc
Merge branch 'main' of https://github.com/SWYP-Link-it/backend
chuuminggg Mar 11, 2026
5efc1b1
refactor : message 필드 추가
chuuminggg Apr 4, 2026
3c71556
refactor : REST API 응답에 message 포함
chuuminggg Apr 4, 2026
c0c0345
refactor : 채팅 메시지 전송 시 알림 발송
chuuminggg Apr 4, 2026
972f5af
Merge branch 'main' into feature/notification/message
chuuminggg Apr 4, 2026
761d298
refactor : null 체크 변경
chuuminggg Apr 4, 2026
bf43b7e
Merge branch 'feature/notification/message' of https://github.com/SWY…
chuuminggg Apr 4, 2026
a310cb4
refactor : 중복 발송 상태 수정
chuuminggg Apr 4, 2026
720feff
fix : RedisConfig에 알림 리스너 등록
chuuminggg Apr 6, 2026
a3642c4
fix : 이미지 메시지 전송 시 ChatMessage.content NPE 발생 문제 해결
chuuminggg Apr 6, 2026
e3ed193
Merge branch 'main' of https://github.com/SWYP-Link-it/backend into f…
chuuminggg Apr 6, 2026
8c31e08
refactor : 닉네임 처리 로직 개선 및 시스템/알 수 없음 구분 (resolveNickname()으로 null/bla…
chuuminggg Apr 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.swyp.linkit.domain.chat.entity.ChatRoom;
import org.swyp.linkit.domain.chat.entity.ChatRoomDelete;
import org.swyp.linkit.domain.chat.entity.ChatRoomStatus;
import org.swyp.linkit.domain.chat.entity.MessageType;
import org.swyp.linkit.domain.chat.repository.ChatMessageRepository;
import org.swyp.linkit.domain.chat.repository.ChatRoomDeleteRepository;
import org.swyp.linkit.domain.chat.repository.ChatRoomRepository;
Expand Down Expand Up @@ -86,7 +87,7 @@ public List<ChatRoomDto> findRoomsByUserId(Long userId) {
ChatMessage lastMessage = (ChatMessage) row[1];

// 마지막 메시지 내용
String lastMessageContent = lastMessage != null ? lastMessage.getContent() : null;
String lastMessageContent = lastMessage != null ? resolveLastMessageContent(lastMessage) : null;

// 상대방 정보 (연관관계로 바로 접근)
boolean isMentor = room.getMentorId().equals(userId);
Expand Down Expand Up @@ -120,7 +121,7 @@ public ChatRoomDto findDtoById(Long roomId, Long currentUserId) {
String lastMessageContent = null;
if (room.getLastMessageId() != null) {
lastMessageContent = chatMessageRepository.findById(room.getLastMessageId())
.map(ChatMessage::getContent)
.map(this::resolveLastMessageContent)
.orElse(null);
}

Expand Down Expand Up @@ -180,6 +181,13 @@ public boolean isMentor(ChatRoom room, Long userId) {

// === Private Helper Methods ===

private String resolveLastMessageContent(ChatMessage message) {
if (message.getMessageType() == MessageType.IMAGE) {
return "[이미지]";
}
return message.getContent();
}

private User findUserById(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new UserNotFoundException("User not found: " + userId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public NotificationDto createNotification(Long receiverId, Long senderId, Notifi
Notification savedNotification = notificationRepository.save(notification);

// WebSocket 실시간 알림 발송
String senderNickname = sender != null ? sender.getNickname() : "시스템";
String senderNickname = resolveNickname(sender);
String message = generateNotificationMessage(type, senderNickname);
publishNotificationToRedis(savedNotification, senderNickname, message);

Expand Down Expand Up @@ -154,8 +154,10 @@ public NotificationListResponseDto getNotifications(Long userId) {
Map<Long, String> nicknameMap = senderIds.isEmpty()
? Collections.emptyMap()
: userRepository.findAllById(senderIds).stream()
.collect(Collectors.toMap(User::getId,
u -> u.getNickname() != null ? u.getNickname() : "시스템"));
.collect(Collectors.toMap(
User::getId,
u -> hasValidNickname(u) ? u.getNickname() : "알 수 없음",
(existing, replacement) -> existing));

List<NotificationDto> notificationDtos = combinedNotifications.stream()
.map(n -> {
Expand Down Expand Up @@ -240,6 +242,18 @@ public int markAllAsRead(Long userId) {

// ===== Private Methods =====

/**
* sender가 null이면 "시스템", 존재하지만 닉네임이 없으면 "알 수 없음"
*/
private String resolveNickname(User sender) {
if (sender == null) return "시스템";
return hasValidNickname(sender) ? sender.getNickname() : "알 수 없음";
}

private boolean hasValidNickname(User user) {
return user.getNickname() != null && !user.getNickname().isBlank();
}

private User findUserById(Long userId) {
return userRepository.findById(userId)
.orElseThrow(UserNotFoundException::new);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/swyp/linkit/global/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.swyp.linkit.domain.chat.redis.RedisChatSubscriber;
import org.swyp.linkit.domain.notification.redis.RedisNotificationSubscriber;

@Profile("!test")
@Configuration
public class RedisConfig {

private static final String CHAT_CHANNEL_PATTERN = "chat:room:*";
private static final String NOTIFICATION_CHANNEL_PATTERN = "notification:user:*";

@Bean
public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory connectionFactory) {
Expand All @@ -23,11 +25,13 @@ public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory connection
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(
RedisConnectionFactory connectionFactory,
RedisChatSubscriber redisChatSubscriber) {
RedisChatSubscriber redisChatSubscriber,
RedisNotificationSubscriber redisNotificationSubscriber) {

RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.addMessageListener(redisChatSubscriber, new PatternTopic(CHAT_CHANNEL_PATTERN));
container.addMessageListener(redisNotificationSubscriber, new PatternTopic(NOTIFICATION_CHANNEL_PATTERN));
return container;
}
}
Loading