forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xep0153.ts
44 lines (40 loc) · 1.43 KB
/
xep0153.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ====================================================================
// XEP-0153: vCard-Based Avatars
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0153.html
// Version: 1.1 (2018-02-26)
// ====================================================================
import { extendPresence, findAll, findOrCreate } from '../jxt';
import { NS_VCARD_TEMP_UPDATE } from '../Namespaces';
declare module './' {
export interface Presence {
vcardAvatar?: string | boolean;
}
}
export default extendPresence({
vcardAvatar: {
importer(xml) {
const update = findAll(xml, NS_VCARD_TEMP_UPDATE, 'x');
if (!update.length) {
return;
}
const photo = findAll(update[0], NS_VCARD_TEMP_UPDATE, 'photo');
if (photo.length) {
return photo[0].getText();
} else {
return true;
}
},
exporter(xml, value) {
const update = findOrCreate(xml, NS_VCARD_TEMP_UPDATE, 'x');
if (value === '') {
findOrCreate(update, NS_VCARD_TEMP_UPDATE, 'photo');
} else if (value === true) {
return;
} else if (value) {
const photo = findOrCreate(update, NS_VCARD_TEMP_UPDATE, 'photo');
photo.children.push(value);
}
}
}
});