Comparison

mod_pubsub_text_interface/mod_pubsub_text_interface.lua @ 3328:7d39ffd058d5

mod_pubsub_text_interface: Handle lack of `pubsub:get_last_item` in Prosody 0.10
author Kim Alvefur <zash@zash.se>
date Sun, 23 Sep 2018 16:43:03 +0200
parent 3293:f728c8c42860
child 3429:1f0c290bd28a
comparison
equal deleted inserted replaced
3327:3af2da030397 3328:7d39ffd058d5
10 Commands: 10 Commands:
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 if pubsub.get_last_item then -- COMPAT not available in 0.10
17 ]]; 17 help = help .. "\n- `last node` - send the last item (again)"
18 end
18 19
19 module:hook("message/host", function (event) 20 module:hook("message/host", function (event)
20 local origin, stanza = event.origin, event.stanza; 21 local origin, stanza = event.origin, event.stanza;
21 local body = stanza:get_child_text("body"); 22 local body = stanza:get_child_text("body");
22 if not body then return end -- bail out 23 if not body then return end -- bail out
46 local ok, err = pubsub:add_subscription(node_arg, from, jid.bare(from), { ["pubsub#include_body"] = true }); 47 local ok, err = pubsub:add_subscription(node_arg, from, jid.bare(from), { ["pubsub#include_body"] = true });
47 reply:body(ok and "OK" or err); 48 reply:body(ok and "OK" or err);
48 elseif command == "unsubscribe" then 49 elseif command == "unsubscribe" then
49 local ok, err = pubsub:remove_subscription(node_arg, from, jid.bare(from)); 50 local ok, err = pubsub:remove_subscription(node_arg, from, jid.bare(from));
50 reply:body(ok and "OK" or err); 51 reply:body(ok and "OK" or err);
51 elseif command == "last" then 52 elseif command == "last" and pubsub.get_last_item then
52 local ok, item_id, item = pubsub:get_last_item(node_arg, from); 53 local ok, item_id, item = pubsub:get_last_item(node_arg, from);
53 if not ok then 54 if not ok then
54 reply:body(item_id); -- err message 55 reply:body(item_id); -- err message
55 elseif not item_id then 56 elseif not item_id then
56 reply:body("node is empty"); 57 reply:body("node is empty");