Skip to content

Commit

Permalink
make LL/non-LL flow in Crypto more alike by always going through _roo…
Browse files Browse the repository at this point in the history
…mDeviceTrackingState
  • Loading branch information
bwindels committed Aug 27, 2018
1 parent 5e5994f commit 7d00c0b
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,10 +688,7 @@ Crypto.prototype.setRoomEncryption = async function(roomId, config, inhibitDevic
console.log("Enabling encryption in " + roomId);

if (!this._lazyLoadMembers) {
const members = await room.getEncryptionTargetMembers();
members.forEach((m) => {
this._deviceList.startTrackingDeviceList(m.userId);
});
await this.trackRoomDevices(roomId);
}
};

Expand All @@ -717,7 +714,6 @@ Crypto.prototype.trackRoomDevices = function(roomId) {
members.forEach((m) => {
this._deviceList.startTrackingDeviceList(m.userId);
});
return this._deviceList.refreshOutdatedDeviceLists();
};

let promise = this._roomDeviceTrackingState[roomId];
Expand Down Expand Up @@ -848,13 +844,11 @@ Crypto.prototype.encryptEvent = async function(event, room) {
);
}

if (this._lazyLoadMembers) {
if (!this._roomDeviceTrackingState[roomId]) {
this.trackRoomDevices(roomId);
}
// wait for all the room devices to be loaded
await this._roomDeviceTrackingState[roomId];
if (!this._roomDeviceTrackingState[roomId]) {
this.trackRoomDevices(roomId);
}
// wait for all the room devices to be loaded
await this._roomDeviceTrackingState[roomId];

let content = event.getContent();
// If event has an m.relates_to then we need
Expand Down Expand Up @@ -1082,7 +1076,7 @@ Crypto.prototype._getTrackedE2eRooms = function() {
if (!alg) {
return false;
}
if (this._lazyLoadMembers && !this._roomDeviceTrackingState[room.roomId]) {
if (!this._roomDeviceTrackingState[room.roomId]) {
return false;
}

Expand Down Expand Up @@ -1157,7 +1151,7 @@ Crypto.prototype._onRoomMembership = function(event, member, oldMembership) {
// this way we don't start device queries after sync on behalf of this room which we won't use
// the result of anyway, as we'll need to do a query again once all the members are fetched
// by calling _trackRoomDevices
if (!this._lazyLoadMembers || this._roomDeviceTrackingState[roomId]) {
if (this._roomDeviceTrackingState[roomId]) {
if (member.membership == 'join') {
console.log('Join event for ' + member.userId + ' in ' + roomId);
// make sure we are tracking the deviceList for this user
Expand Down

0 comments on commit 7d00c0b

Please sign in to comment.