Merge 0.10->trunk
[prosody.git] / plugins / mod_announce.lua
index 2adb6253ac36e2e0c7d23d50c8b947eaf78a7bf6..9327556c5e1b8354dbf3680d07700a0aecee6807 100644 (file)
@@ -1,20 +1,20 @@
 -- Prosody IM
 -- Copyright (C) 2008-2010 Matthew Wild
 -- Copyright (C) 2008-2010 Waqas Hussain
--- 
+--
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
 
-local st, jid, set = require "util.stanza", require "util.jid", require "util.set";
+local st, jid = require "util.stanza", require "util.jid";
 
+local hosts = prosody.hosts;
 local is_admin = require "core.usermanager".is_admin;
-local admins = set.new(config.get(module:get_host(), "core", "admins"));
 
-function send_to_online(message, server)
+function send_to_online(message, host)
        local sessions;
-       if server then
-               sessions = { [server] = hosts[server] };
+       if host then
+               sessions = { [host] = hosts[host] };
        else
                sessions = hosts;
        end
@@ -26,7 +26,7 @@ function send_to_online(message, server)
                        for username in pairs(host_session.sessions) do
                                c = c + 1;
                                message.attr.to = username.."@"..hostname;
-                               core_post_stanza(host_session, message);
+                               module:send(message);
                        end
                end
        end
@@ -36,26 +36,25 @@ end
 
 
 -- Old <message>-based jabberd-style announcement sending
-function handle_announcement(data)
-       local origin, stanza = data.origin, data.stanza;
-       local host, resource = select(2, jid.split(stanza.attr.to));
-       
+function handle_announcement(event)
+       local origin, stanza = event.origin, event.stanza;
+       local node, host, resource = jid.split(stanza.attr.to);
+
        if resource ~= "announce/online" then
                return; -- Not an announcement
        end
-       
+
        if not is_admin(stanza.attr.from) then
                -- Not an admin? Not allowed!
-               module:log("warn", "Non-admin %s tried to send server announcement", tostring(jid.bare(stanza.attr.from)));
+               module:log("warn", "Non-admin '%s' tried to send server announcement", stanza.attr.from);
                return;
        end
-       
+
        module:log("info", "Sending server announcement to all online users");
-       local host_session = hosts[host];
        local message = st.clone(stanza);
        message.attr.type = "headline";
        message.attr.from = host;
-       
+
        local c = send_to_online(message, host);
        module:log("info", "Announcement sent to %d online users", c);
        return true;
@@ -84,13 +83,13 @@ function announce_handler(self, data, state)
                module:log("info", "Sending server announcement to all online users");
                local message = st.message({type = "headline"}, fields.announcement):up()
                        :tag("subject"):text(fields.subject or "Announcement");
-               
+
                local count = send_to_online(message, data.to);
-               
+
                module:log("info", "Announcement sent to %d online users", count);
                return { status = "completed", info = ("Announcement sent to %d online users"):format(count) };
        else
-               return { status = "executing", form = announce_layout }, "executing";
+               return { status = "executing", actions = {"next", "complete", default = "complete"}, form = announce_layout }, "executing";
        end
 
        return true;
@@ -98,5 +97,5 @@ end
 
 local adhoc_new = module:require "adhoc".new;
 local announce_desc = adhoc_new("Send Announcement to Online Users", "http://jabber.org/protocol/admin#announce", announce_handler, "admin");
-module:add_item("adhoc", announce_desc);
+module:provides("adhoc", announce_desc);