plugins/mod_announce.lua

changeset 3278
5ca2ed58788f
parent 3276
4e44469b0583
equal deleted inserted replaced
3277:da0f55661e2b 3278:5ca2ed58788f
8 8
9 local st, jid = require "util.stanza", require "util.jid"; 9 local st, jid = require "util.stanza", require "util.jid";
10 10
11 local is_admin = require "core.usermanager".is_admin; 11 local is_admin = require "core.usermanager".is_admin;
12 12
13 function send_to_online(message, server) 13 function send_to_online(message, host)
14 local sessions; 14 local sessions;
15 if server then 15 if host then
16 sessions = { [server] = hosts[server] }; 16 sessions = { [host] = hosts[host] };
17 else 17 else
18 sessions = hosts; 18 sessions = hosts;
19 end 19 end
20 20
21 local c = 0; 21 local c = 0;
33 return c; 33 return c;
34 end 34 end
35 35
36 36
37 -- Old <message>-based jabberd-style announcement sending 37 -- Old <message>-based jabberd-style announcement sending
38 function handle_announcement(data) 38 function handle_announcement(event)
39 local origin, stanza = data.origin, data.stanza; 39 local origin, stanza = event.origin, event.stanza;
40 local host, resource = select(2, jid.split(stanza.attr.to)); 40 local node, host, resource = jid.split(stanza.attr.to);
41 41
42 if resource ~= "announce/online" then 42 if resource ~= "announce/online" then
43 return; -- Not an announcement 43 return; -- Not an announcement
44 end 44 end
45 45
46 if not is_admin(stanza.attr.from) then 46 if not is_admin(stanza.attr.from) then
47 -- Not an admin? Not allowed! 47 -- Not an admin? Not allowed!
48 module:log("warn", "Non-admin %s tried to send server announcement", tostring(jid.bare(stanza.attr.from))); 48 module:log("warn", "Non-admin '%s' tried to send server announcement", stanza.attr.from);
49 return; 49 return;
50 end 50 end
51 51
52 module:log("info", "Sending server announcement to all online users"); 52 module:log("info", "Sending server announcement to all online users");
53 local host_session = hosts[host];
54 local message = st.clone(stanza); 53 local message = st.clone(stanza);
55 message.attr.type = "headline"; 54 message.attr.type = "headline";
56 message.attr.from = host; 55 message.attr.from = host;
57 56
58 local c = send_to_online(message, host); 57 local c = send_to_online(message, host);

mercurial