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