mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
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:
@@ -408,7 +408,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
return !userSessionFlowCoordinator.isDisplayingRoomScreen(withRoomID: roomID)
|
||||
}
|
||||
|
||||
func notificationTapped(content: UNNotificationContent) async {
|
||||
func notificationTapped(content: UNNotificationContent, isNewestInRoom: Bool) async {
|
||||
MXLog.info("Tapped Notification")
|
||||
|
||||
guard let roomID = content.roomID,
|
||||
@@ -426,11 +426,12 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
handleAppRoute(.room(roomID: roomID, via: []), windowType: nil)
|
||||
} else if appSettings.threadsEnabled, let threadRootEventID = content.threadRootEventID {
|
||||
handleAppRoute(.thread(roomID: roomID, threadRootEventID: threadRootEventID, focusEventID: eventID), windowType: nil)
|
||||
} else if let eventID {
|
||||
} else if let eventID, !isNewestInRoom {
|
||||
// Only track main timeline event deeplinking
|
||||
analyticsService.signpost.startTransaction(.notificationToMessage)
|
||||
handleAppRoute(.event(eventID: eventID, roomID: roomID, via: []), windowType: nil)
|
||||
} else {
|
||||
// The live timeline already ends with the newest message, so there's no need to focus on it.
|
||||
handleAppRoute(.room(roomID: roomID, via: []), windowType: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user