From dec06831452dbd2ee169c3a0774fe04a8c1828ca Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 29 Jun 2021 16:50:42 -0700 Subject: [PATCH] Correctly color archived and invited rooms --- src/domain/session/room/InviteViewModel.js | 2 +- src/matrix/room/ArchivedRoom.js | 4 ++++ src/matrix/room/BaseRoom.js | 4 ++++ src/matrix/room/Invite.js | 6 ++++++ src/matrix/room/Room.js | 4 ---- src/matrix/room/RoomSummary.js | 9 +++++++++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/domain/session/room/InviteViewModel.js b/src/domain/session/room/InviteViewModel.js index a9cc917f..81a08e44 100644 --- a/src/domain/session/room/InviteViewModel.js +++ b/src/domain/session/room/InviteViewModel.js @@ -56,7 +56,7 @@ export class InviteViewModel extends ViewModel { } get avatarColorNumber() { - return getIdentifierColorNumber(this._invite.id) + return getIdentifierColorNumber(this._invite.avatarColorId) } avatarUrl(size) { diff --git a/src/matrix/room/ArchivedRoom.js b/src/matrix/room/ArchivedRoom.js index f975191e..97a92450 100644 --- a/src/matrix/room/ArchivedRoom.js +++ b/src/matrix/room/ArchivedRoom.js @@ -107,6 +107,10 @@ export class ArchivedRoom extends BaseRoom { this._emitUpdate(); } + get avatarColorId() { + return this._summary.data.avatarColorId; + } + get isKicked() { return this._kickDetails?.membership === "leave"; } diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index cef443c1..7d8bf040 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -341,6 +341,10 @@ export class BaseRoom extends EventEmitter { return null; } + get avatarColorId() { + return this._heroes?.roomAvatarColorId || this._roomId + } + get lastMessageTimestamp() { return this._summary.data.lastMessageTimestamp; } diff --git a/src/matrix/room/Invite.js b/src/matrix/room/Invite.js index aa25b0c6..a0391a12 100644 --- a/src/matrix/room/Invite.js +++ b/src/matrix/room/Invite.js @@ -56,6 +56,10 @@ export class Invite extends EventEmitter { return this._inviteData.avatarUrl; } + get avatarColorId() { + return this._inviteData.avatarColorId; + } + get timestamp() { return this._inviteData.timestamp; } @@ -175,6 +179,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 : summaryData.avatarColorId; return { roomId: this.id, isEncrypted: !!summaryData.encryption, @@ -182,6 +187,7 @@ export class Invite extends EventEmitter { // type: name, avatarUrl, + avatarColorId, canonicalAlias: summaryData.canonicalAlias, timestamp: this._platform.clock.now(), joinRule: this._getJoinRule(inviteState), diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 5e002411..482d167f 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -328,10 +328,6 @@ export class Room extends BaseRoom { }); } - get avatarColorId() { - return this._heroes?.roomAvatarColorId || this._roomId - } - get isUnread() { return this._summary.data.isUnread; } diff --git a/src/matrix/room/RoomSummary.js b/src/matrix/room/RoomSummary.js index d0c78659..a99869ac 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -239,6 +239,15 @@ export class SummaryData { return !this.name && !this.canonicalAlias && this.heroes && this.heroes.length > 0; } + get avatarColorId() { + if (this.heroes && this.heroes.length === 1) { + for (const hero of this.heroes) { + return hero; + } + } + return this.roomId; + } + isNewJoin(oldData) { return this.membership === "join" && oldData.membership !== "join"; }