From 3fa1a211c07fcac719cc85e56dc979cd96b2a4fc Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 3 Dec 2019 18:41:17 +0100 Subject: [PATCH 1/3] Create a URL parser for room messages. --- Riot.xcodeproj/project.pbxproj | 12 ++++ .../RoomMessageURLParser.swift | 65 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Riot/Managers/RoomMessageLinkParser/RoomMessageURLParser.swift diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index cfb893378..fd3d454aa 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -168,6 +168,7 @@ B125FE1F231D5DF700B72806 /* SettingsDiscoveryViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B125FE1E231D5DF700B72806 /* SettingsDiscoveryViewModelType.swift */; }; B125FE21231D5E1D00B72806 /* SettingsDiscoveryViewAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B125FE20231D5E1D00B72806 /* SettingsDiscoveryViewAction.swift */; }; B125FE23231D5E4300B72806 /* SettingsDiscoveryViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B125FE22231D5E4300B72806 /* SettingsDiscoveryViewState.swift */; }; + B12C56EF2396CB5E00FAC6DE /* RoomMessageURLParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = B12C56EE2396CB5E00FAC6DE /* RoomMessageURLParser.swift */; }; B139C21B21FE5B9200BB68EC /* KeyBackupRecoverFromPassphraseViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B139C21A21FE5B9100BB68EC /* KeyBackupRecoverFromPassphraseViewModel.swift */; }; B139C21D21FE5BF500BB68EC /* KeyBackupRecoverFromPassphraseViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B139C21C21FE5BF500BB68EC /* KeyBackupRecoverFromPassphraseViewModelType.swift */; }; B139C21F21FE5D6600BB68EC /* KeyBackupRecoverFromPassphraseViewAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B139C21E21FE5D6600BB68EC /* KeyBackupRecoverFromPassphraseViewAction.swift */; }; @@ -844,6 +845,7 @@ B125FE1E231D5DF700B72806 /* SettingsDiscoveryViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDiscoveryViewModelType.swift; sourceTree = ""; }; B125FE20231D5E1D00B72806 /* SettingsDiscoveryViewAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDiscoveryViewAction.swift; sourceTree = ""; }; B125FE22231D5E4300B72806 /* SettingsDiscoveryViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDiscoveryViewState.swift; sourceTree = ""; }; + B12C56EE2396CB5E00FAC6DE /* RoomMessageURLParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMessageURLParser.swift; sourceTree = ""; }; B139C21A21FE5B9100BB68EC /* KeyBackupRecoverFromPassphraseViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyBackupRecoverFromPassphraseViewModel.swift; sourceTree = ""; }; B139C21C21FE5BF500BB68EC /* KeyBackupRecoverFromPassphraseViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyBackupRecoverFromPassphraseViewModelType.swift; sourceTree = ""; }; B139C21E21FE5D6600BB68EC /* KeyBackupRecoverFromPassphraseViewAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyBackupRecoverFromPassphraseViewAction.swift; sourceTree = ""; }; @@ -2041,6 +2043,14 @@ path = Discovery; sourceTree = ""; }; + B12C56ED2396CB0100FAC6DE /* RoomMessageLinkParser */ = { + isa = PBXGroup; + children = ( + B12C56EE2396CB5E00FAC6DE /* RoomMessageURLParser.swift */, + ); + path = RoomMessageLinkParser; + sourceTree = ""; + }; B14F142522144F6400FA0595 /* RecoveryKey */ = { isa = PBXGroup; children = ( @@ -3459,6 +3469,7 @@ B1B5597C20EFC3DF00210D55 /* Managers */ = { isa = PBXGroup; children = ( + B12C56ED2396CB0100FAC6DE /* RoomMessageLinkParser */, B1B9DED822E9B7120065E677 /* Serialization */, B1FDF56321F68C0700BA3834 /* PasswordStrength */, B1798300211B137B001FD722 /* OnBoarding */, @@ -4577,6 +4588,7 @@ B139C21D21FE5BF500BB68EC /* KeyBackupRecoverFromPassphraseViewModelType.swift in Sources */, B157FA9F23264AE900EBFBD4 /* SettingsDiscoveryThreePidDetailsCoordinator.swift in Sources */, B1C45A8B232A8C2600165425 /* SettingsIdentityServerViewModel.swift in Sources */, + B12C56EF2396CB5E00FAC6DE /* RoomMessageURLParser.swift in Sources */, B1C45A86232A8C2600165425 /* SettingsIdentityServerViewModelType.swift in Sources */, F083BE031E7009ED00A9B29C /* EventFormatter.m in Sources */, B157FAA623264AE900EBFBD4 /* SettingsDiscoveryThreePidDetailsViewController.swift in Sources */, diff --git a/Riot/Managers/RoomMessageLinkParser/RoomMessageURLParser.swift b/Riot/Managers/RoomMessageLinkParser/RoomMessageURLParser.swift new file mode 100644 index 000000000..758cf72c6 --- /dev/null +++ b/Riot/Managers/RoomMessageLinkParser/RoomMessageURLParser.swift @@ -0,0 +1,65 @@ +/* + Copyright 2019 New Vector Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +import Foundation + +@objc enum RoomMessageURLType: Int { + case appleDataDetector + case http + case dummy + case unknown +} + +/// URL parser for room messages. +@objcMembers +final class RoomMessageURLParser: NSObject { + + // MARK: - Constants + + private enum Scheme { + static let appleDataDetector = "x-apple-data-detectors" + static let http = "http" + static let https = "https" + } + + private enum Constants { + static let dummyURL = "#" + } + + // MARK: - Public + + func parseURL(_ url: URL) -> RoomMessageURLType { + + let roomMessageLink: RoomMessageURLType + + if let scheme = url.scheme?.lowercased() { + switch scheme { + case Scheme.appleDataDetector: + roomMessageLink = .appleDataDetector + case Scheme.http, Scheme.https: + roomMessageLink = .http + default: + roomMessageLink = .unknown + } + } else if url.absoluteString == Constants.dummyURL { + roomMessageLink = .dummy + } else { + roomMessageLink = .unknown + } + + return roomMessageLink + } +} From 5a593a95d3f787af755cc9fa210bb3cbe5dac899 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 3 Dec 2019 19:58:51 +0100 Subject: [PATCH 2/3] RoomVC: Handle tap and long tap on UITextView detected data other than links (Fix #2803). --- Riot/Modules/Room/RoomViewController.m | 48 +++++++++++++++++++++----- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 47f8f3e3d..2c4fac795 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -228,6 +228,7 @@ @property (nonatomic, strong) ReactionHistoryCoordinatorBridgePresenter *reactionHistoryCoordinatorBridgePresenter; @property (nonatomic, strong) CameraPresenter *cameraPresenter; @property (nonatomic, strong) MediaPickerCoordinatorBridgePresenter *mediaPickerPresenter; +@property (nonatomic, strong) RoomMessageURLParser *roomMessageURLParser; @end @@ -423,6 +424,7 @@ self.roomContextualMenuPresenter = [RoomContextualMenuPresenter new]; self.errorPresenter = [MXKErrorAlertPresentation new]; + self.roomMessageURLParser = [RoomMessageURLParser new]; // Observe user interface theme change. kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { @@ -2915,6 +2917,13 @@ // Retrieve the type of interaction expected with the URL (See UITextItemInteraction) NSNumber *urlItemInteractionValue = userInfo[kMXKRoomBubbleCellUrlItemInteraction]; + RoomMessageURLType roomMessageURLType = RoomMessageURLTypeUnknown; + + if (url) + { + roomMessageURLType = [self.roomMessageURLParser parseURL:url]; + } + // 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. NSString *absoluteURLString = [url.absoluteString stringByRemovingPercentEncoding]; @@ -3007,19 +3016,40 @@ // Fallback case for external links switch (urlItemInteractionValue.integerValue) { case UITextItemInteractionInvokeDefaultAction: - { - [[UIApplication sharedApplication] vc_open:url completionHandler:^(BOOL success) { - if (!success) - { - [self showUnableToOpenLinkErrorAlert]; - } - }]; - shouldDoAction = NO; + { + switch (roomMessageURLType) { + case RoomMessageURLTypeAppleDataDetector: + // Keep the default OS behavior on single tap when UITextView data detector detect a known type. + shouldDoAction = YES; + break; + case RoomMessageURLTypeDummy: + // Do nothing for dummy links + shouldDoAction = NO; + break; + default: + // Try to open the link + [[UIApplication sharedApplication] vc_open:url completionHandler:^(BOOL success) { + if (!success) + { + [self showUnableToOpenLinkErrorAlert]; + } + }]; + shouldDoAction = NO; + break; + } } break; case UITextItemInteractionPresentActions: { - // Long press on link, present room contextual menu. + // Retrieve the tapped event + MXEvent *tappedEvent = userInfo[kMXKRoomBubbleCellEventKey]; + + if (tappedEvent) + { + // Long press on link, present room contextual menu. + [self showContextualMenuForEvent:tappedEvent fromSingleTapGesture:NO cell:cell animated:YES]; + } + shouldDoAction = NO; } break; From a8b03ea8a8d5e047218c3185b85f636ce190cf8e Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 3 Dec 2019 20:01:04 +0100 Subject: [PATCH 3/3] Update changes --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 2cae07157..74103b440 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,8 @@ Improvements: Bug fix: * Accessibility: Make checkboxes accessible in terms of service screen. + * RoomVC: Tapping on location links gives 'unable to open link' (#2803). + * RoomVC: Reply to links fail with 'unable to open link' (#2804). Changes in 0.10.2 (2019-11-15) ===============================================