Merge pull request #5937 from vector-im/andy/4858_resolve_alias

Enable joining a room via identifier from another home server
This commit is contained in:
Anderas
2022-03-29 10:54:48 +01:00
committed by GitHub
5 changed files with 111 additions and 26 deletions
+9 -23
View File
@@ -1487,7 +1487,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
// Ask the HS to resolve the room alias into a room id and then retry
self->universalLinkFragmentPending = fragment;
MXKAccount* account = accountManager.activeAccounts.firstObject;
[account.mxSession.matrixRestClient roomIDForRoomAlias:roomIdOrAlias success:^(NSString *roomId) {
[account.mxSession.matrixRestClient resolveRoomAlias:roomIdOrAlias success:^(MXRoomAliasResolution *resolution) {
// Note: the activity indicator will not disappear if the session is not ready
[homeViewController stopActivityIndicator];
@@ -1495,34 +1495,20 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
// Check that 'fragment' has not been cancelled
if ([self->universalLinkFragmentPending isEqualToString:fragment])
{
// Retry opening the link but with the returned room id
NSString *newUniversalLinkFragment =
[fragment stringByReplacingOccurrencesOfString:[MXTools encodeURIComponent:roomIdOrAlias]
withString:[MXTools encodeURIComponent:roomId]
];
// The previous operation can fail because of percent encoding
// TBH we are not clean on data inputs. For the moment, just give another try with no encoding
// TODO: Have a dedicated module and tests to handle universal links (matrix.to, email link, etc)
if ([newUniversalLinkFragment isEqualToString:fragment])
NSString *newFragment = resolution.deeplinkFragment;
if (newFragment && ![newFragment isEqualToString:fragment])
{
newUniversalLinkFragment =
[fragment stringByReplacingOccurrencesOfString:roomIdOrAlias
withString:[MXTools encodeURIComponent:roomId]];
}
if (![newUniversalLinkFragment isEqualToString:fragment])
{
self->universalLinkFragmentPendingRoomAlias = @{roomId: roomIdOrAlias};
UniversalLinkParameters *newParameters = [[UniversalLinkParameters alloc] initWithFragment:newUniversalLinkFragment universalLinkURL:universalLinkURL presentationParameters:presentationParameters];
self->universalLinkFragmentPendingRoomAlias = @{resolution.roomId: roomIdOrAlias};
UniversalLinkParameters *newParameters = [[UniversalLinkParameters alloc] initWithFragment:newFragment
universalLinkURL:universalLinkURL
presentationParameters:presentationParameters];
[self handleUniversalLinkWithParameters:newParameters];
}
else
{
// Do not continue. Else we will loop forever
MXLogDebug(@"[AppDelegate] Universal link: Error: Cannot resolve alias in %@ to the room id %@", fragment, roomId);
MXLogDebug(@"[AppDelegate] Universal link: Error: Cannot resolve alias in %@ to the room id %@", fragment, resolution.roomId);
}
}