Comparison

mod_pubsub_text_interface/mod_pubsub_text_interface.lua @ 4041:cb5ea9d25cb2

mod_pubsub_text_interface: Hint at possible commands using XEP-0439: Quick Response
author Kim Alvefur <zash@zash.se>
date Wed, 10 Jun 2020 12:15:11 +0200
parent 3644:9980ea72ff91
child 4042:78ac5500a844
comparison
equal deleted inserted replaced
4040:e17c937a71b3 4041:cb5ea9d25cb2
2 local jid = require "util.jid"; 2 local jid = require "util.jid";
3 local id = require "util.id"; 3 local id = require "util.id";
4 4
5 local pubsub = module:depends "pubsub".service; 5 local pubsub = module:depends "pubsub".service;
6 6
7 local xmlns_quick_resp = "urn:xmpp:tmp:quick-response";
7 local name = module:get_option_string("name", "PubSub Service on "..module.host); 8 local name = module:get_option_string("name", "PubSub Service on "..module.host);
8 local help = name..[[ 9 local help = name..[[
9 10
10 Commands: 11 Commands:
11 12
31 local command, node_arg = body:match("^(%a+)%s+(.*)"); 32 local command, node_arg = body:match("^(%a+)%s+(.*)");
32 command = (command or body):lower(); 33 command = (command or body):lower();
33 34
34 if command == "help" then 35 if command == "help" then
35 reply:body(help); 36 reply:body(help);
37 reply:tag("response", { xmlns = xmlns_quick_resp, value = "list", }):up();
38 reply:tag("response", { xmlns = xmlns_quick_resp, value = "subscriptions", }):up();
36 elseif command == "list" then 39 elseif command == "list" then
37 local ok, nodes = pubsub:get_nodes(from); 40 local ok, nodes = pubsub:get_nodes(from);
38 if ok then 41 if ok then
39 local list = {}; 42 local list = {};
40 for node, node_obj in pairs(nodes) do 43 for node, node_obj in pairs(nodes) do
52 reply:body("You are not subscribed to anything from this pubsub service"); 55 reply:body("You are not subscribed to anything from this pubsub service");
53 else 56 else
54 local response = {}; 57 local response = {};
55 for i = 1, #subs do 58 for i = 1, #subs do
56 response[i] = string.format("- `%s`", subs[i].node); 59 response[i] = string.format("- `%s`", subs[i].node);
60 reply:tag("response", { xmlns = xmlns_quick_resp, value = "unsubscribe "..subs[i].node, }):up();
61 reply:tag("response", { xmlns = xmlns_quick_resp, value = "last "..subs[i].node, }):up();
57 end 62 end
58 reply:body(table.concat(response, "\n")); 63 reply:body(table.concat(response, "\n"));
59 end 64 end
60 elseif command == "subscribe" then 65 elseif command == "subscribe" then
61 local ok, err = pubsub:add_subscription(node_arg, from, jid.bare(from), { ["pubsub#include_body"] = true }); 66 local ok, err = pubsub:add_subscription(node_arg, from, jid.bare(from), { ["pubsub#include_body"] = true });
75 }, item); 80 }, item);
76 reply:body("OK"); 81 reply:body("OK");
77 end 82 end
78 else 83 else
79 reply:body("Unknown command. `help` to list commands."); 84 reply:body("Unknown command. `help` to list commands.");
85 reply:tag("response", { xmlns = xmlns_quick_resp, value = "help", }):up();
80 end 86 end
81 reply:reset(); 87 reply:reset();
82 88
83 if stanza:get_child("request", "urn:xmpp:receipts") then 89 if stanza:get_child("request", "urn:xmpp:receipts") then
84 reply:tag("received", { xmlns = "urn:xmpp:receipts", id = stanza.attr.id }):up(); 90 reply:tag("received", { xmlns = "urn:xmpp:receipts", id = stanza.attr.id }):up();