Skip to content

Commit f7554aa

Browse files
authored
Merge pull request #2524 from vector-im/riot_2518
Make sure there are no ugly edge cases running Riot without an integrations manager
2 parents 1c10049 + 918adc5 commit f7554aa

File tree

9 files changed

+261
-31
lines changed

9 files changed

+261
-31
lines changed

Riot.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
32242F1721E8FBE500725742 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32242F0D21E8FBA900725742 /* Theme.swift */; };
2323
32242F1821E8FBF800725742 /* DefaultTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32242F0F21E8FBA900725742 /* DefaultTheme.swift */; };
2424
32242F1921E8FBFB00725742 /* DarkTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32242F1021E8FBA900725742 /* DarkTheme.swift */; };
25+
322C110822BBC6F80043FEAC /* WidgetManagerConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 322C110722BBC6F80043FEAC /* WidgetManagerConfig.swift */; };
2526
3232AB1422564D9100AD6A5C /* swiftgen-config.yml in Resources */ = {isa = PBXBuildFile; fileRef = 3232AB0022564D9100AD6A5C /* swiftgen-config.yml */; };
2627
3232AB1522564D9100AD6A5C /* flat-swift4-vector.stencil in Resources */ = {isa = PBXBuildFile; fileRef = 3232AB0322564D9100AD6A5C /* flat-swift4-vector.stencil */; };
2728
3232AB2122564D9100AD6A5C /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 3232AB1322564D9100AD6A5C /* README.md */; };
@@ -548,6 +549,7 @@
548549
32242F0F21E8FBA900725742 /* DefaultTheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultTheme.swift; sourceTree = "<group>"; };
549550
32242F1021E8FBA900725742 /* DarkTheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DarkTheme.swift; sourceTree = "<group>"; };
550551
32242F1121E8FBA900725742 /* ThemeService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThemeService.h; sourceTree = "<group>"; };
552+
322C110722BBC6F80043FEAC /* WidgetManagerConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetManagerConfig.swift; sourceTree = "<group>"; };
551553
3232AB0022564D9100AD6A5C /* swiftgen-config.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "swiftgen-config.yml"; sourceTree = "<group>"; };
552554
3232AB0322564D9100AD6A5C /* flat-swift4-vector.stencil */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "flat-swift4-vector.stencil"; sourceTree = "<group>"; };
553555
3232AB1322564D9100AD6A5C /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
@@ -3042,6 +3044,7 @@
30423044
B1B5598420EFC3DF00210D55 /* WidgetManager.m */,
30433045
B1B5598120EFC3DF00210D55 /* Widget.h */,
30443046
B1B5598320EFC3DF00210D55 /* Widget.m */,
3047+
322C110722BBC6F80043FEAC /* WidgetManagerConfig.swift */,
30453048
);
30463049
path = Widgets;
30473050
sourceTree = "<group>";
@@ -3987,6 +3990,7 @@
39873990
B1B5593C20EF7BAC00210D55 /* TableViewCellWithCheckBoxes.m in Sources */,
39883991
32891D6B2264CBA300C82226 /* SimpleScreenTemplateViewController.swift in Sources */,
39893992
B1CA3A2721EF6914000D1D89 /* UIViewController.swift in Sources */,
3993+
322C110822BBC6F80043FEAC /* WidgetManagerConfig.swift in Sources */,
39903994
F0D2ADA11F6AA5FD00A7097D /* MXRoomSummary+Riot.m in Sources */,
39913995
B1B5596F20EFA85D00210D55 /* EncryptionInfoView.m in Sources */,
39923996
B1B5573820EE6C4D00210D55 /* GroupParticipantsViewController.m in Sources */,

Riot/Assets/en.lproj/Vector.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@
634634
"bug_report_send" = "Send";
635635

636636
// Widget
637+
"widget_no_integrations_server_configured" = "No integrations server configured";
638+
"widget_integrations_server_failed_to_connect" = "Failed to connect to integrations server";
637639
"widget_no_power_to_manage" = "You need permission to manage widgets in this room";
638640
"widget_creation_failure" = "Widget creation has failed";
639641
"widget_sticker_picker_no_stickerpacks_alert" = "You don't currently have any stickerpacks enabled.";

