Annotate

plugins/pep.lua @ 445:b119dc4d8bc2

plugins.smacks: Don't warn about zero stanzas acked It's only if the count somehow goes backwards that something is really wrong. An ack for zero stanzas is fine and we don't need to do anything.
author Kim Alvefur <zash@zash.se>
date Thu, 10 Jun 2021 11:58:23 +0200
parent 415:37674f8ce263
child 470:e690759c5072
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 249
diff changeset
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)
268
06e6c6de6438 plugins.pep: Load disco, since PEP depends on it
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
7 stream:add_plugin("disco");
216
3aac084855e6 plugins.pep: Reuse the pubsub plugin.
Kim Alvefur <zash@zash.se>
parents: 164
diff changeset
8 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
9 stream.pep = {};
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 268
diff changeset
10
216
3aac084855e6 plugins.pep: Reuse the pubsub plugin.
Kim Alvefur <zash@zash.se>
parents: 164
diff changeset
11 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
12 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
13 end);
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 268
diff changeset
14
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
15 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
16 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
17 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
18 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
19 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
20 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
21 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 268
diff changeset
22
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
23 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
24 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
25 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
26 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
27 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
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 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 268
diff changeset
30
415
37674f8ce263 verse.plugins.pep: Support taking an item id, default to "current"
Kim Alvefur <zash@zash.se>
parents: 380
diff changeset
31 function stream:publish_pep(item, node, id)
37674f8ce263 verse.plugins.pep: Support taking an item id, default to "current"
Kim Alvefur <zash@zash.se>
parents: 380
diff changeset
32 return stream.pubsub:service(nil):node(node or item.attr.xmlns):publish(id or "current", 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
33 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
34 end