mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Refactor the JoinRoom screen to take advantage of newer APIs and support more joinRule/membership combinations (i.e. invite required, restricted, banned) (#3685)
- expose the full RoomPreview and RoomMembershipDetails through their own proxies - implement standard mocks for all the different combinations - converge on a single room info provider - rebuild all the previews - prioritise the preview data over the room one.
This commit is contained in:
@@ -3187,13 +3187,13 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
|
||||
var roomPreviewForIdentifierViaReceivedArguments: (identifier: String, via: [String])?
|
||||
var roomPreviewForIdentifierViaReceivedInvocations: [(identifier: String, via: [String])] = []
|
||||
|
||||
var roomPreviewForIdentifierViaUnderlyingReturnValue: Result<RoomPreviewDetails, ClientProxyError>!
|
||||
var roomPreviewForIdentifierViaReturnValue: Result<RoomPreviewDetails, ClientProxyError>! {
|
||||
var roomPreviewForIdentifierViaUnderlyingReturnValue: Result<RoomPreviewProxyProtocol, ClientProxyError>!
|
||||
var roomPreviewForIdentifierViaReturnValue: Result<RoomPreviewProxyProtocol, ClientProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return roomPreviewForIdentifierViaUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<RoomPreviewDetails, ClientProxyError>? = nil
|
||||
var returnValue: Result<RoomPreviewProxyProtocol, ClientProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = roomPreviewForIdentifierViaUnderlyingReturnValue
|
||||
}
|
||||
@@ -3211,9 +3211,9 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
|
||||
}
|
||||
}
|
||||
}
|
||||
var roomPreviewForIdentifierViaClosure: ((String, [String]) async -> Result<RoomPreviewDetails, ClientProxyError>)?
|
||||
var roomPreviewForIdentifierViaClosure: ((String, [String]) async -> Result<RoomPreviewProxyProtocol, ClientProxyError>)?
|
||||
|
||||
func roomPreviewForIdentifier(_ identifier: String, via: [String]) async -> Result<RoomPreviewDetails, ClientProxyError> {
|
||||
func roomPreviewForIdentifier(_ identifier: String, via: [String]) async -> Result<RoomPreviewProxyProtocol, ClientProxyError> {
|
||||
roomPreviewForIdentifierViaCallsCount += 1
|
||||
roomPreviewForIdentifierViaReceivedArguments = (identifier: identifier, via: via)
|
||||
DispatchQueue.main.async {
|
||||
@@ -13416,6 +13416,15 @@ class RoomMemberProxyMock: RoomMemberProxyProtocol, @unchecked Sendable {
|
||||
}
|
||||
var underlyingRole: RoomMemberRole!
|
||||
|
||||
}
|
||||
class RoomMembershipDetailsProxyMock: RoomMembershipDetailsProxyProtocol, @unchecked Sendable {
|
||||
var ownRoomMember: RoomMemberProxyProtocol {
|
||||
get { return underlyingOwnRoomMember }
|
||||
set(value) { underlyingOwnRoomMember = value }
|
||||
}
|
||||
var underlyingOwnRoomMember: RoomMemberProxyProtocol!
|
||||
var senderRoomMember: RoomMemberProxyProtocol?
|
||||
|
||||
}
|
||||
class RoomNotificationSettingsProxyMock: RoomNotificationSettingsProxyProtocol, @unchecked Sendable {
|
||||
var mode: RoomNotificationModeProxy {
|
||||
@@ -13429,6 +13438,31 @@ class RoomNotificationSettingsProxyMock: RoomNotificationSettingsProxyProtocol,
|
||||
}
|
||||
var underlyingIsDefault: Bool!
|
||||
|
||||
}
|
||||
class RoomPreviewProxyMock: RoomPreviewProxyProtocol, @unchecked Sendable {
|
||||
var info: RoomPreviewInfoProxy {
|
||||
get { return underlyingInfo }
|
||||
set(value) { underlyingInfo = value }
|
||||
}
|
||||
var underlyingInfo: RoomPreviewInfoProxy!
|
||||
var ownMembershipDetailsCallsCount = 0
|
||||
var ownMembershipDetailsCalled: Bool {
|
||||
return ownMembershipDetailsCallsCount > 0
|
||||
}
|
||||
|
||||
var ownMembershipDetails: RoomMembershipDetailsProxyProtocol? {
|
||||
get async {
|
||||
ownMembershipDetailsCallsCount += 1
|
||||
if let ownMembershipDetailsClosure = ownMembershipDetailsClosure {
|
||||
return await ownMembershipDetailsClosure()
|
||||
} else {
|
||||
return underlyingOwnMembershipDetails
|
||||
}
|
||||
}
|
||||
}
|
||||
var underlyingOwnMembershipDetails: RoomMembershipDetailsProxyProtocol?
|
||||
var ownMembershipDetailsClosure: (() async -> RoomMembershipDetailsProxyProtocol?)?
|
||||
|
||||
}
|
||||
class RoomProxyMock: RoomProxyProtocol, @unchecked Sendable {
|
||||
var id: String {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Copyright 2025 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
extension RoomPreviewProxyMock {
|
||||
struct Configuration {
|
||||
var roomID = "1"
|
||||
var canonicalAlias = "#3🌞problem:matrix.org"
|
||||
var name = "The Three-Body Problem - 三体"
|
||||
var topic = "“Science and technology were the only keys to opening the door to the future, and people approached science with the faith and sincerity of elementary school students.”"
|
||||
var avatarURL = URL.mockMXCAvatar.absoluteString
|
||||
var numJoinedMembers = UInt64(100)
|
||||
var numActiveMembers = UInt64(100)
|
||||
var roomType = RoomType.room
|
||||
var membership: Membership?
|
||||
var joinRule: JoinRule
|
||||
}
|
||||
|
||||
static var joinable: RoomPreviewProxyMock {
|
||||
.init(.init(membership: nil, joinRule: .public))
|
||||
}
|
||||
|
||||
static var restricted: RoomPreviewProxyMock {
|
||||
.init(.init(membership: nil, joinRule: .restricted(rules: [])))
|
||||
}
|
||||
|
||||
static var inviteRequired: RoomPreviewProxyMock {
|
||||
.init(.init(membership: nil, joinRule: .invite))
|
||||
}
|
||||
|
||||
static func invited(roomID: String? = nil) -> RoomPreviewProxyMock {
|
||||
if let roomID {
|
||||
return .init(.init(roomID: roomID, membership: .invited, joinRule: .invite))
|
||||
}
|
||||
|
||||
return .init(.init(membership: .invited, joinRule: .invite))
|
||||
}
|
||||
|
||||
static var knockable: RoomPreviewProxyMock {
|
||||
.init(.init(membership: nil, joinRule: .knock))
|
||||
}
|
||||
|
||||
static var knockableRestricted: RoomPreviewProxyMock {
|
||||
.init(.init(membership: nil, joinRule: .knockRestricted(rules: [])))
|
||||
}
|
||||
|
||||
static var knocked: RoomPreviewProxyMock {
|
||||
.init(.init(membership: .knocked, joinRule: .knock))
|
||||
}
|
||||
|
||||
static var banned: RoomPreviewProxyMock {
|
||||
.init(.init(membership: .banned, joinRule: .public))
|
||||
}
|
||||
|
||||
convenience init(_ configuration: RoomPreviewProxyMock.Configuration) {
|
||||
self.init()
|
||||
underlyingInfo = .init(roomPreviewInfo: .init(roomId: configuration.roomID,
|
||||
canonicalAlias: configuration.canonicalAlias,
|
||||
name: configuration.name,
|
||||
topic: configuration.topic,
|
||||
avatarUrl: configuration.avatarURL,
|
||||
numJoinedMembers: configuration.numJoinedMembers,
|
||||
numActiveMembers: configuration.numActiveMembers,
|
||||
roomType: configuration.roomType,
|
||||
isHistoryWorldReadable: nil,
|
||||
membership: configuration.membership,
|
||||
joinRule: configuration.joinRule,
|
||||
isDirect: nil,
|
||||
heroes: nil))
|
||||
|
||||
let roomMembershipDetails = RoomMembershipDetailsProxyMock()
|
||||
|
||||
let mockMember = RoomMemberProxyMock()
|
||||
mockMember.userID = "@bob:matrix.org"
|
||||
mockMember.displayName = "Billy Bob"
|
||||
mockMember.avatarURL = .mockMXCUserAvatar
|
||||
mockMember.membershipChangeReason = "Ain't nobody need no reason"
|
||||
|
||||
roomMembershipDetails.senderRoomMember = mockMember
|
||||
roomMembershipDetails.ownRoomMember = mockMember
|
||||
|
||||
underlyingOwnMembershipDetails = roomMembershipDetails
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user