Skip to content

Commit

Permalink
Merge pull request #7541 from vector-im/nimau/PSB349_force_hs_selection
Browse files Browse the repository at this point in the history
Feat: add a build setting flag to always show the server selection screen in login/registration flow.
  • Loading branch information
nimau authored May 11, 2023
2 parents 0c8c1ce + eae51b3 commit cc9bc24
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
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

/// 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
}
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.

0 comments on commit cc9bc24

Please sign in to comment.