Skip to content

Commit

Permalink
Refactored hook handler in mod_event_pusher_push module
Browse files Browse the repository at this point in the history
  • Loading branch information
pawlooss1 committed Sep 30, 2022
1 parent 975bb21 commit 572b0d3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/event_pusher/mod_event_pusher_push.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
-export([is_virtual_pubsub_host/3]).
-export([disable_node/4]).

-ignore_xref([
iq_handler/4, remove_user/3
]).
-ignore_xref([iq_handler/4]).

%% Types
-type publish_service() :: {PubSub :: jid:jid(), Node :: pubsub_node(), Form :: form()}.
Expand All @@ -68,7 +66,7 @@ start(HostType, Opts) ->
mod_event_pusher_push_backend:init(HostType, Opts),
mod_event_pusher_push_plugin:init(HostType, Opts),
init_iq_handlers(HostType, Opts),
ejabberd_hooks:add(remove_user, HostType, ?MODULE, remove_user, 90),
gen_hook:add_handler(remove_user, HostType, fun ?MODULE:remove_user/3, #{}, 90),
ok.

start_pool(HostType, #{wpool := WpoolOpts}) ->
Expand All @@ -82,7 +80,7 @@ init_iq_handlers(HostType, #{iqdisc := IQDisc}) ->

-spec stop(mongooseim:host_type()) -> ok.
stop(HostType) ->
ejabberd_hooks:delete(remove_user, HostType, ?MODULE, remove_user, 90),
gen_hook:delete_handler(remove_user, HostType, fun ?MODULE:remove_user/3, #{}, 90),

gen_iq_handler:remove_iq_handler(ejabberd_sm, HostType, ?NS_PUSH),
gen_iq_handler:remove_iq_handler(ejabberd_local, HostType, ?NS_PUSH),
Expand Down Expand Up @@ -128,12 +126,14 @@ push_event(Acc, _) ->
%%--------------------------------------------------------------------
%% Hooks and IQ handlers
%%--------------------------------------------------------------------
-spec remove_user(Acc :: mongoose_acc:t(), LUser :: jid:luser(), LServer :: jid:lserver()) ->
mongoose_acc:t().
remove_user(Acc, LUser, LServer) ->
-spec remove_user(Acc, Params, Extra) -> {ok, Acc} when
Acc :: mongoose_acc:t(),
Params :: #{jid := jid:jid()},
Extra :: map().
remove_user(Acc, #{jid := #jid{luser = LUser, lserver = LServer}}, _) ->
R = mod_event_pusher_push_backend:disable(LServer, jid:make_noprep(LUser, LServer, <<>>)),
mongoose_lib:log_if_backend_error(R, ?MODULE, ?LINE, {Acc, LUser, LServer}),
Acc.
{ok, Acc}.

-spec iq_handler(From :: jid:jid(), To :: jid:jid(), Acc :: mongoose_acc:t(),
IQ :: jlib:iq()) ->
Expand Down

0 comments on commit 572b0d3

Please sign in to comment.