Show confirmation alert if given and visible urls different, when tapped a link in a message cell, fixes #3137

This commit is contained in:
ismailgulek
2020-07-03 14:23:44 +03:00
parent 9a81a2372a
commit 2c9f55ab08
+40
View File
@@ -3143,6 +3143,45 @@
shouldDoAction = NO;
break;
default:
{
MXEvent *tappedEvent = userInfo[kMXKRoomBubbleCellEventKey];
NSString *format = tappedEvent.content[@"format"];
NSString *formattedBody = tappedEvent.content[@"formatted_body"];
// if an html formatted body exists
if ([format isEqualToString:kMXRoomMessageFormatHTML] && formattedBody)
{
FormattedBodyParser *parser = [[FormattedBodyParser alloc] initWithFormattedBody:formattedBody];
NSURL *visibleURL = [parser getVisibleURLForURL:url];
if (visibleURL && ![url isEqual:visibleURL])
{
// urls are different, show confirmation alert
NSString *formatStr = NSLocalizedStringFromTable(@"external_link_confirmation_message", @"Vector", nil);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"external_link_confirmation_title", @"Vector", nil) message:[NSString stringWithFormat:formatStr, visibleURL.absoluteString, url.absoluteString] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *continueAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"continue", @"Vector", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// Try to open the link
[[UIApplication sharedApplication] vc_open:url completionHandler:^(BOOL success) {
if (!success)
{
[self showUnableToOpenLinkErrorAlert];
}
}];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"cancel", @"Vector", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// no-op
}];
[alert addAction:continueAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:^{
// no-op
}];
return NO;
}
}
// Try to open the link
[[UIApplication sharedApplication] vc_open:url completionHandler:^(BOOL success) {
if (!success)
@@ -3152,6 +3191,7 @@
}];
shouldDoAction = NO;
break;
}
}
}
break;