diff --git a/Riot/Modules/Application/LegacyAppDelegate.m b/Riot/Modules/Application/LegacyAppDelegate.m index 6fe61c3b1..4201330fd 100644 --- a/Riot/Modules/Application/LegacyAppDelegate.m +++ b/Riot/Modules/Application/LegacyAppDelegate.m @@ -232,6 +232,12 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni */ @property (nonatomic, assign, getter=isRoomListDataReady) BOOL roomListDataReady; +/** + An optional completion block that will be called when a `RecentsViewControllerDataReadyNotification` + is observed during app launch. + */ +@property (nonatomic, copy, nullable) void (^roomListDataReadyCompletion)(void); + /** Flag to indicate whether a cache clear is being performed. */ @@ -417,6 +423,8 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni } [NSBundle mxk_setLanguage:language]; [NSBundle mxk_setFallbackLanguage:@"en"]; + + [self listenForRoomListDataReady]; mxSessionArray = [NSMutableArray array]; callEventsListeners = [NSMutableDictionary dictionary]; @@ -2411,7 +2419,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni return; } - [self ensureRoomListDataReadyWithCompletion:^{ + void (^finishAppLaunch)(void) = ^{ [self hideLaunchAnimation]; if (self.setPinCoordinatorBridgePresenter) @@ -2443,7 +2451,17 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni // Enable listening of incoming key verification requests [self enableIncomingKeyVerificationObserver:mainSession]; } - }]; + }; + + if (self.isRoomListDataReady) + { + finishAppLaunch(); + } + else + { + // An observer has been set in didFinishLaunching that will call the stored block when ready + self.roomListDataReadyCompletion = finishAppLaunch; + } } } @@ -2599,29 +2617,22 @@ 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 +- (void)listenForRoomListDataReady { - 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(); - }]; - } + 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; + + if (self.roomListDataReadyCompletion) + { + self.roomListDataReadyCompletion(); + self.roomListDataReadyCompletion = nil; + } + }]; } #pragma mark - diff --git a/changelog.d/5559.bugfix b/changelog.d/5559.bugfix new file mode 100644 index 000000000..7f27180a0 --- /dev/null +++ b/changelog.d/5559.bugfix @@ -0,0 +1 @@ +App Launch: Fix a potential issue where the green spinner is kept on screen when the room lists are ready. \ No newline at end of file