Merge pull request #405 from DanilaFe/dm-color-fix
Ensure room color in DM, timeline, and left panel is the same.
This commit is contained in:
commit
71d0124146
8 changed files with 42 additions and 4 deletions
|
@ -69,7 +69,7 @@ export class BaseTileViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
get avatarColorNumber() {
|
get avatarColorNumber() {
|
||||||
return getIdentifierColorNumber(this._avatarSource.id);
|
return getIdentifierColorNumber(this._avatarSource.avatarColorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarUrl(size) {
|
avatarUrl(size) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ export class RoomDetailsViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
get avatarColorNumber() {
|
get avatarColorNumber() {
|
||||||
return getIdentifierColorNumber(this.roomId)
|
return getIdentifierColorNumber(this._room.avatarColorId)
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarUrl(size) {
|
avatarUrl(size) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ export class InviteViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
get avatarColorNumber() {
|
get avatarColorNumber() {
|
||||||
return getIdentifierColorNumber(this._invite.id)
|
return getIdentifierColorNumber(this._invite.avatarColorId)
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarUrl(size) {
|
avatarUrl(size) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ export class RoomViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
get avatarColorNumber() {
|
get avatarColorNumber() {
|
||||||
return getIdentifierColorNumber(this._room.id)
|
return getIdentifierColorNumber(this._room.avatarColorId)
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarUrl(size) {
|
avatarUrl(size) {
|
||||||
|
|
|
@ -341,6 +341,16 @@ export class BaseRoom extends EventEmitter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the identifier that should be used to color
|
||||||
|
* this room's avatar. By default this is the room's
|
||||||
|
* ID, but DM rooms should be the same color as their
|
||||||
|
* user's avatar.
|
||||||
|
*/
|
||||||
|
get avatarColorId() {
|
||||||
|
return this._roomId;
|
||||||
|
}
|
||||||
|
|
||||||
get lastMessageTimestamp() {
|
get lastMessageTimestamp() {
|
||||||
return this._summary.data.lastMessageTimestamp;
|
return this._summary.data.lastMessageTimestamp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,11 @@ export class Invite extends EventEmitter {
|
||||||
return this._inviteData.avatarUrl;
|
return this._inviteData.avatarUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @see BaseRoom.avatarColorId */
|
||||||
|
get avatarColorId() {
|
||||||
|
return this._inviteData.avatarColorId;
|
||||||
|
}
|
||||||
|
|
||||||
get timestamp() {
|
get timestamp() {
|
||||||
return this._inviteData.timestamp;
|
return this._inviteData.timestamp;
|
||||||
}
|
}
|
||||||
|
@ -175,6 +180,7 @@ export class Invite extends EventEmitter {
|
||||||
_createData(inviteState, myInvite, inviter, summaryData, heroes) {
|
_createData(inviteState, myInvite, inviter, summaryData, heroes) {
|
||||||
const name = heroes ? heroes.roomName : summaryData.name;
|
const name = heroes ? heroes.roomName : summaryData.name;
|
||||||
const avatarUrl = heroes ? heroes.roomAvatarUrl : summaryData.avatarUrl;
|
const avatarUrl = heroes ? heroes.roomAvatarUrl : summaryData.avatarUrl;
|
||||||
|
const avatarColorId = heroes ? heroes.roomAvatarColorId : this.id;
|
||||||
return {
|
return {
|
||||||
roomId: this.id,
|
roomId: this.id,
|
||||||
isEncrypted: !!summaryData.encryption,
|
isEncrypted: !!summaryData.encryption,
|
||||||
|
@ -182,6 +188,7 @@ export class Invite extends EventEmitter {
|
||||||
// type:
|
// type:
|
||||||
name,
|
name,
|
||||||
avatarUrl,
|
avatarUrl,
|
||||||
|
avatarColorId,
|
||||||
canonicalAlias: summaryData.canonicalAlias,
|
canonicalAlias: summaryData.canonicalAlias,
|
||||||
timestamp: this._platform.clock.now(),
|
timestamp: this._platform.clock.now(),
|
||||||
joinRule: this._getJoinRule(inviteState),
|
joinRule: this._getJoinRule(inviteState),
|
||||||
|
|
|
@ -328,6 +328,10 @@ export class Room extends BaseRoom {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get avatarColorId() {
|
||||||
|
return this._heroes?.roomAvatarColorId || this._roomId;
|
||||||
|
}
|
||||||
|
|
||||||
get isUnread() {
|
get isUnread() {
|
||||||
return this._summary.data.isUnread;
|
return this._summary.data.isUnread;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,4 +97,21 @@ export class Heroes {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In DM rooms, we want the room's color to be
|
||||||
|
* the same as the other user's color. Thus, if the room
|
||||||
|
* only has one hero, we use their ID, instead
|
||||||
|
* of the room's, to get the avatar color.
|
||||||
|
*
|
||||||
|
* @returns {?string} the ID of the single hero.
|
||||||
|
*/
|
||||||
|
get roomAvatarColorId() {
|
||||||
|
if (this._members.size === 1) {
|
||||||
|
for (const member of this._members.keys()) {
|
||||||
|
return member
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue