diff --git a/MatrixSDK/MXSDKOptions.h b/MatrixSDK/MXSDKOptions.h index 541b2625db..73ac64ed66 100644 --- a/MatrixSDK/MXSDKOptions.h +++ b/MatrixSDK/MXSDKOptions.h @@ -175,6 +175,13 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic) Class roomListDataManagerClass; +/** + For use in clients that use a custom base url for permalinks rather than matrix.to. + This baseURL is used to generate permalinks within the app (E.g. timeline message permalinks). + An Optional String, when nil matrix.to format/hostname is used instead. + */ +@property (nonatomic, nullable) NSString *clientPermalinkBaseUrl; + @end NS_ASSUME_NONNULL_END diff --git a/MatrixSDK/MXSDKOptions.m b/MatrixSDK/MXSDKOptions.m index b317069c8a..17bcaae778 100644 --- a/MatrixSDK/MXSDKOptions.m +++ b/MatrixSDK/MXSDKOptions.m @@ -50,6 +50,7 @@ - (instancetype)init _autoAcceptRoomInvites = NO; _callTransferType = MXCallTransferTypeBridged; self.roomListDataManagerClass = [MXStoreRoomListDataManager class]; + _clientPermalinkBaseUrl = nil; } return self; diff --git a/MatrixSDK/Utils/MXTools.h b/MatrixSDK/Utils/MXTools.h index 2da832b5b8..539118cda0 100644 --- a/MatrixSDK/Utils/MXTools.h +++ b/MatrixSDK/Utils/MXTools.h @@ -159,33 +159,34 @@ FOUNDATION_EXPORT NSString *const kMXToolsRegexStringForMatrixGroupIdentifier; */ + (NSString*)encodeURIComponent:(NSString*)string; - #pragma mark - Permalink /* - Return a matrix.to permalink to a room. + Return a permalink to a room. + The permalink could be matrix.to format or a custom client permalink (see `MXSDKOptions.clientPermalinkBaseUrl`). @param roomIdOrAlias the id or the alias of the room to link to. - @return the matrix.to permalink. + @return the permalink. */ + (NSString*)permalinkToRoom:(NSString*)roomIdOrAlias; /* - Return a matrix.to permalink to an event. - + Return a permalink to an event. + The permalink could be matrix.to format or a custom client permalink (see `MXSDKOptions.clientPermalinkBaseUrl`). + @param eventId the id of the event to link to. @param roomIdOrAlias the room the event belongs to. - @return the matrix.to permalink. + @return the permalink. */ + (NSString*)permalinkToEvent:(NSString*)eventId inRoom:(NSString*)roomIdOrAlias; /* - Return a matrix.to permalink to a user. + Return a permalink to a user. + The permalink could be matrix.to format or a custom client permalink (see `MXSDKOptions.clientPermalinkBaseUrl`). @param userId the id of the user to link to. - @return the matrix.to permalink. + @return the permalink. */ + (NSString*)permalinkToUserWithUserId:(NSString*)userId; - #pragma mark - File /** diff --git a/MatrixSDK/Utils/MXTools.m b/MatrixSDK/Utils/MXTools.m index 45b8d9df05..a362109317 100644 --- a/MatrixSDK/Utils/MXTools.m +++ b/MatrixSDK/Utils/MXTools.m @@ -565,20 +565,29 @@ + (NSString *)encodeURIComponent:(NSString *)string #pragma mark - Permalink + + (NSString *)permalinkToRoom:(NSString *)roomIdOrAlias { - return [NSString stringWithFormat:@"%@/#/%@", kMXMatrixDotToUrl, [MXTools encodeURIComponent:roomIdOrAlias]]; + NSString *clientBaseUrl = [MXSDKOptions sharedInstance].clientPermalinkBaseUrl; + NSString *format = clientBaseUrl != nil ? @"%@/#/room/%@" : @"%@/#/%@"; + NSString *baseUrl = clientBaseUrl != nil ? clientBaseUrl : kMXMatrixDotToUrl; + return [NSString stringWithFormat:format, baseUrl, [MXTools encodeURIComponent:roomIdOrAlias]]; } + (NSString *)permalinkToEvent:(NSString *)eventId inRoom:(NSString *)roomIdOrAlias { - return [NSString stringWithFormat:@"%@/#/%@/%@", kMXMatrixDotToUrl, [MXTools encodeURIComponent:roomIdOrAlias], [MXTools encodeURIComponent:eventId]]; - + NSString *clientBaseUrl = [MXSDKOptions sharedInstance].clientPermalinkBaseUrl; + NSString *format = clientBaseUrl != nil ? @"%@/#/room/%@/%@" : @"%@/#/%@/%@"; + NSString *baseUrl = clientBaseUrl != nil ? clientBaseUrl : kMXMatrixDotToUrl; + return [NSString stringWithFormat:format, baseUrl, [MXTools encodeURIComponent:roomIdOrAlias], [MXTools encodeURIComponent:eventId]]; } + (NSString*)permalinkToUserWithUserId:(NSString*)userId { - return [NSString stringWithFormat:@"%@/#/%@", kMXMatrixDotToUrl, userId]; + NSString *clientBaseUrl = [MXSDKOptions sharedInstance].clientPermalinkBaseUrl; + NSString *format = clientBaseUrl != nil ? @"%@/#/user/%@" : @"%@/#/%@"; + NSString *baseUrl = clientBaseUrl != nil ? clientBaseUrl : kMXMatrixDotToUrl; + return [NSString stringWithFormat:format, baseUrl, userId]; } #pragma mark - File diff --git a/changelog.d/4981.feature b/changelog.d/4981.feature new file mode 100644 index 0000000000..2d1a3e79f5 --- /dev/null +++ b/changelog.d/4981.feature @@ -0,0 +1 @@ +Adds clientPermalinkBaseUrl for a custom permalink base url.