Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
Loading