Mon, 05 Dec 2011 15:44:17 +0000
doc/example*.lua: Update to use new .init() method
250 | 1 | local verse = require "verse"; |
114
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | local xmlns_pubsub_event = xmlns_pubsub.."#event"; |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | function verse.plugins.pep(stream) |
216
3aac084855e6
plugins.pep: Reuse the pubsub plugin.
Kim Alvefur <zash@zash.se>
parents:
164
diff
changeset
|
7 | stream:add_plugin("pubsub"); |
114
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | stream.pep = {}; |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | |
216
3aac084855e6
plugins.pep: Reuse the pubsub plugin.
Kim Alvefur <zash@zash.se>
parents:
164
diff
changeset
|
10 | stream:hook("pubsub/event", function(event) |
232
5b49de3aa0f3
plugins.pep: Set item to the first tag instead of first child.
Kim Alvefur <zash@zash.se>
parents:
216
diff
changeset
|
11 | return stream:event("pep/"..event.node, { from = event.from, item = event.item.tags[1] } ); |
114
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | end); |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | function stream:hook_pep(node, callback, priority) |
164
d862093d9f91
plugins.pep: Only add +notify feature if there weren't any handlers for it already
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
15 | local handlers = stream.events._handlers["pep/"..node]; |
d862093d9f91
plugins.pep: Only add +notify feature if there weren't any handlers for it already
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
16 | if not(handlers) or #handlers == 0 then |
d862093d9f91
plugins.pep: Only add +notify feature if there weren't any handlers for it already
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
17 | stream:add_disco_feature(node.."+notify"); |
d862093d9f91
plugins.pep: Only add +notify feature if there weren't any handlers for it already
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
18 | end |
114
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | stream:hook("pep/"..node, callback, priority); |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | end |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | function stream:unhook_pep(node, callback) |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | stream:unhook("pep/"..node, callback); |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | local handlers = stream.events._handlers["pep/"..node]; |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | if not(handlers) or #handlers == 0 then |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | stream:remove_disco_feature(node.."+notify"); |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | end |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | end |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | function stream:publish_pep(item, node) |
249
00891a675634
plugins.pep: Use the new PubSub api.
Kim Alvefur <zash@zash.se>
parents:
232
diff
changeset
|
31 | return stream.pubsub:service(nil):node(node or item.attr.xmlns):publish(nil, nil, item) |
114
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | end |
37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | end |