comparison mod_pubsub_text_interface/mod_pubsub_text_interface.lua @ 3488:4ddb034a8a03

mod_pubsub_text_interface: Add command for listing current subscriptions
author Kim Alvefur <zash@zash.se>
date Fri, 15 Mar 2019 04:26:54 +0100
parents 1f0c290bd28a
children 33b3f02a9e7d
comparison
equal deleted inserted replaced
3487:e60933722248 3488:4ddb034a8a03
9 9
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 - `subscriptions` - list nodes you are subscribed to
14 - `subscribe node` - subscribe to a node 15 - `subscribe node` - subscribe to a node
15 - `unsubscribe node` - unsubscribe from a node]]; 16 - `unsubscribe node` - unsubscribe from a node]];
16 if pubsub.get_last_item then -- COMPAT not available in 0.10 17 if pubsub.get_last_item then -- COMPAT not available in 0.10
17 help = help .. "\n- `last node` - send the last item (again)" 18 help = help .. "\n- `last node` - send the last item (again)"
18 end 19 end
41 end 42 end
42 reply:body(table.concat(list, "\n")); 43 reply:body(table.concat(list, "\n"));
43 else 44 else
44 reply:body(nodes); 45 reply:body(nodes);
45 end 46 end
47 elseif command == "subscriptions" then
48 local ok, subs = pubsub:get_subscriptions(nil, from, from);
49 if not ok then
50 reply:body(subs);
51 elseif #subs == 0 then
52 reply:body("You are not subscribed to anything from this pubsub service");
53 else
54 local response = {};
55 for i = 1, #subs do
56 response[i] = string.format("- `%s`", subs[i].node);
57 end
58 reply:body(table.concat(response, "\n"));
59 end
46 elseif command == "subscribe" then 60 elseif command == "subscribe" then
47 local ok, err = pubsub:add_subscription(node_arg, from, jid.bare(from), { ["pubsub#include_body"] = true }); 61 local ok, err = pubsub:add_subscription(node_arg, from, jid.bare(from), { ["pubsub#include_body"] = true });
48 reply:body(ok and "OK" or err); 62 reply:body(ok and "OK" or err);
49 elseif command == "unsubscribe" then 63 elseif command == "unsubscribe" then
50 local ok, err = pubsub:remove_subscription(node_arg, from, jid.bare(from)); 64 local ok, err = pubsub:remove_subscription(node_arg, from, jid.bare(from));