1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2026-01-03 23:22:30 +03:00

Add 3pid invite endpoints

This commit is contained in:
Kegan Dougal
2015-11-09 11:58:45 +00:00
parent b4bb0f011d
commit 80a6cf34e2

View File

@@ -1330,6 +1330,65 @@ MatrixClient.prototype.invite = function(roomId, userId, callback) {
callback);
};
/**
* Invite a user to a room based on their email address.
* @param {string} roomId The room to invite the user to.
* @param {string} email The email address to invite.
* @param {string} displayName The display name to use. If omitted, everything
* before the '@' in the email address is used.
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixClient.prototype.inviteByEmail = function(roomId, email, displayName, callback) {
if (utils.isFunction(displayName)) {
callback = displayName; displayName = undefined;
}
if (!displayName) {
displayName = email.split("@")[0];
}
return this.inviteByThreePid(
roomId, "email", email, displayName, callback
);
};
/**
* Invite a user to a room based on a third-party identifier.
* @param {string} roomId The room to invite the user to.
* @param {string} medium The medium to invite the user e.g. "email".
* @param {string} address The address for the specified medium.
* @param {string} displayName The human-readable name to show in the room for
* this invite. MUST NOT be the address.
* @param {string} idServer Optional. The identity server URL to use for inviting.
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
* @throws If displayName === address.
*/
MatrixClient.prototype.inviteByThreePid = function(roomId, medium, address,
displayName, idServer, callback) {
if (utils.isFunction(idServer)) { callback = idServer; idServer = undefined; }
idServer = idServer || this.getIdentityServerUrl();
if (displayName === address) {
throw new Error(
"The display name is the same as the address. This leaks the 3PID " +
"address to everyone in the room."
);
}
var path = utils.encodeUri(
"/rooms/$roomId/invite",
{ $roomId: roomId }
);
return this._http.authedRequest(callback, "POST", path, undefined, {
id_server: idServer,
medium: medium,
address: address,
display_name: displayName
});
};
/**
* @param {string} roomId
* @param {module:client.callback} callback Optional.