From 87b1e15f3628244f4232fd73636ac5e65865ce41 Mon Sep 17 00:00:00 2001 From: manuroe Date: Mon, 8 Jul 2019 11:15:44 +0200 Subject: [PATCH 1/2] Join Room: Support via parameters to better handle federation #2547 --- CHANGES.rst | 1 + Riot/AppDelegate.m | 19 +++++++++++++++++-- Riot/Model/Room/RoomPreviewData.h | 6 ++++++ .../Common/Recents/RecentsViewController.m | 5 +++-- Riot/Modules/Room/RoomViewController.m | 5 +++-- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d2bd2d6a0..7427fef55 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changes in 0.8.7 (2019-xx-xx) Improvements: * RoomVC: When replying, use a "Reply" button instead of "Send". * RoomVC: New message actions (#2394). + * Join Room: Support via parameters to better handle federation (#2547). * Reactions: Display existing reactions below the message (#2396). * Menu actions: Display message time (#2463). * Reactions Menu: Fix position (#2447). diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index bc8c22bdd..276c6657d 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -2324,6 +2324,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN [homeViewController stopActivityIndicator]; roomPreviewData = [[RoomPreviewData alloc] initWithRoomId:roomIdOrAlias emailInvitationParams:queryParams andSession:account.mxSession]; + roomPreviewData.viaServers = queryParams[@"via"]; [self showRoomPreview:roomPreviewData]; } else @@ -2522,8 +2523,22 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN { value = [value stringByReplacingOccurrencesOfString:@"+" withString:@" "]; value = [value stringByRemovingPercentEncoding]; - - queryParams[key] = value; + + if ([key isEqualToString:@"via"]) + { + // Special case the via parameter + // As we can have several of them, store each value into an array + if (!queryParams[key]) + { + queryParams[key] = [NSMutableArray array]; + } + + [queryParams[key] addObject:value]; + } + else + { + queryParams[key] = value; + } } } } diff --git a/Riot/Model/Room/RoomPreviewData.h b/Riot/Model/Room/RoomPreviewData.h index 333912c8f..47797327c 100644 --- a/Riot/Model/Room/RoomPreviewData.h +++ b/Riot/Model/Room/RoomPreviewData.h @@ -50,6 +50,12 @@ */ @property (nonatomic) NSString *eventId; +/** + In case of preview, the server names to try and join through in addition to those + that are automatically chosen. + */ +@property (nonatomic) NSArray *viaServers; + /** Preview information. */ diff --git a/Riot/Modules/Common/Recents/RecentsViewController.m b/Riot/Modules/Common/Recents/RecentsViewController.m index 03e582aeb..30a754803 100644 --- a/Riot/Modules/Common/Recents/RecentsViewController.m +++ b/Riot/Modules/Common/Recents/RecentsViewController.m @@ -1815,8 +1815,9 @@ self->currentAlert = nil; [self.activityIndicator startAnimating]; - - self->currentRequest = [self.mainSession joinRoom:roomAliasOrId success:^(MXRoom *room) { + + // TODO + self->currentRequest = [self.mainSession joinRoom:roomAliasOrId viaServers:nil success:^(MXRoom *room) { self->currentRequest = nil; [self.activityIndicator stopAnimating]; diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index c7c0818a8..ceafd6b03 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -1047,7 +1047,8 @@ // Check if (roomAlias.length) { - [self.mainSession joinRoom:roomAlias success:^(MXRoom *room) { + // TODO: /join command does not support via parameters yet + [self.mainSession joinRoom:roomAlias viaServers:nil success:^(MXRoom *room) { // Show the room [[AppDelegate theDelegate] showRoom:room.roomId andEventId:nil withMatrixSession:self.mainSession]; @@ -3685,7 +3686,7 @@ } // Note in case of simple link to a room the signUrl param is nil - [self joinRoomWithRoomIdOrAlias:roomIdOrAlias andSignUrl:roomPreviewData.emailInvitation.signUrl completion:^(BOOL succeed) { + [self joinRoomWithRoomIdOrAlias:roomIdOrAlias viaServers:roomPreviewData.viaServers andSignUrl:roomPreviewData.emailInvitation.signUrl completion:^(BOOL succeed) { if (succeed) { From 0d5eac4cf630fddd7fca1d7c7fa789bf7105e3fe Mon Sep 17 00:00:00 2001 From: manuroe Date: Mon, 8 Jul 2019 11:46:10 +0200 Subject: [PATCH 2/2] Room upgrade: Use the `server_name` parameter when joining the new room #2550 --- CHANGES.rst | 1 + Riot/Modules/Room/RoomViewController.m | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7427fef55..de78b0c24 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changes in 0.8.7 (2019-xx-xx) Improvements: * RoomVC: When replying, use a "Reply" button instead of "Send". * RoomVC: New message actions (#2394). + * Room upgrade: Use the `server_name` parameter when joining the new room (#2550). * Join Room: Support via parameters to better handle federation (#2547). * Reactions: Display existing reactions below the message (#2396). * Menu actions: Display message time (#2463). diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index ceafd6b03..84961aa83 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -4048,8 +4048,15 @@ } else if (customizedRoomDataSource.roomState.isObsolete) { + // Try to join via the server that sent the event + MXEvent *stoneTombEvent = [customizedRoomDataSource.roomState stateEventsWithType:kMXEventTypeStringRoomTombStone].lastObject; + NSString *viaSenderServer = [MXTools serverNameInMatrixIdentifier:stoneTombEvent.sender]; + NSString *replacementRoomId = customizedRoomDataSource.roomState.tombStoneContent.replacementRoomId; - NSString *roomLinkFragment = [NSString stringWithFormat:@"/room/%@", [MXTools encodeURIComponent:replacementRoomId]]; + NSString *roomLinkFragment = [NSString stringWithFormat:@"/room/%@?via=%@", + [MXTools encodeURIComponent:replacementRoomId], + viaSenderServer + ]; [roomActivitiesView displayRoomReplacementWithRoomLinkTappedHandler:^{ [[AppDelegate theDelegate] handleUniversalLinkFragment:roomLinkFragment];