annotate plugins.js @ 0:96898e3812a5

initial push
author Sonny Piers <sonny.piers@gmail.com>
date Sun, 18 Dec 2011 19:03:28 +0100
parents
children f31a75c3b6c8
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
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
3 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
4 //Roster
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
5 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
6 Lighstring.NS.roster = 'jabber:iq:roster';
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
7 Lighstring.stanza.roster = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
8 'get': function() {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
9 return "<iq type='get'><query xmlns='"+Mango.NS.roster+"'/></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
10 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
11 add: function(aAddress, aGroups, aCustomName) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
12 var iq = $iq({type: 'set'}).c('query', {xmlns: Mango.NS.roster}).c('item', {jid: aAddress}).tree();
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
13 if(aCustomName) iq.querySelector('item').setAttribute(aCustomName);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
14 for (var i=0; i<aGroups.length; i++) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
15 if(i === 0) iq.querySelector('item').appendChild(document.createElement('group'));
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
16 iq.querySelector('group').appendChild(document.createElement(aGroups[i]));
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
17 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
18 return iq;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
19 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
20 remove: function(aAddress) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
21 return $iq({type: 'set'}).c('query', {xmlns: Mango.NS.roster}).c('item', {jid: aAddress, subscription: 'remove'}).tree();
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
22 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
23 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
24 Lighstring.getRoster = function(connection, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
25 connection.send(this.stanza.roster.get(), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
26 var contacts = [];
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
27 answer.querySelectorAll('item').forEach(function(item) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
28 var jid = item.getAttribute('jid');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
29 var name = item.getAttribute('name');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
30 var groups = item.querySelectorAll('group');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
31 var subscription = item.getAttribute('subscription');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
32 var contact = {};
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
33 if(name)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
34 contact.name = name;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
35 if(jid)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
36 contact.jid = jid;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
37 if(subscription)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
38 contact.subscription = subscription;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
39 if(groups.length > 0) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
40 contact.groups = [];
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
41 groups.forEach(function(group) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
42 contact.groups.push(group.textContent);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
43 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
44 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
45
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
46 contacts.push(contact);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
47 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
48 aCallback(contacts);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
49 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
50 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
51 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
52 //vCard
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
53 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
54 Lighstring.NS.vcard = 'vcard-temp';
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
55 Lighstring.stanza.vcard = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
56 'get': function(aTo) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
57 if(aTo)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
58 return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Mango.NS.vcard+"'/></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
59 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
60 return "<iq type='get'><vCard xmlns='"+Mango.NS.vcard+"'/></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
61 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
62 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
63 //FIXME we should return a proper vcard, not an XMPP one
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
64 Lighstring.getVcard = function(aConnection, aTo, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
65 aConnection.send(Mango.stanza.vcard.get(aTo), function(answer, err){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
66 if(answer) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
67 var vcard = answer.querySelector('vCard');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
68 if(vcard)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
69 aCallback(vcard);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
70 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
71 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
72 aCallback(null);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
73 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
74 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
75 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
76 //Disco
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
77 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
78 Lighstring.NS['disco#info'] = "http://jabber.org/protocol/disco#info";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
79 Lighstring.NS['disco#items'] = "http://jabber.org/protocol/disco#items";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
80 Lighstring.stanza.disco = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
81 items: function(aTo, aNode) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
82 if(aTo)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
83 var iq = "<iq type='get' to='"+aTo+"'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
84 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
85 var iq = "<iq type='get'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
86
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
87 if(aNode)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
88 var query = "<query xmlns='"+Mango.NS['disco#items']+"' node='"+aNode+"'/>";
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 var query = "<query xmlns='"+Mango.NS['disco#items']+"'/>";
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 return iq+query+"</iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
93 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
94 info: function(aTo, aNode) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
95 if(aTo)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
96 var iq = "<iq type='get' to='"+aTo+"'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
97 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
98 var iq = "<iq type='get'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
99 if(aNode)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
100 var query = "<query xmlns='"+Mango.NS['disco#info']+"' node='"+aNode+"'/>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
101 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
102 var query = "<query xmlns='"+Mango.NS['disco#info']+"'/>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
103
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
104 return iq+query+"</iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
105 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
106 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
107 Lighstring.discoItems = function(aConnection, aTo, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
108 aConnection.send(Mango.stanza.disco.items(aTo), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
109 var items = [];
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
110 answer.querySelectorAll('item').forEach(function(node) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
111 var item = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
112 jid: node.getAttribute('jid'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
113 name: node.getAttribute('name'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
114 node: node.getAttribute('node')
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
115 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
116 items.push(item);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
117 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
118 if(aCallback)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
119 aCallback(items);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
120 });
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 Lighstring.discoInfo = function(aConnection, aTo, aNode, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
123 aConnection.send(Mango.stanza.disco.info(aTo, aNode), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
124 var field = answer.querySelector('field[var="pubsub#creator"] > value');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
125 var creator = field ? field.textContent : '';
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
126 //FIXME callback the entire data
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
127 aCallback(creator);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
128 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
129 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
130 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
131 //PubSub
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
132 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
133 Lighstring.NS.x = "jabber:x:data";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
134 Lighstring.NS.pubsub = "http://jabber.org/protocol/pubsub";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
135 Lighstring.NS.pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
136 Lighstring.stanza.pubsub = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
137 getConfig: function(aTo, aNode) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
138 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub_owner+"'><configure node='"+aNode+"'/></pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
139 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
140 items: function(aTo, aNode) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
141 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub+"'><items node='"+aNode+"'/></pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
142 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
143 affiliations: function(aTo, aNode) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
144 return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub_owner+"'><affiliations node='"+aNode+"'/></pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
145 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
146 publish: function(aTo, aNode, aItem, aId) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
147 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub+"'><publish node='"+aNode+"'><item id='"+aId+"'>"+aItem+"</item></publish></pubsub></iq>";
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 retract: function(aTo, aNode, aItem) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
150 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub+"'><retract node='"+aNode+"'><item id='"+aItem+"'/></retract></pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
151 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
152 'delete': function(aTo, aNode, aURI) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
153 return "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub_owner+"'><delete node='"+aNode+"'/></pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
154 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
155 create: function(aTo, aNode, aFields) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
156 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub+"'><create node='"+aNode+"'/>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
157 if(aFields) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
158 iq += "<configure><x xmlns='"+Mango.NS.x+"' type='submit'>"
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
159 aFields.forEach(function(field) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
160 iq += field;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
161 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
162 iq += "</x></configure>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
163 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
164 iq += "</pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
165 return iq;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
166 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
167 setAffiliations: function(aTo, aNode, aAffiliations) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
168 var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub_owner+"'><affiliations node='"+aNode+"'>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
169 for(var i = 0; i < aAffiliations.length; i++) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
170 iq += "<affiliation jid='"+aAffiliations[i][0]+"' affiliation='"+aAffiliations[i][1]+"'/>"
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 iq += "</affiliations></pubsub></iq>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
173 return iq;
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 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
176 Lighstring.pubsubItems = function(aConnection, aTo, aNode, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
177 aConnection.send(Mango.stanza.pubsub.items(aTo, aNode), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
178 var items = [];
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
179 answer.querySelectorAll('item').forEach(function(node) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
180 var item = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
181 id: node.getAttribute('id'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
182 name: node.querySelector('title').textContent,
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
183 src: node.querySelector('content').getAttribute('src'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
184 type: node.querySelector('content').getAttribute('type'),
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
185 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
186 var thumbnail = node.querySelector('link');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
187 if(thumbnail)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
188 item.thumbnail = thumbnail.getAttribute('href');
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
189 items.push(item);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
190 })
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
191 if(aCallback)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
192 aCallback(items);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
193 });
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 Lighstring.pubsubCreate = function(aConnection, aTo, aNode, aFields, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
196 aConnection.send(Mango.stanza.pubsub.create(aTo, aNode, aFields), function(answer) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
197 if(answer.getAttribute('type') === 'result')
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
198 aCallback(null, answer);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
199 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
200 aCallback(answer, null);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
201 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
202 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
203 Lighstring.pubsubConfig = function(aConnection, aTo, aNode, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
204 aConnection.send(Mango.stanza.pubsub.getConfig(aTo, aNode), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
205 var accessmodel = answer.querySelector('field[var="pubsub#access_model"]').lastChild.textContent;
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
206 if(accessmodel)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
207 aCallback(accessmodel);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
208 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
209 aCallback(null);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
210 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
211 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
212 Lighstring.pubsubRetract = function(aConnection, aTo, aNode, aItem, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
213 aConnection.send(Mango.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
214 if(aCallback)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
215 aCallback(answer);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
216 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
217 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
218 Lighstring.pubsubPublish = function(aConnection, aTo, aNode, aItem, aId, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
219 aConnection.send(Mango.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
220 if(answer.getAttribute('type') === 'result')
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
221 aCallback(null, answer);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
222 else
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
223 aCallback(answer, null);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
224 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
225 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
226 Lighstring.pubsubDelete = function(aConnection, aTo, aNode, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
227 aConnection.send(Mango.stanza.pubsub.delete(aTo, aNode), function(answer){
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
228 if(aCallback)
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
229 aCallback(answer);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
230 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
231 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
232 Lighstring.pubsubGetAffiliations = function(aConnection, aTo, aNode, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
233 aConnection.send(Mango.stanza.pubsub.affiliations(aTo, aNode), function(answer) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
234 if((answer.getAttribute('type') === 'result') && aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
235 var affiliations = {};
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
236 answer.querySelectorAll('affiliation').forEach(function(affiliation) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
237 affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation");
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 aCallback(affiliations);
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
240 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
241 });
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
242 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
243 Lighstring.pubsubSetAffiliations = function(aConnection, aTo, aNode, aAffiliations, aCallback) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
244 aConnection.send(Mango.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations));
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
245 };
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 //IM
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
248 //
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
249 Lighstring.stanza.message = {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
250 normal: function(aTo, aSubject, aText) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
251 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
252 },
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
253 chat: function(aTo, aText) {
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
254 return "<message type='chat' to='"+aTo+"'><body>"+aText+"</body></message>";
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
255 }
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
256 };
96898e3812a5 initial push
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
257