Listen for recents data ready notification in an async method

This commit is contained in:
ismailgulek 2021-09-08 11:21:04 +03:00
parent 65ffa028cc
commit ec23468244
No known key found for this signature in database
GPG key ID: E96336D42D9470A9

View file

@ -229,6 +229,11 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
@property (nonatomic, strong) AppInfo *appInfo;
/**
Listen RecentsViewControllerDataReadyNotification for changes.
*/
@property (nonatomic, assign, getter=isRoomListDataReady) BOOL roomListDataReady;
@end
@implementation LegacyAppDelegate
@ -2255,7 +2260,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
return;
}
void (^dataLoaded)(void) = ^{
[self ensureRoomListDataReadyWithCompletion:^{
[self hideLaunchAnimation];
if (self.setPinCoordinatorBridgePresenter)
@ -2311,21 +2316,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
// Enable listening of incoming key verification requests
[self enableIncomingKeyVerificationObserver:mainSession];
}
};
if (_masterTabBarController.homeViewController.isRoomListDataReady)
{
dataLoaded();
}
else
{
NSNotificationCenter * __weak notificationCenter = [NSNotificationCenter defaultCenter];
__block id observer = [[NSNotificationCenter defaultCenter] addObserverForName:HomeViewControllerRoomListDataReadyNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
[notificationCenter removeObserver:observer];
dataLoaded();
}];
}
}];
}
}
@ -2482,6 +2473,31 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
[self handleAppState];
}
/**
Ensures room list data is ready.
@param completion Completion block to be called when it's ready. Not dispatched in case the data is already ready.
*/
- (void)ensureRoomListDataReadyWithCompletion:(void(^)(void))completion
{
if (self.isRoomListDataReady)
{
completion();
}
else
{
NSNotificationCenter * __weak notificationCenter = [NSNotificationCenter defaultCenter];
__block id observer = [[NSNotificationCenter defaultCenter] addObserverForName:RecentsViewControllerDataReadyNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull notification) {
[notificationCenter removeObserver:observer];
self.roomListDataReady = YES;
completion();
}];
}
}
#pragma mark -
/**