diff --git a/Config/AppVersion.xcconfig b/Config/AppVersion.xcconfig index c2c881a12c..200075ce84 100644 --- a/Config/AppVersion.xcconfig +++ b/Config/AppVersion.xcconfig @@ -15,5 +15,5 @@ // // Version -MARKETING_VERSION = 2.7.8 +MARKETING_VERSION = 2.7.9 CURRENT_PROJECT_VERSION = 1 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 diff --git a/towncrier.toml b/towncrier.toml index e61f87c9c1..81c5824d63 100644 --- a/towncrier.toml +++ b/towncrier.toml @@ -1,6 +1,6 @@ [tool.towncrier] name = "Changes in" -version = "2.7.8" +version = "2.7.9" filename = "TCHAP_CHANGES.md" directory = "changelog.d" template = "changelog.d/_template.md.jinja"