fix(notifications): FG-Service-Notification und Nachrichten-Notification zu einer einzigen zusammenfassen #111
Labels
No labels
block-planning
bug
documentation
duplicate
enhancement
feature
good first issue
help wanted
infrastructure
invalid
planning
priority:high
priority:low
question
refactoring
status:backlog
status:done
status:in-progress
status:todo
tech-decision
test
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: bollwerkadmin/bollwerk#111
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Wenn
MessagingServiceläuft und eine Nachricht eingeht, erscheinen zwei Notifications gleichzeitig im Shade:ID 9999– "Warten auf Nachrichten…" (FG-Service,PRIORITY_MIN,setOngoing(true))ID senderId.hashCode()– "Neue Nachricht von X" (PRIORITY_HIGH,autoCancel)Das ist UX-Spam.
Root cause: Android erzwingt für jeden Foreground Service eine sichtbare Notification. Beide Notifications entstehen unabhängig voneinander – die erste durch
MessagingService.buildForegroundNotification(), die zweite durchNotificationHelper.showNewMessageNotification().Lösung: Eine Notification für zwei Zustände
Die FG-Service-Notification (
ID 9999) übernimmt beim Nachrichteneingang die Rolle der Nachrichten-Notification. Zu jedem Zeitpunkt ist genau eine Notification sichtbar.SERVICE_CHANNEL_IDCHANNEL_IDCHANNEL_IDSERVICE_CHANNEL_IDTechnische Umsetzung
1.
MessagingService.ktNOTIFICATION_ID = 9999aus demprivate companion objectininternal companion objectverschieben (damitNotificationHelperdarauf zugreifen kann)2.
NotificationHelper.ktshowNewMessageNotification():notificationManager.notify(senderNotificationId, notification)entfälltnotificationManager.notify(MessagingService.NOTIFICATION_ID, messageNotification)messageNotificationwird mitCHANNEL_ID(High-Importance) gebaut:contentText = "Neue Nachricht von $senderUsername",contentIntent→ direkt in den Chat (wie bisherchatPendingIntent)contentText = buildSummaryText(...),contentIntent→ Nachrichten-Liste (wie bishermessagesPendingIntent)setAutoCancel(false),setOngoing(true)(da FG-Notification)cancelNotificationForSender()undcancelAllMessageNotifications():notificationManager.cancel(senderNotificationId)entfällt (es gibt keine Sender-spezifischen Notification-IDs mehr)activeSenderNotificationIdsleer ist →notificationManager.notify(MessagingService.NOTIFICATION_ID, buildIdleNotification())aufrufenbuildIdleNotification(): neue private Hilfsmethode, die die gleiche Notification wieMessagingService.buildForegroundNotification()baut (oderMessagingServicestellt eine statische Factory-Methode bereit)updateBadgeCount():NOTIFICATION_ID(9999) umgestellt werden – da keine separaten Sender-IDs mehr existieren, ist sie redundant. Kann vorerst as-is bleiben, schadet nicht.SUMMARY_NOTIFICATION_ID = 0und Summary-Notification:summaryNotificationundshouldShowSummary-Logik entfällt (die FG-Notification übernimmt das zusammengefasste Anzeigen direkt)3.
NotificationHelperTest.ktshowNewMessageNotification()anpassen: erwartete Notification-ID ist jetzt9999stattsenderId.hashCode()cancelNotificationForSender()anpassen: prüfen dass Revert auf Idle-State passiertAbnahme-Kriterien
cancelNotificationForSender): Notification wechselt zurück auf "Warten auf Nachrichten…"./gradlew :app:test)Implementierung abgeschlossen
FG-Service-Notification und Nachrichten-Notifications zu einer einzigen Notification (ID 9999) zusammengefasst.
Umsetzung