1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Initial support for specifying which servers to try in joinRoom

This has a bug when using browser-request where the query string for `server_name: [a, b]` comes out as `?server_name=a,b` instead of `?server_name=a&server_name=b`. This is due to browser-request not supporting the same qs options as request, so the qsStringifyOptions do nothing.
This commit is contained in:
Travis Ralston
2018-10-19 13:34:22 -06:00
parent 1061026f96
commit d8bcc4e3f1
2 changed files with 15 additions and 1 deletions

View File

@@ -921,6 +921,8 @@ MatrixClient.prototype.isUserIgnored = function(userId) {
* </strong> Default: true.
* @param {boolean} opts.inviteSignUrl If the caller has a keypair 3pid invite,
* the signing URL is passed in this parameter.
* @param {string[]} opts.viaServers The server names to try and join through in
* addition to those that are automatically chosen.
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: Room object.
* @return {module:http-api.MatrixError} Rejects: with an error response.
@@ -949,6 +951,13 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) {
);
}
const queryString = {};
if (opts.viaServers) {
queryString["server_name"] = opts.viaServers;
}
const reqOpts = {qsStringifyOptions: {arrayFormat: 'repeat'}};
const defer = Promise.defer();
const self = this;
@@ -959,7 +968,7 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) {
}
const path = utils.encodeUri("/join/$roomid", { $roomid: roomIdOrAlias});
return self._http.authedRequest(undefined, "POST", path, undefined, data);
return self._http.authedRequest(undefined, "POST", path, queryString, data, reqOpts);
}).then(function(res) {
const roomId = res.room_id;
const syncApi = new SyncApi(self, self._clientOpts);

View File

@@ -668,6 +668,9 @@ module.exports.MatrixHttpApi.prototype = {
* @param {function=} opts.bodyParser function to parse the body of the
* response before passing it to the promise and callback.
*
* @param (object=} opts.qsStringifyOptions options for stringifying the
* query string.
*
* @return {module:client.Promise} a promise which resolves to either the
* response object (if this.opts.onlyData is truthy), or the parsed
* body. Rejects
@@ -752,6 +755,8 @@ module.exports.MatrixHttpApi.prototype = {
method: method,
withCredentials: false,
qs: queryParams,
//qsStringifyOptions: opts.qsStringifyOptions,
useQuerystring: true,
body: data,
json: false,
timeout: localTimeoutMs,