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 1 commit
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
nimau marked this conversation as resolved.
Show resolved Hide resolved
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
14 changes: 12 additions & 2 deletions Riot/Modules/Authentication/AuthenticationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,19 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc
}

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

// Use the homeserver defined by a provisioningLink or by the user (if none is set, the default one will be used)
let homeserverAddress = authenticationService.provisioningLink?.homeserverUrl ?? authenticationService.state.homeserver.addressFromUser

// Check if the user must select a server
if BuildSettings.forceHomeserverSelection, homeserverAddress == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, good job remembering to check the provisioning link - I would have forgotten about that 😃

However we shouldn't include the addressFromUser here as it alters the intended behaviour where navigating back to the carousel and starting again defaults to matrix.org once more. Could probably remove the let homeserverAddress here, check the provisioning link directly in the if and then call startFlow(flow) like before without an address.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I updated it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks 👍

showServerSelectionScreen(for: flow)
return
}

do {
// Start the flow using the default server (or a provisioning link if set).
try await authenticationService.startFlow(flow)
// Start the flow (if homeserverAddress is nil, the default server will be used).
try await authenticationService.startFlow(flow, for: homeserverAddress)
} catch {
MXLog.error("[AuthenticationCoordinator] start: Failed to start, showing server selection.")
showServerSelectionScreen(for: flow)
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.