annotate plugins/roster.js @ 109:cd1f57661439 default tip

Fix files permissions.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 01 Aug 2012 23:18:03 +0200
parents 5cb4733c5189
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 /**
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 */
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 //////////
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 //Roster//
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 //////////
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
22 Lightstring.plugins['roster'] = {
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
23 namespaces: {
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
24 roster: 'jabber:iq:roster'
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
25 },
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
26 stanzas: {
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
27 'get': function() {
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
28 return "<iq type='get'>" +
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
29 "<query xmlns='" + Lightstring.ns.roster + "'/>" +
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
30 "</iq>";
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
31 },
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
32 add: function(aAddress, aGroups) {
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
33 var iq = "<iq type='set'>" +
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
34 "<query xmlns='" + Lightstring.ns.roster + "'>" +
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
35 "<item jid='" + aAddress + "'/>" +
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
36 "</query>" +
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
37 "</iq>";
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
38 for (var i = 0; i < aGroups.length; i++) {
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
39 if (i === 0)
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
40 iq.querySelector('item').appendChild(document.createElement('group'));
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
41 iq.querySelector('group').appendChild(document.createElement(aGroups[i]));
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
42 }
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
43 return iq;
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
44 },
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
45 remove: function(aAddress) {
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
46 return "<iq type='set'>" +
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
47 "<query xmlns='" + Lightstring.ns.roster + "'>" +
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
48 "<item jid='" + aAddress + "' subscription='remove'/>" +
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
49 "</query>" +
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
50 "</iq>";
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
51 }
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 },
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
53 methods: {
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 88
diff changeset
54 'get': function(aOnSuccess, aOnError) {
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
55 this.send(Lightstring.stanzas.roster.get(), function(stanza) {
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
56 var contacts = [];
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
57
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 88
diff changeset
58 var items = stanza.el.getElementsByTagName('item');
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
59
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
60 for (var i = 0; i < items.length; i++) {
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
61 var item = items[i];
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
62 var contact = {}
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
63
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
64 var jid = item.getAttribute('jid');
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
65 if (jid)
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
66 contact.jid = jid;
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
67
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
68 var name = item.getAttribute('name');
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
69 if (name)
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
70 contact.name = name;
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
71
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
72 var subscription = item.getAttribute('subscription');
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
73 if (subscription)
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
74 contact.subscription = subscription;
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
75
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
76 var ask = item.getAttribute('ask');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
77 if (ask)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
78 contact.ask = ask;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
79
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
80 var groups = item.getElementsByTagName('group');
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
81 if(groups) {
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
82 contact.groups = [];
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
83 for (var y = 0; y < groups.length; y++)
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
84 contact.groups.push(groups[y].textContent);
52
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
85 }
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
86
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
87 contacts.push(contact);
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
88 }
48e2bd6b1885 Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
89
88
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
90 stanza.roster = {
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
91 contacts: contacts
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
92 };
595be4a8584f fix the roster plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 52
diff changeset
93
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 88
diff changeset
94 if (aOnSuccess)
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 88
diff changeset
95 aOnSuccess(stanza);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 88
diff changeset
96 }, aOnError);
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 }
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 }
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 };