mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 19:44:05 +00:00
Timeline item sender profiles (#463)
* Adopt timeline item sender profiles for displaying user avatars and display names * Prevent images from automatically being evicted from the in-memory cache when entering background * Get rid of all the `urlString: String`s and start using proper URLs * Add back manual display name loading as the sender profiles aren't working properly yet * Implement a sender profile. * Bump the RustSDK to v1.0.32-alpha Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
@@ -20,7 +20,6 @@ import MatrixRustSDK
|
||||
|
||||
class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
private let slidingSyncViewProxy: SlidingSyncViewProxy
|
||||
private let roomMessageFactory: RoomMessageFactoryProtocol
|
||||
private let serialDispatchQueue: DispatchQueue
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
@@ -35,9 +34,8 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
init(slidingSyncViewProxy: SlidingSyncViewProxy, roomMessageFactory: RoomMessageFactoryProtocol) {
|
||||
init(slidingSyncViewProxy: SlidingSyncViewProxy) {
|
||||
self.slidingSyncViewProxy = slidingSyncViewProxy
|
||||
self.roomMessageFactory = roomMessageFactory
|
||||
serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomsummaryprovider")
|
||||
|
||||
rooms = slidingSyncViewProxy.currentRoomsList().map { roomListEntry in
|
||||
@@ -147,22 +145,31 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
var attributedLastMessage: AttributedString?
|
||||
var lastMessageTimestamp: Date?
|
||||
if let latestRoomMessage = room.latestRoomMessage() {
|
||||
let lastMessage = roomMessageFactory.buildRoomMessageFrom(EventTimelineItemProxy(item: latestRoomMessage))
|
||||
|
||||
#warning("Intentionally remove the sender mxid from the room list for now")
|
||||
// if let lastMessageSender = try? AttributedString(markdown: "**\(lastMessage.sender)**") {
|
||||
// // Don't include the message body in the markdown otherwise it makes tappable links.
|
||||
// attributedLastMessage = lastMessageSender + ": " + AttributedString(lastMessage.body)
|
||||
// }
|
||||
attributedLastMessage = AttributedString(lastMessage.body)
|
||||
lastMessageTimestamp = lastMessage.timestamp
|
||||
|
||||
// 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
|
||||
|
||||
if let senderDisplayName = lastMessage.sender.displayName,
|
||||
let attributedSenderDisplayName = try? AttributedString(markdown: "**\(senderDisplayName)**") {
|
||||
// Don't include the message body in the markdown otherwise it makes tappable links.
|
||||
attributedLastMessage = attributedSenderDisplayName + ": " + AttributedString(lastMessage.body ?? "")
|
||||
} else if let body = lastMessage.body {
|
||||
attributedLastMessage = AttributedString(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let avatarURL = room.fullRoom()?.avatarUrl().flatMap(URL.init(string:))
|
||||
|
||||
let details = RoomSummaryDetails(id: room.roomId(),
|
||||
name: room.name() ?? room.roomId(),
|
||||
isDirect: room.isDm() ?? false,
|
||||
avatarURLString: room.fullRoom()?.avatarUrl(),
|
||||
avatarURL: avatarURL,
|
||||
lastMessage: attributedLastMessage,
|
||||
lastMessageTimestamp: lastMessageTimestamp,
|
||||
unreadNotificationCount: UInt(room.unreadNotifications().notificationCount()))
|
||||
|
||||
Reference in New Issue
Block a user