Riot/Generated/Strings.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,14 @@ internal enum VectorL10n {
28342834
internal static var widgetIntegrationUnableToCreate: String {
28352835
return VectorL10n.tr("Vector", "widget_integration_unable_to_create")
28362836
}
2837+
/// Failed to connect to integrations server
2838+
internal static var widgetIntegrationsServerFailedToConnect: String {
2839+
return VectorL10n.tr("Vector", "widget_integrations_server_failed_to_connect")
2840+
}
2841+
/// No integrations server configured
2842+
internal static var widgetNoIntegrationsServerConfigured: String {
2843+
return VectorL10n.tr("Vector", "widget_no_integrations_server_configured")
2844+
}
28372845
/// You need permission to manage widgets in this room
28382846
internal static var widgetNoPowerToManage: String {
28392847
return VectorL10n.tr("Vector", "widget_no_power_to_manage")

Riot/Managers/Widgets/Widget.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2017 Vector Creations Ltd
3+
Copyright 2019 New Vector Ltd
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -100,7 +101,7 @@ - (MXHTTPOperation *)widgetUrl:(void (^)(NSString * _Nonnull))success failure:(v
100101
_widgetId]];
101102

102103
// Check if their scalar token must added
103-
if ([WidgetManager isScalarUrl:widgetUrl])
104+
if ([[WidgetManager sharedManager] isScalarUrl:widgetUrl forUser:userId])
104105
{
105106
return [[WidgetManager sharedManager] getScalarTokenForMXSession:_mxSession validate:NO success:^(NSString *scalarToken) {
106107
// Add the user scalar token

Riot/Managers/Widgets/WidgetManager.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2017 Vector Creations Ltd
3+
Copyright 2019 New Vector Ltd
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -20,6 +21,8 @@
2021

2122
#import "Widget.h"
2223

24+
@class WidgetManagerConfig;
25+
2326
/**
2427
The type of matrix event used for matrix widgets.
2528
*/
@@ -51,7 +54,9 @@ FOUNDATION_EXPORT NSString *const WidgetManagerErrorDomain;
5154
typedef enum : NSUInteger
5255
{
5356
WidgetManagerErrorCodeNotEnoughPower,
54-
WidgetManagerErrorCodeCreationFailed
57+
WidgetManagerErrorCodeCreationFailed,
58+
WidgetManagerErrorCodeNoIntegrationsServerConfigured,
59+
WidgetManagerErrorCodeFailedToConnectToIntegrationsServer
5560
}
5661
WidgetManagerErrorCode;
5762

@@ -180,6 +185,30 @@ WidgetManagerErrorCode;
180185

181186
#pragma mark - Modular interface
182187

188+
/**
189+
Get the integration manager configuration for a user.
190+
191+
@param userId the user id.
192+
@return the integration manager configuration.
193+
*/
194+
- (WidgetManagerConfig*)configForUser:(NSString*)userId;
195+
196+
/**
197+
Store the integration manager configuration for a user.
198+
199+
@param the integration manager configuration.
200+
@param userId the user id.
201+
*/
202+
- (void)setConfig:(WidgetManagerConfig*)config forUser:(NSString*)userId;
203+
204+
/**
205+
Check if the user has URLs for an integration manager configured.
206+
207+
@param userId the user id.
208+
@return YES if they have URLs for an integration manager.
209+
*/
210+
- (BOOL)hasIntegrationManagerForUser:(NSString*)userId;
211+
183212
/**
184213
Make sure there is a scalar token for the given Matrix session.
185214
@@ -201,8 +230,9 @@ WidgetManagerErrorCode;
201230
Returns true if specified url is a scalar URL, typically https://scalar.vector.im/api
202231
203232
@param urlString the URL to check.
233+
@param userId the user id.
204234
@return YES if specified URL is a scalar URL.
205235
*/
206-
+ (BOOL)isScalarUrl:(NSString*)urlString;
236+
- (BOOL)isScalarUrl:(NSString*)urlString forUser:(NSString*)userId;
207237

208238
@end

0 commit comments

Comments
 (0)