Encrypt subscription
This commit is contained in:
parent
7cc5511bc1
commit
eeb6647133
|
@ -349,6 +349,9 @@ class Encryption {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Creating the instance is enough to generate room e2ee key
|
||||||
|
encryptSubscription = (rid: string) => this.getRoomInstance(rid as string);
|
||||||
|
|
||||||
// Decrypt a subscription lastMessage
|
// Decrypt a subscription lastMessage
|
||||||
decryptSubscription = async (subscription: Partial<ISubscription>) => {
|
decryptSubscription = async (subscription: Partial<ISubscription>) => {
|
||||||
// If the subscription doesn't have a lastMessage just return
|
// If the subscription doesn't have a lastMessage just return
|
||||||
|
|
|
@ -177,10 +177,14 @@ export default class EncryptionRoom {
|
||||||
|
|
||||||
// Create an encrypted key for this room based on users
|
// Create an encrypted key for this room based on users
|
||||||
encryptRoomKey = async () => {
|
encryptRoomKey = async () => {
|
||||||
const result = await Services.e2eGetUsersOfRoomWithoutKey(this.roomId);
|
try {
|
||||||
if (result.success) {
|
const result = await Services.e2eGetUsersOfRoomWithoutKey(this.roomId);
|
||||||
const { users } = result;
|
if (result.success) {
|
||||||
await Promise.all(users.map(user => this.encryptRoomKeyForUser(user)));
|
const { users } = result;
|
||||||
|
await Promise.all(users.map(user => this.encryptRoomKeyForUser(user)));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import I18n from '../i18n';
|
||||||
import { events, logEvent } from '../lib/methods/helpers/log';
|
import { events, logEvent } from '../lib/methods/helpers/log';
|
||||||
import { goRoom } from '../lib/methods/helpers/goRoom';
|
import { goRoom } from '../lib/methods/helpers/goRoom';
|
||||||
import { Services } from '../lib/services';
|
import { Services } from '../lib/services';
|
||||||
|
import { Encryption } from '../lib/encryption';
|
||||||
|
|
||||||
const handleRequest = function* handleRequest({ data }) {
|
const handleRequest = function* handleRequest({ data }) {
|
||||||
try {
|
try {
|
||||||
|
@ -65,6 +66,10 @@ const handleRequest = function* handleRequest({ data }) {
|
||||||
Object.assign(s, sub);
|
Object.assign(s, sub);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (data.encrypted) {
|
||||||
|
Encryption.encryptSubscription(sub.rid);
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue