Skip to content

Commit

Permalink
Merge pull request #1061 from tchapgouv/875-generer-des-liens-de-part…
Browse files Browse the repository at this point in the history
…age-avec-parametre-via

875 generer des liens de partage avec parametre via
  • Loading branch information
NicolasBuquet authored Jun 24, 2024
2 parents 4e53cab + b573db3 commit b50d1e6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Config/AppVersion.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
//

// Version
MARKETING_VERSION = 2.7.8
MARKETING_VERSION = 2.7.9
CURRENT_PROJECT_VERSION = 1
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
2 changes: 1 addition & 1 deletion towncrier.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit b50d1e6

Please sign in to comment.