29
29
#import " RLMCredentials_Private.hpp"
30
30
#import " RLMEmailPasswordAuth.h"
31
31
#import " RLMLogger.h"
32
+ #import " RLMProviderClient_Private.hpp"
32
33
#import " RLMPushClient_Private.hpp"
33
34
#import " RLMSyncManager_Private.hpp"
34
35
#import " RLMUser_Private.hpp"
35
36
#import " RLMUtil.hpp"
36
37
38
+ #import < realm/object-store/sync/app_user.hpp>
37
39
#import < realm/object-store/sync/sync_manager.hpp>
38
40
#import < realm/sync/config.hpp>
39
41
@@ -94,15 +96,14 @@ void send_request_to_server(const app::Request& request,
94
96
95
97
#pragma mark RLMAppConfiguration
96
98
@implementation RLMAppConfiguration {
97
- realm::app::App::Config _config;
98
- SyncClientConfig _clientConfig;
99
+ realm::app::AppConfig _config;
99
100
}
100
101
101
102
- (instancetype )init {
102
103
if (self = [super init ]) {
103
104
self.enableSessionMultiplexing = true ;
104
105
self.encryptMetadata = !getenv (" REALM_DISABLE_METADATA_ENCRYPTION" ) && !RLMIsRunningInPlayground ();
105
- RLMNSStringToStdString (_clientConfig .base_file_path , RLMDefaultDirectoryForBundleIdentifier (nil ));
106
+ RLMNSStringToStdString (_config .base_file_path , RLMDefaultDirectoryForBundleIdentifier (nil ));
106
107
configureSyncConnectionParameters (_config);
107
108
}
108
109
return self;
@@ -152,7 +153,7 @@ - (instancetype)initWithBaseURL:(nullable NSString *)baseURL
152
153
return self;
153
154
}
154
155
155
- static void configureSyncConnectionParameters (realm::app::App::Config & config) {
156
+ static void configureSyncConnectionParameters (realm::app::AppConfig & config) {
156
157
// Anonymized BundleId
157
158
NSString *bundleId = [[NSBundle mainBundle ] bundleIdentifier ];
158
159
NSData *bundleIdData = [bundleId dataUsingEncoding: NSUTF8StringEncoding];
@@ -178,21 +179,16 @@ static void configureSyncConnectionParameters(realm::app::App::Config& config) {
178
179
config.device_info .device_version = systemInfo.machine ;
179
180
}
180
181
181
- - (const realm::app::App::Config &)config {
182
+ - (const realm::app::AppConfig &)config {
182
183
if (!_config.transport ) {
183
184
self.transport = nil ;
184
185
}
185
186
return _config;
186
187
}
187
188
188
- - (const realm::SyncClientConfig&)clientConfig {
189
- return _clientConfig;
190
- }
191
-
192
189
- (id )copyWithZone : (NSZone *)zone {
193
190
RLMAppConfiguration *copy = [[RLMAppConfiguration alloc ] init ];
194
191
copy->_config = _config;
195
- copy->_clientConfig = _clientConfig;
196
192
return copy;
197
193
}
198
194
@@ -250,36 +246,36 @@ - (void)setDefaultRequestTimeoutMS:(NSUInteger)defaultRequestTimeoutMS {
250
246
}
251
247
252
248
- (BOOL )enableSessionMultiplexing {
253
- return _clientConfig .multiplex_sessions ;
249
+ return _config. sync_client_config .multiplex_sessions ;
254
250
}
255
251
256
252
- (void )setEnableSessionMultiplexing : (BOOL )enableSessionMultiplexing {
257
- _clientConfig .multiplex_sessions = enableSessionMultiplexing;
253
+ _config. sync_client_config .multiplex_sessions = enableSessionMultiplexing;
258
254
}
259
255
260
256
- (BOOL )encryptMetadata {
261
- return _clientConfig .metadata_mode == SyncManager ::MetadataMode::Encryption;
257
+ return _config .metadata_mode == app::AppConfig ::MetadataMode::Encryption;
262
258
}
263
259
264
260
- (void )setEncryptMetadata : (BOOL )encryptMetadata {
265
- _clientConfig .metadata_mode = encryptMetadata ? SyncManager ::MetadataMode::Encryption
266
- : SyncManager ::MetadataMode::NoEncryption;
261
+ _config .metadata_mode = encryptMetadata ? app::AppConfig ::MetadataMode::Encryption
262
+ : app::AppConfig ::MetadataMode::NoEncryption;
267
263
}
268
264
269
265
- (NSURL *)rootDirectory {
270
- return [NSURL fileURLWithPath: RLMStringViewToNSString (_clientConfig .base_file_path)];
266
+ return [NSURL fileURLWithPath: RLMStringViewToNSString (_config .base_file_path)];
271
267
}
272
268
273
269
- (void )setRootDirectory : (NSURL *)rootDirectory {
274
- RLMNSStringToStdString (_clientConfig .base_file_path , rootDirectory.path );
270
+ RLMNSStringToStdString (_config .base_file_path , rootDirectory.path );
275
271
}
276
272
277
273
- (RLMSyncTimeoutOptions *)syncTimeouts {
278
- return [[RLMSyncTimeoutOptions alloc ] initWithOptions: _clientConfig .timeouts];
274
+ return [[RLMSyncTimeoutOptions alloc ] initWithOptions: _config.sync_client_config .timeouts];
279
275
}
280
276
281
277
- (void )setSyncTimeouts : (RLMSyncTimeoutOptions *)syncTimeouts {
282
- _clientConfig .timeouts = syncTimeouts->_options ;
278
+ _config. sync_client_config .timeouts = syncTimeouts->_options ;
283
279
}
284
280
285
281
@end
@@ -334,16 +330,16 @@ - (instancetype)initWithApp:(std::shared_ptr<realm::app::App>&&)app config:(RLMA
334
330
- (instancetype )initWithConfiguration : (RLMAppConfiguration *)configuration {
335
331
if (self = [super init ]) {
336
332
_app = RLMTranslateError ([&] {
337
- return app::App::get_app (app::App::CacheMode::Enabled , configuration.config , configuration. clientConfig );
333
+ return app::App::get_app (app::App::CacheMode::Disabled , configuration.config );
338
334
});
339
335
_configuration = configuration;
340
336
_syncManager = [[RLMSyncManager alloc ] initWithSyncManager: _app->sync_manager ()];
341
337
}
342
338
return self;
343
339
}
344
340
341
+ static RLMUnfairMutex s_appMutex;
345
342
static NSMutableDictionary *s_apps = [NSMutableDictionary new ];
346
- static std::mutex& s_appMutex = *new std::mutex();
347
343
348
344
+ (NSArray *)allApps {
349
345
std::lock_guard lock (s_appMutex);
@@ -385,6 +381,11 @@ + (instancetype)appWithId:(NSString *)appId {
385
381
return s_apps[appId] = [[RLMApp alloc ] initWithConfiguration: config];
386
382
}
387
383
384
+ + (RLMApp *_Nullable)cachedAppWithId : (NSString *)appId {
385
+ std::lock_guard lock (s_appMutex);
386
+ return s_apps[appId];
387
+ }
388
+
388
389
- (NSString *)appId {
389
390
return @(_app->config ().app_id .c_str ());
390
391
}
@@ -395,42 +396,43 @@ - (NSString *)appId {
395
396
396
397
- (NSDictionary <NSString *, RLMUser *> *)allUsers {
397
398
NSMutableDictionary *buffer = [NSMutableDictionary new ];
398
- for (auto && user : _app->sync_manager ()-> all_users ()) {
399
- NSString *identity = @(user->identity ().c_str ());
400
- buffer[identity ] = [[RLMUser alloc ] initWithUser: std: :move (user) app: self ];
399
+ for (auto && user : _app->all_users ()) {
400
+ NSString *user_id = @(user->user_id ().c_str ());
401
+ buffer[user_id ] = [[RLMUser alloc ] initWithUser: std: :move (user)];
401
402
}
402
403
return buffer;
403
404
}
404
405
405
406
- (RLMUser *)currentUser {
406
- if (auto user = _app->sync_manager ()-> get_current_user ()) {
407
- return [[RLMUser alloc ] initWithUser: user app: self ];
407
+ if (auto user = _app->current_user ()) {
408
+ return [[RLMUser alloc ] initWithUser: user];
408
409
}
409
410
return nil ;
410
411
}
411
412
412
413
- (RLMEmailPasswordAuth *)emailPasswordAuth {
413
- return [[RLMEmailPasswordAuth alloc ] initWithApp: self ];
414
+ return [[RLMEmailPasswordAuth alloc ] initWithApp: _app ];
414
415
}
415
416
416
417
- (void )loginWithCredential : (RLMCredentials *)credentials
417
418
completion : (RLMUserCompletionBlock)completionHandler {
418
- auto completion = ^(std::shared_ptr<SyncUser > user, std::optional<app::AppError> error) {
419
+ auto completion = ^(std::shared_ptr<app::User > user, std::optional<app::AppError> error) {
419
420
if (error) {
420
421
return completionHandler (nil , makeError (*error));
421
422
}
422
423
423
- completionHandler ([[RLMUser alloc ] initWithUser: user app: self ], nil );
424
+ completionHandler ([[RLMUser alloc ] initWithUser: user], nil );
424
425
};
425
426
return RLMTranslateError ([&] {
426
427
return _app->log_in_with_credentials (credentials.appCredentials , completion);
427
428
});
428
429
}
429
430
430
431
- (RLMUser *)switchToUser : (RLMUser *)syncUser {
431
- return RLMTranslateError ([&] {
432
- return [[RLMUser alloc ] initWithUser: _app->switch_user (syncUser._syncUser) app: self ] ;
432
+ RLMTranslateError ([&] {
433
+ _app->switch_user (syncUser.user ) ;
433
434
});
435
+ return syncUser;
434
436
}
435
437
436
438
- (RLMPushClient *)pushClientWithServiceName : (NSString *)serviceName {
0 commit comments