From b573db3b4130b2d97f6ff1e1ca0b1db1c6054485 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Mon, 17 Jun 2024 18:23:24 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20de=20la=20g=C3=A9n=C3=A9ration=20d?= =?UTF-8?q?e=20lien=20de=20partage=20sur=20les=20forums=20(ou=20salon=20sa?= =?UTF-8?q?ns=20alias)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RoomAccessByLinkViewModel.swift | 13 ++++++++ Tchap/Utils/Tools.h | 11 +++++++ Tchap/Utils/Tools.m | 33 +++++++++++++++++++ changelog.d/875.bugfix | 1 + 4 files changed, 58 insertions(+) create mode 100644 changelog.d/875.bugfix diff --git a/Tchap/Modules/Room/RoomAccessByLink/RoomAccessByLinkViewModel.swift b/Tchap/Modules/Room/RoomAccessByLink/RoomAccessByLinkViewModel.swift index 13f5b97b37..4f73c941ef 100644 --- a/Tchap/Modules/Room/RoomAccessByLink/RoomAccessByLinkViewModel.swift +++ b/Tchap/Modules/Room/RoomAccessByLink/RoomAccessByLinkViewModel.swift @@ -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 diff --git a/Tchap/Utils/Tools.h b/Tchap/Utils/Tools.h index 3619b88cab..cd092ca6f2 100644 --- a/Tchap/Utils/Tools.h +++ b/Tchap/Utils/Tools.h @@ -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. @@ -73,4 +83,5 @@ */ + (NSString*)permalinkToEvent:(NSString*)eventId inRoom:(NSString*)roomIdOrAlias; + @end diff --git a/Tchap/Utils/Tools.m b/Tchap/Utils/Tools.m index 1f4e3930b8..598ec7b435 100644 --- a/Tchap/Utils/Tools.m +++ b/Tchap/Utils/Tools.m @@ -150,10 +150,43 @@ + (NSString *)permalinkToRoom:(NSString *)roomIdOrAlias return [NSString stringWithFormat:@"%@/#/room/%@", urlPrefix, roomIdOrAlias]; } ++ (NSString *)permalinkToRoomWithoutAliasFromRoomState:(MXRoomState *)state { + NSString *roomId = state.roomId; + + NSArray *members = state.members.joinedMembers; + + NSMutableSet *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 *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 diff --git a/changelog.d/875.bugfix b/changelog.d/875.bugfix new file mode 100644 index 0000000000..af30f017fb --- /dev/null +++ b/changelog.d/875.bugfix @@ -0,0 +1 @@ +Correction de la génération de lien de partage sur les forums \ No newline at end of file