forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxep0084.ts
106 lines (99 loc) · 2.69 KB
/
xep0084.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// ====================================================================
// XEP-0084: User Avatar
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0084.html
// Version: 1.1.1 (2016-07-09)
// ====================================================================
import {
attribute,
DefinitionOptions,
integerAttribute,
pubsubItemContentAliases,
textBuffer
} from '../jxt';
import { NS_AVATAR_DATA, NS_AVATAR_METADATA } from '../Namespaces';
import { PubsubItemContent } from './';
export interface AvatarData extends PubsubItemContent {
itemType?: typeof NS_AVATAR_DATA;
data?: Buffer;
}
export interface AvatarMetaData extends PubsubItemContent {
itemType?: typeof NS_AVATAR_METADATA;
versions?: AvatarVersion[];
pointers?: AvatarPointer[];
}
export interface AvatarVersion {
bytes?: number;
height?: number;
width?: number;
id: string;
mediaType?: string;
uri?: string;
}
export interface AvatarPointer {
bytes?: number;
height?: number;
width?: number;
id: string;
mediaType?: string;
}
const Protocol: DefinitionOptions[] = [
{
aliases: pubsubItemContentAliases(),
element: 'data',
fields: {
data: textBuffer('base64')
},
namespace: NS_AVATAR_DATA,
path: 'avatar',
type: NS_AVATAR_DATA,
typeField: 'itemType'
},
{
aliases: pubsubItemContentAliases(),
element: 'metadata',
namespace: NS_AVATAR_METADATA,
path: 'avatar',
type: NS_AVATAR_METADATA,
typeField: 'itemType'
},
{
aliases: [
{
multiple: true,
path: 'avatar.versions',
selector: NS_AVATAR_METADATA
}
],
element: 'info',
fields: {
bytes: integerAttribute('bytes'),
height: integerAttribute('height'),
id: attribute('id'),
mediaType: attribute('type'),
uri: attribute('url'),
width: integerAttribute('width')
},
namespace: NS_AVATAR_METADATA
},
{
aliases: [
{
multiple: true,
path: 'avatar.pointers',
selector: NS_AVATAR_METADATA
}
],
element: 'pointer',
fields: {
bytes: integerAttribute('bytes'),
height: integerAttribute('height'),
id: attribute('id'),
mediaType: attribute('type'),
uri: attribute('url'),
width: integerAttribute('width')
},
namespace: NS_AVATAR_METADATA
}
];
export default Protocol;