From 22a81822664ffd81be919ca4e3077587eed5f23a Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Thu, 9 Feb 2023 11:57:30 +0100 Subject: [PATCH] feature-gate calls everywhere in the app --- src/domain/session/SessionViewModel.js | 8 +- src/domain/session/room/RoomViewModel.js | 7 ++ .../session/room/timeline/tiles/index.ts | 2 +- .../session/toast/ToastCollectionViewModel.ts | 6 +- src/matrix/Session.js | 103 ++++++++++-------- src/platform/web/ui/session/room/RoomView.js | 6 +- 6 files changed, 76 insertions(+), 56 deletions(-) diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index 072e1b74..7d1dac3c 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -130,9 +130,11 @@ export class SessionViewModel extends ViewModel { start() { this._sessionStatusViewModel.start(); - this._client.session.callHandler.loadCalls("m.ring"); - // TODO: only do this when opening the room - this._client.session.callHandler.loadCalls("m.prompt"); + if (this.features.calls) { + this._client.session.callHandler.loadCalls("m.ring"); + // TODO: only do this when opening the room + this._client.session.callHandler.loadCalls("m.prompt"); + } } get activeMiddleViewModel() { diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 65afd348..5cd610f2 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -50,6 +50,9 @@ export class RoomViewModel extends ErrorReportViewModel { } _setupCallViewModel() { + if (!this.features.calls) { + return; + } // pick call for this room with lowest key const calls = this.getOption("session").callHandler.calls; this._callObservable = new PickMapObservableValue(calls.filterValues(c => { @@ -421,6 +424,10 @@ export class RoomViewModel extends ErrorReportViewModel { startCall() { return this.logAndCatch("RoomViewModel.startCall", async log => { + if (!this.features.calls) { + log.set("feature_disbled", true); + return; + } log.set("roomId", this._room.id); let localMedia; try { diff --git a/src/domain/session/room/timeline/tiles/index.ts b/src/domain/session/room/timeline/tiles/index.ts index 32bc9c76..e86d61cb 100644 --- a/src/domain/session/room/timeline/tiles/index.ts +++ b/src/domain/session/room/timeline/tiles/index.ts @@ -92,7 +92,7 @@ export function tileClassForEntry(entry: TimelineEntry, options: Options): TileC case "org.matrix.msc3401.call": { // if prevContent is present, it's an update to a call event, which we don't render // as the original event is updated through the call object which receive state event updates - if (entry.stateKey && !entry.prevContent) { + if (options.features.calls && entry.stateKey && !entry.prevContent) { return CallTile; } return undefined; diff --git a/src/domain/session/toast/ToastCollectionViewModel.ts b/src/domain/session/toast/ToastCollectionViewModel.ts index d1595b2d..df4da88f 100644 --- a/src/domain/session/toast/ToastCollectionViewModel.ts +++ b/src/domain/session/toast/ToastCollectionViewModel.ts @@ -33,8 +33,10 @@ export class ToastCollectionViewModel extends ViewModel { constructor(options: Options) { super(options); const session = this.getOption("session"); - const callsObservableMap = session.callHandler.calls; - this.track(callsObservableMap.subscribe(this)); + if (this.features.calls) { + const callsObservableMap = session.callHandler.calls; + this.track(callsObservableMap.subscribe(this)); + } } async onAdd(_, call: GroupCall) { diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 3bcb0ff7..b3bd6f98 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -75,6 +75,61 @@ export class Session { }; this._roomsBeingCreated = new ObservableMap(); this._user = new User(sessionInfo.userId); + this._roomStateHandler = new RoomStateHandlerSet(); + this._deviceMessageHandler = new DeviceMessageHandler({storage, callHandler: this._callHandler}); + this._olm = olm; + this._olmUtil = null; + this._e2eeAccount = null; + this._deviceTracker = null; + this._olmEncryption = null; + this._keyLoader = null; + this._megolmEncryption = null; + this._megolmDecryption = null; + this._getSyncToken = () => this.syncToken; + this._olmWorker = olmWorker; + this._keyBackup = new ObservableValue(undefined); + this._observedRoomStatus = new Map(); + + if (olm) { + this._olmUtil = new olm.Utility(); + this._deviceTracker = new DeviceTracker({ + storage, + getSyncToken: this._getSyncToken, + olmUtil: this._olmUtil, + ownUserId: sessionInfo.userId, + ownDeviceId: sessionInfo.deviceId, + }); + } + this._createRoomEncryption = this._createRoomEncryption.bind(this); + this._forgetArchivedRoom = this._forgetArchivedRoom.bind(this); + this.needsKeyBackup = new ObservableValue(false); + + if (features.calls) { + this._setupCallHandler(); + } + } + + get fingerprintKey() { + return this._e2eeAccount?.identityKeys.ed25519; + } + + get hasSecretStorageKey() { + return this._hasSecretStorageKey; + } + + get deviceId() { + return this._sessionInfo.deviceId; + } + + get userId() { + return this._sessionInfo.userId; + } + + get callHandler() { + return this._callHandler; + } + + _setupCallHandler() { this._callHandler = new CallHandler({ clock: this._platform.clock, random: this._platform.random, @@ -103,55 +158,7 @@ export class Session { logger: this._platform.logger, forceTURN: false, }); - this._roomStateHandler = new RoomStateHandlerSet(); this.observeRoomState(this._callHandler); - this._deviceMessageHandler = new DeviceMessageHandler({storage, callHandler: this._callHandler}); - this._olm = olm; - this._olmUtil = null; - this._e2eeAccount = null; - this._deviceTracker = null; - this._olmEncryption = null; - this._keyLoader = null; - this._megolmEncryption = null; - this._megolmDecryption = null; - this._getSyncToken = () => this.syncToken; - this._olmWorker = olmWorker; - this._keyBackup = new ObservableValue(undefined); - this._observedRoomStatus = new Map(); - - if (olm) { - this._olmUtil = new olm.Utility(); - this._deviceTracker = new DeviceTracker({ - storage, - getSyncToken: this._getSyncToken, - olmUtil: this._olmUtil, - ownUserId: sessionInfo.userId, - ownDeviceId: sessionInfo.deviceId, - }); - } - this._createRoomEncryption = this._createRoomEncryption.bind(this); - this._forgetArchivedRoom = this._forgetArchivedRoom.bind(this); - this.needsKeyBackup = new ObservableValue(false); - } - - get fingerprintKey() { - return this._e2eeAccount?.identityKeys.ed25519; - } - - get hasSecretStorageKey() { - return this._hasSecretStorageKey; - } - - get deviceId() { - return this._sessionInfo.deviceId; - } - - get userId() { - return this._sessionInfo.userId; - } - - get callHandler() { - return this._callHandler; } // called once this._e2eeAccount is assigned diff --git a/src/platform/web/ui/session/room/RoomView.js b/src/platform/web/ui/session/room/RoomView.js index 892cb25e..727fb44d 100644 --- a/src/platform/web/ui/session/room/RoomView.js +++ b/src/platform/web/ui/session/room/RoomView.js @@ -73,8 +73,10 @@ export class RoomView extends TemplateView { } else { const vm = this.value; const options = []; - options.push(Menu.option(vm.i18n`Room details`, () => vm.openDetailsPanel())) - options.push(Menu.option(vm.i18n`Start call`, () => vm.startCall())) + options.push(Menu.option(vm.i18n`Room details`, () => vm.openDetailsPanel())); + if (vm.features.calls) { + options.push(Menu.option(vm.i18n`Start call`, () => vm.startCall())); + } if (vm.canLeave) { options.push(Menu.option(vm.i18n`Leave room`, () => this._confirmToLeaveRoom()).setDestructive()); }