You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-01 04:43:29 +03:00
Make encryption asynchronous
We're going to need to send out a load of messages to distribute the megolm keys; as a first step, deal with the asynchronicity this will require.
This commit is contained in:
@@ -600,7 +600,7 @@ Crypto.prototype.isSenderKeyVerified = function(userId, algorithm, sender_key) {
|
||||
* @param {object} config The encryption config for the room.
|
||||
* @param {string[]} roomMembers userIds of room members to start sessions with
|
||||
*
|
||||
* @return {Object} A promise that will resolve when encryption is setup.
|
||||
* @return {module:client.Promise} A promise that will resolve when encryption is setup.
|
||||
*/
|
||||
Crypto.prototype.setRoomEncryption = function(roomId, config, roomMembers) {
|
||||
// if we already have encryption in this room, we should ignore this event
|
||||
@@ -727,18 +727,21 @@ Crypto.prototype.isRoomEncrypted = function(roomId) {
|
||||
*
|
||||
* @param {module:models/room?} room destination room. Null if the destination
|
||||
* is not a room we have seen over the sync pipe.
|
||||
*
|
||||
* @return {module:client.Promise?} Promise which resolves when the event has been
|
||||
* encrypted, or null if nothing was needed
|
||||
*/
|
||||
Crypto.prototype.encryptEventIfNeeded = function(event, room) {
|
||||
if (event.isEncrypted()) {
|
||||
// this event has already been encrypted; this happens if the
|
||||
// encryption step succeeded, but the send step failed on the first
|
||||
// attempt.
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (event.getType() !== "m.room.message") {
|
||||
// we only encrypt m.room.message
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
var roomId = event.getRoomId();
|
||||
@@ -755,13 +758,14 @@ Crypto.prototype.encryptEventIfNeeded = function(event, room) {
|
||||
"configuration event."
|
||||
);
|
||||
}
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
var encryptedContent = alg.encryptMessage(
|
||||
return alg.encryptMessage(
|
||||
room, event.getType(), event.getContent()
|
||||
);
|
||||
event.makeEncrypted("m.room.encrypted", encryptedContent);
|
||||
).then(function(encryptedContent) {
|
||||
event.makeEncrypted("m.room.encrypted", encryptedContent);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user