Skip to content

Commit

Permalink
Prepare megolm.js for async
Browse files Browse the repository at this point in the history
Make internal methods of megolm.js ready for asynchronous olmdevice
  • Loading branch information
richvdh committed Aug 8, 2017
1 parent 366a88c commit d821082
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/crypto/algorithms/megolm.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
// Updates `session` to hold the final OutboundSessionInfo.
//
// returns a promise which resolves once the keyshare is successful.
function prepareSession(oldSession) {
async function prepareSession(oldSession) {
session = oldSession;

// need to make a brand new session?
Expand All @@ -184,7 +184,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {

if (!session) {
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
Expand Down Expand Up @@ -245,7 +245,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
*
* @return {module:crypto/algorithms/megolm.OutboundSessionInfo} session
*/
MegolmEncryption.prototype._prepareNewSession = function() {
MegolmEncryption.prototype._prepareNewSession = async function() {
const sessionId = this._olmDevice.createOutboundGroupSession();
const key = this._olmDevice.getOutboundGroupSessionKey(sessionId);

Expand Down Expand Up @@ -535,16 +535,14 @@ utils.inherits(MegolmDecryption, base.DecryptionAlgorithm);
* `algorithms.DecryptionError` if there is a problem decrypting the event.
*/
MegolmDecryption.prototype.decryptEvent = function(event) {
return Promise.try(() => {
this._decryptEvent(event, true);
});
return this._decryptEvent(event, true);
};


// helper for the real decryptEvent and for _retryDecryption. If
// requestKeysOnFail is true, we'll send an m.room_key_request when we fail
// 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();

if (!content.sender_key || !content.session_id ||
Expand Down

0 comments on commit d821082

Please sign in to comment.