From a16c3aacab3aaaad36f0454f09415d8da7851695 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 3 Aug 2021 14:51:46 +0530 Subject: [PATCH] Create getter Signed-off-by: RMidhunSuresh --- .../rightpanel/MemberDetailsViewModel.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/domain/session/rightpanel/MemberDetailsViewModel.js b/src/domain/session/rightpanel/MemberDetailsViewModel.js index bf6f0b34..f10f3678 100644 --- a/src/domain/session/rightpanel/MemberDetailsViewModel.js +++ b/src/domain/session/rightpanel/MemberDetailsViewModel.js @@ -25,7 +25,7 @@ export class MemberDetailsViewModel extends ViewModel { this._member = this._observableMember.get(); this._isEncrypted = options.isEncrypted; this._powerLevelsObservable = options.powerLevelsObservable; - this._powerLevel = this._powerLevelsObservable.get().getUserLevel(this._member.userId); + this._powerLevel = null; this.track(this._powerLevelsObservable.subscribe(() => this._onPowerLevelsChange())); this.track(this._observableMember.subscribe( () => this._onMemberChange())); } @@ -38,10 +38,10 @@ export class MemberDetailsViewModel extends ViewModel { get previousSegmentName() { return "members"; } get role() { - if (this._powerLevel >= 100) { return "Admin"; } - else if (this._powerLevel >= 50) { return "Moderator"; } - else if (this._powerLevel === 0) { return "Default"; } - else { return `Custom (${this._powerLevel})`; } + if (this.powerLevel >= 100) { return "Admin"; } + else if (this.powerLevel >= 50) { return "Moderator"; } + else if (this.powerLevel === 0) { return "Default"; } + else { return `Custom (${this.powerLevel})`; } } _onMemberChange() { @@ -75,6 +75,14 @@ export class MemberDetailsViewModel extends ViewModel { return this._isEncrypted; } + get powerLevel() { + if (!this._powerLevel) { + const powerLevels = this._powerLevelsObservable.get(); + this._powerLevel = powerLevels.getUserLevel(this._member.userId); + } + return this._powerLevel; + } + get linkToUser() { return `https://matrix.to/#/${this._member.userId}`; }