Open the room live when tapping the notification for its newest message

Tapping a message notification always opened the room on a timeline
focussed on that event, even when it was the newest message and the
live timeline already ends with it.

On tap, the notification manager now checks whether any other delivered
notification for the same room is more recent. If none is, the room is
opened live instead of focussed. Older notifications in a room keep
focussing on their event.
This commit is contained in:
Stefan Ceriu
2026-09-30 13:07:01 +03:00
parent 7973da8251
commit 4c71cae0f5
6 changed files with 50 additions and 14 deletions
@@ -259,11 +259,21 @@ extension NotificationManager: UNUserNotificationCenterDelegate {
content: response.notification.request.content,
replyText: response.userText)
case UNNotificationDefaultActionIdentifier:
await delegate?.notificationTapped(content: response.notification.request.content)
await delegate?.notificationTapped(content: response.notification.request.content,
isNewestInRoom: isNewestInRoom(response.notification))
default:
break
}
}
/// Whether no other delivered notification for the same room is more recent.
private func isNewestInRoom(_ notification: UNNotification) async -> Bool {
guard let roomID = notification.request.content.roomID else { return false }
return await notificationCenter.deliveredNotifications().allSatisfy { deliveredNotification in
deliveredNotification.request.content.roomID != roomID || deliveredNotification.date <= notification.date
}
}
}
extension UNUserNotificationCenter: UserNotificationCenterProtocol { }
@@ -11,7 +11,8 @@ import UserNotifications
protocol NotificationManagerDelegate: AnyObject {
func shouldDisplayInAppNotification(content: UNNotificationContent) -> Bool
func notificationTapped(content: UNNotificationContent) async
/// - Parameter isNewestInRoom: Whether no other delivered notification for the same room is more recent.
func notificationTapped(content: UNNotificationContent, isNewestInRoom: Bool) async
func handleInlineReply(_ service: NotificationManagerProtocol,
content: UNNotificationContent,
replyText: String) async