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:
Bruno Windels 2021-07-01 08:03:26 +00:00 committed by GitHub
commit 71d0124146
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 4 deletions

View file

@ -69,7 +69,7 @@ export class BaseTileViewModel extends ViewModel {
}
get avatarColorNumber() {
return getIdentifierColorNumber(this._avatarSource.id);
return getIdentifierColorNumber(this._avatarSource.avatarColorId);
}
avatarUrl(size) {

View file

@ -34,7 +34,7 @@ export class RoomDetailsViewModel extends ViewModel {
}
get avatarColorNumber() {
return getIdentifierColorNumber(this.roomId)
return getIdentifierColorNumber(this._room.avatarColorId)
}
avatarUrl(size) {

View file

@ -56,7 +56,7 @@ export class InviteViewModel extends ViewModel {
}
get avatarColorNumber() {
return getIdentifierColorNumber(this._invite.id)
return getIdentifierColorNumber(this._invite.avatarColorId)
}
avatarUrl(size) {

View file

@ -119,7 +119,7 @@ export class RoomViewModel extends ViewModel {
}
get avatarColorNumber() {
return getIdentifierColorNumber(this._room.id)
return getIdentifierColorNumber(this._room.avatarColorId)
}
avatarUrl(size) {

View file

@ -341,6 +341,16 @@ export class BaseRoom extends EventEmitter {
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() {
return this._summary.data.lastMessageTimestamp;
}

View file

@ -56,6 +56,11 @@ export class Invite extends EventEmitter {
return this._inviteData.avatarUrl;
}
/** @see BaseRoom.avatarColorId */
get avatarColorId() {
return this._inviteData.avatarColorId;
}
get timestamp() {
return this._inviteData.timestamp;
}
@ -175,6 +180,7 @@ export class Invite extends EventEmitter {
_createData(inviteState, myInvite, inviter, summaryData, heroes) {
const name = heroes ? heroes.roomName : summaryData.name;
const avatarUrl = heroes ? heroes.roomAvatarUrl : summaryData.avatarUrl;
const avatarColorId = heroes ? heroes.roomAvatarColorId : this.id;
return {
roomId: this.id,
isEncrypted: !!summaryData.encryption,
@ -182,6 +188,7 @@ export class Invite extends EventEmitter {
// type:
name,
avatarUrl,
avatarColorId,
canonicalAlias: summaryData.canonicalAlias,
timestamp: this._platform.clock.now(),
joinRule: this._getJoinRule(inviteState),

View file

@ -328,6 +328,10 @@ export class Room extends BaseRoom {
});
}
get avatarColorId() {
return this._heroes?.roomAvatarColorId || this._roomId;
}
get isUnread() {
return this._summary.data.isUnread;
}

View file

@ -97,4 +97,21 @@ export class Heroes {
}
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;
}
}