-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--
local st, jid = require "util.stanza", require "util.jid";
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--
local st, jid = require "util.stanza", require "util.jid";
local is_admin = require "core.usermanager".is_admin;
function send_to_online(message, host)
local is_admin = require "core.usermanager".is_admin;
function send_to_online(message, host)
function handle_announcement(event)
local origin, stanza = event.origin, event.stanza;
local node, host, resource = 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 not is_admin(stanza.attr.from) then
-- Not an admin? Not allowed!
module:log("warn", "Non-admin '%s' tried to send server announcement", stanza.attr.from);
return;
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", stanza.attr.from);
return;
end
module:log("info", "Sending server announcement to all online users");
local message = st.clone(stanza);
message.attr.type = "headline";
message.attr.from = host;
module:log("info", "Sending server announcement to all online users");
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;
local c = send_to_online(message, host);
module:log("info", "Announcement sent to %d online users", c);
return true;
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");
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");
module:log("info", "Announcement sent to %d online users", count);
return { status = "completed", info = ("Announcement sent to %d online users"):format(count) };
else
module:log("info", "Announcement sent to %d online users", count);
return { status = "completed", info = ("Announcement sent to %d online users"):format(count) };
else