-
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.
- Loading branch information
Showing
21 changed files
with
187 additions
and
13 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
14 changes: 14 additions & 0 deletions
14
domain/src/main/kotlin/com/backgu/amaker/domain/notifiacation/ChatRoomNotification.kt
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,14 @@ | ||
package com.backgu.amaker.domain.notifiacation | ||
|
||
import com.backgu.amaker.domain.notifiacation.method.RealTimeNotificationMethod | ||
|
||
open class ChatRoomNotification( | ||
val chatRoomId: Long, | ||
override val method: RealTimeNotificationMethod, | ||
) : RealTimeBasedNotification(method) { | ||
override val keyPrefix: String | ||
get() = "CHAT_ROOM" | ||
|
||
override val keyValue: String | ||
get() = chatRoomId.toString() | ||
} |
39 changes: 39 additions & 0 deletions
39
domain/src/main/kotlin/com/backgu/amaker/domain/notifiacation/chat/NewChat.kt
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,39 @@ | ||
package com.backgu.amaker.domain.notifiacation.chat | ||
|
||
import com.backgu.amaker.domain.chat.Chat | ||
import com.backgu.amaker.domain.chat.ChatRoom | ||
import com.backgu.amaker.domain.notifiacation.ChatRoomNotification | ||
import com.backgu.amaker.domain.notifiacation.method.TemplateEmailNotificationMethod | ||
import com.backgu.amaker.domain.user.User | ||
|
||
class NewChat( | ||
chatRoom: ChatRoom, | ||
method: TemplateEmailNotificationMethod, | ||
) : ChatRoomNotification( | ||
chatRoom.id, | ||
method, | ||
) { | ||
companion object { | ||
private fun buildDetailMessage( | ||
chatRoom: ChatRoom, | ||
chat: Chat, | ||
): String = | ||
"${chatRoom.name}에 새로운 메시지가 도착했습니다.\n" + | ||
"메시지 내용: ${chat.content}" | ||
|
||
fun of( | ||
sender: User, | ||
chat: Chat, | ||
chatRoom: ChatRoom, | ||
): NewChat = | ||
NewChat( | ||
chatRoom, | ||
TemplateEmailNotificationMethod( | ||
"${sender.name}님이 보낸 메시지", | ||
chat.content, | ||
buildDetailMessage(chatRoom, chat), | ||
"chat-notification", | ||
), | ||
) | ||
} | ||
} |
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
4 changes: 1 addition & 3 deletions
4
...pa/chat/repository/ChatQueryRepository.kt → ...fra/jpa/chat/query/ChatQueryRepository.kt
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
4 changes: 1 addition & 3 deletions
4
...hat/repository/ChatQueryRepositoryImpl.kt → ...jpa/chat/query/ChatQueryRepositoryImpl.kt
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
12 changes: 12 additions & 0 deletions
12
...n/src/main/kotlin/com/backgu/amaker/notification/chatroom/config/ChatRoomServiceConfig.kt
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 @@ | ||
package com.backgu.amaker.notification.chatroom.config | ||
|
||
import com.backgu.amaker.application.chat.service.ChatRoomUserService | ||
import com.backgu.amaker.infra.jpa.chat.repository.ChatRoomUserRepository | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class ChatRoomServiceConfig { | ||
@Bean | ||
fun chatRoomUserService(chatRoomUserRepository: ChatRoomUserRepository) = ChatRoomUserService(chatRoomUserRepository) | ||
} |
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
53 changes: 53 additions & 0 deletions
53
...n/kotlin/com/backgu/amaker/notification/service/adapter/RealTimeChatRoomHandlerAdapter.kt
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,53 @@ | ||
package com.backgu.amaker.notification.service.adapter | ||
|
||
import com.backgu.amaker.application.chat.service.ChatRoomUserService | ||
import com.backgu.amaker.application.user.service.UserDeviceService | ||
import com.backgu.amaker.application.workspace.WorkspaceService | ||
import com.backgu.amaker.domain.notifiacation.ChatRoomNotification | ||
import com.backgu.amaker.domain.notifiacation.Notification | ||
import com.backgu.amaker.domain.notifiacation.method.NotificationMethod | ||
import com.backgu.amaker.domain.notifiacation.method.RealTimeNotificationMethod | ||
import com.backgu.amaker.domain.realtime.RealTimeServer | ||
import com.backgu.amaker.domain.session.Session | ||
import com.backgu.amaker.notification.realtime.handler.RealTimeHandler | ||
import com.backgu.amaker.notification.realtime.service.RealTimeService | ||
import com.backgu.amaker.notification.workspace.service.WorkspaceSessionService | ||
import org.springframework.context.ApplicationEventPublisher | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class RealTimeChatRoomHandlerAdapter( | ||
private val realTimeHandler: RealTimeHandler, | ||
private val realTimeService: RealTimeService, | ||
private val workspaceSessionService: WorkspaceSessionService, | ||
private val workspaceService: WorkspaceService, | ||
private val chatRoomUserService: ChatRoomUserService, | ||
private val userDeviceService: UserDeviceService, | ||
private val applicationEventPublisher: ApplicationEventPublisher, | ||
) : NotificationHandlerAdapter<ChatRoomNotification, RealTimeNotificationMethod> { | ||
override fun supportsNotification(notification: Notification): Boolean = notification is ChatRoomNotification | ||
|
||
override fun supportsMethod(method: NotificationMethod): Boolean = method is RealTimeNotificationMethod | ||
|
||
override fun process( | ||
notification: ChatRoomNotification, | ||
method: RealTimeNotificationMethod, | ||
) { | ||
val workspaceId: Long = workspaceService.getWorkspaceIdByChatRoomId(notification.chatRoomId) | ||
val sessions: List<Session> = workspaceSessionService.findByWorkspaceId(workspaceId) | ||
val realTimeServerSet: Set<RealTimeServer> = | ||
realTimeService.findByIdsToSet(sessions.mapTo(mutableSetOf()) { it.realtimeId }) | ||
|
||
val chatRoomUsers = chatRoomUserService.findUserIdsByChatRoomId(notification.chatRoomId) | ||
val successUsers: List<String> = | ||
realTimeServerSet | ||
.map { | ||
realTimeHandler.handleUserRealTimeNotification(chatRoomUsers, it, notification) | ||
}.flatten() | ||
|
||
val failedUsers: List<String> = chatRoomUsers.filterNot { it in successUsers } | ||
|
||
val pushNotification = notification.toPushNotification(userDeviceService.findByUserIds(failedUsers)) | ||
applicationEventPublisher.publishEvent(pushNotification) | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...lin/com/backgu/amaker/notification/service/adapter/TemplateEmailChatRoomHandlerAdapter.kt
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,27 @@ | ||
package com.backgu.amaker.notification.service.adapter | ||
|
||
import com.backgu.amaker.application.user.service.UserService | ||
import com.backgu.amaker.domain.notifiacation.ChatRoomNotification | ||
import com.backgu.amaker.domain.notifiacation.Notification | ||
import com.backgu.amaker.domain.notifiacation.method.NotificationMethod | ||
import com.backgu.amaker.domain.notifiacation.method.TemplateEmailNotificationMethod | ||
import com.backgu.amaker.notification.email.service.TemplateEmailHandler | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class TemplateEmailChatRoomHandlerAdapter( | ||
private val userService: UserService, | ||
private val templateEmailHandler: TemplateEmailHandler, | ||
) : NotificationHandlerAdapter<ChatRoomNotification, TemplateEmailNotificationMethod> { | ||
override fun supportsNotification(notification: Notification): Boolean = notification is ChatRoomNotification | ||
|
||
override fun supportsMethod(method: NotificationMethod): Boolean = method is TemplateEmailNotificationMethod | ||
|
||
override fun process( | ||
notification: ChatRoomNotification, | ||
method: TemplateEmailNotificationMethod, | ||
) { | ||
val users = userService.getByChatRoomId(notification.chatRoomId) | ||
users.forEach { templateEmailHandler.handleEmailEvent(it, method) } | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...src/main/kotlin/com/backgu/amaker/notification/workspace/config/WorkspaceServiceConfig.kt
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