Skip to content

Commit 2d2ea53

Browse files
committed
fix: fixed notification and event type
1 parent a20d914 commit 2d2ea53

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.chat.yourway.listener;
22

3+
import static com.chat.yourway.model.event.EventType.ONLINE;
34
import static com.chat.yourway.model.event.EventType.SUBSCRIBED;
4-
import static com.chat.yourway.model.event.EventType.UNSUBSCRIBED;
55

66
import com.chat.yourway.config.websocket.WebsocketProperties;
77
import com.chat.yourway.dto.response.LastMessageResponseDto;
@@ -46,10 +46,11 @@ public void handleWebSocketSubscribeListener(SessionSubscribeEvent event) {
4646
.getLastMessage();
4747
var contactEvent = new ContactEvent(email, getTopicId(event), SUBSCRIBED,
4848
getTimestamp(event), lastMessageDto);
49+
contactEventService.updateEventTypeByEmail(ONLINE, email);
4950
contactEventService.save(contactEvent);
5051
}
5152

52-
chatNotificationService.notifyTopicSubscribers(getTopicId(event));
53+
chatNotificationService.notifyAllWhoSubscribedToSameUserTopic(email);
5354
chatNotificationService.notifyAllWhoSubscribedToTopic(getTopicId(event));
5455

5556
} catch (NumberFormatException e) {
@@ -70,7 +71,7 @@ public void handleWebSocketUnsubscribeListener(SessionUnsubscribeEvent event) {
7071

7172
try {
7273
if (isTopicDestination(destination)) {
73-
var contactEvent = new ContactEvent(email, getTopicId(event), UNSUBSCRIBED,
74+
var contactEvent = new ContactEvent(email, getTopicId(event), ONLINE,
7475
getTimestamp(event), lastMessageDto);
7576
contactEventService.save(contactEvent);
7677
}

src/main/java/com/chat/yourway/model/event/EventType.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
public enum EventType {
44
ONLINE,
55
OFFLINE,
6-
SUBSCRIBED,
7-
UNSUBSCRIBED
6+
SUBSCRIBED
87
}

src/test/java/com/chat/yourway/unit/listener/StompSubscriptionListenerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.chat.yourway.unit.listener;
22

3+
import static com.chat.yourway.model.event.EventType.ONLINE;
34
import static com.chat.yourway.model.event.EventType.SUBSCRIBED;
4-
import static com.chat.yourway.model.event.EventType.UNSUBSCRIBED;
55
import static org.assertj.core.api.Assertions.assertThat;
66
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
77
import static org.mockito.ArgumentMatchers.anyInt;
@@ -108,7 +108,7 @@ public void handleWebSocketSubscribeListener_shouldNotifyTopicSubscribers() {
108108
stompSubscriptionListener.handleWebSocketSubscribeListener(event);
109109

110110
// Then
111-
verify(chatNotificationService, times(1)).notifyTopicSubscribers(topicId);
111+
verify(chatNotificationService, times(1)).notifyAllWhoSubscribedToSameUserTopic(email);
112112
}
113113

114114
@Test
@@ -132,7 +132,7 @@ public void handleWebSocketUnsubscribeListener_shouldSaveEvent() {
132132
assertThat(capturedEvent.getTopicId()).isEqualTo(topicId);
133133
assertThat(capturedEvent.getEmail()).isEqualTo(email);
134134
assertThat(capturedEvent.getTimestamp()).isInstanceOfAny(LocalDateTime.class);
135-
assertThat(capturedEvent.getEventType()).isEqualTo(UNSUBSCRIBED);
135+
assertThat(capturedEvent.getEventType()).isEqualTo(ONLINE);
136136
}
137137

138138
@Test

0 commit comments

Comments
 (0)