Skip to content

Commit

Permalink
chore: improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Aug 15, 2024
1 parent 643e5d9 commit e51af03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/components/base/BaseAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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})`;
Expand All @@ -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);
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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 || "";
Expand Down
13 changes: 10 additions & 3 deletions src/store/tables/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
},
Expand Down

0 comments on commit e51af03

Please sign in to comment.