Intercept and create matrix.to URLs within the app #547

This commit is contained in:
manuroe 2016-08-29 11:57:01 +02:00
parent 22f390e487
commit 12f04b1c62
4 changed files with 35 additions and 20 deletions

View file

@ -986,17 +986,29 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
return NO; return NO;
} }
// Check the action to do NSString *roomIdOrAlias;
NSString *eventId;
// Check permalink to room or event
if ([pathParams[0] isEqualToString:@"room"] && pathParams.count >= 2) if ([pathParams[0] isEqualToString:@"room"] && pathParams.count >= 2)
{ {
// The link is the form of "/room/[roomIdOrAlias]" or "/room/[roomIdOrAlias]/[eventId]"
roomIdOrAlias = pathParams[1];
// Is it a link to an event of a room?
eventId = (pathParams.count >= 3) ? pathParams[2] : nil;
}
else if (([pathParams[0] hasPrefix:@"#"] || [pathParams[0] hasPrefix:@"!"]) && pathParams.count >= 1)
{
// The link is the form of "/#/[roomIdOrAlias]" or "/#/[roomIdOrAlias]/[eventId]"
// Such links come from matrix.to permalinks
roomIdOrAlias = pathParams[0];
eventId = (pathParams.count >= 2) ? pathParams[1] : nil;
}
if (roomIdOrAlias)
{
if (accountManager.activeAccounts.count) if (accountManager.activeAccounts.count)
{ {
// The link is the form of "/room/[roomIdOrAlias]" or "/room/[roomIdOrAlias]/[eventId]"
NSString *roomIdOrAlias = pathParams[1];
// Is it a link to an event of a room?
NSString *eventId = (pathParams.count >= 3) ? pathParams[2] : nil;
// Check there is an account that knows this room // Check there is an account that knows this room
MXKAccount *account = [accountManager accountKnowingRoomWithRoomIdOrAlias:roomIdOrAlias]; MXKAccount *account = [accountManager accountKnowingRoomWithRoomIdOrAlias:roomIdOrAlias];
if (account) if (account)

View file

@ -72,8 +72,7 @@
{ {
BOOL isUniversalLink = NO; BOOL isUniversalLink = NO;
if ([url.host isEqualToString:@"vector.im"] || [url.host isEqualToString:@"www.vector.im"] if ([url.host isEqualToString:@"vector.im"] || [url.host isEqualToString:@"www.vector.im"])
|| [url.host isEqualToString:@"matrix.to"] || [url.host isEqualToString:@"www.matrix.to"])
{ {
// iOS Patch: fix vector.im urls before using it // iOS Patch: fix vector.im urls before using it
NSURL *fixedURL = [Tools fixURLWithSeveralHashKeys:url]; NSURL *fixedURL = [Tools fixURLWithSeveralHashKeys:url];
@ -83,6 +82,16 @@
isUniversalLink = YES; isUniversalLink = YES;
} }
} }
else if ([url.host isEqualToString:@"matrix.to"] || [url.host isEqualToString:@"www.matrix.to"])
{
// iOS Patch: fix matrix.to urls before using it
NSURL *fixedURL = [Tools fixURLWithSeveralHashKeys:url];
if ([fixedURL.path isEqualToString:@"/"])
{
isUniversalLink = YES;
}
}
return isUniversalLink; return isUniversalLink;
} }

View file

@ -686,12 +686,8 @@ NSString *const kRoomSettingsAdvancedCellViewIdentifier = @"kRoomSettingsAdvance
__strong __typeof(weakSelf)strongSelf = weakSelf; __strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->currentAlert = nil; strongSelf->currentAlert = nil;
// Create a room url that is common to all Vector.im clients // Create a matrix.to permalink to the room
NSString *roomURL = [NSString stringWithFormat:@"%@/#/room/%@", [[UIPasteboard generalPasteboard] setString:[MXTools permalinkToRoom:roomAliasLabel.text]];
[Tools webAppUrl],
roomAliasLabel.text];
[[UIPasteboard generalPasteboard] setString:roomURL];
} }
}]; }];

View file

@ -1590,12 +1590,10 @@
__strong __typeof(weakSelf)strongSelf = weakSelf; __strong __typeof(weakSelf)strongSelf = weakSelf;
[strongSelf cancelEventSelection]; [strongSelf cancelEventSelection];
// Create a permalink that is common to all Vector.im clients // Create a matrix.to permalink that is common to all matrix clients
NSString *permalink = [NSString stringWithFormat:@"%@/#/room/%@/%@", NSString *permalink = [MXTools permalinkToEvent:selectedEvent.eventId inRoom:selectedEvent.roomId];
[Tools webAppUrl],
selectedEvent.roomId,
selectedEvent.eventId];
// Create a room matrix.to permalink
[[UIPasteboard generalPasteboard] setString:permalink]; [[UIPasteboard generalPasteboard] setString:permalink];
}]; }];