Comparison

mod_pubsub_text_interface/mod_pubsub_text_interface.lua @ 3293:f728c8c42860

mod_pubsub_text_interface: Add a 'last' command for sending the last item
author Kim Alvefur <zash@zash.se>
date Fri, 31 Aug 2018 21:16:45 +0200
parent 3250:5801b5cf8f54
child 3328:7d39ffd058d5
comparison
equal deleted inserted replaced
3292:42dac034b2e0 3293:f728c8c42860
11 11
12 - `help` - this help message 12 - `help` - this help message
13 - `list` - list available nodes 13 - `list` - list available nodes
14 - `subscribe node` - subscribe to a node 14 - `subscribe node` - subscribe to a node
15 - `unsubscribe node` - unsubscribe from a node 15 - `unsubscribe node` - unsubscribe from a node
16 - `last node` - send the last item (again)
16 ]]; 17 ]];
17 18
18 module:hook("message/host", function (event) 19 module:hook("message/host", function (event)
19 local origin, stanza = event.origin, event.stanza; 20 local origin, stanza = event.origin, event.stanza;
20 local body = stanza:get_child_text("body"); 21 local body = stanza:get_child_text("body");
45 local ok, err = pubsub:add_subscription(node_arg, from, jid.bare(from), { ["pubsub#include_body"] = true }); 46 local ok, err = pubsub:add_subscription(node_arg, from, jid.bare(from), { ["pubsub#include_body"] = true });
46 reply:body(ok and "OK" or err); 47 reply:body(ok and "OK" or err);
47 elseif command == "unsubscribe" then 48 elseif command == "unsubscribe" then
48 local ok, err = pubsub:remove_subscription(node_arg, from, jid.bare(from)); 49 local ok, err = pubsub:remove_subscription(node_arg, from, jid.bare(from));
49 reply:body(ok and "OK" or err); 50 reply:body(ok and "OK" or err);
51 elseif command == "last" then
52 local ok, item_id, item = pubsub:get_last_item(node_arg, from);
53 if not ok then
54 reply:body(item_id); -- err message
55 elseif not item_id then
56 reply:body("node is empty");
57 else
58 pubsub.config.broadcaster("items", node_arg, {
59 [from] = { ["pubsub#include_body"] = true }
60 }, item);
61 reply:body("OK");
62 end
50 else 63 else
51 reply:body("Unknown command. `help` to list commands."); 64 reply:body("Unknown command. `help` to list commands.");
52 end 65 end
53 origin.send(reply); 66 origin.send(reply);
54 return true; 67 return true;