mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 15:22:39 +00:00
Privacy: IS Settings: Change the IS to another one
This commit is contained in:
parent
ea36ee0f10
commit
53214189f9
5 changed files with 116 additions and 20 deletions
|
@ -531,6 +531,9 @@
|
|||
"identity_server_settings_alert_no_terms_title" = "Identity server has no terms of services";
|
||||
"identity_server_settings_alert_no_terms" = "The identity server you have chosen does not have any terms of service. Only continue if you trust the owner of the server.";
|
||||
|
||||
"identity_server_settings_alert_change_title" = "Change identity server";
|
||||
"identity_server_settings_alert_change" = "Disconnect from the identity server %1$@ and connect to %2$@ instead?";
|
||||
|
||||
"identity_server_settings_alert_disconnect_title" = "Disconnect identity server";
|
||||
"identity_server_settings_alert_disconnect" = "Disconnect from the identity server %@?";
|
||||
"identity_server_settings_alert_disconnect_button" = "Disconnect";
|
||||
|
@ -540,12 +543,6 @@
|
|||
"identity_server_settings_alert_error_terms_not_accepted" = "You must accept terms of %@ to set it as identity server.";
|
||||
"identity_server_settings_alert_error_invalid_identity_server" = "%@ is not a valid identity server.";
|
||||
|
||||
/* TODO
|
||||
"settings_discovery_disconnect_with_bound_pid" = "You are currently sharing email addresses or phone numbers on the identity server %@. You will need to reconnect to %s to stop sharing them.";
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// Room Details
|
||||
"room_details_title" = "Room Details";
|
||||
|
|
|
@ -1154,6 +1154,14 @@ internal enum VectorL10n {
|
|||
internal static var identityServerSettingsAdd: String {
|
||||
return VectorL10n.tr("Vector", "identity_server_settings_add")
|
||||
}
|
||||
/// Disconnect from the identity server %1$@ and connect to %2$@ instead?
|
||||
internal static func identityServerSettingsAlertChange(_ p1: String, _ p2: String) -> String {
|
||||
return VectorL10n.tr("Vector", "identity_server_settings_alert_change", p1, p2)
|
||||
}
|
||||
/// Change identity server
|
||||
internal static var identityServerSettingsAlertChangeTitle: String {
|
||||
return VectorL10n.tr("Vector", "identity_server_settings_alert_change_title")
|
||||
}
|
||||
/// Disconnect from the identity server %@?
|
||||
internal static func identityServerSettingsAlertDisconnect(_ p1: String) -> String {
|
||||
return VectorL10n.tr("Vector", "identity_server_settings_alert_disconnect", p1)
|
||||
|
|
|
@ -231,27 +231,46 @@ final class SettingsIdentityServerViewController: UIViewController {
|
|||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
|
||||
switch alert {
|
||||
case .addActionAlert(.noTerms):
|
||||
case .addActionAlert(.invalidIdentityServer(let newHost)),
|
||||
.changeActionAlert(.invalidIdentityServer(let newHost)):
|
||||
self.showAlert(title: nil,
|
||||
message: VectorL10n.identityServerSettingsAlertErrorInvalidIdentityServer(newHost),
|
||||
continueButtonTitle: nil,
|
||||
cancelButtonTitle: VectorL10n.cancel,
|
||||
onContinue: onContinue)
|
||||
|
||||
case .addActionAlert(.noTerms),
|
||||
.changeActionAlert(.noTerms):
|
||||
self.showAlert(title: VectorL10n.identityServerSettingsAlertNoTermsTitle,
|
||||
message: VectorL10n.identityServerSettingsAlertNoTerms,
|
||||
continueButtonTitle: VectorL10n.continue,
|
||||
cancelButtonTitle: VectorL10n.cancel,
|
||||
onContinue: onContinue)
|
||||
|
||||
case .addActionAlert(.termsNotAccepted(let newHost)):
|
||||
case .addActionAlert(.termsNotAccepted(let newHost)),
|
||||
.changeActionAlert(.termsNotAccepted(let newHost)):
|
||||
self.showAlert(title: nil,
|
||||
message: VectorL10n.identityServerSettingsAlertErrorTermsNotAccepted(newHost.hostname()),
|
||||
continueButtonTitle: nil,
|
||||
cancelButtonTitle: VectorL10n.cancel,
|
||||
onContinue: onContinue)
|
||||
|
||||
case .addActionAlert(.invalidIdentityServer(let newHost)):
|
||||
self.showAlert(title: nil,
|
||||
message: VectorL10n.identityServerSettingsAlertErrorInvalidIdentityServer(newHost),
|
||||
continueButtonTitle: nil,
|
||||
|
||||
case .changeActionAlert(.stillSharing3Pids(let oldHost, _)):
|
||||
self.showAlert(title: VectorL10n.identityServerSettingsAlertChangeTitle,
|
||||
message: VectorL10n.identityServerSettingsAlertDisconnectStillSharing3pid(oldHost.hostname()),
|
||||
continueButtonTitle: VectorL10n.identityServerSettingsAlertDisconnectStillSharing3pidButton,
|
||||
cancelButtonTitle: VectorL10n.cancel,
|
||||
onContinue: onContinue)
|
||||
|
||||
case .changeActionAlert(.doubleConfirmation(let oldHost, let newHost)):
|
||||
self.showAlert(title: VectorL10n.identityServerSettingsAlertChangeTitle,
|
||||
message: VectorL10n.identityServerSettingsAlertChange(oldHost.hostname(), newHost.hostname()),
|
||||
continueButtonTitle: VectorL10n.continue,
|
||||
cancelButtonTitle: VectorL10n.cancel,
|
||||
onContinue: onContinue)
|
||||
|
||||
|
||||
case .disconnectActionAlert(.stillSharing3Pids(let oldHost)):
|
||||
self.showAlert(title: VectorL10n.identityServerSettingsAlertDisconnectTitle,
|
||||
message: VectorL10n.identityServerSettingsAlertDisconnectStillSharing3pid(oldHost.hostname()),
|
||||
|
|
|
@ -123,7 +123,77 @@ final class SettingsIdentityServerViewModel: SettingsIdentityServerViewModelType
|
|||
}
|
||||
|
||||
private func changeIdentityServer(_ newIdentityServer: String) {
|
||||
|
||||
guard let identityServer = self.identityServer else {
|
||||
return
|
||||
}
|
||||
|
||||
self.update(viewState: .loading)
|
||||
|
||||
let disconnect: () -> Void = {
|
||||
self.checkExistingDataOnIdentityServer { (response) in
|
||||
switch response {
|
||||
case .success(let existingData):
|
||||
if existingData {
|
||||
self.update(viewState: .alert(alert: SettingsIdentityServerAlert.changeActionAlert(.stillSharing3Pids(oldHost: identityServer, newHost: newIdentityServer)), onContinue: {
|
||||
// TODO: Make a /account/logout request
|
||||
self.update(viewState: .loading)
|
||||
self.updateIdentityServerAndRefreshViewState(with: newIdentityServer)
|
||||
}))
|
||||
} else {
|
||||
self.update(viewState: .alert(alert: SettingsIdentityServerAlert.changeActionAlert(.doubleConfirmation(oldHost: identityServer, newHost: newIdentityServer)), onContinue: {
|
||||
// TODO: Make a /account/logout request
|
||||
self.update(viewState: .loading)
|
||||
self.updateIdentityServerAndRefreshViewState(with: newIdentityServer)
|
||||
}))
|
||||
}
|
||||
case .failure(let error):
|
||||
self.update(viewState: .error(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start the flow like addIdentityServer() by verifying the new IS and its terms
|
||||
// And finish like disconnect()
|
||||
self.checkIdentityServerValidity(identityServer: newIdentityServer) { (identityServerValidityResponse) in
|
||||
print("[SettingsIdentityServerViewModel] changeIdentityServer: \(newIdentityServer). Validity: \(identityServerValidityResponse)")
|
||||
|
||||
switch identityServerValidityResponse {
|
||||
case .success(let identityServerValidity):
|
||||
switch identityServerValidity {
|
||||
case .invalid:
|
||||
// Present invalid IS alert
|
||||
self.update(viewState: .alert(alert: SettingsIdentityServerAlert.changeActionAlert(.invalidIdentityServer(newHost: newIdentityServer)), onContinue: {}))
|
||||
case .valid(status: let termsStatus):
|
||||
switch termsStatus {
|
||||
case .noTerms:
|
||||
self.update(viewState: .alert(alert: SettingsIdentityServerAlert.changeActionAlert(.noTerms(newHost: newIdentityServer)), onContinue: {
|
||||
disconnect()
|
||||
}))
|
||||
case .terms(agreed: let termsAgreed):
|
||||
if termsAgreed {
|
||||
disconnect()
|
||||
} else {
|
||||
guard let accessToken = self.session.matrixRestClient.credentials.accessToken else {
|
||||
print("[SettingsIdentityServerViewModel] changeIdentityServer: Error: No access token")
|
||||
self.update(viewState: .error(SettingsIdentityServerViewModelError.unknown))
|
||||
return
|
||||
}
|
||||
|
||||
// Present terms
|
||||
self.update(viewState: .presentTerms(session: self.session, accessToken: accessToken, baseUrl: newIdentityServer, onComplete: { (areTermsAccepted) in
|
||||
if areTermsAccepted {
|
||||
disconnect()
|
||||
} else {
|
||||
self.update(viewState: .alert(alert: SettingsIdentityServerAlert.changeActionAlert(.termsNotAccepted(newHost: newIdentityServer)), onContinue: {}))
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
self.update(viewState: .error(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func disconnect() {
|
||||
|
|
|
@ -34,20 +34,22 @@ enum SettingsIdentityServerDisplayMode {
|
|||
|
||||
enum SettingsIdentityServerAlert {
|
||||
case addActionAlert(AddActionAlert)
|
||||
//case changeActionAlert(ChangeActionAlert)
|
||||
case changeActionAlert(ChangeActionAlert)
|
||||
case disconnectActionAlert(DisconnectActionAlert)
|
||||
|
||||
enum AddActionAlert {
|
||||
case invalidIdentityServer(newHost: String)
|
||||
case noTerms(newHost: String)
|
||||
case termsNotAccepted(newHost: String)
|
||||
case invalidIdentityServer(newHost: String)
|
||||
}
|
||||
|
||||
// enum ChangeActionAlert {
|
||||
// case stillSharing3Pids(oldHost: String, newHost: String)
|
||||
// case doubleConfirmation(oldHost: String, newHost: String)
|
||||
// case noTerms(newHost: String)
|
||||
// }
|
||||
enum ChangeActionAlert {
|
||||
case invalidIdentityServer(newHost: String)
|
||||
case noTerms(newHost: String)
|
||||
case termsNotAccepted(newHost: String)
|
||||
case stillSharing3Pids(oldHost: String, newHost: String)
|
||||
case doubleConfirmation(oldHost: String, newHost: String)
|
||||
}
|
||||
|
||||
enum DisconnectActionAlert {
|
||||
case stillSharing3Pids(oldHost: String)
|
||||
|
|
Loading…
Reference in a new issue