comparison plugins.js @ 7:715726598b23

improvements on plugins
author Sonny Piers <sonny.piers@gmail.com>
date Sun, 15 Jan 2012 01:25:11 +0100
parents 029c12b8f048
children 08a8d8c4c324
comparison
equal deleted inserted replaced
6:b7a582a2b32c 7:715726598b23
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 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 15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19 NodeList.prototype.forEach = function(aCallback) { 19 //////////
20 for(var i = 0; i<this.length; i++) 20 //Roster//
21 aCallback(this[i]); 21 //////////
22 }
23
24
25 //
26 //Roster
27 //
28 Lightstring.NS.roster = 'jabber:iq:roster'; 22 Lightstring.NS.roster = 'jabber:iq:roster';
29 Lightstring.stanza.roster = { 23 Lightstring.stanza.roster = {
30 'get': function() { 24 'get': function() {
31 return "<iq type='get'><query xmlns='"+Lightstring.NS.roster+"'/></iq>"; 25 return "<iq type='get'><query xmlns='"+Lightstring.NS.roster+"'/></iq>";
32 }, 26 },
44 } 38 }
45 }; 39 };
46 Lightstring.getRoster = function(connection, aCallback) { 40 Lightstring.getRoster = function(connection, aCallback) {
47 connection.send(this.stanza.roster.get(), function(answer){ 41 connection.send(this.stanza.roster.get(), function(answer){
48 var contacts = []; 42 var contacts = [];
49 answer.querySelectorAll('item').forEach(function(item) { 43 var items = answer.querySelectorAll('item');
50 var jid = item.getAttribute('jid'); 44 for(var i = 0; i<items.length; i++) {
51 var name = item.getAttribute('name'); 45 var item = items[i];
52 var groups = item.querySelectorAll('group'); 46 var jid = item.getAttribute('jid');
53 var subscription = item.getAttribute('subscription'); 47 var name = item.getAttribute('name');
54 var contact = {}; 48 var groups = item.querySelectorAll('group');
55 if(name) 49 var subscription = item.getAttribute('subscription');
56 contact.name = name; 50 var contact = {};
57 if(jid) 51 if(name)
58 contact.jid = jid; 52 contact.name = name;
59 if(subscription) 53 if(jid)
60 contact.subscription = subscription; 54 contact.jid = jid;
61 if(groups.length > 0) { 55 if(subscription)
62 contact.groups = []; 56 contact.subscription = subscription;
63 groups.forEach(function(group) { 57 if(groups.length > 0) {
64 contact.groups.push(group.textContent); 58 contact.groups = [];
65 }); 59 groups.forEach(function(group) {
66 } 60 contact.groups.push(group.textContent);
67 61 });
68 contacts.push(contact); 62 }
69 }); 63
64 contacts.push(contact);
65 };
70 aCallback(contacts); 66 aCallback(contacts);
71 }); 67 });
72 } 68 }
73 // 69 /////////
74 //vCard 70 //vCard//
75 // 71 /////////
76 Lightstring.NS.vcard = 'vcard-temp'; 72 Lightstring.NS.vcard = 'vcard-temp';
77 Lightstring.stanza.vcard = { 73 Lightstring.stanza.vcard = {
78 'get': function(aTo) { 74 'get': function(aTo) {
79 if(aTo) 75 if(aTo)
80 return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>"; 76 return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
92 } 88 }
93 else 89 else
94 aCallback(null); 90 aCallback(null);
95 }); 91 });
96 } 92 }
97 // 93 /////////
98 //Disco 94 //Disco//
99 // 95 /////////
100 Lightstring.NS['disco#info'] = "http://jabber.org/protocol/disco#info"; 96 Lightstring.NS['disco#info'] = "http://jabber.org/protocol/disco#info";
101 Lightstring.NS['disco#items'] = "http://jabber.org/protocol/disco#items"; 97 Lightstring.NS['disco#items'] = "http://jabber.org/protocol/disco#items";
102 Lightstring.stanza.disco = { 98 Lightstring.stanza.disco = {
103 items: function(aTo, aNode) { 99 items: function(aTo, aNode) {
104 if(aTo) 100 if(aTo)
147 var creator = field ? field.textContent : ''; 143 var creator = field ? field.textContent : '';
148 //FIXME callback the entire data 144 //FIXME callback the entire data
149 aCallback(creator); 145 aCallback(creator);
150 }); 146 });
151 }; 147 };
152 // 148 //////////
153 //PubSub 149 //PubSub//
154 // 150 //////////
155 Lightstring.NS.x = "jabber:x:data"; 151 Lightstring.NS.x = "jabber:x:data";
156 Lightstring.NS.pubsub = "http://jabber.org/protocol/pubsub"; 152 Lightstring.NS.pubsub = "http://jabber.org/protocol/pubsub";
157 Lightstring.NS.pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; 153 Lightstring.NS.pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
158 Lightstring.stanza.pubsub = { 154 Lightstring.stanza.pubsub = {
159 getConfig: function(aTo, aNode) { 155 getConfig: function(aTo, aNode) {
263 }); 259 });
264 }; 260 };
265 Lightstring.pubsubSetAffiliations = function(aConnection, aTo, aNode, aAffiliations, aCallback) { 261 Lightstring.pubsubSetAffiliations = function(aConnection, aTo, aNode, aAffiliations, aCallback) {
266 aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations)); 262 aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations));
267 }; 263 };
268 // 264 //////
269 //IM 265 //IM//
270 // 266 //////
271 Lightstring.stanza.message = { 267 Lightstring.stanza.message = {
272 normal: function(aTo, aSubject, aText) { 268 normal: function(aTo, aSubject, aText) {
273 return "<message type='normal' to='"+aTo+"'><subject>"+aSubject+"</subject><body>"+aText+"</body></message>"; 269 return "<message type='normal' to='"+aTo+"'><subject>"+aSubject+"</subject><body>"+aText+"</body></message>";
274 }, 270 },
275 chat: function(aTo, aText) { 271 chat: function(aTo, aText) {