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:
@@ -21,6 +21,7 @@ final class NotificationManagerTests {
|
||||
private var shouldDisplayInAppNotificationReturnValue = false
|
||||
private var handleInlineReplyDelegateCalled = false
|
||||
private var notificationTappedDelegateCalled = false
|
||||
private var notificationTappedIsNewestInRoom: Bool?
|
||||
private var registerForRemoteNotificationsDelegateCalled: (() -> Void)?
|
||||
private let appSettings: AppSettings
|
||||
|
||||
@@ -238,6 +239,31 @@ final class NotificationManagerTests {
|
||||
#expect(notificationTappedDelegateCalled)
|
||||
}
|
||||
|
||||
@Test
|
||||
func whenTappedNotificationIsTheNewestInItsRoom_delegateIsToldItIsNewest() async throws {
|
||||
notificationManager.delegate = self
|
||||
let date = Date.now
|
||||
notificationCenter.deliveredNotificationsReturnValue = try [UNNotification.with(userInfo: [NotificationConstants.UserInfoKey.roomIdentifier: "!room:matrix.org"], date: date - 60),
|
||||
UNNotification.with(userInfo: [NotificationConstants.UserInfoKey.roomIdentifier: "!other:matrix.org"], date: date + 60)]
|
||||
|
||||
let response = try UNTextInputNotificationResponse.with(userInfo: [NotificationConstants.UserInfoKey.roomIdentifier: "!room:matrix.org"], date: date)
|
||||
await notificationManager.userNotificationCenter(UNUserNotificationCenter.current(), didReceive: response)
|
||||
|
||||
#expect(notificationTappedIsNewestInRoom == true)
|
||||
}
|
||||
|
||||
@Test
|
||||
func whenTappedNotificationIsOlderThanAnotherInItsRoom_delegateIsToldItIsNotNewest() async throws {
|
||||
notificationManager.delegate = self
|
||||
let date = Date.now
|
||||
notificationCenter.deliveredNotificationsReturnValue = try [UNNotification.with(userInfo: [NotificationConstants.UserInfoKey.roomIdentifier: "!room:matrix.org"], date: date + 60)]
|
||||
|
||||
let response = try UNTextInputNotificationResponse.with(userInfo: [NotificationConstants.UserInfoKey.roomIdentifier: "!room:matrix.org"], date: date)
|
||||
await notificationManager.userNotificationCenter(UNUserNotificationCenter.current(), didReceive: response)
|
||||
|
||||
#expect(notificationTappedIsNewestInRoom == false)
|
||||
}
|
||||
|
||||
@Test
|
||||
func updatingAppBadgeCountUsesTheClientSideCount() async {
|
||||
clientProxy.totalUnreadNotifications = 7
|
||||
@@ -272,8 +298,9 @@ extension NotificationManagerTests: @MainActor NotificationManagerDelegate {
|
||||
shouldDisplayInAppNotificationReturnValue
|
||||
}
|
||||
|
||||
func notificationTapped(content: UNNotificationContent) async {
|
||||
func notificationTapped(content: UNNotificationContent, isNewestInRoom: Bool) async {
|
||||
notificationTappedDelegateCalled = true
|
||||
notificationTappedIsNewestInRoom = isNewestInRoom
|
||||
}
|
||||
|
||||
func handleInlineReply(_ service: ElementX.NotificationManagerProtocol, content: UNNotificationContent, replyText: String) async {
|
||||
|
||||
Reference in New Issue
Block a user