annotate plugins/pubsub.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 c06ec02217ee
children
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 //PubSub//
715726598b23 improvements on plugins
Sonny Piers <sonny.piers@gmail.com>
parents: 3
diff changeset
21 //////////
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
22 (function() {
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
23 var event_tags = ['collection', 'configuration', 'delete', 'items', 'purge', 'subscription'];
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
24
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
25 Lightstring.plugins['pubsub'] = {
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
26 namespaces: {
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
27 x: "jabber:x:data", //XXX
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
28 pubsub: "http://jabber.org/protocol/pubsub",
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
29 pubsub_owner: "http://jabber.org/protocol/pubsub#owner",
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
30 pubsub_event: "http://jabber.org/protocol/pubsub#event",
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
31 pubsub_error: "http://jabber.org/protocol/pubsub#error"
53
d1a7895b3dce Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
32 },
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
33 stanzas: {
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
34 getConfig: function(aTo, aNode) {
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 75
diff changeset
35 return "<iq type='get' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub_owner + "'><configure node='" + aNode + "'/></pubsub></iq>";
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
36 },
96
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
37 items: function(aTo, aNode, aItems) {
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
38 var stanza = "<iq type='get' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub + "'><items node='" + aNode + "'>";
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
39 if (aItems) {
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
40 aItems.forEach(function(item) {
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
41 stanza += "<item id='" + item + "'/>"
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
42 });
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
43 }
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
44 return stanza + "</items></pubsub></iq>";
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
45 },
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
46 affiliations: function(aTo, aNode) {
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 96
diff changeset
47 return(
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 96
diff changeset
48 "<iq type='get' to='" + aTo + "'>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 96
diff changeset
49 "<pubsub xmlns='" + Lightstring.ns.pubsub_owner + "'>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 96
diff changeset
50 "<affiliations node='" + aNode + "'/>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 96
diff changeset
51 "</pubsub>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 96
diff changeset
52 "</iq>"
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 96
diff changeset
53 );
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
54 },
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
55 publish: function(aTo, aNode, aItem, aId) {
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 75
diff changeset
56 return "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub + "'><publish node='" + aNode + "'><item id='" + aId + "'>" + aItem + "</item></publish></pubsub></iq>";
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
57 },
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
58 retract: function(aTo, aNode, aItem) {
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 75
diff changeset
59 return "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub + "'><retract node='" + aNode + "'><item id='" + aItem + "'/></retract></pubsub></iq>";
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
60 },
89
Sonny Piers <sonny.piers@gmail.com>
parents: 87
diff changeset
61 delete: function(aTo, aNode) {
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 75
diff changeset
62 return "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub_owner + "'><delete node='" + aNode + "'/></pubsub></iq>";
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
63 },
89
Sonny Piers <sonny.piers@gmail.com>
parents: 87
diff changeset
64 purge: function(aTo, aNode) {
Sonny Piers <sonny.piers@gmail.com>
parents: 87
diff changeset
65 return "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub_owner + "'><purge node='" + aNode + "'/></pubsub></iq>";
Sonny Piers <sonny.piers@gmail.com>
parents: 87
diff changeset
66 },
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
67 create: function(aTo, aNode, aFields) {
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 75
diff changeset
68 var iq = "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub + "'><create node='" + aNode + "'/>";
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
69 if (aFields) {
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 75
diff changeset
70 iq += "<configure><x xmlns='" + Lightstring.ns.x + "' type='submit'>"
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
71 aFields.forEach(function(field) {
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
72 iq += field;
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
73 });
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
74 iq += "</x></configure>";
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
75 }
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
76 iq += "</pubsub></iq>";
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
77 return iq;
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
78 },
90
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
79 setConfig: function(aTo, aNode, aFields) {
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
80 var iq = "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub_owner + "'><configure node='" + aNode + "'><x xmlns='" + Lightstring.ns.x + "' type='submit'>";
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
81 aFields.forEach(function(field) {
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
82 iq += field;
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
83 });
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
84 iq += "</x></configure></pubsub></iq>";
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
85 return iq;
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
86 },
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
87 setAffiliations: function(aTo, aNode, aAffiliations) {
80
50d36b093e3a Lightstring.namespaces/NS has been renamed by Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 75
diff changeset
88 var iq = "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.ns.pubsub_owner + "'><affiliations node='" + aNode + "'>";
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
89 for (var i = 0; i < aAffiliations.length; i++)
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
90 iq += "<affiliation jid='" + aAffiliations[i][0] + "' affiliation='" + aAffiliations[i][1] + "'/>";
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
91 iq += "</affiliations></pubsub></iq>";
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
92 return iq;
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
93 },
53
d1a7895b3dce Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
94 },
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
95 methods: {
96
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
96 items: function(aTo, aNode, aItems, aOnSuccess, aOnError) {
646695bde8e9 better pubsub.items method
Sonny Piers <sonny.piers@gmail.com>
parents: 95
diff changeset
97 this.send(Lightstring.stanzas.pubsub.items(aTo, aNode, aItems), function(stanza) {
95
7affe7ac8fc7 fix the items method on the PubSub plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 90
diff changeset
98 var items = stanza.DOM.querySelectorAll('item') || [];
87
0f6f213f0a33 Makes the PubSub items method to return the stanza object.
Sonny Piers <sonny.piers@gmail.com>
parents: 86
diff changeset
99 stanza.items = items;
95
7affe7ac8fc7 fix the items method on the PubSub plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 90
diff changeset
100 if (aOnSuccess)
7affe7ac8fc7 fix the items method on the PubSub plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 90
diff changeset
101 aOnSuccess(stanza);
7affe7ac8fc7 fix the items method on the PubSub plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 90
diff changeset
102 }, aOnError);
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
103 },
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
104 create: function(aTo, aNode, aFields, aResult, aError) {
86
0c10c9a69c69 Lightstring.stanza has been renamed to Lightstring.stanzas.
Sonny Piers <sonny.piers@gmail.com>
parents: 84
diff changeset
105 this.send(Lightstring.stanzas.pubsub.create(aTo, aNode, aFields), aResult, aError);
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
106 },
90
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
107 configure: function(aTo, aNode, aFields, aResult, aError) {
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
108 this.send(Lightstring.stanzas.pubsub.setConfig(aTo, aNode, aFields), aResult, aError);
c1566c6981e5 Pubsub configure stanza and method
Sonny Piers <sonny.piers@gmail.com>
parents: 89
diff changeset
109 },
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
110 config: function(aTo, aNode, aResult, aError) {
86
0c10c9a69c69 Lightstring.stanza has been renamed to Lightstring.stanzas.
Sonny Piers <sonny.piers@gmail.com>
parents: 84
diff changeset
111 this.send(Lightstring.stanzas.pubsub.getConfig(aTo, aNode), function(stanza) {
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
112 //FIXME: wtf?
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
113 var accessmodel = stanza.DOM.querySelector('field[var="pubsub#access_model"]').lastChild.textContent;
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
114 if(accessmodel)
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
115 aResult, aError(accessmodel);
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
116 else
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
117 aResult, aError(null);
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
118 });
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
119 },
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
120 retract: function(aTo, aNode, aItem, aResult, aError) {
86
0c10c9a69c69 Lightstring.stanza has been renamed to Lightstring.stanzas.
Sonny Piers <sonny.piers@gmail.com>
parents: 84
diff changeset
121 this.send(Lightstring.stanzas.pubsub.retract(aTo, aNode, aItem), aResult, aError);
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
122 },
74
7cb0037bf43c Fix a little typo error.
Sonny Piers <sonny.piers@gmail.com>
parents: 61
diff changeset
123 publish: function(aTo, aNode, aItem, aId, aResult, aError) {
86
0c10c9a69c69 Lightstring.stanza has been renamed to Lightstring.stanzas.
Sonny Piers <sonny.piers@gmail.com>
parents: 84
diff changeset
124 this.send(Lightstring.stanzas.pubsub.publish(aTo, aNode, aItem, aId), aResult, aError);
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
125 },
89
Sonny Piers <sonny.piers@gmail.com>
parents: 87
diff changeset
126 delete: function(aTo, aNode, aResult, aError) {
86
0c10c9a69c69 Lightstring.stanza has been renamed to Lightstring.stanzas.
Sonny Piers <sonny.piers@gmail.com>
parents: 84
diff changeset
127 this.send(Lightstring.stanzas.pubsub.delete(aTo, aNode), aResult, aError);
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
128 },
89
Sonny Piers <sonny.piers@gmail.com>
parents: 87
diff changeset
129 purge: function(aTo, aNode, aResult, aError) {
Sonny Piers <sonny.piers@gmail.com>
parents: 87
diff changeset
130 this.send(Lightstring.stanzas.pubsub.purge(aTo, aNode), aResult, aError);
Sonny Piers <sonny.piers@gmail.com>
parents: 87
diff changeset
131 },
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
132 getAffiliations: function(aTo, aNode, aResult, aError) {
86
0c10c9a69c69 Lightstring.stanza has been renamed to Lightstring.stanzas.
Sonny Piers <sonny.piers@gmail.com>
parents: 84
diff changeset
133 this.send(Lightstring.stanzas.pubsub.affiliations(aTo, aNode), function(stanza) {
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
134 if((stanza.DOM.getAttribute('type') === 'result') && aResult, aError) {
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
135 var affiliations = {};
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
136 stanza.DOM.querySelectorAll('affiliation').forEach(function(affiliation) {
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
137 affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation");
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
138 })
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
139 if (aResult)
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
140 aResult(affiliations);
53
d1a7895b3dce Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
141 }
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
142 }, aError);
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
143 },
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
144 setAffiliations: function(aTo, aNode, aAffiliations, aResult, aError) {
86
0c10c9a69c69 Lightstring.stanza has been renamed to Lightstring.stanzas.
Sonny Piers <sonny.piers@gmail.com>
parents: 84
diff changeset
145 this.send(Lightstring.stanzas.pubsub.setAffiliations(aTo, aNode, aAffiliations), aResult, aError);
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
146 }
53
d1a7895b3dce Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
147 },
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
148 init: function() {
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
149 //TODO: find a way to put that in handlers, it’s UGLY!
75
619f3ffa125a Lightstring.namespaces has been renamed to Lightstring.ns.
Sonny Piers <sonny.piers@gmail.com>
parents: 74
diff changeset
150 this.on('in-message-*-' + Lightstring.ns['pubsub_event'] + ':event', function(stanza) {
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
151 var payload = stanza.firstChild.firstChild; //XXX
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
152 if (payload.namespaceURI !== Lightstring.namespaces['pubsub_event'])
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
153 return; //TODO: emit something.
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
154
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
155 var name = payload.localName;
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
156 if (event_tags.indexOf(name) === -1)
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
157 return; //TODO: emit something.
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
158
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
159 this.emit('pubsub:' + name);
53
d1a7895b3dce Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
160 });
d1a7895b3dce Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
161 }
61
d1ba6f0e2a92 Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 53
diff changeset
162 };
84
7f4e43d6cb15 My mistake.
Sonny Piers <sonny.piers@gmail.com>
parents: 83
diff changeset
163 })();