25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Use user_receive_packet hook in mod_block_strangers

This commit is contained in:
Alexey Shchepin 2017-01-16 18:40:30 +03:00
parent 5a8dea1591
commit b080b8f54d
2 changed files with 11 additions and 30 deletions

View File

@ -546,7 +546,7 @@ process_iq_in(State, #iq{} = IQ) ->
-spec process_message_in(state(), message()) -> {boolean(), state()}.
process_message_in(State, #message{type = T} = Msg) ->
case filter_incoming_message(State, Msg) of
case privacy_check_packet(State, Msg, in) of
allow ->
{true, State};
deny when T == groupchat; T == headline ->
@ -561,24 +561,6 @@ process_message_in(State, #message{type = T} = Msg) ->
{false, State}
end.
filter_incoming_message(State, Msg) ->
case privacy_check_packet(State, Msg, in) of
allow ->
#{lserver := LServer} = State,
case ejabberd_hooks:run_fold(
c2s_filter_incoming_packet,
LServer,
allow,
[State, Msg]) of
allow ->
allow;
deny ->
deny
end;
deny ->
deny
end.
-spec process_presence_in(state(), presence()) -> {boolean(), state()}.
process_presence_in(#{lserver := LServer, pres_a := PresA} = State0,
#presence{from = From, to = To, type = T} = Pres) ->

View File

@ -32,7 +32,7 @@
-export([start/2, stop/1,
depends/2, mod_opt_type/1]).
-export([filter_packet/3]).
-export([filter_packet/1]).
-include("xmpp.hrl").
-include("ejabberd.hrl").
@ -41,18 +41,16 @@
-define(SETS, gb_sets).
start(Host, _Opts) ->
ejabberd_hooks:add(c2s_filter_incoming_packet, Host,
?MODULE, filter_packet, 50),
ejabberd_hooks:add(user_receive_packet, Host,
?MODULE, filter_packet, 25),
ok.
stop(Host) ->
ejabberd_hooks:delete(c2s_filter_incoming_packet, Host,
?MODULE, filter_packet, 50),
ejabberd_hooks:delete(user_receive_packet, Host,
?MODULE, filter_packet, 25),
ok.
filter_packet(deny = Acc, _State, _Msg) ->
Acc;
filter_packet(Acc, State, Msg) ->
filter_packet({#message{} = Msg, State} = Acc) ->
From = xmpp:get_from(Msg),
LFrom = jid:tolower(From),
LBFrom = jid:remove_resource(LFrom),
@ -83,12 +81,13 @@ filter_packet(Acc, State, Msg) ->
end,
if
Drop ->
deny;
{drop, State};
true ->
Acc
end
end.
end;
filter_packet(Acc) ->
Acc.
sets_bare_member({U, S, <<"">>} = LBJID, Set) ->
case ?SETS:next(?SETS:iterator_from(LBJID, Set)) of