mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +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:
@@ -516,11 +516,10 @@ class ClientProxy: ClientProxyProtocol {
|
||||
return await buildRoomForIdentifier(identifier)
|
||||
}
|
||||
|
||||
func roomPreviewForIdentifier(_ identifier: String, via: [String]) async -> Result<RoomPreviewDetails, ClientProxyError> {
|
||||
func roomPreviewForIdentifier(_ identifier: String, via: [String]) async -> Result<RoomPreviewProxyProtocol, ClientProxyError> {
|
||||
do {
|
||||
let roomPreview = try await client.getRoomPreviewFromRoomId(roomId: identifier, viaServers: via)
|
||||
let roomPreviewInfo = try roomPreview.info()
|
||||
return .success(.init(roomPreviewInfo))
|
||||
return try .success(RoomPreviewProxy(roomPreview: roomPreview))
|
||||
} catch let error as ClientError where error.code == .forbidden {
|
||||
return .failure(.roomPreviewIsPrivate)
|
||||
} catch {
|
||||
@@ -1155,40 +1154,3 @@ private class SendQueueRoomErrorListenerProxy: SendQueueRoomErrorListener {
|
||||
onErrorClosure(roomId, error)
|
||||
}
|
||||
}
|
||||
|
||||
private extension RoomPreviewDetails {
|
||||
init(_ roomPreviewInfo: RoomPreviewInfo) {
|
||||
self = RoomPreviewDetails(roomID: roomPreviewInfo.roomId,
|
||||
name: roomPreviewInfo.name,
|
||||
canonicalAlias: roomPreviewInfo.canonicalAlias,
|
||||
topic: roomPreviewInfo.topic,
|
||||
avatarURL: roomPreviewInfo.avatarUrl.flatMap(URL.init(string:)),
|
||||
memberCount: UInt(roomPreviewInfo.numJoinedMembers),
|
||||
isHistoryWorldReadable: roomPreviewInfo.isHistoryWorldReadable ?? false,
|
||||
isJoined: roomPreviewInfo.membership == .joined,
|
||||
isInvited: roomPreviewInfo.membership == .invited,
|
||||
isPublic: roomPreviewInfo.isPublic,
|
||||
canKnock: roomPreviewInfo.canKnock)
|
||||
}
|
||||
}
|
||||
|
||||
private extension RoomPreviewInfo {
|
||||
var canKnock: Bool {
|
||||
switch joinRule {
|
||||
case .knock, .knockRestricted:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var isPublic: Bool {
|
||||
switch joinRule {
|
||||
// for restricted rooms we want to show optimistically that the we may be able to join the room
|
||||
case .public, .restricted:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user