forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxep0334.ts
83 lines (74 loc) · 2.62 KB
/
xep0334.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// ====================================================================
// XEP-0334: Message Processing Hints
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0334.html
// Version: 0.3.0 (2018-01-25)
// ====================================================================
import { createElement, extendMessage, FieldDefinition } from '../jxt';
import { NS_HINTS } from '../Namespaces';
declare module './' {
export interface Message {
processingHints?: ProcessingHints;
}
}
export interface ProcessingHints {
noCopy?: boolean;
noPermanentStore?: boolean;
noStore?: boolean;
store?: boolean;
}
function processingHints(): FieldDefinition<ProcessingHints> {
return {
importer(xml) {
const results: ProcessingHints = {};
let found = false;
for (const child of xml.children) {
/* istanbul ignore next */
if (typeof child === 'string') {
continue;
}
if (child.getNamespace() !== NS_HINTS) {
continue;
}
switch (child.getName()) {
case 'no-copy':
results.noCopy = true;
found = true;
break;
case 'no-permanent-store':
results.noPermanentStore = true;
found = true;
break;
case 'no-store':
results.noStore = true;
found = true;
break;
case 'store':
results.store = true;
found = true;
break;
}
}
return found ? results : undefined;
},
exporter(xml, value, context) {
if (value.noCopy) {
xml.appendChild(createElement(NS_HINTS, 'no-copy', context.namespace, xml));
}
if (value.noPermanentStore) {
xml.appendChild(
createElement(NS_HINTS, 'no-permanent-store', context.namespace, xml)
);
}
if (value.noStore) {
xml.appendChild(createElement(NS_HINTS, 'no-store', context.namespace, xml));
}
if (value.store) {
xml.appendChild(createElement(NS_HINTS, 'store', context.namespace, xml));
}
}
};
}
export default extendMessage({
processingHints: processingHints()
});