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
Use to-device events for key sharing
Synapse now supports out-of-band messages, so use them instead of sending the key-sharing messages in-band.
This commit is contained in:
@@ -66,8 +66,9 @@ function MatrixBaseApis(opts) {
|
||||
extraParams: opts.queryParams
|
||||
};
|
||||
this._http = new httpApi.MatrixHttpApi(this, httpOpts);
|
||||
}
|
||||
|
||||
this._txnCtr = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Homeserver URL of this client
|
||||
@@ -100,6 +101,15 @@ MatrixBaseApis.prototype.isLoggedIn = function() {
|
||||
return this._http.opts.accessToken !== undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Make up a new transaction id
|
||||
*
|
||||
* @return {string} a new, unique, transaction id
|
||||
*/
|
||||
MatrixBaseApis.prototype.makeTxnId = function() {
|
||||
return "m" + new Date().getTime() + "." + (this._txnCtr++);
|
||||
};
|
||||
|
||||
|
||||
// Registration/Login operations
|
||||
// =============================
|
||||
@@ -970,6 +980,39 @@ MatrixBaseApis.prototype.lookupThreePid = function(medium, address, callback) {
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// Direct-to-device messaging
|
||||
// ==========================
|
||||
|
||||
/**
|
||||
* Send an event to a specific list of devices
|
||||
*
|
||||
* @param {string} eventType type of event to send
|
||||
* @param {Object.<string, Object<string, Object>>} contentMap
|
||||
* content to send. Map from user_id to device_id to content object.
|
||||
* @param {string=} txnId transaction id. One will be made up if not
|
||||
* supplied.
|
||||
* @return {module:client.Promise} Resolves to the result object
|
||||
*/
|
||||
MatrixBaseApis.prototype.sendToDevice = function(
|
||||
eventType, contentMap, txnId
|
||||
) {
|
||||
var path = utils.encodeUri("/sendToDevice/$eventType/$txnId", {
|
||||
$eventType: eventType,
|
||||
$txnId: txnId ? txnId : this.makeTxnId(),
|
||||
});
|
||||
|
||||
var body = {
|
||||
messages: contentMap,
|
||||
};
|
||||
|
||||
return this._http.authedRequestWithPrefix(
|
||||
undefined, "PUT", path, undefined, body,
|
||||
httpApi.PREFIX_UNSTABLE
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* MatrixBaseApis object
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user