From 1a21b03d6e5c2a98f8b840530422c51d0b5cddf9 Mon Sep 17 00:00:00 2001 From: Frank Rotermund Date: Thu, 15 Jun 2023 07:40:58 +0200 Subject: [PATCH] MESSENGER-3539 prevent logout and error popup when logging out --- Riot/Assets/de.lproj/Bwi.strings | 1 + Riot/Assets/en.lproj/Bwi.strings | 1 + Riot/Generated/BWIStrings.swift | 4 +++ .../Modules/Settings/SettingsViewController.h | 8 ++++++ .../Modules/Settings/SettingsViewController.m | 27 ++++++++++++++----- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Riot/Assets/de.lproj/Bwi.strings b/Riot/Assets/de.lproj/Bwi.strings index 40345b21f..87ea882eb 100644 --- a/Riot/Assets/de.lproj/Bwi.strings +++ b/Riot/Assets/de.lproj/Bwi.strings @@ -501,6 +501,7 @@ "bwi_error_invite_already_in_room" = "%@ ist bereits im Raum."; "bwi_error_invite_banned_in_room" = "%@ ist vom Raum gebannt."; "bwi_error_invite_general" = "%@ konnte nicht eingeladen werden."; +"bwi_error_logout_offline" = "Abmelden ist ohne Internetverbindung nicht möglich."; // MARK: - Matomo diff --git a/Riot/Assets/en.lproj/Bwi.strings b/Riot/Assets/en.lproj/Bwi.strings index f7ace9edb..dad7187c4 100644 --- a/Riot/Assets/en.lproj/Bwi.strings +++ b/Riot/Assets/en.lproj/Bwi.strings @@ -410,6 +410,7 @@ "bwi_error_invite_already_in_room" = "%@ is already in the room."; "bwi_error_invite_banned_in_room" = "%@ is banned from the room."; "bwi_error_invite_general" = "%@ could not be invited."; +"bwi_error_logout_offline" = "Logout not possible without internet connection."; // MARK: - Matomo diff --git a/Riot/Generated/BWIStrings.swift b/Riot/Generated/BWIStrings.swift index 5d67dcb14..c5f4c7907 100644 --- a/Riot/Generated/BWIStrings.swift +++ b/Riot/Generated/BWIStrings.swift @@ -211,6 +211,10 @@ public class BWIL10n: NSObject { public static func bwiErrorInviteGeneral(_ p1: String) -> String { return BWIL10n.tr("Bwi", "bwi_error_invite_general", p1) } + /// Abmelden ist ohne Internetverbindung nicht möglich. + public static var bwiErrorLogoutOffline: String { + return BWIL10n.tr("Bwi", "bwi_error_logout_offline") + } /// Du kannst jetzt aktive und vergangene Umfragen gesammelt in den Raumdetails einsehen (erreichbar unter Raumdetails, im Bereich "Umfrageverlauf"). public static var bwiFeatureBannerAdvertisementText: String { return BWIL10n.tr("Bwi", "bwi_feature_banner_advertisement_text") diff --git a/Riot/Modules/Settings/SettingsViewController.h b/Riot/Modules/Settings/SettingsViewController.h index 3e99593fc..5b5f87b27 100644 --- a/Riot/Modules/Settings/SettingsViewController.h +++ b/Riot/Modules/Settings/SettingsViewController.h @@ -16,6 +16,14 @@ #import "MatrixKit.h" +FOUNDATION_EXPORT NSString *const BWISettingsErrorDomain; + +typedef enum : NSUInteger +{ + BWISettingsOfflineLogoutErrorCode +} +BWISettingsErrorCode; + @interface SettingsViewController : MXKTableViewController + (instancetype)instantiate; diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 6bec36352..56a3f6565 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -47,6 +47,8 @@ NSString* const kSettingsViewControllerPhoneBookCountryCellId = @"kSettingsViewControllerPhoneBookCountryCellId"; +NSString *const BWISettingsErrorDomain = @"BWISettingsErrorDomain"; + typedef NS_ENUM(NSUInteger, SECTION_TAG) { SECTION_TAG_SIGN_OUT = 0, @@ -3452,13 +3454,24 @@ ChangePasswordCoordinatorBridgePresenterDelegate> - (void)onSignout:(id)sender { - self.signOutButton = (UIButton*)sender; - - SignOutFlowPresenter *flowPresenter = [[SignOutFlowPresenter alloc] initWithSession:self.mainSession presentingViewController:self]; - flowPresenter.delegate = self; - - [flowPresenter startWithSourceView:self.signOutButton]; - self.signOutFlowPresenter = flowPresenter; + // bwi (#3539) Check connectivity before login out. Logout can have strange effects when occuring without network connection + if ([AppDelegate theDelegate].isOffline) + { + NSError *error = [NSError errorWithDomain:BWISettingsErrorDomain + code:BWISettingsOfflineLogoutErrorCode + userInfo:@{ + NSLocalizedDescriptionKey : BWIL10n.bwiErrorLogoutOffline + }]; + [[AppDelegate theDelegate] showErrorAsAlert:error]; + } else { + self.signOutButton = (UIButton*)sender; + + SignOutFlowPresenter *flowPresenter = [[SignOutFlowPresenter alloc] initWithSession:self.mainSession presentingViewController:self]; + flowPresenter.delegate = self; + + [flowPresenter startWithSourceView:self.signOutButton]; + self.signOutFlowPresenter = flowPresenter; + } } - (void)onRemove3PID:(NSIndexPath*)indexPath