comparison mod_block_strangers/mod_block_strangers.lua @ 772:954532e273be

mod_block_strangers: Module to block message and iqs from people not on your roster
author Matthew Wild <mwild1@gmail.com>
date Sun, 05 Aug 2012 01:46:24 +0100
parents
children 52caf54fc270
comparison
equal deleted inserted replaced
771:889e7a60a2e7 772:954532e273be
1
2 local jid_split = require "util.jid".split;
3 local jid_bare = require "util.jid".bare;
4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
5
6 function check_subscribed(event)
7 local stanza = event.stanza;
8 local to_user, to_host, to_resource = jid_split(stanza.attr.to);
9 local from_jid = jid_bare(stanza.attr.from);
10 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then
11 if to_resource and stanza.attr.type == "groupchat" then
12 return nil; -- Pass through
13 end
14 return true; -- Drop stanza
15 end
16 end
17
18 module:hook("message/bare", check_subscribed, 100);
19 module:hook("message/full", check_subscribed, 100);
20
21 module:hook("iq/full", check_subscribed, 100);