Skip to content

Commit 27260d8

Browse files
committed
Load avatar data over HTTP if available in vCard EXTVAL
1 parent 292bea1 commit 27260d8

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

src/headless/plugins/vcard/parsers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function parseVCardResultStanza(iq) {
1212
fullname: iq.querySelector(':scope > vCard FN')?.textContent,
1313
image: iq.querySelector(':scope > vCard PHOTO BINVAL')?.textContent,
1414
image_type: iq.querySelector(':scope > vCard PHOTO TYPE')?.textContent,
15+
image_url: iq.querySelector(':scope > vCard PHOTO EXTVAL')?.textContent,
1516
nickname: iq.querySelector(':scope > vCard NICKNAME')?.textContent,
1617
role: iq.querySelector(':scope > vCard ROLE')?.textContent,
1718
stanza: iq, // TODO: remove?
@@ -21,7 +22,10 @@ export async function parseVCardResultStanza(iq) {
2122
vcard_error: undefined,
2223
image_hash: undefined,
2324
};
24-
if (result.image) {
25+
if (result.image_url) {
26+
result['image_url'] = result.image_url;
27+
}
28+
else if (result.image) {
2529
const buffer = u.base64ToArrayBuffer(result.image);
2630
const ab = await crypto.subtle.digest('SHA-1', buffer);
2731
result['image_hash'] = u.arrayBufferToHex(ab);

src/headless/plugins/vcard/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface VCardResult {
1010
image?: string;
1111
image_hash?: string;
1212
image_type?: string;
13+
image_url?: string;
1314
nickname?: string;
1415
role?: string;
1516
stanza: Element;
@@ -25,6 +26,7 @@ export type VCardData = {
2526
role?: string;
2627
email?: string;
2728
url?: string;
29+
image_url?: string;
2830
image_type?: string;
2931
image?: string;
3032
};

src/headless/plugins/vcard/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +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');
4243
const hash = occupant.get('image_hash');
4344
const vcards = [];
4445
if (occupant.get('jid')) {
4546
vcards.push(_converse.state.vcards.get(occupant.get('jid')));
4647
}
4748
vcards.push(_converse.state.vcards.get(occupant.get('from')));
48-
vcards.forEach((v) => hash && v && v?.get('image_hash') !== hash && api.vcard.update(v, true));
49+
vcards.forEach((v) => hash && v && (v?.get('image_url') !== url || v?.get('image_hash') !== hash) && api.vcard.update(v, true));
4950
}
5051

5152
/**

src/shared/avatar/avatar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,25 @@ export default class Avatar extends CustomElement {
2929
}
3030

3131
render() {
32+
let image_url;
3233
let image_type;
3334
let image;
3435
let data_uri;
3536
if (this.pickerdata) {
3637
image_type = this.pickerdata.image_type;
3738
data_uri = this.pickerdata.data_uri;
3839
} else {
40+
image_url = this.model?.vcard?.get('image_url');
3941
image_type = this.model?.vcard?.get('image_type');
4042
image = this.model?.vcard?.get('image');
4143
}
4244

43-
if (image_type && (image || data_uri)) {
45+
if (image_type && (image_url || image || data_uri)) {
4446
return tplAvatar({
4547
classes: this.getAttribute('class'),
4648
height: this.height,
4749
width: this.width,
48-
image: data_uri || `data:${image_type};base64,${image}`,
50+
image: image_url || data_uri || `data:${image_type};base64,${image}`,
4951
image_type,
5052
alt_text: __('The profile picture of %1$s', this.name),
5153
});

src/shared/avatar/templates/avatar.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { html, nothing } from 'lit';
55
* @param {string} image_type
66
*/
77
const getImgHref = (image, image_type) => {
8-
return image.startsWith('data:') ? image : `data:${image_type};base64,${image}`;
8+
if (image.startsWith('https:') || image.startsWith('data:')) {
9+
return image;
10+
}
11+
else {
12+
return `data:${image_type};base64,${image}`;
13+
}
914
};
1015

1116
export default (o) => {

0 commit comments

Comments
 (0)