diff --git a/src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java b/src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java index 2fae796c..bf0766cc 100644 --- a/src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java +++ b/src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java @@ -1,7 +1,7 @@ package com.chat.yourway.listener; +import static com.chat.yourway.model.event.EventType.ONLINE; import static com.chat.yourway.model.event.EventType.SUBSCRIBED; -import static com.chat.yourway.model.event.EventType.UNSUBSCRIBED; import com.chat.yourway.config.websocket.WebsocketProperties; import com.chat.yourway.dto.response.LastMessageResponseDto; @@ -46,10 +46,11 @@ public void handleWebSocketSubscribeListener(SessionSubscribeEvent event) { .getLastMessage(); var contactEvent = new ContactEvent(email, getTopicId(event), SUBSCRIBED, getTimestamp(event), lastMessageDto); + contactEventService.updateEventTypeByEmail(ONLINE, email); contactEventService.save(contactEvent); } - chatNotificationService.notifyTopicSubscribers(getTopicId(event)); + chatNotificationService.notifyAllWhoSubscribedToSameUserTopic(email); chatNotificationService.notifyAllWhoSubscribedToTopic(getTopicId(event)); } catch (NumberFormatException e) { @@ -70,7 +71,7 @@ public void handleWebSocketUnsubscribeListener(SessionUnsubscribeEvent event) { try { if (isTopicDestination(destination)) { - var contactEvent = new ContactEvent(email, getTopicId(event), UNSUBSCRIBED, + var contactEvent = new ContactEvent(email, getTopicId(event), ONLINE, getTimestamp(event), lastMessageDto); contactEventService.save(contactEvent); } diff --git a/src/main/java/com/chat/yourway/model/event/EventType.java b/src/main/java/com/chat/yourway/model/event/EventType.java index 03916f44..f72005fe 100644 --- a/src/main/java/com/chat/yourway/model/event/EventType.java +++ b/src/main/java/com/chat/yourway/model/event/EventType.java @@ -3,6 +3,5 @@ public enum EventType { ONLINE, OFFLINE, - SUBSCRIBED, - UNSUBSCRIBED + SUBSCRIBED } diff --git a/src/test/java/com/chat/yourway/unit/listener/StompSubscriptionListenerTest.java b/src/test/java/com/chat/yourway/unit/listener/StompSubscriptionListenerTest.java index 481ce221..38685b4a 100644 --- a/src/test/java/com/chat/yourway/unit/listener/StompSubscriptionListenerTest.java +++ b/src/test/java/com/chat/yourway/unit/listener/StompSubscriptionListenerTest.java @@ -1,7 +1,7 @@ package com.chat.yourway.unit.listener; +import static com.chat.yourway.model.event.EventType.ONLINE; import static com.chat.yourway.model.event.EventType.SUBSCRIBED; -import static com.chat.yourway.model.event.EventType.UNSUBSCRIBED; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.anyInt; @@ -108,7 +108,7 @@ public void handleWebSocketSubscribeListener_shouldNotifyTopicSubscribers() { stompSubscriptionListener.handleWebSocketSubscribeListener(event); // Then - verify(chatNotificationService, times(1)).notifyTopicSubscribers(topicId); + verify(chatNotificationService, times(1)).notifyAllWhoSubscribedToSameUserTopic(email); } @Test @@ -132,7 +132,7 @@ public void handleWebSocketUnsubscribeListener_shouldSaveEvent() { assertThat(capturedEvent.getTopicId()).isEqualTo(topicId); assertThat(capturedEvent.getEmail()).isEqualTo(email); assertThat(capturedEvent.getTimestamp()).isInstanceOfAny(LocalDateTime.class); - assertThat(capturedEvent.getEventType()).isEqualTo(UNSUBSCRIBED); + assertThat(capturedEvent.getEventType()).isEqualTo(ONLINE); } @Test