Software /
code /
prosody-modules
Comparison
mod_broadcast/mod_broadcast.lua @ 786:e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 07 Aug 2012 15:51:15 +0100 |
child | 1015:0fc9e1f086c1 |
comparison
equal
deleted
inserted
replaced
785:e781e63a49f4 | 786:e318a341d332 |
---|---|
1 local allowed_senders = module:get_option_set("broadcast_senders", {}); | |
2 | |
3 local jid_bare = require "util.jid".bare; | |
4 | |
5 function send_to_online(message) | |
6 local c = 0; | |
7 for hostname, host_session in pairs(hosts) do | |
8 if host_session.sessions then | |
9 for username in pairs(host_session.sessions) do | |
10 c = c + 1; | |
11 message.attr.to = username.."@"..hostname; | |
12 module:send(message); | |
13 end | |
14 end | |
15 end | |
16 return c; | |
17 end | |
18 | |
19 function send_message(event) | |
20 local stanza = event.stanza; | |
21 if allowed_senders:contains(jid_bare(stanza.attr.from)) then | |
22 local c = send_to_online(stanza); | |
23 module:log("debug", "Broadcast stanza from %s to %d online users", stanza.attr.from, c); | |
24 return true; | |
25 else | |
26 module:log("warn", "Broadcasting is not allowed for %s", stanza.attr.from); | |
27 end | |
28 end | |
29 | |
30 module:hook("message/bare", send_message); |