Widgets: Display an error if the IM is disabled

#2843
This commit is contained in:
manuroe 2019-11-21 16:36:08 +01:00
parent 98354f24aa
commit 3296a7561f
5 changed files with 48 additions and 2 deletions

View file

@ -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";

View file

@ -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")

View file

@ -56,6 +56,7 @@ typedef enum : NSUInteger
WidgetManagerErrorCodeNotEnoughPower,
WidgetManagerErrorCodeCreationFailed,
WidgetManagerErrorCodeNoIntegrationsServerConfigured,
WidgetManagerErrorCodeDisabledIntegrationsServer,
WidgetManagerErrorCodeFailedToConnectToIntegrationsServer,
WidgetManagerErrorCodeTermsNotSigned
}

View file

@ -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

View file

@ -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