-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* hotfix/file-profileImg-1: File presignURL ID로 가져오기 작업 - ProfileImg (#253) * Feat/single chatroom exit : 싱글 채팅방 퇴장 및 혼자 남아있을 경우 (상대방 퇴장 시)알림 구현 (#255) * feat/singleChatroom-1: 싱글 채팅방 퇴장 구현 - 기존 채팅방 퇴장은 그룹 채팅방 퇴장만 구현되어 있음 -> 싱글 채팅방 퇴장도 추가 구현 - 그룹 채팅방은 Redisson 처리한 사항이 있어 DB 저장 작업이 필수적임 -> 구별되게 그룹 채팅방 퇴장과 싱글 채팅방 퇴장을 구분 - 채팅 퇴장 시 퇴장 채팅 저장과 Redis 발행은 기존대로 유지 (채팅 보내기와 동일하게 동작함) * feat/singleChatroom-2: 채팅방 퇴장 시 혼자 남은 채팅방 알림구현 - 그룹, 싱글 알림 모두 구현 - 기존 알림 서비스와 동일 - Set의 members에서 한 명의 유저만 남아있을 경우 stream.findFirst() 사용함 - 사용자 언어설정에 따른 번역 알림 추가 * feat/singleChatroom-isRead-1: 싱글 채팅방 읽음 대상자(상대방) 읽었는지 표시 구현 (#256) * feat/singleChatroom-isRead- 1: 싱글 채팅방 읽음 대상자(상대방) 읽었는지 표시 구현 - Chat 엔티티에 해당 Boolean 값인 isOtherRead 생성 - 읽음 대상자 (상대방)이 GET :chats?chatroomId={채팅방 ID}를 하면 해당 isOtherRead를 true로 바꿔줌 * hotfix/chatroom-bookmark-individual-1: 채팅방 별 북마크 조회 가능하도록 수정 * feat/singleChatroom-isRead- 2: 싱글 채팅방 퇴장 시 알림 구현 사항 되돌리기 - 이유 : 불필요
- Loading branch information
Showing
12 changed files
with
115 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 45 additions & 17 deletions
62
src/main/java/com/dife/api/handler/NotificationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,59 @@ | ||
package com.dife.api.handler; | ||
|
||
import com.dife.api.model.Chatroom; | ||
import com.dife.api.model.ChatroomSetting; | ||
import com.dife.api.model.*; | ||
import com.dife.api.service.NotificationService; | ||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.SimpMessageSendingOperations; | ||
import org.springframework.messaging.simp.stomp.StompCommand; | ||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class NotificationHandler { | ||
|
||
private final SimpMessageSendingOperations messagingTemplate; | ||
private final NotificationService notificationService; | ||
|
||
public void isAlone(Chatroom chatroom, String sessionId) { | ||
ChatroomSetting setting = chatroom.getChatroomSetting(); | ||
if (setting.getCount() < 2) { | ||
notificate(chatroom.getId(), sessionId); | ||
} | ||
public void isAlone(Chatroom chatroom, Member exitMember) { | ||
if (chatroom.getMembers().size() < 2 && chatroom.getChatroomType() == ChatroomType.GROUP) | ||
notificate(chatroom, exitMember); | ||
} | ||
|
||
public void notificate(Long chatroomId, String sessionId) { | ||
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.MESSAGE); | ||
accessor.setSessionId(sessionId); | ||
accessor.setDestination("/sub/chatroom/" + chatroomId); | ||
messagingTemplate.convertAndSend( | ||
"/sub/chatroom/" + chatroomId, "해당 채팅방은 한 명만 남은 채팅방입니다!", accessor.getMessageHeaders()); | ||
private String translationDivide(Chatroom chatroom, String settingLanguage, Member exitMember) { | ||
|
||
String baseMessage = "📢 "; | ||
ResourceBundle resourceBundle; | ||
String chatroomName = chatroom.getName(); | ||
baseMessage += "(IN CHATROOM, " + chatroomName + ")"; | ||
resourceBundle = | ||
ResourceBundle.getBundle("notification.whenGroupChatroomAlone", Locale.getDefault()); | ||
String messageSuffix = resourceBundle.getString(settingLanguage.toUpperCase()); | ||
baseMessage += messageSuffix; | ||
return baseMessage; | ||
} | ||
|
||
public void notificate(Chatroom chatroom, Member exitMember) { | ||
|
||
Set<Member> members = chatroom.getMembers(); | ||
Member member = | ||
members.stream() | ||
.findFirst() | ||
.orElseThrow(() -> new NoSuchElementException("Member not found")); | ||
|
||
String settingLanguage = member.getSettingLanguage(); | ||
List<NotificationToken> notificationTokens = member.getNotificationTokens(); | ||
|
||
String notificationMessage = translationDivide(chatroom, settingLanguage, exitMember); | ||
|
||
for (NotificationToken notificationToken : notificationTokens) { | ||
Notification notification = new Notification(); | ||
notification.setNotificationToken(notificationToken); | ||
notification.setType(NotificationType.CHATROOM); | ||
notification.setCreated(LocalDateTime.now()); | ||
notification.setMessage(notificationMessage); | ||
notificationToken.getNotifications().add(notification); | ||
|
||
notificationService.sendPushNotification( | ||
notificationToken.getPushToken(), notification.getCreated(), notificationMessage); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
|
||
<changeSet id="add-type-column-from-chat-20240929-0630" author="suyeon"> | ||
<addColumn tableName="chat"> | ||
<column name="is_other_read" type="boolean"/> | ||
</addColumn> | ||
</changeSet> | ||
</databaseChangeLog> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/notification/whenSingleChatroomAlone.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
EN = You are the only one left in the chatroom | ||
KO = \uCC44\uD305\uBC29\uC5D0 \uD63C\uC790 \uB0A8\uC558\uC2B5\uB2C8\uB2E4 | ||
ZH = \u7684\u804A\u5929\u623F\u95F4\u91CC\u72EC\u81EA\u7559\u4E0B\u4E86 | ||
JA = \u3068\u306E\u30C1\u30E3\u30C3\u30C8\u30EB\u30FC\u30E0\u306B\u4E00\u4EBA\u3060\u3051\u6B8B\u3063\u3066\u3044\u307E\u3059 | ||
ES = \u00A1Te has quedado solo en la sala de chat con |