1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +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:
Richard van der Hoff
2016-09-07 13:56:54 +01:00
parent af0f5b37d8
commit 9c18893ae5
4 changed files with 109 additions and 79 deletions

View File

@@ -144,7 +144,6 @@ function MatrixClient(opts) {
this._peekSync = null;
this._isGuest = false;
this._ongoingScrollbacks = {};
this._txnCtr = 0;
this.timelineSupport = Boolean(opts.timelineSupport);
this.urlPreviewCache = {};
@@ -424,6 +423,12 @@ function setupCryptoEventHandler(client) {
});
client.on("RoomMember.membership",
client._crypto.onRoomMembership.bind(client._crypto));
client.on("toDeviceEvent", function(event) {
if (event.getType() == "m.room_key") {
client._crypto.onRoomKeyEvent(event);
}
});
}
function onCryptoEvent(client, event) {
@@ -438,20 +443,6 @@ function onCryptoEvent(client, event) {
}
}
/**
* handle a room key event
*
* @private
*
* @param {MatrixEvent} event
*/
MatrixClient.prototype._onRoomKeyEvent = function(event) {
if (!this._crypto) {
return;
}
this._crypto.onRoomKeyEvent(event);
};
/**
* Enable end-to-end encryption for a room.
* @param {string} roomId The room ID to enable encryption in.
@@ -820,7 +811,7 @@ MatrixClient.prototype.sendEvent = function(roomId, eventType, content, txnId,
if (utils.isFunction(txnId)) { callback = txnId; txnId = undefined; }
if (!txnId) {
txnId = "m" + new Date().getTime() + "." + (this._txnCtr++);
txnId = this.makeTxnId();
}
// we always construct a MatrixEvent when sending because the store and
@@ -921,11 +912,13 @@ function _updatePendingEventStatus(room, event, newStatus) {
}
function _sendEventHttpRequest(client, event) {
var txnId = event._txnId ? event._txnId : client.makeTxnId();
var pathParams = {
$roomId: event.getRoomId(),
$eventType: event.getWireType(),
$stateKey: event.getStateKey(),
$txnId: event._txnId ? event._txnId : new Date().getTime()
$txnId: txnId,
};
var path;
@@ -2663,13 +2656,6 @@ function _PojoToMatrixEventMapper(client) {
clearData = _decryptMessage(client, plainOldJsObject);
}
var matrixEvent = new MatrixEvent(plainOldJsObject, clearData);
// XXXX massive hack to deal with the fact that megolm keys are in the
// room for now, and we need to handle them before attempting to
// decrypt the following megolm messages.
if (matrixEvent.getType() == "m.room_key") {
client._onRoomKeyEvent(matrixEvent);
}
return matrixEvent;
}
return mapper;