Skip to content

Commit

Permalink
Merge pull request #2869 from vector-im/riot_2803
Browse files Browse the repository at this point in the history
BF: Tapping on location links gives 'unable to open link'
  • Loading branch information
SBiOSoftWhare authored Dec 4, 2019
2 parents 23c3c60 + a8b03ea commit ae96b2e
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
===============================================
Expand Down
12 changes: 12 additions & 0 deletions Riot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -844,6 +845,7 @@
B125FE1E231D5DF700B72806 /* SettingsDiscoveryViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDiscoveryViewModelType.swift; sourceTree = "<group>"; };
B125FE20231D5E1D00B72806 /* SettingsDiscoveryViewAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDiscoveryViewAction.swift; sourceTree = "<group>"; };
B125FE22231D5E4300B72806 /* SettingsDiscoveryViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDiscoveryViewState.swift; sourceTree = "<group>"; };
B12C56EE2396CB5E00FAC6DE /* RoomMessageURLParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMessageURLParser.swift; sourceTree = "<group>"; };
B139C21A21FE5B9100BB68EC /* KeyBackupRecoverFromPassphraseViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyBackupRecoverFromPassphraseViewModel.swift; sourceTree = "<group>"; };
B139C21C21FE5BF500BB68EC /* KeyBackupRecoverFromPassphraseViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyBackupRecoverFromPassphraseViewModelType.swift; sourceTree = "<group>"; };
B139C21E21FE5D6600BB68EC /* KeyBackupRecoverFromPassphraseViewAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyBackupRecoverFromPassphraseViewAction.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2041,6 +2043,14 @@
path = Discovery;
sourceTree = "<group>";
};
B12C56ED2396CB0100FAC6DE /* RoomMessageLinkParser */ = {
isa = PBXGroup;
children = (
B12C56EE2396CB5E00FAC6DE /* RoomMessageURLParser.swift */,
);
path = RoomMessageLinkParser;
sourceTree = "<group>";
};
B14F142522144F6400FA0595 /* RecoveryKey */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3459,6 +3469,7 @@
B1B5597C20EFC3DF00210D55 /* Managers */ = {
isa = PBXGroup;
children = (
B12C56ED2396CB0100FAC6DE /* RoomMessageLinkParser */,
B1B9DED822E9B7120065E677 /* Serialization */,
B1FDF56321F68C0700BA3834 /* PasswordStrength */,
B1798300211B137B001FD722 /* OnBoarding */,
Expand Down Expand Up @@ -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 */,
Expand Down
65 changes: 65 additions & 0 deletions Riot/Managers/RoomMessageLinkParser/RoomMessageURLParser.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
48 changes: 39 additions & 9 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ @interface RoomViewController () <UISearchBarDelegate, UIGestureRecognizerDelega
@property (nonatomic, strong) ReactionHistoryCoordinatorBridgePresenter *reactionHistoryCoordinatorBridgePresenter;
@property (nonatomic, strong) CameraPresenter *cameraPresenter;
@property (nonatomic, strong) MediaPickerCoordinatorBridgePresenter *mediaPickerPresenter;
@property (nonatomic, strong) RoomMessageURLParser *roomMessageURLParser;

@end

Expand Down Expand Up @@ -423,6 +424,7 @@ - (void)viewDidLoad

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) {
Expand Down Expand Up @@ -2915,6 +2917,13 @@ - (BOOL)dataSource:(MXKDataSource *)dataSource shouldDoAction:(NSString *)action
// 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];
Expand Down Expand Up @@ -3007,19 +3016,40 @@ - (BOOL)dataSource:(MXKDataSource *)dataSource shouldDoAction:(NSString *)action
// 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;
Expand Down

0 comments on commit ae96b2e

Please sign in to comment.