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

Feat: add a build setting flag to always show the server selection screen in login/registration flow. #7541

Merged
merged 2 commits into from
May 11, 2023
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
9 changes: 7 additions & 2 deletions Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ final class BuildSettings: NSObject {

// MARK: - Server configuration

// Default servers proposed on the authentication screen
/// Force the user to set a homeserver instead of using the default one
static let forceHomeserverSelection = false
nimau marked this conversation as resolved.
Show resolved Hide resolved

/// Default server proposed on the authentication screen
static let serverConfigDefaultHomeserverUrlString = "https://matrix.org"
static let serverConfigDefaultIdentityServerUrlString = "https://vector.im"

/// Default identity server
static let serverConfigDefaultIdentityServerUrlString = "https://vector.im"

static let serverConfigSygnalAPIUrlString = "https://matrix.org/_matrix/push/v1/notify"


Expand Down
9 changes: 8 additions & 1 deletion Riot/Modules/Authentication/AuthenticationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc
}

let flow: AuthenticationFlow = initialScreen == .login ? .login : .register

// Check if the user must select a server
if BuildSettings.forceHomeserverSelection, authenticationService.provisioningLink?.homeserverUrl == nil {
showServerSelectionScreen(for: flow)
return
}

do {
// Start the flow using the default server (or a provisioning link if set).
// Start the flow (if homeserverAddress is nil, the default server will be used).
try await authenticationService.startFlow(flow)
} catch {
MXLog.error("[AuthenticationCoordinator] start: Failed to start, showing server selection.")
Expand Down
18 changes: 16 additions & 2 deletions Riot/Modules/Authentication/Legacy/AuthenticationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ - (void)viewDidLoad
target:self
action:@selector(onButtonPressed:)];

self.defaultHomeServerUrl = RiotSettings.shared.homeserverUrlString;
if (BuildSettings.forceHomeserverSelection)
{
self.defaultHomeServerUrl = nil;
}
else
{
self.defaultHomeServerUrl = RiotSettings.shared.homeserverUrlString;
}

self.defaultIdentityServerUrl = RiotSettings.shared.identityServerUrlString;

Expand Down Expand Up @@ -1207,7 +1214,14 @@ - (void)setCustomServerFieldsVisible:(BOOL)isVisible
[self saveCustomServerInputs];

// Restore default configuration
[self setHomeServerTextFieldText:self.defaultHomeServerUrl];
if (BuildSettings.forceHomeserverSelection)
{
[self setHomeServerTextFieldText:nil];
}
else
{
[self setHomeServerTextFieldText:self.defaultHomeServerUrl];
}
[self setIdentityServerTextFieldText:self.defaultIdentityServerUrl];

[self.customServersTickButton setImage:AssetImages.selectionUntick.image forState:UIControlStateNormal];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class HomeserverAddress: NSObject {
/// - Ensure the address contains a scheme, otherwise make it `https`.
/// - Remove any trailing slashes.
static func sanitized(_ address: String) -> String {
guard !address.isEmpty else {
// prevent prefixing an empty string with "https:"
return address
}
nimau marked this conversation as resolved.
Show resolved Hide resolved
var address = address.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()

if !address.contains("://") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ final class AuthenticationServerSelectionCoordinator: Coordinator, Presentable {
self.parameters = parameters

let homeserver = parameters.authenticationService.state.homeserver
let viewModel = AuthenticationServerSelectionViewModel(homeserverAddress: homeserver.displayableAddress,
let homeserverAddress: String
if BuildSettings.forceHomeserverSelection, homeserver.addressFromUser == nil {
homeserverAddress = ""
} else {
homeserverAddress = homeserver.displayableAddress
}
let viewModel = AuthenticationServerSelectionViewModel(homeserverAddress: homeserverAddress,
flow: parameters.authenticationService.state.flow,
hasModalPresentation: parameters.hasModalPresentation)
let view = AuthenticationServerSelectionScreen(viewModel: viewModel.context)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7541.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a flag in the build settings to force the user to define a homeserver instead of using the default one.