-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'new/homepage' of github.com:RocketChat/Rocket.Chat into…
… 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
Showing
23 changed files
with
709 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.