mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Expose sliding sync proxy URL on the server selection screen; make app more resilient to slidinc sync configuration errors, remove fatal errors
This commit is contained in:
committed by
Stefan Ceriu
parent
2fd0491a18
commit
276daf0355
@@ -59,6 +59,8 @@ struct ServerSelectionViewState: BindableState {
|
||||
struct ServerSelectionBindings {
|
||||
/// The homeserver address input by the user.
|
||||
var homeserverAddress: String
|
||||
/// The sliding sync proxy address input by the user.
|
||||
var slidingSyncProxyAddress: String
|
||||
/// Information describing the currently displayed alert.
|
||||
var alertInfo: AlertInfo<ServerSelectionErrorType>?
|
||||
}
|
||||
|
||||
+7
-1
@@ -30,7 +30,9 @@ class ServerSelectionViewModel: ServerSelectionViewModelType, ServerSelectionVie
|
||||
// MARK: - Setup
|
||||
|
||||
init(homeserverAddress: String, isModallyPresented: Bool) {
|
||||
let bindings = ServerSelectionBindings(homeserverAddress: homeserverAddress)
|
||||
let bindings = ServerSelectionBindings(homeserverAddress: homeserverAddress,
|
||||
slidingSyncProxyAddress: ElementSettings.shared.slidingSyncProxyBaseURLString)
|
||||
|
||||
super.init(initialViewState: ServerSelectionViewState(bindings: bindings,
|
||||
isModallyPresented: isModallyPresented))
|
||||
}
|
||||
@@ -40,6 +42,10 @@ class ServerSelectionViewModel: ServerSelectionViewModelType, ServerSelectionVie
|
||||
override func process(viewAction: ServerSelectionViewAction) async {
|
||||
switch viewAction {
|
||||
case .confirm:
|
||||
if !state.bindings.slidingSyncProxyAddress.isEmpty {
|
||||
ElementSettings.shared.slidingSyncProxyBaseURLString = state.bindings.slidingSyncProxyAddress
|
||||
}
|
||||
|
||||
callback?(.confirm(homeserverAddress: state.bindings.homeserverAddress))
|
||||
case .dismiss:
|
||||
callback?(.dismiss)
|
||||
|
||||
+13
-12
@@ -17,18 +17,8 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ServerSelectionScreen: View {
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@FocusState var isTextFieldFocused: Bool
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@ObservedObject var context: ServerSelectionViewModel.Context
|
||||
|
||||
// MARK: Views
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(spacing: 0) {
|
||||
@@ -69,8 +59,8 @@ struct ServerSelectionScreen: View {
|
||||
var serverForm: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
TextField(ElementL10n.ftueAuthChooseServerEntryHint, text: $context.homeserverAddress)
|
||||
.focused($isTextFieldFocused)
|
||||
.textFieldStyle(.elementInput(footerText: context.viewState.footerMessage,
|
||||
.textFieldStyle(.elementInput(labelText: ElementL10n.hsUrl,
|
||||
footerText: context.viewState.footerMessage,
|
||||
isError: context.viewState.isShowingFooterError))
|
||||
.keyboardType(.URL)
|
||||
.autocapitalization(.none)
|
||||
@@ -80,6 +70,17 @@ struct ServerSelectionScreen: View {
|
||||
.onSubmit(submit)
|
||||
.accessibilityIdentifier("addressTextField")
|
||||
|
||||
Divider()
|
||||
|
||||
TextField(ElementL10n.ftueAuthChooseServerEntryHint, text: $context.slidingSyncProxyAddress)
|
||||
.textFieldStyle(.elementInput(labelText: "Sliding sync proxy URL"))
|
||||
.keyboardType(.URL)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.submitLabel(.done)
|
||||
.onSubmit(submit)
|
||||
.accessibilityIdentifier("slidingSyncProxyAddressTextField")
|
||||
|
||||
Button(action: submit) {
|
||||
Text(context.viewState.buttonTitle)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ typealias HomeScreenViewModelType = StateStoreViewModel<HomeScreenViewState, Hom
|
||||
|
||||
class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol {
|
||||
private let userSession: UserSessionProtocol
|
||||
private let roomSummaryProvider: RoomSummaryProviderProtocol
|
||||
private let roomSummaryProvider: RoomSummaryProviderProtocol?
|
||||
private let attributedStringBuilder: AttributedStringBuilderProtocol
|
||||
private var roomsForIdentifiers = [String: HomeScreenRoom]()
|
||||
|
||||
@@ -51,6 +51,25 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
Task {
|
||||
if case let .success(userAvatarURLString) = await userSession.clientProxy.loadUserAvatarURLString() {
|
||||
if case let .success(avatar) = await userSession.mediaProvider.loadImageFromURLString(userAvatarURLString, avatarSize: .user(on: .home)) {
|
||||
state.userAvatar = avatar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Task {
|
||||
if case let .success(userDisplayName) = await userSession.clientProxy.loadUserDisplayName() {
|
||||
state.userDisplayName = userDisplayName
|
||||
}
|
||||
}
|
||||
|
||||
guard let roomSummaryProvider else {
|
||||
MXLog.error("Room summary provider unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
Publishers.CombineLatest3(roomSummaryProvider.statePublisher,
|
||||
roomSummaryProvider.countPublisher,
|
||||
roomSummaryProvider.roomListPublisher)
|
||||
@@ -77,20 +96,6 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
Task {
|
||||
if case let .success(userAvatarURLString) = await userSession.clientProxy.loadUserAvatarURLString() {
|
||||
if case let .success(avatar) = await userSession.mediaProvider.loadImageFromURLString(userAvatarURLString, avatarSize: .user(on: .home)) {
|
||||
state.userAvatar = avatar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Task {
|
||||
if case let .success(userDisplayName) = await userSession.clientProxy.loadUserDisplayName() {
|
||||
state.userDisplayName = userDisplayName
|
||||
}
|
||||
}
|
||||
|
||||
updateRooms()
|
||||
}
|
||||
|
||||
@@ -99,7 +104,9 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
override func process(viewAction: HomeScreenViewAction) async {
|
||||
switch viewAction {
|
||||
case .loadRoomData(let roomIdentifier):
|
||||
loadDataForRoomIdentifier(roomIdentifier)
|
||||
if state.roomListMode != .skeletons {
|
||||
loadDataForRoomIdentifier(roomIdentifier)
|
||||
}
|
||||
case .selectRoom(let roomIdentifier):
|
||||
callback?(.selectRoom(roomIdentifier: roomIdentifier))
|
||||
case .userMenu(let action):
|
||||
@@ -118,6 +125,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
// MARK: - Private
|
||||
|
||||
private func loadDataForRoomIdentifier(_ identifier: String) {
|
||||
guard let roomSummaryProvider else {
|
||||
MXLog.error("Room summary provider unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
guard let roomSummary = roomSummaryProvider.roomListPublisher.value.first(where: { $0.asFilled?.id == identifier })?.asFilled,
|
||||
let roomIndex = state.rooms.firstIndex(where: { $0.id == identifier }) else {
|
||||
return
|
||||
@@ -140,6 +152,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
}
|
||||
|
||||
private func updateRooms() {
|
||||
guard let roomSummaryProvider else {
|
||||
MXLog.error("Room summary provider unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
var rooms = [HomeScreenRoom]()
|
||||
var newRoomsForIdentifiers = [String: HomeScreenRoom]()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user