From 3296a7561ff14e69d83d1aa85907554a895e8315 Mon Sep 17 00:00:00 2001 From: manuroe Date: Thu, 21 Nov 2019 16:36:08 +0100 Subject: [PATCH] Widgets: Display an error if the IM is disabled #2843 --- Riot/Assets/en.lproj/Vector.strings | 1 + Riot/Generated/Strings.swift | 4 +++ Riot/Managers/Widgets/WidgetManager.h | 1 + Riot/Managers/Widgets/WidgetManager.m | 15 ++++++++++ .../IntegrationManagerViewController.m | 29 +++++++++++++++++-- 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 60cd59440..4cf0a7cf9 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -775,6 +775,7 @@ "widget_integration_missing_room_id" = "Missing room_id in request."; "widget_integration_missing_user_id" = "Missing user_id in request."; "widget_integration_room_not_visible" = "Room %@ is not visible."; +"widget_integration_manager_disabled" = "You need to enable Integration Manager in settings"; // Widget Picker "widget_picker_title" = "Integrations"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 5ba4b674b..08463dd29 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -3262,6 +3262,10 @@ internal enum VectorL10n { internal static var widgetIntegrationFailedToSendRequest: String { return VectorL10n.tr("Vector", "widget_integration_failed_to_send_request") } + /// You need to enable Integration Manager in settings + internal static var widgetIntegrationManagerDisabled: String { + return VectorL10n.tr("Vector", "widget_integration_manager_disabled") + } /// Missing room_id in request. internal static var widgetIntegrationMissingRoomId: String { return VectorL10n.tr("Vector", "widget_integration_missing_room_id") diff --git a/Riot/Managers/Widgets/WidgetManager.h b/Riot/Managers/Widgets/WidgetManager.h index f8d027185..c808de9d6 100644 --- a/Riot/Managers/Widgets/WidgetManager.h +++ b/Riot/Managers/Widgets/WidgetManager.h @@ -56,6 +56,7 @@ typedef enum : NSUInteger WidgetManagerErrorCodeNotEnoughPower, WidgetManagerErrorCodeCreationFailed, WidgetManagerErrorCodeNoIntegrationsServerConfigured, + WidgetManagerErrorCodeDisabledIntegrationsServer, WidgetManagerErrorCodeFailedToConnectToIntegrationsServer, WidgetManagerErrorCodeTermsNotSigned } diff --git a/Riot/Managers/Widgets/WidgetManager.m b/Riot/Managers/Widgets/WidgetManager.m index 7f462d66a..e7b4704b5 100644 --- a/Riot/Managers/Widgets/WidgetManager.m +++ b/Riot/Managers/Widgets/WidgetManager.m @@ -269,6 +269,14 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; return nil; } + RiotSharedSettings *sharedSettings = [[RiotSharedSettings alloc] initWithSession:room.mxSession]; + if (!sharedSettings.hasIntegrationProvisioningEnabled) + { + NSLog(@"[WidgetManager] createJitsiWidgetInRoom: Error: Disabled integration manager for user %@", userId); + failure(self.errorForDisabledIntegrationManager); + return nil; + } + // Build data for a jitsi widget NSString *widgetId = [NSString stringWithFormat:@"%@_%@_%@", kWidgetTypeJitsi, room.mxSession.myUser.userId, @((uint64_t)([[NSDate date] timeIntervalSince1970] * 1000))]; @@ -791,4 +799,11 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; userInfo:@{NSLocalizedDescriptionKey: NSLocalizedStringFromTable(@"widget_no_integrations_server_configured", @"Vector", nil)}]; } +- (NSError*)errorForDisabledIntegrationManager +{ + return [NSError errorWithDomain:WidgetManagerErrorDomain + code:WidgetManagerErrorCodeDisabledIntegrationsServer + userInfo:@{NSLocalizedDescriptionKey: NSLocalizedStringFromTable(@"widget_integration_manager_disabled", @"Vector", nil)}]; +} + @end diff --git a/Riot/Modules/Integrations/IntegrationManagerViewController.m b/Riot/Modules/Integrations/IntegrationManagerViewController.m index 7f04c678d..809f280b8 100644 --- a/Riot/Modules/Integrations/IntegrationManagerViewController.m +++ b/Riot/Modules/Integrations/IntegrationManagerViewController.m @@ -69,15 +69,22 @@ NSString *const kIntegrationManagerAddIntegrationScreen = @"add_integ"; operation = nil; } -- (void)viewDidLoad +- (void)viewWillAppear:(BOOL)animated { - [super viewDidLoad]; + [super viewWillAppear:animated]; [self loadData]; } - (void)loadData { + RiotSharedSettings *sharedSettings = [[RiotSharedSettings alloc] initWithSession:mxSession]; + if (!sharedSettings.hasIntegrationProvisioningEnabled) + { + [self showDisabledIntegrationManagerError]; + return; + } + if (!self.URL && !operation) { [self startActivityIndicator]; @@ -706,6 +713,24 @@ NSString *const kIntegrationManagerAddIntegrationScreen = @"add_integ"; } +#pragma mark - Disabled Integrations + +- (void)showDisabledIntegrationManagerError +{ + NSString *message = NSLocalizedStringFromTable(@"widget_integration_manager_disabled", @"Vector", nil); + UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil + message:message + preferredStyle:UIAlertControllerStyleAlert]; + + [alert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + [self withdrawViewControllerAnimated:YES completion:nil]; + }]]; + + [self presentViewController:alert animated:YES completion:nil]; +} + #pragma mark - Service terms - (void)presentTerms