Display avatars in contacts and message list

An enhancement that will seal tight the already closed #15!
This commit is contained in:
Badri Sunderarajan 2024-03-24 21:48:36 +05:30
parent e63d9978bb
commit 5e986b0ae1
Signed by: badrihippo
GPG key ID: 9F594532AD60DE03
2 changed files with 37 additions and 1 deletions

View file

@ -54,6 +54,22 @@
// TODO: use a sliding window so that only the contacts
// that are in view get rendered
// Helper function to fetch avatars for a chatbox
function getAvatar(chatJID) {
let vcard = _converse.vcards.get(chatJID)
if (vcard && vcard.attributes?.image) {
return {
src: 'data:'
+ vcard.attributes.image_type
+ ';base64,'
+ vcard.attributes.image,
alt: 'Profile picture for ' + chatJID,
}
} else {
return undefined
}
}
// Helper function to convert contacts list into
// (exceedingly lightweight) object array for
// final rendering
@ -61,6 +77,7 @@
return contacts.map(c => ({
jid: c.attributes.jid,
name: c.attributes.nickname || c.attributes.user_id,
avatar: getAvatar(c.attributes.jid),
}))
}
@ -115,6 +132,7 @@
<ListItem
text={contact.name}
subtext={contact.jid}
image={contact.avatar}
tabindex={index}
onclick={() => createChat(contact.jid)}
/>

View file

@ -53,14 +53,31 @@
// TODO: use a sliding window so that only the chatboxes
// that are in view get rendered
// Helper function to fetch avatars for a chatbox
function getAvatar(chatJID) {
let vcard = _converse.vcards.get(chatJID)
if (vcard && vcard.attributes?.image) {
return {
src: 'data:'
+ vcard.attributes.image_type
+ ';base64,'
+ vcard.attributes.image,
alt: 'Profile picture for ' + chatJID,
}
} else {
return undefined
}
}
// Helper function to convert chatboxes into
// (exceedingly lightweight) object array for
// final rendering
function chatboxesToArray(chatboxes) {
return chatboxes.models.map(c => ({
id: c.id,
title: c.attributes.name || c.attributes.id,
title: c.attributes.nickname || c.attributes.id,
lastMessage: c.messages?.last()?.attributes?.body,
avatar: getAvatar(c.id),
}))
}
@ -115,6 +132,7 @@
<ListItem
text={convo.title}
subtext={convo.lastMessage}
image={convo.avatar}
tabindex={index}
onclick={() => openChat(convo.id)}
/>