Фикс: пуш-уведомления не читались при открытии приложения
- cancelAll() в onResume — сбрасывает все уведомления и бейдж при открытии приложения - showSimpleNotification принимает senderPublicKey и использует тот же ID что cancelNotificationForChat — теперь fallback-уведомления тоже удаляются при входе в чат Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -423,6 +423,8 @@ class MainActivity : FragmentActivity() {
|
||||
super.onResume()
|
||||
// 🔥 Приложение стало видимым - отключаем уведомления
|
||||
com.rosetta.messenger.push.RosettaFirebaseMessagingService.isAppInForeground = true
|
||||
// 🔔 Сбрасываем все уведомления из шторки при открытии приложения
|
||||
(getSystemService(NOTIFICATION_SERVICE) as android.app.NotificationManager).cancelAll()
|
||||
// ⚡ На возврате в приложение пробуем мгновенный reconnect без ожидания backoff.
|
||||
ProtocolManager.reconnectNowIfNeeded("activity_onResume")
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
|
||||
lower.contains("body")
|
||||
}
|
||||
if (!handledMessageData && !isReadEvent && looksLikeMessagePayload) {
|
||||
showSimpleNotification(senderName, messagePreview)
|
||||
showSimpleNotification(senderName, messagePreview, senderPublicKey)
|
||||
handledMessageData = true
|
||||
}
|
||||
}
|
||||
@@ -218,13 +218,13 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
|
||||
}
|
||||
|
||||
/** Показать простое уведомление */
|
||||
private fun showSimpleNotification(title: String, body: String) {
|
||||
private fun showSimpleNotification(title: String, body: String, senderPublicKey: String? = null) {
|
||||
// 🔥 Не показываем уведомление если приложение открыто
|
||||
if (isAppInForeground || !areNotificationsEnabled()) {
|
||||
return
|
||||
}
|
||||
// Dedup: suppress duplicate pushes within DEDUP_WINDOW_MS
|
||||
val dedupKey = "__simple__"
|
||||
val dedupKey = senderPublicKey?.trim()?.ifEmpty { null } ?: "__simple__"
|
||||
val now = System.currentTimeMillis()
|
||||
val lastTs = lastNotifTimestamps[dedupKey]
|
||||
if (lastTs != null && now - lastTs < DEDUP_WINDOW_MS) {
|
||||
@@ -234,8 +234,12 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
|
||||
|
||||
createNotificationChannel()
|
||||
|
||||
// Deterministic ID — duplicates replace each other instead of stacking
|
||||
val notifId = (title + body).hashCode() and 0x7FFFFFFF
|
||||
// Используем sender-based ID если известен ключ — чтобы cancelNotificationForChat мог убрать уведомление
|
||||
val notifId = if (!senderPublicKey.isNullOrBlank()) {
|
||||
getNotificationIdForChat(senderPublicKey.trim())
|
||||
} else {
|
||||
(title + body).hashCode() and 0x7FFFFFFF
|
||||
}
|
||||
|
||||
val intent =
|
||||
Intent(this, MainActivity::class.java).apply {
|
||||
|
||||
Reference in New Issue
Block a user