Use powerlevel

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-07-21 13:51:57 +05:30
parent c9224c13a7
commit fe6551ff3c
3 changed files with 17 additions and 4 deletions

View file

@ -24,6 +24,9 @@ export class MemberDetailsViewModel extends ViewModel {
this._mediaRepository = options.mediaRepository;
this._member = this._observableMember.get();
this._isEncrypted = options.isEncrypted;
this._powerLevelsObservable = options.powerLevelsObservable;
this._powerLevel = this._powerLevelFromObservable(this._powerLevelsObservable);
this.track(this._powerLevelsObservable.subscribe(() => this._onPowerLevelsChange()));
this.track(this._observableMember.subscribe( () => this._onMemberChange()));
}
@ -33,7 +36,10 @@ export class MemberDetailsViewModel extends ViewModel {
get type() { return "member-details"; }
get role() {
return "Admin";
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() {
@ -41,6 +47,12 @@ export class MemberDetailsViewModel extends ViewModel {
this.emitChange();
}
_onPowerLevelsChange() {
const powerLevels = this._powerLevelsObservable.get();
this._powerLevel = powerLevels.getUserLevel(this._member.userId);
this.emitChange();
}
get avatarLetter() {
return avatarInitials(this.name);
}

View file

@ -24,7 +24,8 @@ export class RightPanelViewModel extends ViewModel {
const userId = segment.value;
const observableMember = await this._room.observeMember(userId);
const isEncrypted = this._room.isEncrypted;
return {observableMember, isEncrypted, mediaRepository: this._room.mediaRepository};
const powerLevelsObservable = await this._room.observePowerLevels();
return {observableMember, isEncrypted, powerLevelsObservable, mediaRepository: this._room.mediaRepository};
}
_setupNavigation() {

View file

@ -25,9 +25,9 @@ export class MemberDetailsView extends TemplateView {
};
return t.div({className: "MemberDetailsView"},
[ t.view(new AvatarView(vm, 128)),
t.div({className: "MemberDetailsView_name"}, t.h2(vm.name)),
t.div({className: "MemberDetailsView_name"}, t.h2(vm => vm.name)),
t.div({className: "MemberDetailsView_id"}, vm.userId),
this._createSection(t, vm.i18n`ROLE`, vm.role),
this._createSection(t, vm.i18n`ROLE`, vm => vm.role),
this._createSection(t, vm.i18n`SECURITY`, encryptionMessages[vm.isEncrypted]),
this._createOptions(t, vm)
]);