Fix confirmation for RTL overridden links

This commit is contained in:
ismailgulek
2022-05-26 17:48:39 +03:00
parent c633637f68
commit 33f893a672
2 changed files with 47 additions and 18 deletions
+32 -18
View File
@@ -4279,6 +4279,7 @@ static CGSize kThreadListBarButtonItemImageSize;
MXEvent *tappedEvent = userInfo[kMXKRoomBubbleCellEventKey];
NSString *format = tappedEvent.content[@"format"];
NSString *formattedBody = tappedEvent.content[@"formatted_body"];
NSString *body = tappedEvent.content[kMXMessageBodyKey];
// if an html formatted body exists
if ([format isEqualToString:kMXRoomMessageFormatHTML] && formattedBody)
{
@@ -4287,27 +4288,17 @@ static CGSize kThreadListBarButtonItemImageSize;
if (visibleURL && ![url isEqual:visibleURL])
{
// urls are different, show confirmation alert
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[VectorL10n externalLinkConfirmationTitle] message:[VectorL10n externalLinkConfirmationMessage:visibleURL.absoluteString :url.absoluteString] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *continueAction = [UIAlertAction actionWithTitle:[VectorL10n continue] 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:[VectorL10n cancel] style:UIAlertActionStyleCancel handler:nil];
[alert addAction:continueAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
[self showDifferentURLsAlertFor:url visibleString:visibleURL.absoluteString];
return NO;
}
}
else if ([body mxk_containsRTLOverride] && ![body isEqualToString:url.absoluteString])
{
// we don't know where the url in the body, assuming visibleString is just a reverse of the url
[self showDifferentURLsAlertFor:url
visibleString:[url.absoluteString mxk_reversed]];
return NO;
}
// Try to open the link
[[UIApplication sharedApplication] vc_open:url completionHandler:^(BOOL success) {
if (!success)
@@ -4432,6 +4423,29 @@ static CGSize kThreadListBarButtonItemImageSize;
return roomInputToolbarView;
}
- (void)showDifferentURLsAlertFor:(NSURL *)url visibleString:(NSString *)visibleString
{
// urls are different, show confirmation alert
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[VectorL10n externalLinkConfirmationTitle] message:[VectorL10n externalLinkConfirmationMessage:visibleString :url.absoluteString] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *continueAction = [UIAlertAction actionWithTitle:[VectorL10n continue] 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:[VectorL10n cancel] style:UIAlertActionStyleCancel handler:nil];
[alert addAction:continueAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - RoomDataSourceDelegate
- (void)roomDataSourceDidUpdateEncryptionTrustLevel:(RoomDataSource *)roomDataSource