1 local st, jid, set = require "util.stanza", require "util.jid", require "util.set";
3 local is_admin = require "core.usermanager".is_admin;
4 local admins = set.new(config.get(module:get_host(), "core", "admins"));
6 function handle_announcement(data)
7 local origin, stanza = data.origin, data.stanza;
8 local host, resource = select(2, jid.split(stanza.attr.to));
10 if resource ~= "announce/online" then
11 return; -- Not an announcement
14 if not is_admin(stanza.attr.from) then
15 -- Not an admin? Not allowed!
16 module:log("warn", "Non-admin %s tried to send server announcement", tostring(jid.bare(stanza.attr.from)));
17 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
21 module:log("info", "Sending server announcement to all online users");
22 local host_session = hosts[host];
23 local message = st.clone(stanza);
24 message.attr.type = "headline";
25 message.attr.from = host;
28 for user in pairs(host_session.sessions) do
30 message.attr.to = user.."@"..host;
31 core_post_stanza(host_session, message);
34 module:log("info", "Announcement sent to %d online users", c);
38 module:hook("message/host", handle_announcement);