Skip to content

Commit

Permalink
Merge pull request #1279 from matrix-org/langleyd/4981_client_permalinks
Browse files Browse the repository at this point in the history
Client permalinks
  • Loading branch information
langleyd authored Nov 4, 2021
2 parents 76bfce9 + 9817f32 commit 8093a86
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
7 changes: 7 additions & 0 deletions MatrixSDK/MXSDKOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions MatrixSDK/MXSDKOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ - (instancetype)init
_autoAcceptRoomInvites = NO;
_callTransferType = MXCallTransferTypeBridged;
self.roomListDataManagerClass = [MXStoreRoomListDataManager class];
_clientPermalinkBaseUrl = nil;
}

return self;
Expand Down
19 changes: 10 additions & 9 deletions MatrixSDK/Utils/MXTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
17 changes: 13 additions & 4 deletions MatrixSDK/Utils/MXTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4981.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds clientPermalinkBaseUrl for a custom permalink base url.

0 comments on commit 8093a86

Please sign in to comment.