forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfc6121.ts
118 lines (111 loc) · 3.47 KB
/
rfc6121.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
107
108
109
110
111
112
113
114
115
116
117
118
// ====================================================================
// RFC 6121: Extensible Messaging and Presence Protocol (XMPP):
// Instant Messaging and Presence
// --------------------------------------------------------------------
// Source: https://tools.ietf.org/html/rfc6121
// ====================================================================
import { MessageType, PresenceShow, PresenceType, RosterSubscription } from '../Constants';
import {
attribute,
booleanAttribute,
childAlternateLanguageText,
childAttribute,
childBoolean,
childInteger,
childText,
DefinitionOptions,
extendMessage,
extendPresence,
extendStreamFeatures,
JIDAttribute,
LanguageSet,
multipleChildText
} from '../jxt';
import { NS_ROSTER, NS_ROSTER_VERSIONING, NS_SUBSCRIPTION_PREAPPROVAL } from '../Namespaces';
declare module './' {
export interface StreamFeatures {
rosterVersioning?: boolean;
rosterPreApproval?: boolean;
}
export interface Message {
type?: MessageType;
body?: string;
alternateLanguageBodies?: LanguageSet<string>;
alternateLanguageSubjects?: LanguageSet<string>;
hasSubject?: boolean;
subject?: string;
thread?: string;
parentThread?: string;
}
export interface Presence {
type?: PresenceType;
show?: PresenceShow;
status?: string;
alternateLanguageStatuses?: LanguageSet<string>;
priority?: number;
}
export interface IQPayload {
roster?: Roster;
}
}
export interface Roster {
version?: string;
items?: RosterItem[];
}
export interface RosterResult extends Roster {
items: RosterItem[];
}
export interface RosterItem {
jid: string;
name?: string;
subscription: RosterSubscription;
pending?: 'subscribe';
preApproved?: boolean;
ask?: boolean;
groups?: string[];
}
const Protocol: DefinitionOptions[] = [
extendStreamFeatures({
rosterPreApproval: childBoolean(NS_SUBSCRIPTION_PREAPPROVAL, 'sub'),
rosterVersioning: childBoolean(NS_ROSTER_VERSIONING, 'ver')
}),
extendMessage({
alternateLanguageBodies: childAlternateLanguageText(null, 'body'),
alternateLanguageSubjects: childAlternateLanguageText(null, 'subject'),
body: childText(null, 'body'),
hasSubject: childBoolean(null, 'subject'),
parentThread: childAttribute(null, 'thread', 'parent'),
subject: childText(null, 'subject'),
thread: childText(null, 'thread'),
type: attribute('type')
}),
extendPresence({
alternateLanguageStatuses: childAlternateLanguageText(null, 'status'),
priority: childInteger(null, 'priority', 0),
show: childText(null, 'show'),
status: childText(null, 'status'),
type: attribute('type')
}),
{
element: 'query',
fields: {
version: attribute('ver', undefined, { emitEmpty: true })
},
namespace: NS_ROSTER,
path: 'iq.roster'
},
{
aliases: [{ path: 'iq.roster.items', multiple: true }],
element: 'item',
fields: {
groups: multipleChildText(null, 'group'),
jid: JIDAttribute('jid'),
name: attribute('name'),
pending: attribute('ask'),
preApproved: booleanAttribute('approved'),
subscription: attribute('subscription')
},
namespace: NS_ROSTER
}
];
export default Protocol;