1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Add support for new keypair style 3pid invites (add an option to joinRoom for specifying the signing url)

This commit is contained in:
David Baker
2016-02-23 10:11:04 +00:00
parent 363b08c4d8
commit bd600f65fb
2 changed files with 64 additions and 17 deletions

View File

@@ -661,31 +661,50 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) {
if (utils.isFunction(opts)) { if (utils.isFunction(opts)) {
throw new Error("Expected 'opts' object, got function."); throw new Error("Expected 'opts' object, got function.");
} }
opts = opts || { opts = opts || {};
syncRoom: true if (opts.syncRoom === undefined) { opts.syncRoom = true; }
};
var room = this.getRoom(roomIdOrAlias); var room = this.getRoom(roomIdOrAlias);
if (room && room.hasMembershipState(this.credentials.userId, "join")) { if (room && room.hasMembershipState(this.credentials.userId, "join")) {
return q(room); return q(room);
} }
var path = utils.encodeUri("/join/$roomid", { $roomid: roomIdOrAlias});
var sign_promise = q();
if (opts.inviteSignUrl) {
sign_promise = this._http.requestOtherUrl(
undefined, 'POST',
opts.inviteSignUrl, { mxid: this.credentials.userId }
);
}
var defer = q.defer(); var defer = q.defer();
var self = this; var self = this;
this._http.authedRequest(undefined, "POST", path, undefined, {}).then( sign_promise.done(function(signed_invite_object) {
function(res) { var data = {};
var roomId = res.room_id; if (signed_invite_object) {
var syncApi = new SyncApi(self); data.third_party_signed = signed_invite_object;
var room = syncApi.createRoom(roomId);
if (opts.syncRoom) {
// v2 will do this for us
// return syncApi.syncRoom(room);
} }
return q(room);
}, function(err) { var path = utils.encodeUri("/join/$roomid", { $roomid: roomIdOrAlias});
_reject(callback, defer, err); self._http.authedRequest(undefined, "POST", path, undefined, data).then(
}).done(function(room) { function(res) {
_resolve(callback, defer, room); var roomId = res.room_id;
var syncApi = new SyncApi(self);
var room = syncApi.createRoom(roomId);
if (opts.syncRoom) {
// v2 will do this for us
// return syncApi.syncRoom(room);
}
return q(room);
}, function(err) {
_reject(callback, defer, err);
}).done(function(room) {
_resolve(callback, defer, room);
}, function(err) {
_reject(callback, defer, err);
});
}, function(err) { }, function(err) {
_reject(callback, defer, err); _reject(callback, defer, err);
}); });

View File

@@ -365,6 +365,34 @@ module.exports.MatrixHttpApi.prototype = {
); );
}, },
/**
* Perform a request to an arbitrary URL.
* @param {Function} callback Optional. The callback to invoke on
* success/failure. See the promise return values for more information.
* @param {string} method The HTTP method e.g. "GET".
* @param {string} uri The HTTP URI
* @param {Object} queryParams A dict of query params (these will NOT be
* urlencoded).
* @param {Object} data The HTTP JSON body.
* @param {Number=} localTimeoutMs The maximum amount of time to wait before
* timing out the request. If not specified, there is no timeout.
* @return {module:client.Promise} Resolves to <code>{data: {Object},
* headers: {Object}, code: {Number}}</code>.
* If <code>onlyData</code> is set, this will resolve to the <code>data</code>
* object only.
* @return {module:http-api.MatrixError} Rejects with an error if a problem
* occurred. This includes network problems and Matrix-specific error JSON.
*/
requestOtherUrl: function(callback, method, uri, queryParams, data,
localTimeoutMs) {
if (!queryParams) {
queryParams = {};
}
return this._request(
callback, method, uri, queryParams, data, localTimeoutMs
);
},
/** /**
* Form and return a homeserver request URL based on the given path * Form and return a homeserver request URL based on the given path
* params and prefix. * params and prefix.