Annotate

plugins/pep.lua @ 191:e0664081654c

plugins.presence: Fix priority setting. (Thanks Florob)
author Kim Alvefur <zash@zash.se>
date Mon, 07 Mar 2011 21:53:02 +0100
parent 164:d862093d9f91
child 216:3aac084855e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1
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 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
3 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
4
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 function verse.plugins.pep(stream)
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 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
7
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:hook("message", function (message)
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 local event = message:get_child("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
10 if not event then return; 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
11 local items = event:get_child("items");
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 if not items then return; 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 local node = items.attr.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
14 for item in items:childtags() do
37f5966cff15 verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 if item.name == "item" and item.attr.xmlns == xmlns_pubsub_event 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
16 stream:event("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
17 from = message.attr.from,
37f5966cff15 verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 item = item.tags[1],
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 });
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 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
22 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
23
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 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
25 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
26 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
27 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
28 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
29 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
30 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
31
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 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
33 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
34 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
35 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
36 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
37 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
38 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
39
37f5966cff15 verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 function stream:publish_pep(item, 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
41 local publish = verse.iq({ type = "set" })
37f5966cff15 verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 :tag("pubsub", { xmlns = xmlns_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
43 :tag("publish", { node = node or item.attr.xmlns })
37f5966cff15 verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 :tag("item")
37f5966cff15 verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 :add_child(item);
37f5966cff15 verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 return stream:send_iq(publish);
37f5966cff15 verse.plugins.pep: New plugin to add an API for sending and catching PEP events
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 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
48 end