From d292e1f5adc8ebdda19cd9c5db93b5148ff5bf00 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Thu, 7 Jul 2022 17:23:23 +0530 Subject: [PATCH] Extract into function --- src/domain/session/room/RoomViewModel.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index fac0ed9d..74dda426 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -69,7 +69,8 @@ export class RoomViewModel extends ViewModel { async _recreateComposerOnPowerLevelChange() { const powerLevelObservable = await this._room.observePowerLevels(); - let oldCanSendMessage = powerLevelObservable.get().canSendType("m.room.message"); + const canSendMessage = () => powerLevelObservable.get().canSendType("m.room.message"); + let oldCanSendMessage = canSendMessage(); const recreateComposer = newCanSendMessage => { this._composerVM = this.disposeTracked(this._composerVM); if (newCanSendMessage) { @@ -80,8 +81,8 @@ export class RoomViewModel extends ViewModel { } this.emitChange("powerLevelObservable") }; - this.track(powerLevelObservable.subscribe(newPowerLevel => { - const newCanSendMessage = newPowerLevel.canSendType("m.room.message"); + this.track(powerLevelObservable.subscribe(() => { + const newCanSendMessage = canSendMessage(); if (oldCanSendMessage !== newCanSendMessage) { recreateComposer(newCanSendMessage); oldCanSendMessage = newCanSendMessage;