diff --git a/lib/client.js b/lib/client.js
index 5e57a75db..93e494aea 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -661,31 +661,50 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) {
if (utils.isFunction(opts)) {
throw new Error("Expected 'opts' object, got function.");
}
- opts = opts || {
- syncRoom: true
- };
+ opts = opts || {};
+ if (opts.syncRoom === undefined) { opts.syncRoom = true; }
var room = this.getRoom(roomIdOrAlias);
if (room && room.hasMembershipState(this.credentials.userId, "join")) {
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 self = this;
- this._http.authedRequest(undefined, "POST", path, undefined, {}).then(
- function(res) {
- 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);
+ sign_promise.done(function(signed_invite_object) {
+ var data = {};
+ if (signed_invite_object) {
+ data.third_party_signed = signed_invite_object;
}
- return q(room);
- }, function(err) {
- _reject(callback, defer, err);
- }).done(function(room) {
- _resolve(callback, defer, room);
+
+ var path = utils.encodeUri("/join/$roomid", { $roomid: roomIdOrAlias});
+ self._http.authedRequest(undefined, "POST", path, undefined, data).then(
+ function(res) {
+ 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) {
_reject(callback, defer, err);
});
diff --git a/lib/http-api.js b/lib/http-api.js
index a3ab93cfa..3b3bb124d 100644
--- a/lib/http-api.js
+++ b/lib/http-api.js
@@ -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 {data: {Object},
+ * headers: {Object}, code: {Number}}.
+ * If onlyData is set, this will resolve to the data
+ * 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
* params and prefix.