1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Prepare megolm.js for async

Make internal methods of megolm.js ready for asynchronous olmdevice
This commit is contained in:
Richard van der Hoff
2017-07-26 08:04:46 +01:00
parent 366a88cc5c
commit d821082843

View File

@@ -166,7 +166,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
// Updates `session` to hold the final OutboundSessionInfo. // Updates `session` to hold the final OutboundSessionInfo.
// //
// returns a promise which resolves once the keyshare is successful. // returns a promise which resolves once the keyshare is successful.
function prepareSession(oldSession) { async function prepareSession(oldSession) {
session = oldSession; session = oldSession;
// need to make a brand new session? // need to make a brand new session?
@@ -184,7 +184,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
if (!session) { if (!session) {
console.log(`Starting new megolm session for room ${self._roomId}`); console.log(`Starting new megolm session for room ${self._roomId}`);
session = self._prepareNewSession(); session = await self._prepareNewSession();
} }
// now check if we need to share with any devices // now check if we need to share with any devices
@@ -245,7 +245,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
* *
* @return {module:crypto/algorithms/megolm.OutboundSessionInfo} session * @return {module:crypto/algorithms/megolm.OutboundSessionInfo} session
*/ */
MegolmEncryption.prototype._prepareNewSession = function() { MegolmEncryption.prototype._prepareNewSession = async function() {
const sessionId = this._olmDevice.createOutboundGroupSession(); const sessionId = this._olmDevice.createOutboundGroupSession();
const key = this._olmDevice.getOutboundGroupSessionKey(sessionId); const key = this._olmDevice.getOutboundGroupSessionKey(sessionId);
@@ -535,16 +535,14 @@ utils.inherits(MegolmDecryption, base.DecryptionAlgorithm);
* `algorithms.DecryptionError` if there is a problem decrypting the event. * `algorithms.DecryptionError` if there is a problem decrypting the event.
*/ */
MegolmDecryption.prototype.decryptEvent = function(event) { MegolmDecryption.prototype.decryptEvent = function(event) {
return Promise.try(() => { return this._decryptEvent(event, true);
this._decryptEvent(event, true);
});
}; };
// helper for the real decryptEvent and for _retryDecryption. If // helper for the real decryptEvent and for _retryDecryption. If
// requestKeysOnFail is true, we'll send an m.room_key_request when we fail // requestKeysOnFail is true, we'll send an m.room_key_request when we fail
// to decrypt the event due to missing megolm keys. // to decrypt the event due to missing megolm keys.
MegolmDecryption.prototype._decryptEvent = function(event, requestKeysOnFail) { MegolmDecryption.prototype._decryptEvent = async function(event, requestKeysOnFail) {
const content = event.getWireContent(); const content = event.getWireContent();
if (!content.sender_key || !content.session_id || if (!content.sender_key || !content.session_id ||