From ee1f1500e9617a0aebc15662a1b5225461eee1c7 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 30 Jun 2021 15:07:27 -0700 Subject: [PATCH] Roll back to using heroes for computing DM color --- src/domain/session/leftpanel/BaseTileViewModel.js | 2 +- src/domain/session/leftpanel/RoomTileViewModel.js | 5 ----- src/matrix/room/BaseRoom.js | 8 +++++++- src/matrix/room/Invite.js | 3 ++- src/matrix/room/Room.js | 4 ++++ src/matrix/room/RoomSummary.js | 9 --------- src/matrix/room/members/Heroes.js | 9 +++++++++ 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/domain/session/leftpanel/BaseTileViewModel.js b/src/domain/session/leftpanel/BaseTileViewModel.js index 62ea6380..95e91458 100644 --- a/src/domain/session/leftpanel/BaseTileViewModel.js +++ b/src/domain/session/leftpanel/BaseTileViewModel.js @@ -69,7 +69,7 @@ export class BaseTileViewModel extends ViewModel { } get avatarColorNumber() { - return getIdentifierColorNumber(this._avatarSource.id); + return getIdentifierColorNumber(this._avatarSource.avatarColorId); } avatarUrl(size) { diff --git a/src/domain/session/leftpanel/RoomTileViewModel.js b/src/domain/session/leftpanel/RoomTileViewModel.js index e901e17d..eebea618 100644 --- a/src/domain/session/leftpanel/RoomTileViewModel.js +++ b/src/domain/session/leftpanel/RoomTileViewModel.js @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {getIdentifierColorNumber} from "../../avatar.js"; import {BaseTileViewModel} from "./BaseTileViewModel.js"; export class RoomTileViewModel extends BaseTileViewModel { @@ -76,10 +75,6 @@ export class RoomTileViewModel extends BaseTileViewModel { return timeDiff; } - get avatarColorNumber() { - return getIdentifierColorNumber(this._room.avatarColorId); - } - get isUnread() { return this._room.isUnread; } diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index 70fe5663..9d33c5c5 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -341,8 +341,14 @@ 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._summary.data.avatarColorId; + return this._roomId; } get lastMessageTimestamp() { diff --git a/src/matrix/room/Invite.js b/src/matrix/room/Invite.js index 7346298b..3e6a417c 100644 --- a/src/matrix/room/Invite.js +++ b/src/matrix/room/Invite.js @@ -179,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 : this.id; return { roomId: this.id, isEncrypted: !!summaryData.encryption, @@ -186,7 +187,7 @@ export class Invite extends EventEmitter { // type: name, avatarUrl, - avatarColorId: summaryData.avatarColorId, + 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 482d167f..a8e94326 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -328,6 +328,10 @@ 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 a99869ac..d0c78659 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -239,15 +239,6 @@ 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"; } diff --git a/src/matrix/room/members/Heroes.js b/src/matrix/room/members/Heroes.js index f6ad3085..921eed47 100644 --- a/src/matrix/room/members/Heroes.js +++ b/src/matrix/room/members/Heroes.js @@ -97,4 +97,13 @@ export class Heroes { } return null; } + + get roomAvatarColorId() { + if (this._members.size === 1) { + for (const member of this._members.keys()) { + return member + } + } + return null; + } }