Changed subscription query to only load subscriptions that don't have E2E keys (#12692)

pull/12855/head
Pierre H. Lehnen 7 years ago committed by Rodrigo Nascimento
parent 5757163867
commit f397690106
  1. 6
      packages/rocketchat-e2e/server/methods/requestSubscriptionKeys.js
  2. 11
      packages/rocketchat-e2e/server/models/Subscriptions.js

@ -9,11 +9,11 @@ Meteor.methods({
});
}
// Get all encrypted rooms that the user is subscribed to
const subscriptions = RocketChat.models.Subscriptions.findByUserId(Meteor.userId());
// Get all encrypted rooms that the user is subscribed to and has no E2E key yet
const subscriptions = RocketChat.models.Subscriptions.findByUserIdWithoutE2E(Meteor.userId());
const roomIds = subscriptions.map((subscription) => subscription.rid);
// For all subscriptions without E2E key, get the rooms that have encryption enabled
const query = {
e2eKeyId : {
$exists: true,

@ -27,3 +27,14 @@ RocketChat.models.Subscriptions.resetUserE2EKey = function(userId) {
multi: true,
});
};
RocketChat.models.Subscriptions.findByUserIdWithoutE2E = function(userId, options) {
const query = {
'u._id': userId,
E2EKey: {
$exists: false,
},
};
return this.find(query, options);
};

Loading…
Cancel
Save