diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index c328fd026..d5b38c51c 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -240,6 +240,7 @@ "room_many_users_are_typing" = "%@, %@ & others are typing…"; "room_message_placeholder" = "Send a message (unencrypted)…"; "room_message_reply_to_placeholder" = "Send a reply (unencrypted)…"; +"room_message_unable_open_link_error_message" = "Unable to open the link."; "room_do_not_have_permission_to_post" = "You do not have permission to post to this room"; "encrypted_room_message_placeholder" = "Send an encrypted message…"; "encrypted_room_message_reply_to_placeholder" = "Send an encrypted reply…"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 7322f28f3..2d9e3ef37 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -1434,6 +1434,10 @@ internal enum VectorL10n { internal static var roomMessageShortPlaceholder: String { return VectorL10n.tr("Vector", "room_message_short_placeholder") } + /// Unable to open the link. + internal static var roomMessageUnableOpenLinkErrorMessage: String { + return VectorL10n.tr("Vector", "room_message_unable_open_link_error_message") + } /// %d new message internal static func roomNewMessageNotification(_ p1: Int) -> String { return VectorL10n.tr("Vector", "room_new_message_notification", p1) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 9eb6616ea..49440b8da 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -2753,6 +2753,8 @@ { // Try to catch universal link supported by the app NSURL *url = userInfo[kMXKRoomBubbleCellUrl]; + // Retrieve the type of interaction expected with the URL (See UITextItemInteraction) + NSNumber *urlItemInteractionValue = userInfo[kMXKRoomBubbleCellUrlItemInteraction]; // When a link refers to a room alias/id, a user id or an event id, the non-ASCII characters (like '#' in room alias) has been escaped // to be able to convert it into a legal URL string. @@ -2831,6 +2833,37 @@ } } } + else if (url && urlItemInteractionValue) + { + // Fallback case for external links + + // TODO: Use UITextItemInteraction enum when minimum deployement target will be iOS 10 + switch (urlItemInteractionValue.integerValue) { + case 0: //UITextItemInteractionInvokeDefaultAction + { + [[UIApplication sharedApplication] vc_open:url completionHandler:^(BOOL success) { + if (!success) + { + [self showUnableToOpenLinkErrorAlert]; + } + }]; + shouldDoAction = NO; + } + break; + case 1: //UITextItemInteractionPresentActions + // Long press on link, let MXKRoomBubbleTableViewCell UITextView present the default contextual menu. + break; + case 2: //UITextItemInteractionPreview + // Force touch on link, let MXKRoomBubbleTableViewCell UITextView use default peek and pop behavior. + break; + default: + break; + } + } + else + { + [self showUnableToOpenLinkErrorAlert]; + } } return shouldDoAction; @@ -2861,6 +2894,12 @@ [self dataSource:self.roomDataSource didCellChange:nil]; } +- (void)showUnableToOpenLinkErrorAlert +{ + [[AppDelegate theDelegate] showAlertWithTitle:[NSBundle mxk_localizedStringForKey:@"error"] + message:NSLocalizedStringFromTable(@"room_message_unable_open_link_error_message", @"Vector", nil)]; +} + #pragma mark - Segues - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender