Enable OIDC support (#1541)

Notification content is bypassed for now.
This commit is contained in:
Doug
2023-08-22 15:53:27 +01:00
committed by GitHub
parent d633b87609
commit 5e3a32157a
27 changed files with 239 additions and 70 deletions
@@ -48,6 +48,8 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
switch action {
case .close:
self.callback?(.dismiss)
case .account:
self.presentAccountSettings()
case .analytics:
self.presentAnalyticsScreen()
case .reportBug:
@@ -74,6 +76,26 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
// MARK: - Private
private var accountSettingsPresenter: OIDCAccountSettingsPresenter?
private func presentAccountSettings() {
guard let accountURL = viewModel.context.viewState.accountURL else {
MXLog.error("Account URL is missing.")
return
}
guard let window = viewModel.context.viewState.window else {
MXLog.error("The window is missing.")
return
}
// Safari never works in the simulator, use a Web Authentication Session instead.
accountSettingsPresenter = OIDCAccountSettingsPresenter(accountURL: accountURL, presentationAnchor: window)
accountSettingsPresenter?.start()
// Safari isn't working with the shared browser session 😕
// UIApplication.shared.open(accountURL)
}
private func presentAnalyticsScreen() {
let coordinator = AnalyticsSettingsScreenCoordinator(parameters: .init(appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics))
@@ -19,6 +19,7 @@ import UIKit
enum SettingsScreenViewModelAction {
case close
case account
case analytics
case reportBug
case about
@@ -32,11 +33,15 @@ struct SettingsScreenViewState: BindableState {
var bindings: SettingsScreenViewStateBindings
var deviceID: String?
var userID: String
var accountURL: URL?
var userAvatarURL: URL?
var userDisplayName: String?
var showSessionVerificationSection: Bool
var showNotificationSettings: Bool
var showDeveloperOptions: Bool
/// The presentation anchor used to display the OIDC account URL.
var window: UIWindow?
}
struct SettingsScreenViewStateBindings {
@@ -45,6 +50,7 @@ struct SettingsScreenViewStateBindings {
enum SettingsScreenViewAction {
case close
case account
case analytics
case reportBug
case about
@@ -53,4 +59,7 @@ enum SettingsScreenViewAction {
case changedTimelineStyle
case developerOptions
case notifications
/// Updates the window used for the OIDC account URL anchor.
case updateWindow(UIWindow)
}
@@ -39,6 +39,7 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
super.init(initialViewState: .init(bindings: bindings,
deviceID: userSession.deviceID,
userID: userSession.userID,
accountURL: userSession.clientProxy.accountURL,
showSessionVerificationSection: showSessionVerificationSection,
showNotificationSettings: appSettings.notificationSettingsEnabled,
showDeveloperOptions: appSettings.canShowDeveloperOptions),
@@ -85,6 +86,8 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
switch viewAction {
case .close:
callback?(.close)
case .account:
callback?(.account)
case .analytics:
callback?(.analytics)
case .reportBug:
@@ -101,6 +104,12 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
callback?(.notifications)
case .developerOptions:
callback?(.developerOptions)
case .updateWindow(let window):
Task {
guard state.window != window else { return }
state.window = window
}
}
}
}
@@ -46,6 +46,9 @@ struct SettingsScreen: View {
doneButton
}
}
.introspect(.window, on: .iOS(.v16)) { window in
context.send(viewAction: .updateWindow(window))
}
}
private var versionText: Text {
@@ -100,6 +103,17 @@ struct SettingsScreen: View {
private var simplifiedSection: some View {
Section {
// Account
if context.viewState.accountURL != nil {
ListRow(label: .default(title: L10n.screenSettingsOidcAccount,
systemIcon: .person),
kind: .button {
context.send(viewAction: .account)
})
.accessibilityIdentifier("notificationsButton")
}
// Message layout
ListRow(label: .default(title: L10n.commonMessageLayout,
systemIcon: .rectangleGrid1x2),
kind: .picker(selection: $context.timelineStyle,
@@ -207,7 +221,8 @@ struct SettingsScreen_Previews: PreviewProvider {
verificationController.isVerified = false
let userSession = MockUserSession(sessionVerificationController: verificationController,
clientProxy: MockClientProxy(userID: "@userid:example.com",
deviceID: "AAAAAAAAAAA"),
deviceID: "AAAAAAAAAAA",
accountURL: "https://matrix.org/account"),
mediaProvider: MockMediaProvider())
ServiceLocator.shared.settings.notificationSettingsEnabled = true
return SettingsScreenViewModel(userSession: userSession,