comparison mod_block_strangers/mod_block_strangers.lua @ 2196:09f6e1a09b2b

mod_block_strangers: Allow stanzas form jids the user has sent directed presence to
author Kim Alvefur <zash@zash.se>
date Wed, 01 Jun 2016 14:50:39 +0200
parents bd0c5d546bf8
children 045d594a3707
comparison
equal deleted inserted replaced
2195:967ba20e1202 2196:09f6e1a09b2b
1 1
2 local st = require"util.stanza"; 2 local st = require"util.stanza";
3 local jid_split = require "util.jid".split; 3 local jid_split = require "util.jid".split;
4 local jid_bare = require "util.jid".bare; 4 local jid_bare = require "util.jid".bare;
5 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; 5 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
6 local full_sessions = prosody.full_sessions;
7
8 local function has_directed_presence(user, jid)
9 local session = full_sessions[user];
10 return session and session.directed[jid];
11 end
6 12
7 function check_subscribed(event) 13 function check_subscribed(event)
8 local stanza = event.stanza; 14 local stanza = event.stanza;
9 local to_user, to_host, to_resource = jid_split(stanza.attr.to); 15 local to_user, to_host, to_resource = jid_split(stanza.attr.to);
10 local from_jid = jid_bare(stanza.attr.from); 16 local from_jid = jid_bare(stanza.attr.from);
11 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then 17 if to_user and not has_directed_presence(stanza.attr.to, from_jid) and not is_contact_subscribed(to_user, to_host, from_jid) then
12 if to_resource and stanza.attr.type == "groupchat" 18 if to_resource and stanza.attr.type == "groupchat"
13 or stanza.name == "iq" and (stanza.attr.type == "result" or stanza.attr.type == "error") then 19 or stanza.name == "iq" and (stanza.attr.type == "result" or stanza.attr.type == "error") then
14 return nil; -- Pass through 20 return nil; -- Pass through
15 end 21 end
16 if stanza.name == "iq" and ( stanza.attr.type == "get" or stanza.attr.type == "set" ) then 22 if stanza.name == "iq" and ( stanza.attr.type == "get" or stanza.attr.type == "set" ) then