The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/packages/rocketchat-e2e/server/methods/requestSubscriptionKeys.js

34 lines
954 B

import { Meteor } from 'meteor/meteor';
import { Subscriptions, Rooms } from 'meteor/rocketchat:models';
import { Notifications } from 'meteor/rocketchat:notifications';
Meteor.methods({
'e2e.requestSubscriptionKeys'() {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'requestSubscriptionKeys',
});
}
// Get all encrypted rooms that the user is subscribed to and has no E2E key yet
const subscriptions = 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,
},
_id : {
$in: roomIds,
},
};
const rooms = Rooms.find(query);
rooms.forEach((room) => {
Notifications.notifyRoom('e2e.keyRequest', room._id, room.e2eKeyId);
});
return true;
},
});