Skip to content

Commit

Permalink
Use the same UI as Android when tapping a link to a private room. (#3044
Browse files Browse the repository at this point in the history
)

* Use the same UI as Android when tapping a link to a private room.

* Fix preview of knocking.

* Fix snapshots.
  • Loading branch information
pixlwave authored Jul 18, 2024
1 parent 6339fe2 commit 7fbdc2c
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ struct JoinRoomScreenViewState: BindableState {
roomDetails?.name ?? L10n.screenJoinRoomTitleNoPreview
}

var subtitle: String? {
switch mode {
case .loading: nil
case .unknown: L10n.screenJoinRoomSubtitleNoPreview
case .invited, .join, .knock: roomDetails?.canonicalAlias
}
}

var avatar: RoomAvatar {
.room(id: roomID, name: title, avatarURL: roomDetails?.avatarURL)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typealias JoinRoomScreenViewModelType = StateStoreViewModel<JoinRoomScreenViewSt
class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewModelProtocol {
private let roomID: String
private let via: [String]
private let allowKnocking: Bool // For preview tests only, actions aren't sent.
private let clientProxy: ClientProxyProtocol
private let userIndicatorController: UserIndicatorControllerProtocol

Expand All @@ -32,11 +33,13 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo

init(roomID: String,
via: [String],
allowKnocking: Bool = false,
clientProxy: ClientProxyProtocol,
mediaProvider: MediaProviderProtocol,
userIndicatorController: UserIndicatorControllerProtocol) {
self.roomID = roomID
self.via = via
self.allowKnocking = allowKnocking
self.clientProxy = clientProxy
self.userIndicatorController = userIndicatorController

Expand Down Expand Up @@ -81,6 +84,8 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
switch await clientProxy.roomPreviewForIdentifier(roomID, via: via) {
case .success(let roomDetails):
state.roomDetails = roomDetails
case .failure(.roomPreviewIsPrivate):
break // Handled by the mode, we don't need an error indicator.
case .failure:
userIndicatorController.submitIndicator(UserIndicator(title: L10n.errorUnknown))
}
Expand All @@ -96,8 +101,8 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
state.mode = .join
} else if roomDetails.isInvited {
state.mode = .invited
} else if roomDetails.canKnock { // Knocking is not supported yet, treat it as .unknown
state.mode = .unknown
} else if roomDetails.canKnock, allowKnocking { // Knocking is not supported yet, the flag is purely for preview tests.
state.mode = .knock
} else {
state.mode = .unknown
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ struct JoinRoomScreen: View {
.foregroundStyle(.compound.textPrimary)
.multilineTextAlignment(.center)

if let alias = context.viewState.roomDetails?.canonicalAlias {
Text(alias)
if let subtitle = context.viewState.subtitle {
Text(subtitle)
.font(.compound.bodyMD)
.foregroundStyle(.compound.textSecondary)
.multilineTextAlignment(.center)
}

if let memberCount = context.viewState.roomDetails?.memberCount {
Expand Down Expand Up @@ -168,6 +169,7 @@ struct JoinRoomScreen_Previews: PreviewProvider, TestablePreview {

return JoinRoomScreenViewModel(roomID: "1",
via: [],
allowKnocking: true,
clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
Expand Down
2 changes: 2 additions & 0 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ class ClientProxy: ClientProxyProtocol {
do {
let roomPreview = try await client.getRoomPreviewFromRoomId(roomId: identifier, viaServers: via)
return .success(.init(roomPreview))
} catch let error as ClientError where error.code == .forbidden {
return .failure(.roomPreviewIsPrivate)
} catch {
MXLog.error("Failed retrieving preview for room: \(identifier) with error: \(error)")
return .failure(.sdkError(error))
Expand Down
1 change: 1 addition & 0 deletions ElementX/Sources/Services/Client/ClientProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum ClientProxyError: Error {
case invalidMedia
case invalidUserIDServerName
case failedUploadingMedia(Error, MatrixErrorCode)
case roomPreviewIsPrivate
}

enum SlidingSyncConstants {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7fbdc2c

Please sign in to comment.