Add avatar to tile

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-06-26 14:32:39 +05:30
parent 86c1550850
commit 7139711314
4 changed files with 25 additions and 3 deletions

View file

@ -9,6 +9,7 @@ export class MemberListViewModel extends ViewModel {
this.memberTileViewModels = this._mapTileViewModels(this._filterJoinedMembers(options.members)) this.memberTileViewModels = this._mapTileViewModels(this._filterJoinedMembers(options.members))
.sortValues(createMemberComparator(options.powerLevels)); .sortValues(createMemberComparator(options.powerLevels));
this.nameDisambiguator = new Disambiguator(); this.nameDisambiguator = new Disambiguator();
this.mediaRepository = options.mediaRepository;
} }
_filterJoinedMembers(members) { _filterJoinedMembers(members) {
@ -17,7 +18,8 @@ export class MemberListViewModel extends ViewModel {
_mapTileViewModels(members) { _mapTileViewModels(members) {
const mapper = (member, emitChange) => { const mapper = (member, emitChange) => {
const vm = new MemberTileViewModel(this.childOptions({member, emitChange})); const mediaRepository = this.mediaRepository;
const vm = new MemberTileViewModel(this.childOptions({member, emitChange, mediaRepository}));
this.nameDisambiguator.disambiguate(vm); this.nameDisambiguator.disambiguate(vm);
return vm; return vm;
} }

View file

@ -1,9 +1,11 @@
import {ViewModel} from "../../ViewModel.js"; import {ViewModel} from "../../ViewModel.js";
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
export class MemberTileViewModel extends ViewModel { export class MemberTileViewModel extends ViewModel {
constructor(options) { constructor(options) {
super(options); super(options);
this._member = this._options.member; this._member = this._options.member;
this._mediaRepository = options.mediaRepository
this._previousName = null; this._previousName = null;
this._nameChanged = true; this._nameChanged = true;
} }
@ -47,4 +49,20 @@ export class MemberTileViewModel extends ViewModel {
this._updatePreviousName(newMember.name); this._updatePreviousName(newMember.name);
this._member = newMember; this._member = newMember;
} }
get avatarLetter() {
return avatarInitials(this.name);
}
get avatarColorNumber() {
return getIdentifierColorNumber(this.userId)
}
avatarUrl(size) {
return getAvatarHttpUrl(this._member.avatarUrl, size, this.platform, this._mediaRepository);
}
get avatarTitle() {
return this.name;
}
} }

View file

@ -39,8 +39,9 @@ export class RightPanelViewModel extends ViewModel {
const list = await this._room.loadMemberList(); const list = await this._room.loadMemberList();
const members = list.members; const members = list.members;
const powerLevels = this._room.powerLevels; const powerLevels = this._room.powerLevels;
const mediaRepository = this._room.mediaRepository;
this._memberListViewModel = this.track( this._memberListViewModel = this.track(
new MemberListViewModel(this.childOptions({members, powerLevels})) new MemberListViewModel(this.childOptions({members, powerLevels, mediaRepository}))
); );
} }
this.emitChange("memberListViewModel"); this.emitChange("memberListViewModel");

View file

@ -1,7 +1,8 @@
import {TemplateView} from "../../general/TemplateView.js"; import {TemplateView} from "../../general/TemplateView.js";
import {AvatarView} from "../../avatar.js";
export class MemberTileView extends TemplateView { export class MemberTileView extends TemplateView {
render(t, vm) { render(t, vm) {
return t.div(vm => vm.name); return t.div([t.view(new AvatarView(vm, 32)), vm => vm.name]);
} }
} }