From e51af03d07ad6cd6b03a53059b887d75b634f531 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 15 Aug 2024 12:47:13 +0200 Subject: [PATCH] chore: improve code quality --- src/components/base/BaseAvatar.vue | 14 +++++++------- src/store/tables/room.ts | 13 ++++++++++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/base/BaseAvatar.vue b/src/components/base/BaseAvatar.vue index 29b0936a..25d8cfbf 100644 --- a/src/components/base/BaseAvatar.vue +++ b/src/components/base/BaseAvatar.vue @@ -125,7 +125,7 @@ export default { }, computed: { - jidLike(): string | null { + jidLikeSource(): string | null { // #1. Prefer using JID (if given) if (this.jid !== null) { return this.jid.toString(); @@ -152,11 +152,11 @@ export default { backgroundImage(): string | void { // Acquire background image? (a JID-like is required to obtain avatar \ // data) - if (this.jidLike !== null) { + if (this.jidLikeSource !== null) { const avatarDataUrl = this.dataUrl !== null ? this.dataUrl - : Store.$avatar.getAvatarDataUrl(this.jidLike); + : Store.$avatar.getAvatarDataUrl(this.jidLikeSource); if (avatarDataUrl) { return `url(${avatarDataUrl})`; @@ -169,7 +169,7 @@ export default { backgroundColor(): string | void { // Generate background color? (as avatar is textual) if (this.isTextual === true) { - const value = this.jidLike || this.name || ""; + const value = this.jidLikeSource || this.name || ""; if (value) { return this.generateTextualPalette(value); @@ -185,7 +185,7 @@ export default { const name = this.name || this.roomName || ""; return this.normalizeTextualInitials( - this.generateTextualInitials(this.jidLike, name) || undefined + this.generateTextualInitials(this.jidLikeSource, name) || undefined ); } @@ -232,8 +232,8 @@ export default { roomName(): string { const room = - this.jidLike !== null - ? Store.$room.getRoom(this.jidLike as RoomID) + this.jidLikeSource !== null + ? Store.$room.getRoom(this.jidLikeSource as RoomID) : undefined; return room?.name || ""; diff --git a/src/store/tables/room.ts b/src/store/tables/room.ts index 8ec83ebd..68d6e564 100644 --- a/src/store/tables/room.ts +++ b/src/store/tables/room.ts @@ -257,10 +257,17 @@ const $room = defineStore("room", { requestRefreshRoomAssociations(roomID: RoomID): void { this.getRoom(roomID)?.participants.forEach(participant => { - // Refresh avatar for participant + // Refresh avatar for participant? // Notice: this is a cross-store operation, for convenience. - if (participant.jid !== undefined && participant.avatar !== undefined) { - Store.$avatar.refresh(participant.jid.toString(), participant.avatar); + if (participant.avatar !== undefined) { + // Notice: prefer using JID over abstract participant identifier, \ + // if JID is known. + const userId = + participant.jid !== undefined + ? participant.jid.toString() + : participant.id.toString(); + + Store.$avatar.refresh(userId, participant.avatar); } }); },