Remove delivered notifications for rooms that have meantime become fully read and have messages newer than what's delivered

- this is a best effort solution to cleanup outdated notifications when using multiple clients and reading them elsewhere
This commit is contained in:
Stefan Ceriu
2025-04-17 15:01:01 +03:00
committed by Stefan Ceriu
parent e14672e1f6
commit 899c33a5ad
12 changed files with 128 additions and 29 deletions
@@ -40,6 +40,7 @@ struct RoomSummary {
let avatarURL: URL?
let heroes: [UserProfileProxy]
let lastMessage: AttributedString?
let lastMessageDate: Date?
let lastMessageFormattedTimestamp: String?
let unreadMessagesCount: UInt
let unreadMentionsCount: UInt
@@ -95,6 +96,7 @@ extension RoomSummary {
avatarURL = nil
heroes = []
lastMessage = AttributedString(string)
lastMessageDate = .now
lastMessageFormattedTimestamp = "Now"
unreadMessagesCount = hasUnreadMessages ? 1 : 0
unreadMentionsCount = hasUnreadMentions ? 1 : 0
@@ -242,10 +242,12 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
}
var attributedLastMessage: AttributedString?
var lastMessageDate: Date?
var lastMessageFormattedTimestamp: String?
if let latestRoomMessage = roomDetails.latestEvent {
let lastMessage = EventTimelineItemProxy(item: latestRoomMessage, uniqueID: .init("0"))
lastMessageDate = lastMessage.timestamp
lastMessageFormattedTimestamp = lastMessage.timestamp.formattedMinimal()
attributedLastMessage = eventStringBuilder.buildAttributedString(for: lastMessage)
}
@@ -271,6 +273,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
avatarURL: roomInfo.avatarUrl.flatMap(URL.init(string:)),
heroes: roomInfo.heroes.map(UserProfileProxy.init),
lastMessage: attributedLastMessage,
lastMessageDate: lastMessageDate,
lastMessageFormattedTimestamp: lastMessageFormattedTimestamp,
unreadMessagesCount: UInt(roomInfo.numUnreadMessages),
unreadMentionsCount: UInt(roomInfo.numUnreadMentions),