mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Caching memberDetailProviders, showing sender display names in home screen last message, cleaner homescreen design.
This commit is contained in:
@@ -20,8 +20,8 @@ import Combine
|
||||
struct HomeScreenCoordinatorParameters {
|
||||
let userSession: UserSession
|
||||
let mediaProvider: MediaProviderProtocol
|
||||
let eventBriefFactory: EventBriefFactoryProtocol
|
||||
let attributedStringBuilder: AttributedStringBuilderProtocol
|
||||
let memberDetailProviderManager: MemberDetailProviderManager
|
||||
}
|
||||
|
||||
enum HomeScreenCoordinatorResult {
|
||||
@@ -96,14 +96,20 @@ final class HomeScreenCoordinator: Coordinator, Presentable {
|
||||
// MARK: - Private
|
||||
|
||||
func updateRoomsList() {
|
||||
self.roomSummaries = parameters.userSession.rooms.map { roomProxy in
|
||||
self.roomSummaries = parameters.userSession.rooms.compactMap { roomProxy in
|
||||
guard !roomProxy.isSpace, !roomProxy.isTombstoned else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if let summary = self.roomSummaries.first(where: { $0.id == roomProxy.id }) {
|
||||
return summary
|
||||
}
|
||||
|
||||
let memberDetailProvider = parameters.memberDetailProviderManager.memberDetailProviderForRoomProxy(roomProxy)
|
||||
|
||||
return RoomSummary(roomProxy: roomProxy,
|
||||
mediaProvider: parameters.mediaProvider,
|
||||
eventBriefFactory: parameters.eventBriefFactory)
|
||||
eventBriefFactory: EventBriefFactory(memberDetailProvider: memberDetailProvider))
|
||||
}
|
||||
|
||||
self.viewModel.updateWithRoomList(roomSummaries)
|
||||
|
||||
@@ -36,27 +36,19 @@ struct HomeScreenViewState: BindableState {
|
||||
var isLoadingRooms: Bool = false
|
||||
|
||||
var unencryptedDMs: [HomeScreenRoom] {
|
||||
Array(sortedRooms.filter { $0.isDirect && !$0.isEncrypted })
|
||||
Array(rooms.filter { $0.isDirect && !$0.isEncrypted })
|
||||
}
|
||||
|
||||
var encryptedDMs: [HomeScreenRoom] {
|
||||
Array(sortedRooms.filter { $0.isDirect && $0.isEncrypted})
|
||||
Array(rooms.filter { $0.isDirect && $0.isEncrypted})
|
||||
}
|
||||
|
||||
var unencryptedRooms: [HomeScreenRoom] {
|
||||
Array(sortedRooms.filter { !$0.isDirect && !$0.isEncrypted })
|
||||
Array(rooms.filter { !$0.isDirect && !$0.isEncrypted })
|
||||
}
|
||||
|
||||
var encryptedRooms: [HomeScreenRoom] {
|
||||
Array(sortedRooms.filter { !$0.isDirect && $0.isEncrypted })
|
||||
}
|
||||
|
||||
private var filteredRooms: [HomeScreenRoom] {
|
||||
rooms.filter { !$0.isSpace && !$0.isTombstoned }
|
||||
}
|
||||
|
||||
private var sortedRooms: [HomeScreenRoom] {
|
||||
filteredRooms.sorted(by: { ($0.displayName ?? $0.id).lowercased() < ($1.displayName ?? $1.id).lowercased() })
|
||||
Array(rooms.filter { !$0.isDirect && $0.isEncrypted })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,12 +113,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
}
|
||||
|
||||
private func buildOrUpdateRoomFromSummary(_ roomSummary: RoomSummaryProtocol) -> HomeScreenRoom {
|
||||
|
||||
let lastMessage = lastMessageFromEventBrief(roomSummary.lastMessage)
|
||||
|
||||
guard var room = self.state.rooms.first(where: { $0.id == roomSummary.id }) else {
|
||||
return HomeScreenRoom(id: roomSummary.id,
|
||||
displayName: roomSummary.name,
|
||||
displayName: roomSummary.displayName ?? roomSummary.name,
|
||||
topic: roomSummary.topic,
|
||||
lastMessage: lastMessage,
|
||||
avatar: roomSummary.avatar,
|
||||
@@ -140,11 +139,17 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
return nil
|
||||
}
|
||||
|
||||
let senderDisplayName = senderDisplayNameForBrief(eventBrief)
|
||||
|
||||
if let htmlBody = eventBrief.htmlBody,
|
||||
let lastMessageAttributedString = attributedStringBuilder.fromHTML(htmlBody) {
|
||||
return "\(eventBrief.senderName): \(String(lastMessageAttributedString.characters))"
|
||||
return "\(senderDisplayName): \(String(lastMessageAttributedString.characters))"
|
||||
} else {
|
||||
return "\(eventBrief.senderName): \(eventBrief.body)"
|
||||
return "\(senderDisplayName): \(eventBrief.body)"
|
||||
}
|
||||
}
|
||||
|
||||
private func senderDisplayNameForBrief(_ brief: EventBrief) -> String {
|
||||
brief.senderDisplayName ?? brief.senderId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,23 +115,23 @@ struct RoomCell: View {
|
||||
.frame(width: 40, height: 40)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 4.0) {
|
||||
VStack(alignment: .leading, spacing: 2.0) {
|
||||
Text(roomName(room))
|
||||
.font(.headline)
|
||||
.fontWeight(.regular)
|
||||
.foregroundStyle(.primary)
|
||||
|
||||
if let roomTopic = room.topic, roomTopic.count > 0 {
|
||||
Text(roomTopic)
|
||||
.font(.footnote)
|
||||
.fontWeight(.bold)
|
||||
.font(.footnote.weight(.semibold))
|
||||
.lineLimit(1)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
if let lastMessage = room.lastMessage {
|
||||
Text(lastMessage)
|
||||
.font(.footnote)
|
||||
.fontWeight(.medium)
|
||||
.font(.callout)
|
||||
.lineLimit(1)
|
||||
.foregroundStyle(.secondary)
|
||||
.padding(.top, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,9 +156,16 @@ struct HomeScreen_Previews: PreviewProvider {
|
||||
mediaProvider: MockMediaProvider(),
|
||||
attributedStringBuilder: AttributedStringBuilder())
|
||||
|
||||
let rooms = [MockRoomSummary(displayName: "Alpha"),
|
||||
let eventBrief = EventBrief(eventId: "id",
|
||||
senderId: "senderId",
|
||||
senderDisplayName: "Sender",
|
||||
body: "Some message",
|
||||
htmlBody: nil,
|
||||
date: .now)
|
||||
|
||||
let rooms = [MockRoomSummary(topic: "Topic", displayName: "Alpha"),
|
||||
MockRoomSummary(displayName: "Beta"),
|
||||
MockRoomSummary(displayName: "Omega")]
|
||||
MockRoomSummary(displayName: "Omega", lastMessage: eventBrief)]
|
||||
|
||||
viewModel.updateWithRoomList(rooms)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user