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:
Doug
2024-02-21 14:19:05 +00:00
committed by GitHub
parent 9b949ce84e
commit 730d099a76
48 changed files with 255 additions and 191 deletions
@@ -94,9 +94,9 @@ class MockClientProxy: ClientProxyProtocol {
switch room {
case .empty:
return RoomProxyMock(with: .init(displayName: "Empty room"))
return RoomProxyMock(with: .init(name: "Empty room"))
case .filled(let details), .invalidated(let details):
return RoomProxyMock(with: .init(displayName: details.name))
return RoomProxyMock(with: .init(name: details.name))
}
}
@@ -0,0 +1,24 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
struct RoomDetails {
let id: String
let name: String?
let avatarURL: URL?
let canonicalAlias: String?
}
@@ -41,6 +41,17 @@ extension RoomMemberDetails {
isBanned = proxy.membership == .ban
role = .init(proxy.role)
}
init(loading id: String) {
self.id = id
name = nil
avatarURL = nil
permalink = nil
isAccountOwner = false
isIgnored = false
isBanned = false
role = .user
}
}
extension RoomMemberDetails.Role {
@@ -37,8 +37,6 @@ class RoomProxy: RoomProxyProtocol {
private var typingNotificationObservationToken: TaskHandle?
private var subscribedForUpdates = false
private(set) var displayName: String?
private let membersSubject = CurrentValueSubject<[RoomMemberProxyProtocol], Never>([])
var members: CurrentValuePublisher<[RoomMemberProxyProtocol], Never> {
@@ -57,8 +57,6 @@ protocol RoomProxyProtocol {
var name: String? { get }
var displayName: String? { get }
var topic: String? { get }
var avatarURL: URL? { get }
@@ -130,6 +128,13 @@ protocol RoomProxyProtocol {
}
extension RoomProxyProtocol {
var details: RoomDetails {
RoomDetails(id: id,
name: name,
avatarURL: avatarURL,
canonicalAlias: canonicalAlias)
}
var permalink: URL? {
if let canonicalAlias, let link = try? PermalinkBuilder.permalinkTo(roomAlias: canonicalAlias,
baseURL: ServiceLocator.shared.settings.permalinkBaseURL) {
@@ -146,7 +151,7 @@ extension RoomProxyProtocol {
// Avoids to duplicate the same logic around in the app
// Probably this should be done in rust.
var roomTitle: String {
displayName ?? name ?? "Unknown room 💥"
name ?? "Unknown room 💥"
}
var isEncryptedOneToOneRoom: Bool {
@@ -301,7 +301,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
switch timelineProvider.backPaginationState {
case .timelineStartReached:
if !roomProxy.isEncryptedOneToOneRoom {
let timelineStart = TimelineStartRoomTimelineItem(name: roomProxy.displayName ?? roomProxy.name)
let timelineStart = TimelineStartRoomTimelineItem(name: roomProxy.name)
newTimelineItems.insert(timelineStart, at: 0)
}
canBackPaginate = false