Move last message timestamp formatting to the room summary provider and its background processing queue

This commit is contained in:
Stefan Ceriu
2023-01-26 13:38:51 +02:00
committed by Stefan Ceriu
parent 1433100535
commit 413b433806
6 changed files with 18 additions and 20 deletions
@@ -53,21 +53,21 @@ class MockRoomSummaryProvider: RoomSummaryProviderProtocol {
isDirect: true,
avatarURL: nil,
lastMessage: AttributedString("Prosciutto beef ribs pancetta filet mignon kevin hamburger, chuck ham venison picanha. Beef ribs chislic turkey biltong tenderloin."),
lastMessageTimestamp: .distantPast,
lastMessageFormattedTimestamp: "Now",
unreadNotificationCount: 4)),
.filled(details: RoomSummaryDetails(id: "2",
name: "Second room",
isDirect: true,
avatarURL: URL.picturesDirectory,
lastMessage: nil,
lastMessageTimestamp: nil,
lastMessageFormattedTimestamp: nil,
unreadNotificationCount: 1)),
.filled(details: RoomSummaryDetails(id: "3",
name: "Third room",
isDirect: true,
avatarURL: nil,
lastMessage: try? AttributedString(markdown: "**@mock:client.com**: T-bone beef ribs bacon"),
lastMessageTimestamp: .distantPast,
lastMessageFormattedTimestamp: "Later",
unreadNotificationCount: 0)),
.empty
]
@@ -22,7 +22,7 @@ struct RoomSummaryDetails {
let isDirect: Bool
let avatarURL: URL?
let lastMessage: AttributedString?
let lastMessageTimestamp: Date?
let lastMessageFormattedTimestamp: String?
let unreadNotificationCount: UInt
}
@@ -97,14 +97,14 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
}
var attributedLastMessage: AttributedString?
var lastMessageTimestamp: Date?
var lastMessageFormattedTimestamp: String?
// Dispatch onto another queue otherwise the rust method latestRoomMessage crashes.
// This will be fixed when we get async uniffi support.
DispatchQueue.global(qos: .default).sync {
if let latestRoomMessage = room.latestRoomMessage() {
let lastMessage = EventTimelineItemProxy(item: latestRoomMessage)
lastMessageTimestamp = lastMessage.timestamp
lastMessageFormattedTimestamp = lastMessage.timestamp.formattedMinimal()
attributedLastMessage = eventStringBuilder.buildAttributedString(for: lastMessage)
}
}
@@ -116,7 +116,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
isDirect: room.isDm() ?? false,
avatarURL: avatarURL,
lastMessage: attributedLastMessage,
lastMessageTimestamp: lastMessageTimestamp,
lastMessageFormattedTimestamp: lastMessageFormattedTimestamp,
unreadNotificationCount: UInt(room.unreadNotifications().notificationCount()))
return invalidated ? .invalidated(details: details) : .filled(details: details)