feat(fcm): 수신 언어별 크리에이터 이름을 알림에 반영한다

This commit is contained in:
2026-10-16 14:03:33 +09:00
parent 698cdc1fe3
commit 995b41e89d
4 changed files with 320 additions and 15 deletions
@@ -7,6 +7,7 @@ import kr.co.vividnext.sodalive.i18n.Lang
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
import kr.co.vividnext.sodalive.live.room.GenderRestriction
import kr.co.vividnext.sodalive.member.MemberRepository
import kr.co.vividnext.sodalive.v2.creatorname.application.CreatorLocalizedNameService
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Propagation
@@ -56,7 +57,9 @@ class FcmEvent(
val commentParentId: Long? = null,
val myMemberId: Long? = null,
val isAvailableJoinCreator: Boolean? = null,
val genderRestriction: GenderRestriction? = null
val genderRestriction: GenderRestriction? = null,
val titleMemberId: Long? = null,
val nameArgumentMemberIds: Map<Int, Long> = emptyMap()
)
@Component
@@ -65,7 +68,8 @@ class FcmSendListener(
private val memberRepository: MemberRepository,
private val contentCommentRepository: AudioContentCommentRepository,
private val messageSource: SodaMessageSource,
private val pushNotificationService: PushNotificationService
private val pushNotificationService: PushNotificationService,
private val localizedNameService: CreatorLocalizedNameService
) {
@Async
@TransactionalEventListener
@@ -169,18 +173,26 @@ class FcmSendListener(
creatorId: Long? = null,
auditionId: Long? = null
) {
val tokensByLang = pushTokens.groupBy { it.languageCode }
val tokensByLang = pushTokens.groupBy { Lang.fromAcceptLanguage(it.languageCode) }
val nameMemberIds = listOfNotNull(fcmEvent.senderMemberId, fcmEvent.titleMemberId)
.plus(fcmEvent.nameArgumentMemberIds.values)
.distinct()
for ((langCode, tokens) in tokensByLang) {
val lang = Lang.fromAcceptLanguage(langCode)
val title = translate(fcmEvent.titleKey, fcmEvent.title, lang, fcmEvent.args)
val message = translate(fcmEvent.messageKey, fcmEvent.message, lang, fcmEvent.args)
for ((lang, tokens) in tokensByLang) {
val names = localizedNameService.findLocalizedNames(nameMemberIds, lang)
val args = fcmEvent.args.mapIndexed { index, argument ->
fcmEvent.nameArgumentMemberIds[index]?.let { names[it] } ?: argument
}
val defaultTitle = fcmEvent.titleMemberId?.let { names[it] } ?: fcmEvent.title
val title = translate(fcmEvent.titleKey, defaultTitle, lang, args)
val message = translate(fcmEvent.messageKey, fcmEvent.message, lang, args)
pushNotificationService.saveNotification(
fcmEvent = fcmEvent,
languageCode = lang.code,
translatedMessage = message,
recipientPushTokens = tokens
recipientPushTokens = tokens,
localizedSenderNickname = fcmEvent.senderMemberId?.let { names[it] }
)
val tokensByOS = tokens.groupBy { it.deviceType }
@@ -36,7 +36,8 @@ class PushNotificationService(
fcmEvent: FcmEvent,
languageCode: String,
translatedMessage: String,
recipientPushTokens: List<PushTokenInfo>
recipientPushTokens: List<PushTokenInfo>,
localizedSenderNickname: String?
) {
if (recipientPushTokens.isEmpty()) return
@@ -58,7 +59,7 @@ class PushNotificationService(
)
val notification = PushNotificationList(
senderNicknameSnapshot = senderSnapshot.nickname,
senderNicknameSnapshot = localizedSenderNickname ?: senderSnapshot.nickname,
senderProfileImageSnapshot = senderSnapshot.profileImage,
message = translatedMessage,
category = category,