diff --git a/CHANGES.rst b/CHANGES.rst index 05ffb0c64..063007d2e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,7 @@ Improvements: * SerializationService: Add deserialisation of Any. * RiotSharedSettings: New class to handle user settings shared accross Riot apps. * Widgets: Check user permission before opening a widget (TODO design: #2833). + * Widgets: Add a contextual menu to refresh, open outside and revoke the permission (#2834). Changes in 0.10.2 (2019-11-15) =============================================== diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 59b4a686b..681654fbc 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -755,6 +755,9 @@ "widget_creation_failure" = "Widget creation has failed"; "widget_sticker_picker_no_stickerpacks_alert" = "You don't currently have any stickerpacks enabled."; "widget_sticker_picker_no_stickerpacks_alert_add_now" = "Add some now?"; +"widget_menu_refresh" = "Refresh"; +"widget_menu_open_outside" = "Open outside"; +"widget_menu_revoke_permission" = "Revoke access for me"; // Widget Integration Manager "widget_integration_need_to_be_able_to_invite" = "You need to be able to invite users to do that."; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 12b5d5b6b..db248ff05 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -3290,6 +3290,18 @@ internal enum VectorL10n { internal static var widgetIntegrationsServerFailedToConnect: String { return VectorL10n.tr("Vector", "widget_integrations_server_failed_to_connect") } + /// Open outside + internal static var widgetMenuOpenOutside: String { + return VectorL10n.tr("Vector", "widget_menu_open_outside") + } + /// Refresh + internal static var widgetMenuRefresh: String { + return VectorL10n.tr("Vector", "widget_menu_refresh") + } + /// Revoke access for me + internal static var widgetMenuRevokePermission: String { + return VectorL10n.tr("Vector", "widget_menu_revoke_permission") + } /// No integrations server configured internal static var widgetNoIntegrationsServerConfigured: String { return VectorL10n.tr("Vector", "widget_no_integrations_server_configured") diff --git a/Riot/Modules/Integrations/Widgets/WidgetViewController.m b/Riot/Modules/Integrations/Widgets/WidgetViewController.m index 4ded0d177..d67f667a1 100644 --- a/Riot/Modules/Integrations/Widgets/WidgetViewController.m +++ b/Riot/Modules/Integrations/Widgets/WidgetViewController.m @@ -58,6 +58,9 @@ NSString *const kJavascriptSendResponseToPostMessageAPI = @"riotIOS.sendResponse if (widget) { self.navigationItem.title = widget.name ? widget.name : widget.type; + + UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"room_context_menu_more"] style:UIBarButtonItemStylePlain target:self action:@selector(onMenuButtonPressed:)]; + self.navigationItem.rightBarButtonItem = menuButton; } } @@ -78,6 +81,11 @@ NSString *const kJavascriptSendResponseToPostMessageAPI = @"riotIOS.sendResponse }]; } +- (void)reloadWidget +{ + self.URL = self.widgetUrl; +} + - (void)showErrorAsAlert:(NSError*)error { NSString *title = [error.userInfo valueForKey:NSLocalizedFailureReasonErrorKey]; @@ -181,6 +189,71 @@ NSString *const kJavascriptSendResponseToPostMessageAPI = @"riotIOS.sendResponse [self presentViewController:alert animated:YES completion:nil]; } +- (void)revokePermissionForCurrentWidget +{ + MXSession *session = widget.mxSession; + __block RiotSharedSettings *sharedSettings = [[RiotSharedSettings alloc] initWithSession:session]; + + [sharedSettings setPermissionForWidget:widget permission:WidgetPermissionDeclined success:^{ + sharedSettings = nil; + } failure:^(NSError * _Nullable error) { + NSLog(@"[WidgetVC] revokePermissionForCurrentWidget failed. Error: %@", error); + sharedSettings = nil; + }]; +} + + +#pragma mark - Contextual Menu + +- (IBAction)onMenuButtonPressed:(id)sender +{ + [self showMenu]; +} + +-(void)showMenu +{ + MXSession *session = widget.mxSession; + + UIAlertController *menu = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + + [menu addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"widget_menu_refresh", @"Vector", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) + { + [self reloadWidget]; + }]]; + + NSURL *url = [NSURL URLWithString:self.widgetUrl]; + if (url && [[UIApplication sharedApplication] canOpenURL:url]) + { + [menu addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"widget_menu_open_outside", @"Vector", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) + { + [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { + }]; + }]]; + } + + if (![widget.widgetEvent.sender isEqualToString:session.myUser.userId]) + { + [menu addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"widget_menu_revoke_permission", @"Vector", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) + { + [self revokePermissionForCurrentWidget]; + [self withdrawViewControllerAnimated:YES completion:nil]; + }]]; + } + + [menu addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { + }]]; + + [self presentViewController:menu animated:YES completion:nil]; +} + #pragma mark - WKNavigationDelegate