Mercurial > eldonilo > lightstring
annotate plugins/pubsub.js @ 74:7cb0037bf43c
Fix a little typo error.
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Mon, 06 Feb 2012 17:36:39 +0100 |
parents | d1ba6f0e2a92 |
children | 619f3ffa125a |
rev | line source |
---|---|
0 | 1 'use strict'; |
2 | |
2 | 3 /** |
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net> | |
5 | |
6 Permission to use, copy, modify, and/or distribute this software for any | |
7 purpose with or without fee is hereby granted, provided that the above | |
8 copyright notice and this permission notice appear in all copies. | |
9 | |
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
7 | 19 ////////// |
20 //PubSub// | |
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) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
35 return "<iq type='get' to='" + aTo + "'><pubsub xmlns='" + Lightstring.NS.pubsub_owner + "'><configure node='" + aNode + "'/></pubsub></iq>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
36 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
37 items: function(aTo, aNode) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
38 return "<iq type='get' to='" + aTo + "'><pubsub xmlns='" + Lightstring.NS.pubsub + "'><items node='" + aNode + "'/></pubsub></iq>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
39 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
40 affiliations: function(aTo, aNode) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
41 return "<iq type='get' to='" + aTo + "'><pubsub xmlns='" + Lightstring.NS.pubsub_owner + "'><affiliations node='" + aNode + "'/></pubsub></iq>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
42 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
43 publish: function(aTo, aNode, aItem, aId) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
44 return "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.NS.pubsub + "'><publish node='" + aNode + "'><item id='" + aId + "'>" + aItem + "</item></publish></pubsub></iq>"; |
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 retract: function(aTo, aNode, aItem) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
47 return "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.NS.pubsub + "'><retract node='" + aNode + "'><item id='" + aItem + "'/></retract></pubsub></iq>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
48 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
49 'delete': function(aTo, aNode, aURI) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
50 return "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.NS.pubsub_owner + "'><delete node='" + aNode + "'/></pubsub></iq>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
51 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
52 create: function(aTo, aNode, aFields) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
53 var iq = "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.NS.pubsub + "'><create node='" + aNode + "'/>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
54 if (aFields) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
55 iq += "<configure><x xmlns='" + Lightstring.NS.x + "' type='submit'>" |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
56 aFields.forEach(function(field) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
57 iq += field; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
58 }); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
59 iq += "</x></configure>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
60 } |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
61 iq += "</pubsub></iq>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
62 return iq; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
63 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
64 setAffiliations: function(aTo, aNode, aAffiliations) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
65 var iq = "<iq type='set' to='" + aTo + "'><pubsub xmlns='" + Lightstring.NS.pubsub_owner + "'><affiliations node='" + aNode + "'>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
66 for (var i = 0; i < aAffiliations.length; i++) |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
67 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
|
68 iq += "</affiliations></pubsub></iq>"; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
69 return iq; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
70 }, |
53
d1a7895b3dce
Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
71 }, |
61
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
72 methods: { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
73 items: function(aTo, aNode, aResult, aError) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
74 this.send(Lightstring.stanza.pubsub.items(aTo, aNode), function(stanza) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
75 var items = []; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
76 var elms = stanza.DOM.querySelectorAll('item'); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
77 for (var i = 0; i < elms.length; i++) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
78 var node = elms[i]; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
79 var item = { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
80 id: node.getAttribute('id'), |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
81 name: node.querySelector('title').textContent, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
82 src: node.querySelector('content').getAttribute('src'), |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
83 type: node.querySelector('content').getAttribute('type'), |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
84 } |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
85 var miniature = node.querySelector('link'); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
86 if (miniature) |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
87 item.miniature = miniature.getAttribute('href'); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
88 items.push(item); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
89 }; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
90 |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
91 if (aResult) |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
92 aResult(items); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
93 }, aError); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
94 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
95 create: function(aTo, aNode, aFields, aResult, aError) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
96 this.send(Lightstring.stanza.pubsub.create(aTo, aNode, aFields), aResult, aError); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
97 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
98 config: function(aTo, aNode, aResult, aError) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
99 this.send(Lightstring.stanza.pubsub.getConfig(aTo, aNode), function(stanza) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
100 //FIXME: wtf? |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
101 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
|
102 if(accessmodel) |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
103 aResult, aError(accessmodel); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
104 else |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
105 aResult, aError(null); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
106 }); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
107 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
108 retract: function(aTo, aNode, aItem, aResult, aError) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
109 this.send(Lightstring.stanza.pubsub.retract(aTo, aNode, aItem), aResult, aError); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
110 }, |
74
7cb0037bf43c
Fix a little typo error.
Sonny Piers <sonny.piers@gmail.com>
parents:
61
diff
changeset
|
111 publish: function(aTo, aNode, aItem, aId, aResult, aError) { |
61
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
112 this.send(Lightstring.stanza.pubsub.publish(aTo, aNode, aItem, aId), aResult, aError); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
113 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
114 'delete': function(aTo, aNode, aResult, aError) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
115 this.send(Lightstring.stanza.pubsub.delete(aTo, aNode), aResult, aError); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
116 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
117 getAffiliations: function(aTo, aNode, aResult, aError) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
118 this.send(Lightstring.stanza.pubsub.affiliations(aTo, aNode), function(stanza) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
119 if((stanza.DOM.getAttribute('type') === 'result') && aResult, aError) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
120 var affiliations = {}; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
121 stanza.DOM.querySelectorAll('affiliation').forEach(function(affiliation) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
122 affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation"); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
123 }) |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
124 if (aResult) |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
125 aResult(affiliations); |
53
d1a7895b3dce
Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
126 } |
61
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
127 }, aError); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
128 }, |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
129 setAffiliations: function(aTo, aNode, aAffiliations, aResult, aError) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
130 this.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations), aResult, aError); |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
131 } |
53
d1a7895b3dce
Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
132 }, |
61
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
133 init: function() { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
134 //TODO: find a way to put that in handlers, it’s UGLY! |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
135 this.on('in-message-*-' + Lightstring.namespaces['pubsub_event'] + ':event', function(stanza) { |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
136 var payload = stanza.firstChild.firstChild; //XXX |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
137 if (payload.namespaceURI !== Lightstring.namespaces['pubsub_event']) |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
138 return; //TODO: emit something. |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
139 |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
140 var name = payload.localName; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
141 if (event_tags.indexOf(name) === -1) |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
142 return; //TODO: emit something. |
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 this.emit('pubsub:' + name); |
53
d1a7895b3dce
Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
145 }); |
d1a7895b3dce
Fix PubSub plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
146 } |
61
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
147 }; |
d1ba6f0e2a92
Add PubSub events emitter.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
53
diff
changeset
|
148 })(); |