comparison mod_block_strangers/mod_block_strangers.lua @ 1325:b21236b6b8d8

Backed out changeset 853a382c9bd6
author Kim Alvefur <zash@zash.se>
date Fri, 28 Feb 2014 15:37:55 +0100
parents 853a382c9bd6
children 252b634b065d
comparison
equal deleted inserted replaced
1324:853a382c9bd6 1325:b21236b6b8d8
1 1
2 local jid_split = require "util.jid".split; 2 local jid_split = require "util.jid".split;
3 local jid_bare = require "util.jid".bare; 3 local jid_bare = require "util.jid".bare;
4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; 4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
5 local error_reply = require "util.stanza".error_reply;
6 5
7 function check_subscribed(event) 6 function check_subscribed(event)
8 local stanza = event.stanza; 7 local stanza = event.stanza;
9 local to_user, to_host, to_resource = jid_split(stanza.attr.to); 8 local to_user, to_host, to_resource = jid_split(stanza.attr.to);
10 local from_jid = jid_bare(stanza.attr.from); 9 local from_jid = jid_bare(stanza.attr.from);
11 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then 10 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then
12 if to_resource and stanza.attr.type == "groupchat" then 11 if to_resource and stanza.attr.type == "groupchat" then
13 return nil; -- Pass through 12 return nil; -- Pass through
14 end 13 end
15 return error_reply("auth", "forbidden", "Subscription required"); -- Bounce with error 14 return true; -- Drop stanza
16 end 15 end
17 end 16 end
18 17
19 module:hook("message/bare", check_subscribed, 200); 18 module:hook("message/bare", check_subscribed, 200);
20 module:hook("message/full", check_subscribed, 200); 19 module:hook("message/full", check_subscribed, 200);