Handle quick tap on link in RoomViewController. Retrieve URL interaction information when user tap a link in a MXKRoomBubbleTableViewCell to indicate the type of interaction expected with the URL.

This commit is contained in:
SBiOSoftWhare 2019-03-04 18:29:13 +01:00
parent b0d456b028
commit 396f184bc1
3 changed files with 44 additions and 0 deletions

View file

@ -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…";

View file

@ -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)

View file

@ -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