Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

875 generer des liens de partage avec parametre via #1061

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should update permalinkToRoom in Tools.m from Tchap > Utils and using it. What do you think about that ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it be didn't make it because the modification here, building via parameters does a lot more stuff than permalinkToRoom. It will denaturate permalinkToRoom.
That's why I prefered to define a standalone permalinkToRoomWithoutAliasFromRoomState.


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
Loading