annotate plugins.js @ 15:521962f10743

better list of supported browsers
author Sonny Piers <sonny.piers@gmail.com>
date Sun, 15 Jan 2012 15:31:59 +0100
parents 08a8d8c4c324
children 6707f450549e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
1 'use strict';
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
2
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
3 /**
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
5
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
8 copyright notice and this permission notice appear in all copies.
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
9
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
17 */
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
18
7
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
19 //////////
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
20 //Roster//
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
21 //////////
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
22 Lightstring.NS.roster = 'jabber:iq:roster';
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
23 Lightstring.stanza.roster = {
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
24 'get': function() {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
25 return "<iq type='get'><query xmlns='"+Lightstring.NS.roster+"'/></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
26 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
27 add: function(aAddress, aGroups, aCustomName) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
28 var iq = $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress}).tree();
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
29 if(aCustomName) iq.querySelector('item').setAttribute(aCustomName);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
30 for (var i=0; i<aGroups.length; i++) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
31 if(i === 0) iq.querySelector('item').appendChild(document.createElement('group'));
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
32 iq.querySelector('group').appendChild(document.createElement(aGroups[i]));
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
33 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
34 return iq;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
35 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
36 remove: function(aAddress) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
37 return $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress, subscription: 'remove'}).tree();
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
38 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
39 };
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
40 Lightstring.getRoster = function(connection, aCallback) {
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
41 connection.send(this.stanza.roster.get(), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
42 var contacts = [];
8
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
43 var elems = answer.querySelectorAll('item');
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
44 for(var i = 0; i<elms.length; i++) {
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
45 var item = elms[i];
7
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
46 var jid = item.getAttribute('jid');
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
47 var name = item.getAttribute('name');
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
48 var groups = item.querySelectorAll('group');
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
49 var subscription = item.getAttribute('subscription');
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
50 var contact = {};
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
51 if(name)
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
52 contact.name = name;
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
53 if(jid)
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
54 contact.jid = jid;
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
55 if(subscription)
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
56 contact.subscription = subscription;
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
57 if(groups.length > 0) {
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
58 contact.groups = [];
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
59 groups.forEach(function(group) {
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
60 contact.groups.push(group.textContent);
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
61 });
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
62 }
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
63
7
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
64 contacts.push(contact);
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
65 };
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
66 aCallback(contacts);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
67 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
68 }
7
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
69 /////////
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
70 //vCard//
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
71 /////////
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
72 Lightstring.NS.vcard = 'vcard-temp';
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
73 Lightstring.stanza.vcard = {
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
74 'get': function(aTo) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
75 if(aTo)
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
76 return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
77 else
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
78 return "<iq type='get'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
79 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
80 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
81 //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
82 Lightstring.getVcard = function(aConnection, aTo, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
83 aConnection.send(Lightstring.stanza.vcard.get(aTo), function(answer, err){
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
84 if(answer) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
85 var vcard = answer.querySelector('vCard');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
86 if(vcard)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
87 aCallback(vcard);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
88 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
89 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
90 aCallback(null);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
91 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
92 }
7
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
93 /////////
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
94 //Disco//
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
95 /////////
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
96 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
97 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
98 Lightstring.stanza.disco = {
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
99 items: function(aTo, aNode) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
100 if(aTo)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
101 var iq = "<iq type='get' to='"+aTo+"'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
102 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
103 var iq = "<iq type='get'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
104
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
105 if(aNode)
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
106 var query = "<query xmlns='"+Lightstring.NS['disco#items']+"' node='"+aNode+"'/>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
107 else
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
108 var query = "<query xmlns='"+Lightstring.NS['disco#items']+"'/>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
109
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
110 return iq+query+"</iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
111 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
112 info: function(aTo, aNode) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
113 if(aTo)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
114 var iq = "<iq type='get' to='"+aTo+"'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
115 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
116 var iq = "<iq type='get'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
117 if(aNode)
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
118 var query = "<query xmlns='"+Lightstring.NS['disco#info']+"' node='"+aNode+"'/>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
119 else
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
120 var query = "<query xmlns='"+Lightstring.NS['disco#info']+"'/>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
121
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
122 return iq+query+"</iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
123 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
124 };
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
125 Lightstring.discoItems = function(aConnection, aTo, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
126 aConnection.send(Lightstring.stanza.disco.items(aTo), function(answer){
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
127 var items = [];
8
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
128 var elms = answer.querySelectorAll('item');
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
129 for(var i = 0; i < elms.length; i++) {
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
130 var node = elms[i];
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
131 var item = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
132 jid: node.getAttribute('jid'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
133 name: node.getAttribute('name'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
134 node: node.getAttribute('node')
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
135 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
136 items.push(item);
8
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
137 };
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
138 if(aCallback)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
139 aCallback(items);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
140 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
141 };
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
142 Lightstring.discoInfo = function(aConnection, aTo, aNode, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
143 aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(answer){
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
144 var field = answer.querySelector('field[var="pubsub#creator"] > value');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
145 var creator = field ? field.textContent : '';
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
146 //FIXME callback the entire data
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
147 aCallback(creator);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
148 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
149 };
7
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
150 //////////
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
151 //PubSub//
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
152 //////////
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
153 Lightstring.NS.x = "jabber:x:data";
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
154 Lightstring.NS.pubsub = "http://jabber.org/protocol/pubsub";
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
155 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
156 Lightstring.stanza.pubsub = {
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
157 getConfig: function(aTo, aNode) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
158 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><configure node='"+aNode+"'/></pubsub></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
159 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
160 items: function(aTo, aNode) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
161 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><items node='"+aNode+"'/></pubsub></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
162 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
163 affiliations: function(aTo, aNode) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
164 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'/></pubsub></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
165 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
166 publish: function(aTo, aNode, aItem, aId) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
167 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><publish node='"+aNode+"'><item id='"+aId+"'>"+aItem+"</item></publish></pubsub></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
168 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
169 retract: function(aTo, aNode, aItem) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
170 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><retract node='"+aNode+"'><item id='"+aItem+"'/></retract></pubsub></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
171 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
172 'delete': function(aTo, aNode, aURI) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
173 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><delete node='"+aNode+"'/></pubsub></iq>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
174 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
175 create: function(aTo, aNode, aFields) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
176 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><create node='"+aNode+"'/>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
177 if(aFields) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
178 iq += "<configure><x xmlns='"+Lightstring.NS.x+"' type='submit'>"
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
179 aFields.forEach(function(field) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
180 iq += field;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
181 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
182 iq += "</x></configure>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
183 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
184 iq += "</pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
185 return iq;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
186 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
187 setAffiliations: function(aTo, aNode, aAffiliations) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
188 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'>";
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
189 for(var i = 0; i < aAffiliations.length; i++) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
190 iq += "<affiliation jid='"+aAffiliations[i][0]+"' affiliation='"+aAffiliations[i][1]+"'/>"
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
191 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
192 iq += "</affiliations></pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
193 return iq;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
194 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
195 };
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
196 Lightstring.pubsubItems = function(aConnection, aTo, aNode, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
197 aConnection.send(Lightstring.stanza.pubsub.items(aTo, aNode), function(answer){
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
198 var items = [];
8
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
199 var elms = answer.querySelectorAll('item');
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
200 for(var i = 0; i < elms.length; i++) {
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
201 var node = elms[i];
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
202 var item = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
203 id: node.getAttribute('id'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
204 name: node.querySelector('title').textContent,
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
205 src: node.querySelector('content').getAttribute('src'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
206 type: node.querySelector('content').getAttribute('type'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
207 }
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
208 var miniature = node.querySelector('link');
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
209 if(miniature)
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
210 item.miniature = miniature.getAttribute('href');
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
211 items.push(item);
8
08a8d8c4c324 fixes on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 7
diff changeset
212 };
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
213 if(aCallback)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
214 aCallback(items);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
215 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
216 }
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
217 Lightstring.pubsubCreate = function(aConnection, aTo, aNode, aFields, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
218 aConnection.send(Lightstring.stanza.pubsub.create(aTo, aNode, aFields), function(answer) {
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
219 if(answer.getAttribute('type') === 'result')
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
220 aCallback(null, answer);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
221 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
222 aCallback(answer, null);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
223 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
224 };
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
225 Lightstring.pubsubConfig = function(aConnection, aTo, aNode, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
226 aConnection.send(Lightstring.stanza.pubsub.getConfig(aTo, aNode), function(answer){
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
227 var accessmodel = answer.querySelector('field[var="pubsub#access_model"]').lastChild.textContent;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
228 if(accessmodel)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
229 aCallback(accessmodel);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
230 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
231 aCallback(null);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
232 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
233 }
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
234 Lightstring.pubsubRetract = function(aConnection, aTo, aNode, aItem, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
235 aConnection.send(Lightstring.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
236 if(aCallback)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
237 aCallback(answer);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
238 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
239 }
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
240 Lightstring.pubsubPublish = function(aConnection, aTo, aNode, aItem, aId, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
241 aConnection.send(Lightstring.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
242 if(answer.getAttribute('type') === 'result')
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
243 aCallback(null, answer);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
244 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
245 aCallback(answer, null);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
246 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
247 }
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
248 Lightstring.pubsubDelete = function(aConnection, aTo, aNode, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
249 aConnection.send(Lightstring.stanza.pubsub.delete(aTo, aNode), function(answer){
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
250 if(aCallback)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
251 aCallback(answer);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
252 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
253 }
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
254 Lightstring.pubsubGetAffiliations = function(aConnection, aTo, aNode, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
255 aConnection.send(Lightstring.stanza.pubsub.affiliations(aTo, aNode), function(answer) {
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
256 if((answer.getAttribute('type') === 'result') && aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
257 var affiliations = {};
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
258 answer.querySelectorAll('affiliation').forEach(function(affiliation) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
259 affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation");
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
260 })
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
261 aCallback(affiliations);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
262 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
263 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
264 };
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
265 Lightstring.pubsubSetAffiliations = function(aConnection, aTo, aNode, aAffiliations, aCallback) {
2
f31a75c3b6c8 code cleaning
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
266 aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations));
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
267 };
7
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
268 //////
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
269 //IM//
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
270 //////
3
029c12b8f048 various bug fixes and improvements
Sonny Piers <sonny.piers@gmail.com>
parents: 2
diff changeset
271 Lightstring.stanza.message = {
0
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
272 normal: function(aTo, aSubject, aText) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
273 return "<message type='normal' to='"+aTo+"'><subject>"+aSubject+"</subject><body>"+aText+"</body></message>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
274 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
275 chat: function(aTo, aText) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
276 return "<message type='chat' to='"+aTo+"'><body>"+aText+"</body></message>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
277 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
278 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
279