comparison mod_broadcast/mod_broadcast.lua @ 1016:9f7c97e55593

mod_broadcast: Allow overriding from address on the broadcast stanza
author Matthew Wild <mwild1@gmail.com>
date Sun, 19 May 2013 22:25:54 +0100
parents 0fc9e1f086c1
children
comparison
equal deleted inserted replaced
1015:0fc9e1f086c1 1016:9f7c97e55593
1 local is_admin = require "core.usermanager".is_admin; 1 local is_admin = require "core.usermanager".is_admin;
2 local allowed_senders = module:get_option_set("broadcast_senders", {}); 2 local allowed_senders = module:get_option_set("broadcast_senders", {});
3 local from_address = module:get_option_string("broadcast_from");
3 4
4 local jid_bare = require "util.jid".bare; 5 local jid_bare = require "util.jid".bare;
5 6
6 function send_to_online(message) 7 function send_to_online(message)
7 local c = 0; 8 local c = 0;
19 20
20 function send_message(event) 21 function send_message(event)
21 local stanza = event.stanza; 22 local stanza = event.stanza;
22 local from = stanza.attr.from; 23 local from = stanza.attr.from;
23 if is_admin(from) or allowed_senders:contains(jid_bare(from)) then 24 if is_admin(from) or allowed_senders:contains(jid_bare(from)) then
25 if from_address then
26 stanza = st.clone(stanza);
27 stanza.attr.from = from_address;
28 end
24 local c = send_to_online(stanza); 29 local c = send_to_online(stanza);
25 module:log("debug", "Broadcast stanza from %s to %d online users", from, c); 30 module:log("debug", "Broadcast stanza from %s to %d online users", from, c);
26 return true; 31 return true;
27 else 32 else
28 module:log("warn", "Broadcasting is not allowed for %s", from); 33 module:log("warn", "Broadcasting is not allowed for %s", from);