Univeral links: Improved UX: Display a loading wheel while the app is gathering information from the hs about the universal link

This commit is contained in:
manuroe 2016-04-19 15:18:24 +02:00
parent dd4327b9ab
commit 998371317d
2 changed files with 91 additions and 62 deletions

View file

@ -798,51 +798,91 @@
continueUserActivity = YES; continueUserActivity = YES;
} }
else if ([roomIdOrAlias hasPrefix:@"#"]) else
{ {
// The alias may be not part of user's rooms states // We will display something but we need to do some requests before.
// Ask the HS to resolve the room alias into a room id and then retry // So, come back to the home VC and show its loading wheel while processing
universalLinkFragmentPending = fragment; [self restoreInitialDisplay:^{
MXKAccount* account = accountManager.activeAccounts.firstObject;
[account.mxSession.matrixRestClient roomIDForRoomAlias:roomIdOrAlias success:^(NSString *roomId) {
// Check that 'fragment' has not been cancelled [_homeViewController startActivityIndicator];
if ([universalLinkFragmentPending isEqualToString:fragment])
if ([roomIdOrAlias hasPrefix:@"#"])
{ {
// Retry opening the link but with the returned room id // The alias may be not part of user's rooms states
NSString *newUniversalLinkFragment = // Ask the HS to resolve the room alias into a room id and then retry
[fragment stringByReplacingOccurrencesOfString:[roomIdOrAlias stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] universalLinkFragmentPending = fragment;
withString:[roomId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; MXKAccount* account = accountManager.activeAccounts.firstObject;
[self handleUniversalLinkFragment:newUniversalLinkFragment]; [account.mxSession.matrixRestClient roomIDForRoomAlias:roomIdOrAlias success:^(NSString *roomId) {
// Note: the activity indicator will not disappear if the session is not ready
[_homeViewController stopActivityIndicator];
// Check that 'fragment' has not been cancelled
if ([universalLinkFragmentPending isEqualToString:fragment])
{
// Retry opening the link but with the returned room id
NSString *newUniversalLinkFragment =
[fragment stringByReplacingOccurrencesOfString:[roomIdOrAlias stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
withString:[roomId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[self handleUniversalLinkFragment:newUniversalLinkFragment];
}
} failure:^(NSError *error) {
NSLog(@"[AppDelegate] Universal link: Error: The home server failed to resolve the room alias (%@)", roomIdOrAlias);
}];
} }
else if ([roomIdOrAlias hasPrefix:@"!"] && ((MXKAccount*)accountManager.activeAccounts.firstObject).mxSession.state != MXSessionStateRunning)
} failure:^(NSError *error) {
NSLog(@"[AppDelegate] Universal link: Error: The home server failed to resolve the room alias (%@)", roomIdOrAlias);
}];
// Let's say we are handling the case
continueUserActivity = YES;
}
else if ([roomIdOrAlias hasPrefix:@"!"] && ((MXKAccount*)accountManager.activeAccounts.firstObject).mxSession.state != MXSessionStateRunning)
{
// The user does not know the room id but this may be because their session is not yet sync'ed
// So, wait for the completion of the sync and then retry
// FIXME: Manange all user's accounts not only the first one
MXKAccount* account = accountManager.activeAccounts.firstObject;
NSLog(@"[AppDelegate] Universal link: Need to wait for the session to be sync'ed and running");
universalLinkFragmentPending = fragment;
universalLinkWaitingObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionStateDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notif) {
// Check that 'fragment' has not been cancelled
if ([universalLinkFragmentPending isEqualToString:fragment])
{ {
// Check whether the concerned session is the associated one // The user does not know the room id but this may be because their session is not yet sync'ed
if (notif.object == account.mxSession && account.mxSession.state == MXSessionStateRunning) // So, wait for the completion of the sync and then retry
// FIXME: Manange all user's accounts not only the first one
MXKAccount* account = accountManager.activeAccounts.firstObject;
NSLog(@"[AppDelegate] Universal link: Need to wait for the session to be sync'ed and running");
universalLinkFragmentPending = fragment;
universalLinkWaitingObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionStateDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notif) {
// Check that 'fragment' has not been cancelled
if ([universalLinkFragmentPending isEqualToString:fragment])
{
// Check whether the concerned session is the associated one
if (notif.object == account.mxSession && account.mxSession.state == MXSessionStateRunning)
{
NSLog(@"[AppDelegate] Universal link: The session is running. Retry the link");
[self handleUniversalLinkFragment:fragment];
}
}
}];
}
else
{
NSLog(@"[AppDelegate] Universal link: The room (%@) is not known by any account (email invitation: %@). Display its preview to try to join it", roomIdOrAlias, queryParams ? @"YES" : @"NO");
// FIXME: In case of multi-account, ask the user which one to use
MXKAccount* account = accountManager.activeAccounts.firstObject;
RoomPreviewData *roomPreviewData;
if (queryParams)
{ {
NSLog(@"[AppDelegate] Universal link: The session is running. Retry the link"); // Note: the activity indicator will not disappear if the session is not ready
[self handleUniversalLinkFragment:fragment]; [_homeViewController stopActivityIndicator];
roomPreviewData = [[RoomPreviewData alloc] initWithRoomId:roomIdOrAlias emailInvitationParams:queryParams andSession:account.mxSession];
[self showRoomPreview:roomPreviewData];
}
else
{
roomPreviewData = [[RoomPreviewData alloc] initWithRoomId:roomIdOrAlias andSession:account.mxSession];
// Try to get more information about the room before opening its preview
[roomPreviewData fetchPreviewData:^(BOOL successed) {
// Note: the activity indicator will not disappear if the session is not ready
[_homeViewController stopActivityIndicator];
[self showRoomPreview:roomPreviewData];
}];
} }
} }
}]; }];
@ -850,29 +890,6 @@
// Let's say we are handling the case // Let's say we are handling the case
continueUserActivity = YES; continueUserActivity = YES;
} }
else
{
NSLog(@"[AppDelegate] Universal link: The room (%@) is not known by any account (email invitation: %@). Display its preview to try to join it", roomIdOrAlias, queryParams ? @"YES" : @"NO");
// FIXME: In case of multi-account, ask the user which one to use
MXKAccount* account = accountManager.activeAccounts.firstObject;
RoomPreviewData *roomPreviewData;
if (queryParams)
{
roomPreviewData = [[RoomPreviewData alloc] initWithRoomId:roomIdOrAlias emailInvitationParams:queryParams andSession:account.mxSession];
[self showRoomPreview:roomPreviewData];
}
else
{
roomPreviewData = [[RoomPreviewData alloc] initWithRoomId:roomIdOrAlias andSession:account.mxSession];
// Try to get more information about the room before opening its preview
[roomPreviewData fetchPreviewData:^(BOOL successed) {
[self showRoomPreview:roomPreviewData];
}];
}
}
} }
else else
{ {

View file

@ -367,6 +367,18 @@
[super setKeyboardHeight:keyboardHeight]; [super setKeyboardHeight:keyboardHeight];
} }
- (void)startActivityIndicator
{
// Redirect the operation to main displayed VC
[recentsViewController startActivityIndicator];
}
- (void)stopActivityIndicator
{
// Redirect the operation to main displayed VC
[recentsViewController stopActivityIndicator];
}
#pragma mark - Override UIViewController+VectorSearch #pragma mark - Override UIViewController+VectorSearch
- (void)setKeyboardHeightForBackgroundImage:(CGFloat)keyboardHeight - (void)setKeyboardHeightForBackgroundImage:(CGFloat)keyboardHeight