Skip to content

Commit

Permalink
Correction de la génération de lien de partage sur les forums (ou sal…
Browse files Browse the repository at this point in the history
…on sans alias)
  • Loading branch information
Nicolas Buquet committed Jun 17, 2024
1 parent 916d452 commit b573db3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ final class RoomAccessByLinkViewModel: RoomAccessByLinkViewModelType {
} else {
isUnrestrictedRoom = false
}
} else if let permalink = Tools.permalinkToRoomWithoutAlias(from: roomState) {
// If room as no canonical alias but permalink can be computed uing roomId and homeServers from members
// use this form of permalink (Tchap on web does like this).
link = permalink
if let room = self.session.room(withRoomId: roomId), let summary = room.summary {
if case RoomAccessRule.unrestricted = summary.tc_roomAccessRule() {
isUnrestrictedRoom = true
} else {
isUnrestrictedRoom = false
}
} else {
isUnrestrictedRoom = false
}
} else {
link = TchapL10n.roomSettingsRoomAccessByLinkInvalid
isUnrestrictedRoom = false
Expand Down
11 changes: 11 additions & 0 deletions Tchap/Utils/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
*/
+ (NSString*)permalinkToRoom:(NSString*)roomIdOrAlias;


/*
Return a permalink to a room which has no alias.
@param roomState the RoomState of the room, containing the roomId and the room members necessary to build the permalink.
@return the Tchap permalink.
*/
+ (NSString *)permalinkToRoomWithoutAliasFromRoomState:(MXRoomState *)roomState;


/*
Return a permalink to an event.
Expand All @@ -73,4 +83,5 @@
*/
+ (NSString*)permalinkToEvent:(NSString*)eventId inRoom:(NSString*)roomIdOrAlias;


@end
33 changes: 33 additions & 0 deletions Tchap/Utils/Tools.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,43 @@ + (NSString *)permalinkToRoom:(NSString *)roomIdOrAlias
return [NSString stringWithFormat:@"%@/#/room/%@", urlPrefix, roomIdOrAlias];
}

+ (NSString *)permalinkToRoomWithoutAliasFromRoomState:(MXRoomState *)state {
NSString *roomId = state.roomId;

NSArray<MXRoomMember *> *members = state.members.joinedMembers;

NSMutableSet<NSString *> *memberHomeservers = [NSMutableSet setWithCapacity:members.count];

// Add the homeServer hosting the room.
[memberHomeservers addObject:[roomId componentsSeparatedByString:@":"].lastObject];

// List unique members' homeServers in memberHomeservers. Limit to 3
[members enumerateObjectsUsingBlock:^(MXRoomMember * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSArray<NSString *> *userIdParts = [obj.userId componentsSeparatedByString:@":"];
if (userIdParts.count > 1)
{
[memberHomeservers addObject:userIdParts.lastObject]; // NSMutableSet only add object if not already present in the Set.

// Stop if 3 homeServers are listed.
if (memberHomeservers.count >= 3)
{
*stop = YES;
}
}
}];

NSString *urlPrefix = BuildSettings.clientPermalinkBaseUrl;
NSString *viaParameters = [NSString stringWithFormat:@"?via=%@", [memberHomeservers.allObjects componentsJoinedByString:@"&via="]];
NSString *permalinkToRoom = [NSString stringWithFormat:@"%@/#/room/%@%@", urlPrefix, roomId, viaParameters];

return permalinkToRoom;
}

+ (NSString *)permalinkToEvent:(NSString *)eventId inRoom:(NSString *)roomIdOrAlias
{
NSString *urlPrefix = BuildSettings.clientPermalinkBaseUrl;
return [NSString stringWithFormat:@"%@/#/room/%@/%@", urlPrefix, roomIdOrAlias, eventId];
}


@end
1 change: 1 addition & 0 deletions changelog.d/875.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correction de la génération de lien de partage sur les forums

0 comments on commit b573db3

Please sign in to comment.