2021-06-11 23:51:55 +05:30
|
|
|
import {ViewModel} from "../../ViewModel.js";
|
2021-06-26 14:32:39 +05:30
|
|
|
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
|
2021-06-11 23:51:55 +05:30
|
|
|
|
|
|
|
export class MemberTileViewModel extends ViewModel {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2021-06-22 15:51:18 +05:30
|
|
|
this._member = this._options.member;
|
2021-06-26 14:32:39 +05:30
|
|
|
this._mediaRepository = options.mediaRepository
|
2021-06-25 20:12:31 +05:30
|
|
|
this._previousName = null;
|
|
|
|
this._nameChanged = true;
|
2021-06-11 23:51:55 +05:30
|
|
|
}
|
|
|
|
|
2021-06-18 13:29:08 +05:30
|
|
|
get name() {
|
2021-06-25 20:12:31 +05:30
|
|
|
return `${this._member.name}${this._disambiguationPart}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
get _disambiguationPart() {
|
|
|
|
return this._disambiguate ? ` (${this.userId})` : "";
|
2021-06-18 13:12:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
get userId() {
|
|
|
|
return this._member.userId;
|
2021-06-11 23:51:55 +05:30
|
|
|
}
|
2021-06-22 15:51:18 +05:30
|
|
|
|
2021-06-25 20:12:31 +05:30
|
|
|
get previousName() {
|
|
|
|
return this._previousName;
|
|
|
|
}
|
|
|
|
|
|
|
|
get nameChanged() {
|
|
|
|
return this._nameChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
_updatePreviousName(newName) {
|
|
|
|
const currentName = this._member.name;
|
|
|
|
if (currentName !== newName) {
|
|
|
|
this._previousName = currentName;
|
|
|
|
this._nameChanged = true;
|
|
|
|
} else {
|
|
|
|
this._nameChanged = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setDisambiguation(status) {
|
|
|
|
this._disambiguate = status;
|
|
|
|
this.emitChange();
|
|
|
|
}
|
|
|
|
|
2021-06-22 15:51:18 +05:30
|
|
|
updateFrom(newMember) {
|
2021-06-25 20:12:31 +05:30
|
|
|
this._updatePreviousName(newMember.name);
|
2021-06-22 15:51:18 +05:30
|
|
|
this._member = newMember;
|
|
|
|
}
|
2021-06-26 14:32:39 +05:30
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-06-11 23:51:55 +05:30
|
|
|
}
|