Software /
code /
prosody
Comparison
plugins/adhoc/mod_adhoc.lua @ 5760:e599d9a367cf
mod_adhoc: Sort commands by node. This guarantees the order remains the same across restarts etc.
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Wed, 24 Jul 2013 22:08:07 +0200 (2013-07-24) |
parent | 4926:58714123f600 |
child | 5761:91f8cd53584c |
comparison
equal
deleted
inserted
replaced
5759:767e29b2cd3a | 5760:e599d9a367cf |
---|---|
4 -- This file is MIT/X11 licensed. Please see the | 4 -- This file is MIT/X11 licensed. Please see the |
5 -- COPYING file in the source package for more information. | 5 -- COPYING file in the source package for more information. |
6 -- | 6 -- |
7 | 7 |
8 local st = require "util.stanza"; | 8 local st = require "util.stanza"; |
9 local keys = require "util.iterators".keys; | |
10 local array_collect = require "util.array".collect; | |
9 local is_admin = require "core.usermanager".is_admin; | 11 local is_admin = require "core.usermanager".is_admin; |
10 local adhoc_handle_cmd = module:require "adhoc".handle_cmd; | 12 local adhoc_handle_cmd = module:require "adhoc".handle_cmd; |
11 local xmlns_cmd = "http://jabber.org/protocol/commands"; | 13 local xmlns_cmd = "http://jabber.org/protocol/commands"; |
12 local xmlns_disco = "http://jabber.org/protocol/disco"; | 14 local xmlns_disco = "http://jabber.org/protocol/disco"; |
13 local commands = {}; | 15 local commands = {}; |
54 local admin = is_admin(stanza.attr.from, stanza.attr.to); | 56 local admin = is_admin(stanza.attr.from, stanza.attr.to); |
55 local global_admin = is_admin(stanza.attr.from); | 57 local global_admin = is_admin(stanza.attr.from); |
56 reply = st.reply(stanza); | 58 reply = st.reply(stanza); |
57 reply:tag("query", { xmlns = xmlns_disco.."#items", | 59 reply:tag("query", { xmlns = xmlns_disco.."#items", |
58 node = xmlns_cmd }); | 60 node = xmlns_cmd }); |
59 for node, command in pairs(commands) do | 61 local nodes = array_collect(keys(commands)):sort(); |
62 for _, node in ipairs(nodes) do | |
63 local command = commands[node]; | |
60 if (command.permission == "admin" and admin) | 64 if (command.permission == "admin" and admin) |
61 or (command.permission == "global_admin" and global_admin) | 65 or (command.permission == "global_admin" and global_admin) |
62 or (command.permission == "user") then | 66 or (command.permission == "user") then |
63 reply:tag("item", { name = command.name, | 67 reply:tag("item", { name = command.name, |
64 node = node, jid = module:get_host() }); | 68 node = node, jid = module:get_host() }); |