Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Add more flexibility to open links in other browsers, e.g. FF Mobile #662

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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)
=========================================

Expand All @@ -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)
=========================================

Expand Down
16 changes: 14 additions & 2 deletions MatrixKit/Models/MXKAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
65 changes: 64 additions & 1 deletion MatrixKit/Models/MXKAppSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,6 +117,8 @@ -(instancetype)init

httpLinkScheme = @"http";
httpsLinkScheme = @"https";
httpHttpsBaseURL = @"";
httpHttpsQueryParam = @"";

enableCallKit = YES;

Expand Down Expand Up @@ -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"];
}
Expand All @@ -218,6 +223,8 @@ - (void)reset

httpLinkScheme = @"http";
httpsLinkScheme = @"https";
httpHttpsBaseURL = @"";
httpHttpsQueryParam = @"";

enableCallKit = YES;
}
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions MatrixKit/Utils/EventFormatter/MXKEventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down