Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions app/e2e/client/rocketchat.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Emitter } from '@rocket.chat/emitter';

import { E2ERoom } from './rocketchat.e2e.room';
import {
Deferred,
toString,
toArrayBuffer,
joinVectorAndEcryptedData,
Expand All @@ -22,15 +21,17 @@ import {
importRawKey,
deriveKey,
} from './helper';
import * as banners from '../../../client/lib/banners';
import { Rooms, Subscriptions, Messages } from '../../models';
import { promises } from '../../promises/client';
import { settings } from '../../settings';
import { Notifications } from '../../notifications/client';
import { Layout, call, modal } from '../../ui-utils';
import * as banners from '../../../client/lib/banners';

import './events.js';
import './tabbar';
import { getConfig } from '../../ui-utils/client/config';

const debug = [getConfig('debug'), getConfig('debug-e2e')].includes('true');

let failedToDecodeKey = false;

Expand All @@ -47,23 +48,23 @@ class E2E extends Emitter {
this.enabled = new ReactiveVar(false);
this._ready = new ReactiveVar(false);
this.instancesByRoomId = {};
this.readyPromise = new Deferred();

this.on('ready', () => {
this._ready.set(true);
this.log('startClient -> Done');
this.log('decryptPendingSubscriptions');
this.decryptPendingSubscriptions();
this.log('decryptPendingSubscriptions -> Done');
this.log('decryptSubscriptions');

this.decryptSubscriptions();
this.log('decryptSubscriptions -> Done');
});
}

log(...msg) {
console.log('[E2E]', ...msg);
debug && console.log('[E2E]', ...msg);
}

error(...msg) {
console.error('[E2E]', ...msg);
debug && console.error('[E2E]', ...msg);
}


Expand All @@ -75,10 +76,6 @@ class E2E extends Emitter {
return this.enabled.get() && this._ready.get();
}

async ready() {
return this.readyPromise;
}

getE2ERoom(rid) {
return this.instancesByRoomId[rid];
}
Expand All @@ -88,8 +85,6 @@ class E2E extends Emitter {
}

async getInstanceByRoomId(roomId) {
await this.ready();

const room = await waitUntilFind(() => Rooms.findOne({
_id: roomId,
}));
Expand Down Expand Up @@ -191,12 +186,6 @@ class E2E extends Emitter {
},
});
}

this.log('startClient -> Done');
this.log('decryptSubscriptions');

this.decryptSubscriptions();
this.log('decryptSubscriptions -> Done');
this.emit('ready');
}

Expand Down Expand Up @@ -415,7 +404,7 @@ class E2E extends Emitter {
async decryptSubscription(rid) {
const e2eRoom = await this.getInstanceByRoomId(rid);
this.log('decryptSubscription ->', rid);
e2eRoom?.decryptPendingSubscription();
e2eRoom?.decryptSubscription();
}

async decryptSubscriptions() {
Expand Down Expand Up @@ -498,7 +487,7 @@ Meteor.startup(function() {
if (!e2eRoom.isReady()) {
return;
}
e2eRoom.decryptPendingSubscription();
e2eRoom.decryptSubscription();
},
added: async (doc) => {
if (!doc.encrypted && !doc.E2EKey) {
Expand Down
6 changes: 4 additions & 2 deletions app/e2e/client/rocketchat.e2e.room.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Notifications } from '../../notifications/client';
import { Rooms, Subscriptions, Messages } from '../../models';
import { call } from '../../ui-utils';
import { roomTypes, RoomSettingsEnum } from '../../utils';
import { getConfig } from '../../ui-utils/client/config';

export const E2E_ROOM_STATES = {
NO_PASSWORD_SET: 'NO_PASSWORD_SET',
Expand Down Expand Up @@ -64,15 +65,16 @@ const reduce = (prev, next) => {
}
};

const debug = [getConfig('debug'), getConfig('debug-e2e')].includes('true');
export class E2ERoom extends Emitter {
log(...msg) {
if (this.roomId === Session.get('openedRoom')) {
if (debug) {
console.log('[E2E ROOM]', `[STATE: ${ this.state }]`, `[RID: ${ this.roomId }]`, ...msg);
}
}

error(...msg) {
if (this.roomId === Session.get('openedRoom')) {
if (debug) {
console.error('[E2E ROOM]', `[STATE: ${ this.state }]`, `[RID: ${ this.roomId }]`, ...msg);
}
}
Expand Down