@@ -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}
0 commit comments