mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Added the banned room proxy (#3744)
* added the banned room proxy and a way to have a consistent loading + a retry alert * trailing closure * indent a comment * push package.resolved * updated test case
This commit is contained in:
@@ -91,6 +91,7 @@ struct JoinRoomScreenViewStateBindings {
|
||||
enum JoinRoomScreenAlertType {
|
||||
case declineInvite
|
||||
case cancelKnock
|
||||
case loadingError
|
||||
}
|
||||
|
||||
enum JoinRoomScreenViewAction {
|
||||
|
||||
@@ -19,6 +19,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
||||
|
||||
private var roomPreview: RoomPreviewProxyProtocol?
|
||||
private var room: RoomProxyType?
|
||||
private var isLoadingPreview = true
|
||||
private var membershipStateChangeCancellable: AnyCancellable?
|
||||
|
||||
private let actionsSubject: PassthroughSubject<JoinRoomScreenViewModelAction, Never> = .init()
|
||||
@@ -81,12 +82,19 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
||||
|
||||
switch await clientProxy.roomPreviewForIdentifier(roomID, via: via) {
|
||||
case .success(let roomPreview):
|
||||
isLoadingPreview = false
|
||||
self.roomPreview = roomPreview
|
||||
await updateRoomDetails()
|
||||
case .failure(.roomPreviewIsPrivate):
|
||||
break // Handled by the mode, we don't need an error indicator.
|
||||
// Handled by the mode, we don't need an error indicator.
|
||||
isLoadingPreview = false
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(UserIndicator(title: L10n.errorUnknown))
|
||||
hideLoadingIndicator()
|
||||
state.bindings.alertInfo = .init(id: .loadingError,
|
||||
title: L10n.commonError,
|
||||
message: L10n.screenJoinRoomLoadingAlertMessage,
|
||||
primaryButton: .init(title: L10n.actionTryAgain) { [weak self] in Task { await self?.loadRoomDetails() }},
|
||||
secondaryButton: .init(title: L10n.actionCancel, role: .cancel) { [weak self] in self?.actionsSubject.send(.dismiss) })
|
||||
}
|
||||
|
||||
hideLoadingIndicator()
|
||||
@@ -131,6 +139,8 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
||||
Task { await self?.loadRoomDetails() }
|
||||
}
|
||||
}
|
||||
case .banned(let bannedRoomProxy):
|
||||
roomInfo = bannedRoomProxy.info
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -155,6 +165,11 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
||||
}
|
||||
|
||||
private func updateMode() async {
|
||||
if isLoadingPreview {
|
||||
state.mode = .loading
|
||||
return
|
||||
}
|
||||
|
||||
if roomPreview == nil, room == nil {
|
||||
state.mode = .unknown
|
||||
return
|
||||
@@ -336,12 +351,12 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
||||
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: roomID, type: .modal, title: L10n.commonLoading, persistent: true))
|
||||
|
||||
guard case .banned = room, let roomPreview else {
|
||||
guard case let .banned(roomProxy) = room else {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
let result = await roomPreview.forgetRoom()
|
||||
let result = await roomProxy.forgetRoom()
|
||||
|
||||
if case .failure = result {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
|
||||
@@ -330,7 +330,7 @@ struct JoinRoomScreen_Previews: PreviewProvider, TestablePreview {
|
||||
|
||||
switch mode {
|
||||
case .unknown:
|
||||
clientProxy.roomPreviewForIdentifierViaReturnValue = .failure(.sdkError(ClientProxyMockError.generic))
|
||||
clientProxy.roomPreviewForIdentifierViaReturnValue = .failure(.roomPreviewIsPrivate)
|
||||
clientProxy.roomForIdentifierReturnValue = nil
|
||||
case .joinable:
|
||||
clientProxy.roomPreviewForIdentifierViaReturnValue = .success(RoomPreviewProxyMock.joinable)
|
||||
@@ -364,7 +364,7 @@ struct JoinRoomScreen_Previews: PreviewProvider, TestablePreview {
|
||||
case .banned:
|
||||
clientProxy.roomPreviewForIdentifierViaReturnValue = .success(RoomPreviewProxyMock.banned)
|
||||
clientProxy.roomForIdentifierClosure = { _ in
|
||||
.banned
|
||||
.banned(BannedRoomProxyMock(.init(avatarURL: .mockMXCAvatar)))
|
||||
}
|
||||
case .forbidden:
|
||||
clientProxy.roomPreviewForIdentifierViaReturnValue = .success(RoomPreviewProxyMock.restricted)
|
||||
|
||||
Reference in New Issue
Block a user