You've already forked matrix-js-sdk
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:
@@ -661,18 +661,34 @@ 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) {
|
||||||
|
var data = {};
|
||||||
|
if (signed_invite_object) {
|
||||||
|
data.third_party_signed = signed_invite_object;
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = utils.encodeUri("/join/$roomid", { $roomid: roomIdOrAlias});
|
||||||
|
self._http.authedRequest(undefined, "POST", path, undefined, data).then(
|
||||||
function(res) {
|
function(res) {
|
||||||
var roomId = res.room_id;
|
var roomId = res.room_id;
|
||||||
var syncApi = new SyncApi(self);
|
var syncApi = new SyncApi(self);
|
||||||
@@ -689,6 +705,9 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) {
|
|||||||
}, function(err) {
|
}, function(err) {
|
||||||
_reject(callback, defer, err);
|
_reject(callback, defer, err);
|
||||||
});
|
});
|
||||||
|
}, function(err) {
|
||||||
|
_reject(callback, defer, err);
|
||||||
|
});
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user