util.pubsub
util.pubsub
implements an abstract pubsub service
along the lines of XEP-0060.
The module itself exposes a single constructor function,
new()
, which takes table with configuration and returns a
service instance.
Usage
Example usage from a module:
local st = require "util.stanza";
local pubsub_service = module:depends("pubsub").service;
local node_name = "example";
function module.load()
:create(node_name, true);
pubsub_serviceend
function module.unload()
:delete(node_name, true);
pubsub_serviceend
:hook("message/host", function (event)
modulelocal stanza, origin = event.stanza, event.origin;
local id = "current";
local item = st.stanza("item", { id = id });
:add_child(event.stanza); -- the message
item:publish(node_name, true, id, item);
pubsub_service.send(st.reply(stanza):tag("body"):text("Your message has been published"));
originreturn true;
end);
Service methods
The service has bunch of methods:
:jids_equal(jid1, jid2)
service:may(node, actor, action)
service:set_affiliation(node, actor, jid, affiliation)
service:add_subscription(node, actor, jid, options)
service:remove_subscription(node, actor, jid)
service:remove_all_subscriptions(actor, jid)
service:get_subscription(node, actor, jid)
service:create(node, actor, options)
service:delete(node, actor)
service:publish(node, actor, id, item)
service:retract(node, actor, id, retract)
service:purge(node, actor, notify)
service:get_items(node, actor, id)
service:get_nodes(actor)
service:get_subscriptions(node, actor, jid)
service:set_node_capabilities(node, actor, capabilities)
service:set_node_config(node, actor, new_config) service
These mostly correspond to XEP-0060 actions.