mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Widgets: Add a contextual menu to refresh, open outside and revoke the permission
#2834
This commit is contained in:
parent
eca3ad7278
commit
5de5b3dec6
4 changed files with 89 additions and 0 deletions
|
@ -7,6 +7,7 @@ Improvements:
|
||||||
* SerializationService: Add deserialisation of Any.
|
* SerializationService: Add deserialisation of Any.
|
||||||
* RiotSharedSettings: New class to handle user settings shared accross Riot apps.
|
* RiotSharedSettings: New class to handle user settings shared accross Riot apps.
|
||||||
* Widgets: Check user permission before opening a widget (TODO design: #2833).
|
* 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)
|
Changes in 0.10.2 (2019-11-15)
|
||||||
===============================================
|
===============================================
|
||||||
|
|
|
@ -755,6 +755,9 @@
|
||||||
"widget_creation_failure" = "Widget creation has failed";
|
"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" = "You don't currently have any stickerpacks enabled.";
|
||||||
"widget_sticker_picker_no_stickerpacks_alert_add_now" = "Add some now?";
|
"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 Manager
|
||||||
"widget_integration_need_to_be_able_to_invite" = "You need to be able to invite users to do that.";
|
"widget_integration_need_to_be_able_to_invite" = "You need to be able to invite users to do that.";
|
||||||
|
|
|
@ -3290,6 +3290,18 @@ internal enum VectorL10n {
|
||||||
internal static var widgetIntegrationsServerFailedToConnect: String {
|
internal static var widgetIntegrationsServerFailedToConnect: String {
|
||||||
return VectorL10n.tr("Vector", "widget_integrations_server_failed_to_connect")
|
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
|
/// No integrations server configured
|
||||||
internal static var widgetNoIntegrationsServerConfigured: String {
|
internal static var widgetNoIntegrationsServerConfigured: String {
|
||||||
return VectorL10n.tr("Vector", "widget_no_integrations_server_configured")
|
return VectorL10n.tr("Vector", "widget_no_integrations_server_configured")
|
||||||
|
|
|
@ -58,6 +58,9 @@ NSString *const kJavascriptSendResponseToPostMessageAPI = @"riotIOS.sendResponse
|
||||||
if (widget)
|
if (widget)
|
||||||
{
|
{
|
||||||
self.navigationItem.title = widget.name ? widget.name : widget.type;
|
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
|
- (void)showErrorAsAlert:(NSError*)error
|
||||||
{
|
{
|
||||||
NSString *title = [error.userInfo valueForKey:NSLocalizedFailureReasonErrorKey];
|
NSString *title = [error.userInfo valueForKey:NSLocalizedFailureReasonErrorKey];
|
||||||
|
@ -181,6 +189,71 @@ NSString *const kJavascriptSendResponseToPostMessageAPI = @"riotIOS.sendResponse
|
||||||
[self presentViewController:alert animated:YES completion:nil];
|
[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
|
#pragma mark - WKNavigationDelegate
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue