Add support for joining rooms from a space. (#4501)

* Add support for joining rooms from a space.

Doesn't yet handle the Join button 🤔

* Handle the join button for both rooms and spaces.

Also refactor more instances of spaceRoom to spaceRoomProxy.
This commit is contained in:
Doug
2025-09-11 16:41:19 +01:00
committed by GitHub
parent 880f2060f4
commit c2ac60f1e6
30 changed files with 304 additions and 34 deletions
+14 -2
View File
@@ -15,6 +15,7 @@ struct ClientProxyMockConfiguration {
var deviceID: String?
var roomSummaryProvider: RoomSummaryProviderProtocol = RoomSummaryProviderMock(.init())
var joinedSpaceRooms: [SpaceRoomProxyProtocol] = []
var roomPreviews: [RoomPreviewProxyProtocol]?
var roomDirectorySearchProxy: RoomDirectorySearchProxyProtocol?
var recoveryState: SecureBackupRecoveryState = .enabled
@@ -65,6 +66,7 @@ extension ClientProxyMock {
directRoomForUserIDReturnValue = .failure(.sdkError(ClientProxyMockError.generic))
createDirectRoomWithExpectedRoomNameReturnValue = .failure(.sdkError(ClientProxyMockError.generic))
createRoomNameTopicIsRoomPrivateIsKnockingOnlyUserIDsAvatarURLAliasLocalPartReturnValue = .failure(.sdkError(ClientProxyMockError.generic))
canJoinRoomWithReturnValue = true
uploadMediaReturnValue = .failure(.sdkError(ClientProxyMockError.generic))
loadUserDisplayNameReturnValue = .failure(.sdkError(ClientProxyMockError.generic))
setUserDisplayNameReturnValue = .failure(.sdkError(ClientProxyMockError.generic))
@@ -95,13 +97,23 @@ extension ClientProxyMock {
roomForIdentifierClosure = { [weak self] identifier in
if let room = self?.roomSummaryProvider.roomListPublisher.value.first(where: { $0.id == identifier }) {
await .joined(JoinedRoomProxyMock(.init(id: room.id, name: room.name)))
} else if let spaceRoom = configuration.joinedSpaceRooms.first(where: { $0.id == identifier }) {
await .joined(JoinedRoomProxyMock(.init(id: spaceRoom.id, name: spaceRoom.name)))
} else if let spaceRoomProxy = configuration.joinedSpaceRooms.first(where: { $0.id == identifier }) {
await .joined(JoinedRoomProxyMock(.init(id: spaceRoomProxy.id, name: spaceRoomProxy.name)))
} else {
nil
}
}
if let roomPreviews = configuration.roomPreviews {
roomPreviewForIdentifierViaClosure = { roomID, _ in
if let preview = roomPreviews.first(where: { $0.info.id == roomID }) {
.success(preview)
} else {
.failure(.roomPreviewIsPrivate)
}
}
}
userIdentityForReturnValue = .success(UserIdentityProxyMock(configuration: .init()))
underlyingIsReportRoomSupported = true
@@ -2987,6 +2987,76 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
return knockRoomAliasMessageReturnValue
}
}
//MARK: - canJoinRoom
var canJoinRoomWithUnderlyingCallsCount = 0
var canJoinRoomWithCallsCount: Int {
get {
if Thread.isMainThread {
return canJoinRoomWithUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = canJoinRoomWithUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
canJoinRoomWithUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
canJoinRoomWithUnderlyingCallsCount = newValue
}
}
}
}
var canJoinRoomWithCalled: Bool {
return canJoinRoomWithCallsCount > 0
}
var canJoinRoomWithReceivedRules: [AllowRule]?
var canJoinRoomWithReceivedInvocations: [[AllowRule]] = []
var canJoinRoomWithUnderlyingReturnValue: Bool!
var canJoinRoomWithReturnValue: Bool! {
get {
if Thread.isMainThread {
return canJoinRoomWithUnderlyingReturnValue
} else {
var returnValue: Bool? = nil
DispatchQueue.main.sync {
returnValue = canJoinRoomWithUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
canJoinRoomWithUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
canJoinRoomWithUnderlyingReturnValue = newValue
}
}
}
}
var canJoinRoomWithClosure: (([AllowRule]) -> Bool)?
func canJoinRoom(with rules: [AllowRule]) -> Bool {
canJoinRoomWithCallsCount += 1
canJoinRoomWithReceivedRules = rules
DispatchQueue.main.async {
self.canJoinRoomWithReceivedInvocations.append(rules)
}
if let canJoinRoomWithClosure = canJoinRoomWithClosure {
return canJoinRoomWithClosure(rules)
} else {
return canJoinRoomWithReturnValue
}
}
//MARK: - uploadMedia
var uploadMediaUnderlyingCallsCount = 0
@@ -96,4 +96,18 @@ extension RoomPreviewProxyMock {
underlyingOwnMembershipDetails = roomMembershipDetails
}
convenience init(spaceRoomProxy: SpaceRoomProxyProtocol) {
self.init(Configuration(roomID: spaceRoomProxy.id,
canonicalAlias: spaceRoomProxy.canonicalAlias ?? "",
name: spaceRoomProxy.name ?? "",
topic: spaceRoomProxy.topic ?? "",
avatarURL: spaceRoomProxy.avatarURL?.absoluteString ?? "",
numJoinedMembers: UInt64(spaceRoomProxy.joinedMembersCount),
numActiveMembers: UInt64(spaceRoomProxy.joinedMembersCount),
roomType: spaceRoomProxy.isSpace ? .space : .room,
membership: nil,
joinRule: spaceRoomProxy.joinRule ?? .restricted(rules: []),
isDirect: false))
}
}
@@ -19,8 +19,8 @@ extension SpaceServiceProxyMock {
self.init()
joinedSpacesPublisher = .init(configuration.joinedSpaces)
spaceRoomListForClosure = { spaceRoom in
if let spaceRoomList = configuration.spaceRoomLists[spaceRoom.id] {
spaceRoomListForClosure = { spaceRoomProxy in
if let spaceRoomList = configuration.spaceRoomLists[spaceRoomProxy.id] {
.success(spaceRoomList)
} else {
.failure(.sdkError(ClientProxyMockError.generic))