Skip to content

Commit

Permalink
Join Room: Support via parameters to better handle federation
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Jul 8, 2019
1 parent bada623 commit b65dbbd
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes in Matrix iOS SDK in 0.12.6 (2019-05-)
Improvements:
* MXHTTPClient: support multiple SSL pinning modes (none/public key/certificate)
* MXHTTPClient: Enable the certificate pinning mode by default as soon as some certificates are present in the application bundle.
* Join Room: Support via parameters to better handle federation (vector-im/riot-ios/issues/2547).
* MXEvent: Create a MXEventUnsignedData model for `MXEvent.unsignedData`.
* MXEvent: Add relatesTo property.
* Aggregations: Create MXSession.MXAggregations to manage Matrix aggregations API.
Expand All @@ -19,6 +20,7 @@ Bug Fix:

API break:
* MXEvent: unsignedData is now of type MXEventUnsignedData.
* MXSession, MXSession, MXRestClient: Add viaServers parameters to all joinRoom methods.

Changes in Matrix iOS SDK in 0.12.5 (2019-05-03)
===============================================
Expand Down
6 changes: 4 additions & 2 deletions MatrixSDK/Contrib/Swift/Data/MXRoom.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2017 Avery Pierce
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -471,13 +472,14 @@ public extension MXRoom {
Join this room where the user has been invited.
- parameters:
- viaServers The server names to try and join through in addition to those that are automatically chosen
- completion: A block object called when the operation completes.
- response: Indicates whether the operation was a success or failure.
- returns: a `MXHTTPOperation` instance.
*/
@nonobjc @discardableResult func join(completion: @escaping (_ response: MXResponse<Void>) -> Void) -> MXHTTPOperation {
return __join(currySuccess(completion), failure: curryFailure(completion))
@nonobjc @discardableResult func join(viaServers: [String]? = nil, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> MXHTTPOperation {
return __join(viaServers: viaServers, success:currySuccess(completion), failure: curryFailure(completion))
}

/**
Expand Down
6 changes: 4 additions & 2 deletions MatrixSDK/Contrib/Swift/MXRestClient.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2017 Avery Pierce
Copyright 2017 Vector Creations Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -851,15 +852,16 @@ public extension MXRestClient {
- parameters:
- roomIdOrAlias: The id or an alias of the room to join.
- viaServers The server names to try and join through in addition to those that are automatically chosen.
- thirdPartySigned: The signed data obtained by the validation of the 3PID invitation, if 3PID validation is used. The validation is made by `self.signUrl()`.
- completion: A block object called when the operation completes.
- response: Provides the room id on success.
- returns: a `MXHTTPOperation` instance.
*/
@nonobjc @discardableResult func joinRoom(_ roomIdOrAlias: String, withThirdPartySigned dictionary: [String: Any]? = nil, completion: @escaping (_ response: MXResponse<String>) -> Void) -> MXHTTPOperation {
@nonobjc @discardableResult func joinRoom(_ roomIdOrAlias: String, viaServers: [String]? = nil, withThirdPartySigned dictionary: [String: Any]? = nil, completion: @escaping (_ response: MXResponse<String>) -> Void) -> MXHTTPOperation {
if let dictionary = dictionary {
return __joinRoom(roomIdOrAlias, withThirdPartySigned: dictionary, success: currySuccess(completion), failure: curryFailure(completion))
return __joinRoom(roomIdOrAlias, viaServers: viaServers, withThirdPartySigned: dictionary, success: currySuccess(completion), failure: curryFailure(completion))
} else {
return __joinRoom(roomIdOrAlias, success: currySuccess(completion), failure: curryFailure(completion))
}
Expand Down
8 changes: 5 additions & 3 deletions MatrixSDK/Contrib/Swift/MXSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Created by Avery Pierce on 2/11/17.
// Copyright © 2017 matrix.org. All rights reserved.
// Copyright 2019 The Matrix.org Foundation C.I.C
//

import Foundation
Expand Down Expand Up @@ -189,17 +190,18 @@ public extension MXSession {
- parameters:
- roomIdOrAlias: The id or an alias of the room to join.
- viaServers The server names to try and join through in addition to those that are automatically chosen.
- signUrl: the url provided in an invitation.
- completion: A block object called when the operation completes.
- response: Provides the room on success.
- returns: a `MXHTTPOperation` instance.
*/
@nonobjc @discardableResult func joinRoom(_ roomIdOrAlias: String, withSignUrl signUrl: URL? = nil, completion: @escaping (_ response: MXResponse<MXRoom>) -> Void) -> MXHTTPOperation {
@nonobjc @discardableResult func joinRoom(_ roomIdOrAlias: String, viaServers: [String]? = nil, withSignUrl signUrl: URL? = nil, completion: @escaping (_ response: MXResponse<MXRoom>) -> Void) -> MXHTTPOperation {
if let signUrl = signUrl {
return __joinRoom(roomIdOrAlias, withSignUrl: signUrl.absoluteString, success: currySuccess(completion), failure: curryFailure(completion))
return __joinRoom(roomIdOrAlias, viaServers: viaServers, withSignUrl: signUrl.absoluteString, success: currySuccess(completion), failure: curryFailure(completion))
} else {
return __joinRoom(roomIdOrAlias, success: currySuccess(completion), failure: curryFailure(completion))
return __joinRoom(roomIdOrAlias, viaServers: viaServers, success: currySuccess(completion), failure: curryFailure(completion))
}
}

Expand Down
11 changes: 8 additions & 3 deletions MatrixSDK/Data/MXRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright 2014 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -632,14 +633,18 @@ FOUNDATION_EXPORT NSString *const kMXRoomDidFlushDataNotification;

/**
Join this room where the user has been invited.
@param viaServers The server names to try and join through in addition to those
that are automatically chosen. Can be nil.
@param success A block object called when the operation is complete.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)join:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
- (MXHTTPOperation*)joinViaServers:(NSArray<NSString*>*)viaServers
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;

/**
Leave this room.
Expand Down
8 changes: 5 additions & 3 deletions MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright 2014 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1621,10 +1622,11 @@ - (MXHTTPOperation*)directoryVisibility:(void (^)(MXRoomDirectoryVisibility dire
return [mxSession.matrixRestClient directoryVisibilityOfRoom:self.roomId success:success failure:failure];
}

- (MXHTTPOperation*)join:(void (^)(void))success
failure:(void (^)(NSError *error))failure
- (MXHTTPOperation*)joinViaServers:(NSArray<NSString*>*)viaServers
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure
{
return [mxSession joinRoom:self.roomId success:^(MXRoom *room) {
return [mxSession joinRoom:self.roomId viaServers:viaServers success:^(MXRoom *room) {
success();
} failure:failure];
}
Expand Down
3 changes: 3 additions & 0 deletions MatrixSDK/MXRestClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,8 @@ FOUNDATION_EXPORT NSString *const kMXMembersOfRoomParametersNotMembership;
Join a room where the user has been invited by a 3PID invitation.
@param roomIdOrAlias the id or an alias of the room to join.
@param viaServers The server names to try and join through in addition to those
that are automatically chosen.
@param thirdPartySigned the signed data obtained by the validation of the 3PID invitation.
The valisation is made by [self signUrl].
@param success A block object called when the operation succeeds. It provides the room id.
Expand All @@ -1014,6 +1016,7 @@ FOUNDATION_EXPORT NSString *const kMXMembersOfRoomParametersNotMembership;
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
viaServers:(NSArray<NSString*>*)viaServers
withThirdPartySigned:(NSDictionary*)thirdPartySigned
success:(void (^)(NSString *theRoomId))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
Expand Down
26 changes: 24 additions & 2 deletions MatrixSDK/MXRestClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1835,11 +1835,12 @@ - (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
success:(void (^)(NSString *theRoomId))success
failure:(void (^)(NSError *error))failure
{
return [self joinRoom:roomIdOrAlias withThirdPartySigned:nil success:success failure:failure];
return [self joinRoom:roomIdOrAlias viaServers:nil withThirdPartySigned:nil success:success failure:failure];
}

- (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
withThirdPartySigned:(NSDictionary*)thirdPartySigned
viaServers:(NSArray<NSString*>*)viaServers
withThirdPartySigned:(NSDictionary*)thirdPartySigned
success:(void (^)(NSString *theRoomId))success
failure:(void (^)(NSError *error))failure
{
Expand All @@ -1856,6 +1857,27 @@ - (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
apiPathPrefix,
[MXTools encodeURIComponent:roomIdOrAlias]];

// Add all servers as query parameters
if (viaServers.count)
{
NSMutableString *queryParameters;
for (NSString *viaServer in viaServers)
{
NSString *value = [MXTools encodeURIComponent:viaServer];

if (!queryParameters)
{
queryParameters = [NSMutableString stringWithFormat:@"?server_name=%@", value];
}
else
{
[queryParameters appendFormat:@"&server_name=%@", value];
}
}

path = [path stringByAppendingString:queryParameters];
}

MXWeakify(self);
return [httpClient requestWithMethod:@"POST"
path:path
Expand Down
7 changes: 7 additions & 0 deletions MatrixSDK/MXSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright 2014 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -736,20 +737,25 @@ typedef void (^MXOnBackgroundSyncFail)(NSError *error);
Join a room.
@param roomIdOrAlias the id or an alias of the room to join.
@param viaServers The server names to try and join through in addition to those
that are automatically chosen. Can be nil.
@param success A block object called when the operation succeeds. It provides the MXRoom
instance of the joined room.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
viaServers:(NSArray<NSString*>*)viaServers
success:(void (^)(MXRoom *room))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;

/**
Join a room where the user has been invited by a 3PID invitation.
@param roomIdOrAlias the id or an alias of the room to join.
@param viaServers The server names to try and join through in addition to those
that are automatically chosen. Can be nil.
@param signUrl the url provided in the invitation.
@param success A block object called when the operation succeeds. It provides the MXRoom
instance of the joined room.
Expand All @@ -758,6 +764,7 @@ typedef void (^MXOnBackgroundSyncFail)(NSError *error);
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
viaServers:(NSArray<NSString*>*)viaServers
withSignUrl:(NSString*)signUrl
success:(void (^)(MXRoom *room))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
Expand Down
7 changes: 5 additions & 2 deletions MatrixSDK/MXSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright 2014 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1834,17 +1835,19 @@ - (void)onJoinedRoom:(NSString*)roomId success:(void (^)(MXRoom *room))success
}

- (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
viaServers:(NSArray<NSString*>*)viaServers
success:(void (^)(MXRoom *room))success
failure:(void (^)(NSError *error))failure
{
return [matrixRestClient joinRoom:roomIdOrAlias success:^(NSString *theRoomId) {
return [matrixRestClient joinRoom:roomIdOrAlias viaServers:viaServers withThirdPartySigned:nil success:^(NSString *theRoomId) {

[self onJoinedRoom:theRoomId success:success];

} failure:failure];
}

- (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
viaServers:(NSArray<NSString*>*)viaServers
withSignUrl:(NSString*)signUrl
success:(void (^)(MXRoom *room))success
failure:(void (^)(NSError *error))failure
Expand All @@ -1855,7 +1858,7 @@ - (MXHTTPOperation*)joinRoom:(NSString*)roomIdOrAlias
httpOperation = [matrixRestClient signUrl:signUrl success:^(NSDictionary *thirdPartySigned) {
MXStrongifyAndReturnIfNil(self);

MXHTTPOperation *httpOperation2 = [self->matrixRestClient joinRoom:roomIdOrAlias withThirdPartySigned:thirdPartySigned success:^(NSString *theRoomId) {
MXHTTPOperation *httpOperation2 = [self->matrixRestClient joinRoom:roomIdOrAlias viaServers:viaServers withThirdPartySigned:thirdPartySigned success:^(NSString *theRoomId) {

[self onJoinedRoom:theRoomId success:success];

Expand Down

0 comments on commit b65dbbd

Please sign in to comment.