Skip to content

Commit

Permalink
Merge branch 'new/homepage' of github.com:RocketChat/Rocket.Chat into…
Browse files Browse the repository at this point in the history
… new/homepage

* 'new/homepage' of github.com:RocketChat/Rocket.Chat:
  [IMPROVE] OTR refactoring (#24757)
  [FIX] Prevent VoIP issues during disconnection when network failed (#26321)
  • Loading branch information
gabriellsh committed Aug 9, 2022
2 parents 41de667 + 5381a78 commit 61e1cc0
Show file tree
Hide file tree
Showing 23 changed files with 709 additions and 538 deletions.
52 changes: 52 additions & 0 deletions apps/meteor/app/otr/client/OTR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';

import { IOTR } from '../lib/IOTR';
import { Subscriptions } from '../../models/client';
import { OTRRoom } from './OTRRoom';

class OTR implements IOTR {
private enabled: ReactiveVar<boolean>;

private instancesByRoomId: { [rid: string]: OTRRoom };

constructor() {
this.enabled = new ReactiveVar(false);
this.instancesByRoomId = {};
}

isEnabled(): boolean {
return this.enabled.get();
}

setEnabled(enabled: boolean): void {
this.enabled.set(enabled);
}

getInstanceByRoomId(roomId: string): OTRRoom | undefined {
const userId = Meteor.userId();
if (!userId) {
return;
}
if (!this.enabled.get()) {
return;
}

if (this.instancesByRoomId[roomId]) {
return this.instancesByRoomId[roomId];
}

const subscription = Subscriptions.findOne({
rid: roomId,
});

if (!subscription || subscription.t !== 'd') {
return;
}

this.instancesByRoomId[roomId] = new OTRRoom(userId, roomId);
return this.instancesByRoomId[roomId];
}
}

export default new OTR();
Loading

0 comments on commit 61e1cc0

Please sign in to comment.