mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Intercept and create matrix.to URLs within the app #547
This commit is contained in:
parent
22f390e487
commit
12f04b1c62
4 changed files with 35 additions and 20 deletions
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}];
|
}];
|
||||||
|
|
|
@ -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];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue