diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index a56514817..041c491ed 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -986,17 +986,29 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN 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) { + // 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) { - // 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 MXKAccount *account = [accountManager accountKnowingRoomWithRoomIdOrAlias:roomIdOrAlias]; if (account) diff --git a/Vector/Utils/Tools.m b/Vector/Utils/Tools.m index 861554382..c826911f1 100644 --- a/Vector/Utils/Tools.m +++ b/Vector/Utils/Tools.m @@ -72,8 +72,7 @@ { BOOL isUniversalLink = NO; - if ([url.host isEqualToString:@"vector.im"] || [url.host isEqualToString:@"www.vector.im"] - || [url.host isEqualToString:@"matrix.to"] || [url.host isEqualToString:@"www.matrix.to"]) + if ([url.host isEqualToString:@"vector.im"] || [url.host isEqualToString:@"www.vector.im"]) { // iOS Patch: fix vector.im urls before using it NSURL *fixedURL = [Tools fixURLWithSeveralHashKeys:url]; @@ -83,6 +82,16 @@ 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; } diff --git a/Vector/ViewController/RoomSettingsViewController.m b/Vector/ViewController/RoomSettingsViewController.m index 879661776..750781ee5 100644 --- a/Vector/ViewController/RoomSettingsViewController.m +++ b/Vector/ViewController/RoomSettingsViewController.m @@ -686,12 +686,8 @@ NSString *const kRoomSettingsAdvancedCellViewIdentifier = @"kRoomSettingsAdvance __strong __typeof(weakSelf)strongSelf = weakSelf; strongSelf->currentAlert = nil; - // Create a room url that is common to all Vector.im clients - NSString *roomURL = [NSString stringWithFormat:@"%@/#/room/%@", - [Tools webAppUrl], - roomAliasLabel.text]; - - [[UIPasteboard generalPasteboard] setString:roomURL]; + // Create a matrix.to permalink to the room + [[UIPasteboard generalPasteboard] setString:[MXTools permalinkToRoom:roomAliasLabel.text]]; } }]; diff --git a/Vector/ViewController/RoomViewController.m b/Vector/ViewController/RoomViewController.m index a8362c24b..c3ccb0507 100644 --- a/Vector/ViewController/RoomViewController.m +++ b/Vector/ViewController/RoomViewController.m @@ -1590,12 +1590,10 @@ __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; - // Create a permalink that is common to all Vector.im clients - NSString *permalink = [NSString stringWithFormat:@"%@/#/room/%@/%@", - [Tools webAppUrl], - selectedEvent.roomId, - selectedEvent.eventId]; + // Create a matrix.to permalink that is common to all matrix clients + NSString *permalink = [MXTools permalinkToEvent:selectedEvent.eventId inRoom:selectedEvent.roomId]; + // Create a room matrix.to permalink [[UIPasteboard generalPasteboard] setString:permalink]; }];