Skip to content

Commit 9fd2718

Browse files
committed
HTTP avatar review changes
1 parent 5bc57d0 commit 9fd2718

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

src/headless/plugins/vcard/parsers.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,33 @@ export async function parseVCardResultStanza(iq) {
1010
const result = {
1111
email: iq.querySelector(':scope > vCard EMAIL USERID')?.textContent,
1212
fullname: iq.querySelector(':scope > vCard FN')?.textContent,
13-
image: iq.querySelector(':scope > vCard PHOTO BINVAL')?.textContent,
14-
image_type: iq.querySelector(':scope > vCard PHOTO TYPE')?.textContent,
15-
image_url: iq.querySelector(':scope > vCard PHOTO EXTVAL')?.textContent,
1613
nickname: iq.querySelector(':scope > vCard NICKNAME')?.textContent,
1714
role: iq.querySelector(':scope > vCard ROLE')?.textContent,
1815
stanza: iq, // TODO: remove?
1916
url: iq.querySelector(':scope > vCard URL')?.textContent,
2017
vcard_updated: new Date().toISOString(),
2118
error: undefined,
2219
vcard_error: undefined,
23-
image_hash: undefined,
2420
};
25-
if (result.image_url) {
26-
result['image_url'] = result.image_url;
27-
}
28-
else if (result.image) {
29-
const buffer = u.base64ToArrayBuffer(result.image);
21+
22+
const image = iq.querySelector(':scope > vCard PHOTO BINVAL')?.textContent;
23+
const image_type = iq.querySelector(':scope > vCard PHOTO TYPE')?.textContent;
24+
const image_url = iq.querySelector(':scope > vCard PHOTO EXTVAL')?.textContent;
25+
26+
if (image) {
27+
const buffer = u.base64ToArrayBuffer(image);
3028
const ab = await crypto.subtle.digest('SHA-1', buffer);
31-
result['image_hash'] = u.arrayBufferToHex(ab);
29+
30+
Object.assign(result, {
31+
image,
32+
image_type,
33+
image_hash: u.arrayBufferToHex(ab),
34+
});
35+
}
36+
else if (image_url) {
37+
Object.assign(result, {
38+
image_url,
39+
});
3240
}
3341
return result;
3442
}

src/headless/plugins/vcard/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ export function createStanza(type, jid, vcard_el) {
3939
* @param {MUCOccupant} occupant
4040
*/
4141
export function onOccupantAvatarChanged(occupant) {
42-
const url = occupant.get('image_url');
4342
const hash = occupant.get('image_hash');
43+
const url = occupant.get('image_url');
4444
const vcards = [];
4545
if (occupant.get('jid')) {
4646
vcards.push(_converse.state.vcards.get(occupant.get('jid')));
4747
}
4848
vcards.push(_converse.state.vcards.get(occupant.get('from')));
49-
vcards.forEach((v) => hash && v && (v?.get('image_url') !== url || v?.get('image_hash') !== hash) && api.vcard.update(v, true));
49+
vcards.forEach((v) => (hash || url) && v && (v?.get('image_hash') !== hash || v?.get('image_url') !== url) && api.vcard.update(v, true));
5050
}
5151

5252
/**

src/shared/avatar/avatar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class Avatar extends CustomElement {
4242
image = this.model?.vcard?.get('image');
4343
}
4444

45-
if (image_type && (image_url || image || data_uri)) {
45+
if ((image_type && (image || data_uri)) || (image_url)) {
4646
return tplAvatar({
4747
classes: this.getAttribute('class'),
4848
height: this.height,

src/shared/avatar/templates/avatar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { html, nothing } from 'lit';
22

33
/**
44
* @param {string} image
5-
* @param {string} image_type
5+
* @param {string} [image_type]
66
*/
7-
const getImgHref = (image, image_type) => {
7+
function getImgHref(image, image_type) {
88
if (image.startsWith('https:') || image.startsWith('data:')) {
99
return image;
1010
}

0 commit comments

Comments
 (0)