feat: Implement deduplication for FCM token subscription and update related logic

This commit is contained in:
2026-02-25 23:03:28 +05:00
parent b7b99cdb40
commit 48861633ee
4 changed files with 41 additions and 85 deletions

View File

@@ -13,9 +13,7 @@ import com.rosetta.messenger.MainActivity
import com.rosetta.messenger.R
import com.rosetta.messenger.data.AccountManager
import com.rosetta.messenger.data.PreferencesManager
import com.rosetta.messenger.network.PacketPushNotification
import com.rosetta.messenger.network.ProtocolManager
import com.rosetta.messenger.network.PushNotificationAction
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
@@ -70,15 +68,9 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
saveFcmToken(token)
// Best-effort: если соединение уже авторизовано — сразу обновляем подписку на push.
// Используем единую точку отправки в ProtocolManager (с дедупликацией).
if (ProtocolManager.isAuthenticated()) {
runCatching {
ProtocolManager.send(
PacketPushNotification().apply {
notificationsToken = token
action = PushNotificationAction.SUBSCRIBE
}
)
}
runCatching { ProtocolManager.subscribePushTokenIfAvailable(forceToken = token) }
}
}