Mercurial > eldonilo > lightstring
annotate plugins.js @ 27:b6e4bc19ff5a
undoing
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Sat, 28 Jan 2012 01:27:00 +0100 |
parents | fc577e5b2f4a 82bffc4a07a9 |
children | 630b9579fe4a |
rev | line source |
---|---|
0 | 1 'use strict'; |
2 | |
2 | 3 /** |
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net> | |
5 | |
6 Permission to use, copy, modify, and/or distribute this software for any | |
7 purpose with or without fee is hereby granted, provided that the above | |
8 copyright notice and this permission notice appear in all copies. | |
9 | |
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
16 | 19 //////////// |
20 //Presence// http://xmpp.org/rfcs/rfc6121.html#presence | |
21 //////////// | |
22 Lightstring.stanza.presence = function(aPriority) { | |
23 if(aPriority) | |
24 return "<presence><priority>"+aPriority+"</priority></presence>"; | |
25 else | |
26 return "<presence/>"; | |
27 }; | |
28 Lightstring.presence = function(aConnection, aPriority) { | |
29 aConnection.send(Lightstring.stanza.presence(aPriority)); | |
30 }; | |
31 | |
7 | 32 ////////// |
33 //Roster// | |
34 ////////// | |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
35 Lightstring.NS.roster = 'jabber:iq:roster'; |
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
36 Lightstring.stanza.roster = { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
37 'get': function() { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
38 return "<iq type='get'><query xmlns='"+Lightstring.NS.roster+"'/></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
39 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
40 add: function(aAddress, aGroups, aCustomName) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
41 var iq = $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress}).tree(); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
42 if(aCustomName) iq.querySelector('item').setAttribute(aCustomName); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
43 for (var i=0; i<aGroups.length; i++) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
44 if(i === 0) iq.querySelector('item').appendChild(document.createElement('group')); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
45 iq.querySelector('group').appendChild(document.createElement(aGroups[i])); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
46 } |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
47 return iq; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
48 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
49 remove: function(aAddress) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
50 return $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress, subscription: 'remove'}).tree(); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
51 } |
0 | 52 }; |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
53 Lightstring.getRoster = function(connection, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
54 connection.send(this.stanza.roster.get(), function(answer){ |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
55 var contacts = []; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
56 var elems = answer.querySelectorAll('item'); |
8 | 57 for(var i = 0; i<elms.length; i++) { |
58 var item = elms[i]; | |
7 | 59 var jid = item.getAttribute('jid'); |
60 var name = item.getAttribute('name'); | |
61 var groups = item.querySelectorAll('group'); | |
62 var subscription = item.getAttribute('subscription'); | |
63 var contact = {}; | |
64 if(name) | |
65 contact.name = name; | |
66 if(jid) | |
67 contact.jid = jid; | |
68 if(subscription) | |
69 contact.subscription = subscription; | |
70 if(groups.length > 0) { | |
71 contact.groups = []; | |
72 groups.forEach(function(group) { | |
73 contact.groups.push(group.textContent); | |
74 }); | |
75 } | |
0 | 76 |
7 | 77 contacts.push(contact); |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
78 }; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
79 aCallback(contacts); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
80 }); |
0 | 81 } |
7 | 82 ///////// |
83 //vCard// | |
84 ///////// | |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
85 Lightstring.NS.vcard = 'vcard-temp'; |
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
86 Lightstring.stanza.vcard = { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
87 'get': function(aTo) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
88 if(aTo) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
89 return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
90 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
91 return "<iq type='get'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
92 } |
0 | 93 }; |
94 //FIXME we should return a proper vcard, not an XMPP one | |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
95 Lightstring.getVcard = function(aConnection, aTo, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
96 aConnection.send(Lightstring.stanza.vcard.get(aTo), function(answer, err){ |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
97 if(answer) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
98 var vcard = answer.querySelector('vCard'); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
99 if(vcard) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
100 aCallback(vcard); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
101 } |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
102 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
103 aCallback(null); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
104 }); |
0 | 105 } |
7 | 106 ///////// |
107 //Disco// | |
108 ///////// | |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
109 Lightstring.NS['disco#info'] = "http://jabber.org/protocol/disco#info"; |
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
110 Lightstring.NS['disco#items'] = "http://jabber.org/protocol/disco#items"; |
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
111 Lightstring.stanza.disco = { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
112 items: function(aTo, aNode) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
113 if(aTo) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
114 var iq = "<iq type='get' to='"+aTo+"'>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
115 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
116 var iq = "<iq type='get'>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
117 |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
118 if(aNode) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
119 var query = "<query xmlns='"+Lightstring.NS['disco#items']+"' node='"+aNode+"'/>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
120 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
121 var query = "<query xmlns='"+Lightstring.NS['disco#items']+"'/>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
122 |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
123 return iq+query+"</iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
124 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
125 info: function(aTo, aNode) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
126 if(aTo) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
127 var iq = "<iq type='get' to='"+aTo+"'>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
128 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
129 var iq = "<iq type='get'>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
130 if(aNode) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
131 var query = "<query xmlns='"+Lightstring.NS['disco#info']+"' node='"+aNode+"'/>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
132 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
133 var query = "<query xmlns='"+Lightstring.NS['disco#info']+"'/>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
134 |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
135 return iq+query+"</iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
136 } |
0 | 137 }; |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
138 Lightstring.discoItems = function(aConnection, aTo, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
139 aConnection.send(Lightstring.stanza.disco.items(aTo), function(answer){ |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
140 var items = []; |
8 | 141 var elms = answer.querySelectorAll('item'); |
142 for(var i = 0; i < elms.length; i++) { | |
143 var node = elms[i]; | |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
144 var item = { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
145 jid: node.getAttribute('jid'), |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
146 name: node.getAttribute('name'), |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
147 node: node.getAttribute('node') |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
148 } |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
149 items.push(item); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
150 }; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
151 if(aCallback) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
152 aCallback(items); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
153 }); |
0 | 154 }; |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
155 Lightstring.discoInfo = function(aConnection, aTo, aNode, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
156 aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(answer){ |
26
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
157 var identities = []; |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
158 var features = []; |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
159 |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
160 var children = answer.firstChild.children; |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
161 var length = children.length; |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
162 |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
163 for (var i = 0; i < length; i++) { |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
164 var child = children[i]; |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
165 |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
166 if (child.localName === 'feature') |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
167 features.push(child.getAttributeNS(null, 'var')); |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
168 |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
169 else if (child.localName === 'identity') { |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
170 var identity = { |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
171 category: child.getAttributeNS(null, 'category'), |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
172 type: child.getAttributeNS(null, 'type') |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
173 }; |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
174 var name = child.getAttributeNS(null, 'name'); |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
175 if (name) |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
176 identity.name = name; |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
177 identities.push(identity); |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
178 } |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
179 } |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
180 |
82bffc4a07a9
Fix disco info.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
20
diff
changeset
|
181 aCallback({identities: identities, features: features}); |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
182 }); |
0 | 183 }; |
7 | 184 ////////// |
185 //PubSub// | |
186 ////////// | |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
187 Lightstring.NS.x = "jabber:x:data"; |
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
188 Lightstring.NS.pubsub = "http://jabber.org/protocol/pubsub"; |
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
189 Lightstring.NS.pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
190 Lightstring.stanza.pubsub = { |
27 | 191 <<<<<<< HEAD |
0 | 192 getConfig: function(aTo, aNode) { |
2 | 193 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><configure node='"+aNode+"'/></pubsub></iq>"; |
0 | 194 }, |
195 items: function(aTo, aNode) { | |
2 | 196 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><items node='"+aNode+"'/></pubsub></iq>"; |
0 | 197 }, |
198 affiliations: function(aTo, aNode) { | |
2 | 199 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'/></pubsub></iq>"; |
0 | 200 }, |
201 publish: function(aTo, aNode, aItem, aId) { | |
2 | 202 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><publish node='"+aNode+"'><item id='"+aId+"'>"+aItem+"</item></publish></pubsub></iq>"; |
0 | 203 }, |
204 retract: function(aTo, aNode, aItem) { | |
2 | 205 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><retract node='"+aNode+"'><item id='"+aItem+"'/></retract></pubsub></iq>"; |
0 | 206 }, |
207 'delete': function(aTo, aNode, aURI) { | |
2 | 208 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><delete node='"+aNode+"'/></pubsub></iq>"; |
0 | 209 }, |
19
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
210 config: function(aTo, aNode, aFields) { |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
211 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><configure node='"+aNode+"'><x xmlns='"+Lightstring.NS.x+"' type='submit'>"; |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
212 if(aFields) { |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
213 aFields.forEach(function(field) { |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
214 iq += field; |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
215 }); |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
216 } |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
217 iq += "</x></configure></pubsub></iq>"; |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
218 return iq; |
fc577e5b2f4a
add pusbub config plugins
Sonny Piers <sonny.piers@gmail.com>
parents:
16
diff
changeset
|
219 }, |
0 | 220 create: function(aTo, aNode, aFields) { |
2 | 221 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><create node='"+aNode+"'/>"; |
0 | 222 if(aFields) { |
2 | 223 iq += "<configure><x xmlns='"+Lightstring.NS.x+"' type='submit'>" |
0 | 224 aFields.forEach(function(field) { |
225 iq += field; | |
226 }); | |
227 iq += "</x></configure>"; | |
228 } | |
229 iq += "</pubsub></iq>"; | |
230 return iq; | |
231 }, | |
232 setAffiliations: function(aTo, aNode, aAffiliations) { | |
2 | 233 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'>"; |
0 | 234 for(var i = 0; i < aAffiliations.length; i++) { |
235 iq += "<affiliation jid='"+aAffiliations[i][0]+"' affiliation='"+aAffiliations[i][1]+"'/>" | |
236 } | |
237 iq += "</affiliations></pubsub></iq>"; | |
238 return iq; | |
239 }, | |
27 | 240 ======= |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
241 getConfig: function(aTo, aNode) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
242 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><configure node='"+aNode+"'/></pubsub></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
243 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
244 items: function(aTo, aNode) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
245 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><items node='"+aNode+"'/></pubsub></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
246 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
247 affiliations: function(aTo, aNode) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
248 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'/></pubsub></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
249 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
250 publish: function(aTo, aNode, aItem, aId) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
251 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><publish node='"+aNode+"'><item id='"+aId+"'>"+aItem+"</item></publish></pubsub></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
252 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
253 retract: function(aTo, aNode, aItem) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
254 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><retract node='"+aNode+"'><item id='"+aItem+"'/></retract></pubsub></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
255 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
256 'delete': function(aTo, aNode, aURI) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
257 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><delete node='"+aNode+"'/></pubsub></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
258 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
259 create: function(aTo, aNode, aFields) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
260 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><create node='"+aNode+"'/>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
261 if(aFields) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
262 iq += "<configure><x xmlns='"+Lightstring.NS.x+"' type='submit'>" |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
263 aFields.forEach(function(field) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
264 iq += field; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
265 }); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
266 iq += "</x></configure>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
267 } |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
268 iq += "</pubsub></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
269 return iq; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
270 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
271 setAffiliations: function(aTo, aNode, aAffiliations) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
272 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
273 for(var i = 0; i < aAffiliations.length; i++) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
274 iq += "<affiliation jid='"+aAffiliations[i][0]+"' affiliation='"+aAffiliations[i][1]+"'/>" |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
275 } |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
276 iq += "</affiliations></pubsub></iq>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
277 return iq; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
278 }, |
27 | 279 >>>>>>> f6a7c0f93d154c2cd34dfdda4ab8eec808b91b34 |
0 | 280 }; |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
281 Lightstring.pubsubItems = function(aConnection, aTo, aNode, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
282 aConnection.send(Lightstring.stanza.pubsub.items(aTo, aNode), function(answer){ |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
283 var items = []; |
8 | 284 var elms = answer.querySelectorAll('item'); |
285 for(var i = 0; i < elms.length; i++) { | |
286 var node = elms[i]; | |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
287 var item = { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
288 id: node.getAttribute('id'), |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
289 name: node.querySelector('title').textContent, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
290 src: node.querySelector('content').getAttribute('src'), |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
291 type: node.querySelector('content').getAttribute('type'), |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
292 } |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
293 var miniature = node.querySelector('link'); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
294 if(miniature) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
295 item.miniature = miniature.getAttribute('href'); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
296 items.push(item); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
297 }; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
298 if(aCallback) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
299 aCallback(items); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
300 }); |
0 | 301 } |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
302 Lightstring.pubsubCreate = function(aConnection, aTo, aNode, aFields, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
303 aConnection.send(Lightstring.stanza.pubsub.create(aTo, aNode, aFields), function(answer) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
304 if(answer.getAttribute('type') === 'result') |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
305 aCallback(null, answer); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
306 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
307 aCallback(answer, null); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
308 }); |
0 | 309 }; |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
310 Lightstring.pubsubConfig = function(aConnection, aTo, aNode, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
311 aConnection.send(Lightstring.stanza.pubsub.getConfig(aTo, aNode), function(answer){ |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
312 var accessmodel = answer.querySelector('field[var="pubsub#access_model"]').lastChild.textContent; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
313 if(accessmodel) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
314 aCallback(accessmodel); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
315 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
316 aCallback(null); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
317 }); |
0 | 318 } |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
319 Lightstring.pubsubRetract = function(aConnection, aTo, aNode, aItem, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
320 aConnection.send(Lightstring.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){ |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
321 if(aCallback) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
322 aCallback(answer); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
323 }); |
0 | 324 } |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
325 Lightstring.pubsubPublish = function(aConnection, aTo, aNode, aItem, aId, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
326 aConnection.send(Lightstring.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){ |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
327 if(answer.getAttribute('type') === 'result') |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
328 aCallback(null, answer); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
329 else |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
330 aCallback(answer, null); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
331 }); |
0 | 332 } |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
333 Lightstring.pubsubDelete = function(aConnection, aTo, aNode, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
334 aConnection.send(Lightstring.stanza.pubsub.delete(aTo, aNode), function(answer){ |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
335 if(aCallback) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
336 aCallback(answer); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
337 }); |
0 | 338 } |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
339 Lightstring.pubsubGetAffiliations = function(aConnection, aTo, aNode, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
340 aConnection.send(Lightstring.stanza.pubsub.affiliations(aTo, aNode), function(answer) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
341 if((answer.getAttribute('type') === 'result') && aCallback) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
342 var affiliations = {}; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
343 answer.querySelectorAll('affiliation').forEach(function(affiliation) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
344 affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation"); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
345 }) |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
346 aCallback(affiliations); |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
347 } |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
348 }); |
0 | 349 }; |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
350 Lightstring.pubsubSetAffiliations = function(aConnection, aTo, aNode, aAffiliations, aCallback) { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
351 aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations)); |
0 | 352 }; |
7 | 353 ////// |
354 //IM// | |
355 ////// | |
3
029c12b8f048
various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents:
2
diff
changeset
|
356 Lightstring.stanza.message = { |
20
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
357 normal: function(aTo, aSubject, aText) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
358 return "<message type='normal' to='"+aTo+"'><subject>"+aSubject+"</subject><body>"+aText+"</body></message>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
359 }, |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
360 chat: function(aTo, aText) { |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
361 return "<message type='chat' to='"+aTo+"'><body>"+aText+"</body></message>"; |
7fcccf59e6ec
Always use two-spaces indent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
16
diff
changeset
|
362 } |
0 | 363 }; |
364 |