mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Clear notifications for fully read rooms using the event's timestamp instead of delivery date
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
import Combine
|
||||
@testable import ElementX
|
||||
import MatrixRustSDKMocks
|
||||
import NotificationCenter
|
||||
import Testing
|
||||
|
||||
@@ -192,6 +193,28 @@ final class NotificationManagerTests {
|
||||
#expect(authorizationStatusWasGranted)
|
||||
}
|
||||
|
||||
@Test
|
||||
func removeDeliveredNotificationsForFullyReadRooms() async throws {
|
||||
let room = RoomSummary(room: RoomSDKMock(), id: "!room:matrix.org", settingsMode: .allMessages,
|
||||
hasUnreadMessages: false, hasUnreadMentions: false, hasUnreadNotifications: false)
|
||||
let lastMessageDate = try #require(room.lastMessageDate)
|
||||
|
||||
// Delivered after the last message was sent, which is always the case for the last message's notification.
|
||||
let readNotification = try UNNotification.with(userInfo: [NotificationConstants.UserInfoKey.roomIdentifier: room.id,
|
||||
NotificationConstants.UserInfoKey.eventDate: lastMessageDate.addingTimeInterval(0.5)],
|
||||
identifier: "read",
|
||||
date: lastMessageDate.addingTimeInterval(5))
|
||||
let newerNotification = try UNNotification.with(userInfo: [NotificationConstants.UserInfoKey.roomIdentifier: room.id,
|
||||
NotificationConstants.UserInfoKey.eventDate: lastMessageDate.addingTimeInterval(1)],
|
||||
identifier: "newer",
|
||||
date: lastMessageDate.addingTimeInterval(5))
|
||||
notificationCenter.deliveredNotificationsReturnValue = [readNotification, newerNotification]
|
||||
|
||||
await notificationManager.removeDeliveredNotificationsForFullyReadRooms([room])
|
||||
|
||||
#expect(notificationCenter.removeDeliveredNotificationsWithIdentifiersReceivedIdentifiers == ["read"])
|
||||
}
|
||||
|
||||
@Test
|
||||
func whenWillPresentNotificationsDelegateNotSet_CorrectPresentationOptionsReturned() async throws {
|
||||
let archiver = MockCoder(requiringSecureCoding: false)
|
||||
|
||||
Reference in New Issue
Block a user