From f3a34361ea18ad7c53f10f0abf58cdddcfbf6d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20M=C3=BCller?= Date: Sat, 2 May 2020 22:25:12 +0200 Subject: [PATCH] Add more flexibility to open links in other browsers, e.g. FF Mobile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Müller --- CHANGES.rst | 12 ++++ MatrixKit/Models/MXKAppSettings.h | 16 ++++- MatrixKit/Models/MXKAppSettings.m | 65 ++++++++++++++++++- .../Utils/EventFormatter/MXKEventFormatter.m | 16 +++-- 4 files changed, 102 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8d7df8803..10f0ef432 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +Changes in MatrixKit in 0.12.5 (2020-05-XX) +========================================= + +Improvements: + * Add more flexibility to open links in other browsers, e.g. FF Mobile + Changes in MatrixKit in 0.12.5 (2020-05-13) ========================================= @@ -19,6 +25,12 @@ Changes in MatrixKit in 0.12.3 (2020-05-07) Improvements: * Upgrade MatrixSDK version ([v0.16.3](https://github.com/matrix-org/matrix-ios-sdk/releases/tag/v0.16.3)). +Changes in MatrixKit in 0.12.3 (2020-XX-XX) +========================================= + +Improvements: + * Add more flexibility to open links in other browsers, e.g. FF Mobile (vector-im/riot-ios#2949). + Changes in MatrixKit in 0.12.2 (2020-05-01) ========================================= diff --git a/MatrixKit/Models/MXKAppSettings.h b/MatrixKit/Models/MXKAppSettings.h index be36f2613..a308edf97 100644 --- a/MatrixKit/Models/MXKAppSettings.h +++ b/MatrixKit/Models/MXKAppSettings.h @@ -85,17 +85,29 @@ @property (nonatomic) BOOL showUnsupportedEventsInRoomHistory; /** - Scheme with which to open HTTP links. e.g. if this is set to "googlechrome", any http:// links displayed in a room will be rewritten to use the googlechrome:// scheme. + Scheme with which to open HTTP links. e.g. if this is set to "googlechrome" and httpHttpsBaseURL is empty, any http:// links displayed in a room will be rewritten to use the googlechrome:// scheme. Defaults to "http". */ @property (nonatomic) NSString *httpLinkScheme; /** - Scheme with which to open HTTPS links. e.g. if this is set to "googlechromes", any https:// links displayed in a room will be rewritten to use the googlechromes:// scheme. + Scheme with which to open HTTPS links. e.g. if this is set to "googlechromes" and httpHttpsBaseURL is empty, any https:// links displayed in a room will be rewritten to use the googlechromes:// scheme. Defaults to "https". */ @property (nonatomic) NSString *httpsLinkScheme; +/** + Base URL which to use to open HTTP and HTTPS links. If this is set and httpLinkScheme or httpsLinkScheme has a value other than its default, any HTTP(S) links displayed in a room will be rewritten to httpHttpsBaseURL?httpHttpsQueryParam=URL. + The http(s)LinkScheme params are not used for the construction of the URL. They are only needed to detect the presence of this parameter. + Defaults to "". + */ +@property (nonatomic) NSString *httpHttpsBaseURL; + +/** + Name of the query parameter with which the URL of any link is concatenated (escaped) to the httpHttpsBaseURL if the conditions to use it are met. + Defaults to "". + */ +@property (nonatomic) NSString *httpHttpsQueryParam; #pragma mark - Room members diff --git a/MatrixKit/Models/MXKAppSettings.m b/MatrixKit/Models/MXKAppSettings.m index 50593b911..f411353a9 100644 --- a/MatrixKit/Models/MXKAppSettings.m +++ b/MatrixKit/Models/MXKAppSettings.m @@ -42,7 +42,8 @@ @interface MXKAppSettings () @implementation MXKAppSettings @synthesize syncWithLazyLoadOfRoomMembers; -@synthesize showAllEventsInRoomHistory, showRedactionsInRoomHistory, showUnsupportedEventsInRoomHistory, httpLinkScheme, httpsLinkScheme; +@synthesize showAllEventsInRoomHistory, showRedactionsInRoomHistory, showUnsupportedEventsInRoomHistory; +@synthesize httpLinkScheme, httpsLinkScheme, httpHttpsBaseURL, httpHttpsQueryParam; @synthesize showLeftMembersInRoomMemberList, sortRoomMembersUsingLastSeenTime; @synthesize syncLocalContacts, syncLocalContactsPermissionRequested, phonebookCountryCode; @synthesize presenceColorForOnlineUser, presenceColorForUnavailableUser, presenceColorForOfflineUser; @@ -116,6 +117,8 @@ -(instancetype)init httpLinkScheme = @"http"; httpsLinkScheme = @"https"; + httpHttpsBaseURL = @""; + httpHttpsQueryParam = @""; enableCallKit = YES; @@ -194,6 +197,8 @@ - (void)reset [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"httpLinkScheme"]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"httpsLinkScheme"]; + [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"httpHttpsBaseURL"]; + [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"httpHttpsQueryParam"]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"enableCallKit"]; } @@ -218,6 +223,8 @@ - (void)reset httpLinkScheme = @"http"; httpsLinkScheme = @"https"; + httpHttpsBaseURL = @""; + httpHttpsQueryParam = @""; enableCallKit = YES; } @@ -451,6 +458,62 @@ - (void)setHttpsLinkScheme:(NSString *)stringValue } } +- (NSString *)httpHttpsBaseURL +{ + if (self == [MXKAppSettings standardAppSettings]) + { + NSString *ret = [[NSUserDefaults standardUserDefaults] stringForKey:@"httpHttpsBaseURL"]; + if (ret == nil) { + ret = @""; + } + return ret; + } + else + { + return httpHttpsBaseURL; + } +} + +- (void)setHttpHttpsBaseURL:(NSString *)stringValue +{ + if (self == [MXKAppSettings standardAppSettings]) + { + [[NSUserDefaults standardUserDefaults] setObject:stringValue forKey:@"httpHttpsBaseURL"]; + } + else + { + httpHttpsBaseURL = stringValue; + } +} + +- (NSString *)httpHttpsQueryParam +{ + if (self == [MXKAppSettings standardAppSettings]) + { + NSString *ret = [[NSUserDefaults standardUserDefaults] stringForKey:@"httpHttpsQueryParam"]; + if (ret == nil) { + ret = @""; + } + return ret; + } + else + { + return httpHttpsQueryParam; + } +} + +- (void)setHttpHttpsQueryParam:(NSString *)stringValue +{ + if (self == [MXKAppSettings standardAppSettings]) + { + [[NSUserDefaults standardUserDefaults] setObject:stringValue forKey:@"httpHttpsQueryParam"]; + } + else + { + httpHttpsQueryParam = stringValue; + } +} + #pragma mark - Room members - (BOOL)sortRoomMembersUsingLastSeenTime diff --git a/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m b/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m index 2e2bb1dc7..29ce74c6d 100644 --- a/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m +++ b/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m @@ -1186,13 +1186,21 @@ - (NSAttributedString*)renderString:(NSString*)string forEvent:(MXEvent*)event if (url) { - if ([url.scheme isEqualToString: @"http"]) + if ([[_settings httpHttpsBaseURL] length] != 0) { - url.scheme = [_settings httpLinkScheme]; + url = [[NSURLComponents new] initWithURL:[_settings httpHttpsBaseURL] resolvingAgainstBaseURL:NO]; + [url setQueryItems:@[[[NSURLQueryItem new] initWithName:[_settings httpHttpsQueryParam] value:matchUrl]]]; } - else if ([url.scheme isEqualToString: @"https"]) + else { - url.scheme = [_settings httpsLinkScheme]; + if ([url.scheme isEqualToString: @"http"]) + { + url.scheme = [_settings httpLinkScheme]; + } + else if ([url.scheme isEqualToString: @"https"]) + { + url.scheme = [_settings httpsLinkScheme]; + } } if (url.URL)