mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add RoomDetails for use (with RoomMemberDetails) in AvatarHeaderView. (#2490)
* Add RoomDetails and refactor AvatarHeaderView to use it. * Remove old displayName property and use RoomDetails in the RoomDetailsScreenViewState
This commit is contained in:
@@ -33,16 +33,14 @@ enum RoomDetailsScreenViewModelAction {
|
||||
// MARK: View
|
||||
|
||||
struct RoomDetailsScreenViewState: BindableState {
|
||||
let roomId: String
|
||||
let canonicalAlias: String?
|
||||
var details: RoomDetails
|
||||
|
||||
let isEncrypted: Bool
|
||||
let isDirect: Bool
|
||||
let permalink: URL?
|
||||
|
||||
var title = ""
|
||||
var topic: AttributedString?
|
||||
var topicSummary: AttributedString?
|
||||
var avatarURL: URL?
|
||||
var joinedMembersCount: Int
|
||||
var isProcessingIgnoreRequest = false
|
||||
var canInviteUsers = false
|
||||
@@ -148,7 +146,7 @@ struct LeaveRoomAlertItem: AlertProtocol {
|
||||
case `private`
|
||||
}
|
||||
|
||||
let roomId: String
|
||||
let roomID: String
|
||||
let isDM: Bool
|
||||
let state: RoomState
|
||||
let confirmationTitle = L10n.actionLeave
|
||||
|
||||
@@ -57,15 +57,12 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
|
||||
let topic = attributedStringBuilder.fromPlain(roomProxy.topic)
|
||||
|
||||
super.init(initialViewState: .init(roomId: roomProxy.id,
|
||||
canonicalAlias: roomProxy.canonicalAlias,
|
||||
super.init(initialViewState: .init(details: roomProxy.details,
|
||||
isEncrypted: roomProxy.isEncrypted,
|
||||
isDirect: roomProxy.isDirect,
|
||||
permalink: roomProxy.permalink,
|
||||
title: roomProxy.roomTitle,
|
||||
topic: topic,
|
||||
topicSummary: topic?.unattributedStringByReplacingNewlinesWithSpaces(),
|
||||
avatarURL: roomProxy.avatarURL,
|
||||
joinedMembersCount: roomProxy.joinedMembersCount,
|
||||
notificationSettingsState: .loading,
|
||||
bindings: .init()),
|
||||
@@ -95,10 +92,10 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
actionsSubject.send(.requestInvitePeoplePresentation)
|
||||
case .processTapLeave:
|
||||
guard state.joinedMembersCount > 1 else {
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomId: roomProxy.id, isDM: roomProxy.isEncryptedOneToOneRoom, state: .empty)
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomProxy.id, isDM: roomProxy.isEncryptedOneToOneRoom, state: .empty)
|
||||
return
|
||||
}
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomId: roomProxy.id, isDM: roomProxy.isEncryptedOneToOneRoom, state: roomProxy.isPublic ? .public : .private)
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomProxy.id, isDM: roomProxy.isEncryptedOneToOneRoom, state: roomProxy.isPublic ? .public : .private)
|
||||
case .confirmLeave:
|
||||
Task { await leaveRoom() }
|
||||
case .processTapIgnore:
|
||||
@@ -145,12 +142,11 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
}
|
||||
|
||||
private func updateRoomInfo() {
|
||||
state.title = roomProxy.roomTitle
|
||||
state.details = roomProxy.details
|
||||
|
||||
let topic = attributedStringBuilder.fromPlain(roomProxy.topic)
|
||||
state.topic = topic
|
||||
state.topicSummary = topic?.unattributedStringByReplacingNewlinesWithSpaces()
|
||||
state.avatarURL = roomProxy.avatarURL
|
||||
state.joinedMembersCount = roomProxy.joinedMembersCount
|
||||
|
||||
Task {
|
||||
|
||||
@@ -68,12 +68,9 @@ struct RoomDetailsScreen: View {
|
||||
// MARK: - Private
|
||||
|
||||
private var normalRoomHeaderSection: some View {
|
||||
AvatarHeaderView(avatarUrl: context.viewState.avatarURL,
|
||||
name: context.viewState.title,
|
||||
id: context.viewState.roomId,
|
||||
AvatarHeaderView(room: context.viewState.details,
|
||||
avatarSize: .room(on: .details),
|
||||
imageProvider: context.imageProvider,
|
||||
subtitle: context.viewState.canonicalAlias) {
|
||||
imageProvider: context.imageProvider) {
|
||||
context.send(viewAction: .displayAvatar)
|
||||
} footer: {
|
||||
if !context.viewState.shortcuts.isEmpty {
|
||||
@@ -84,12 +81,9 @@ struct RoomDetailsScreen: View {
|
||||
}
|
||||
|
||||
private func dmHeaderSection(recipient: RoomMemberDetails) -> some View {
|
||||
AvatarHeaderView(avatarUrl: recipient.avatarURL,
|
||||
name: recipient.name,
|
||||
id: recipient.id,
|
||||
AvatarHeaderView(member: recipient,
|
||||
avatarSize: .user(on: .memberDetails),
|
||||
imageProvider: context.imageProvider,
|
||||
subtitle: recipient.id) {
|
||||
imageProvider: context.imageProvider) {
|
||||
context.send(viewAction: .displayAvatar)
|
||||
} footer: {
|
||||
if !context.viewState.shortcuts.isEmpty {
|
||||
@@ -291,7 +285,7 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
.mockCharlie
|
||||
]
|
||||
let roomProxy = RoomProxyMock(with: .init(id: "room_a_id",
|
||||
displayName: "Room A",
|
||||
name: "Room A",
|
||||
topic: """
|
||||
Discussions about Element X iOS | https://github.com/vector-im/element-x-ios
|
||||
|
||||
@@ -327,7 +321,7 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
]
|
||||
|
||||
let roomProxy = RoomProxyMock(with: .init(id: "dm_room_id",
|
||||
displayName: "DM Room",
|
||||
name: "DM Room",
|
||||
topic: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
isDirect: true,
|
||||
isEncrypted: true,
|
||||
@@ -354,7 +348,7 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
.mockCharlie
|
||||
]
|
||||
let roomProxy = RoomProxyMock(with: .init(id: "simple_room_id",
|
||||
displayName: "Room A",
|
||||
name: "Room A",
|
||||
isDirect: false,
|
||||
isEncrypted: false,
|
||||
members: members))
|
||||
|
||||
Reference in New Issue
Block a user