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:
@@ -226,6 +226,7 @@ nonisolated struct NotificationContentBuilderTests {
|
||||
mutating func liveLocationStartNotification() async {
|
||||
let event = TimelineEventSDKMock()
|
||||
event.eventIdReturnValue = UUID().uuidString
|
||||
event.timestampReturnValue = 0
|
||||
event.contentReturnValue = .state(content: .beaconInfo)
|
||||
|
||||
let notificationItem = NotificationItemProxyMock(.init(event: .timeline(event: event),
|
||||
@@ -253,6 +254,7 @@ nonisolated struct NotificationContentBuilderTests {
|
||||
mutating func otherStateEventNotification() async {
|
||||
let event = TimelineEventSDKMock()
|
||||
event.eventIdReturnValue = UUID().uuidString
|
||||
event.timestampReturnValue = 0
|
||||
event.contentReturnValue = .state(content: .roomName)
|
||||
|
||||
let notificationItem = NotificationItemProxyMock(.init(event: .timeline(event: event),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,15 +11,16 @@ import UserNotifications
|
||||
import XCTest
|
||||
|
||||
extension UNNotification {
|
||||
static func with(userInfo: [AnyHashable: Any]) throws -> UNNotification {
|
||||
static func with(userInfo: [AnyHashable: Any], identifier: String = "", date: Date = .now) throws -> UNNotification {
|
||||
let content = UNMutableNotificationContent()
|
||||
content.userInfo = userInfo
|
||||
let request = UNNotificationRequest(identifier: "",
|
||||
let request = UNNotificationRequest(identifier: identifier,
|
||||
content: content,
|
||||
trigger: nil)
|
||||
let archiver = MockCoder(requiringSecureCoding: false)
|
||||
let notification = try XCTUnwrap(UNNotification(coder: archiver))
|
||||
notification.setValue(request, forKey: "request")
|
||||
notification.setValue(date, forKey: "date")
|
||||
return notification
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user