Skip to content

Commit

Permalink
removing run_global/2 and run_for_host_type/3 interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysGonchar committed Apr 19, 2021
1 parent f00daf3 commit 2150d7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
36 changes: 14 additions & 22 deletions src/ejabberd_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
add/5,
delete/4,
delete/5,
run_global/2,
run_global/3,
run_for_host_type/3,
run_for_host_type/4]).

%% gen_server callbacks
Expand Down Expand Up @@ -133,31 +131,13 @@ delete(Hooks) when is_list(Hooks) ->
delete_hook(Hook) ->
gen_server:call(ejabberd_hooks, {delete, Hook}).

%% @doc Run the calls of this hook in order, don't care about function results.
%% If a call returns stop, no more calls are performed.
-spec run_global(HookName :: atom(),
Args :: [any()]) -> ok.
run_global(HookName, Args) ->
run_fold(HookName, global, ok, Args).

-spec run_for_host_type(HookName :: atom(),
HostType :: binary(),
Args :: [any()]) -> ok.
run_for_host_type(HookName, HostType, Args) ->
%% We don't provide mongoose_acc here because we can't create a valid one.
run_fold(HookName, HostType, ok, Args).

%% @spec (HookName::atom(), Acc, Args) -> Val | stopped | NewVal
%% @doc Run the calls of this hook in order.
%% The arguments passed to the function are: [Acc | Args].
%% The result of a call is used as Acc for the next call.
%% If a call returns 'stop', no more calls are performed and 'stopped' is returned.
%% If a call returns {stop, NewAcc}, no more calls are performed and NewAcc is returned.
%% @doc run global hook, for more details see run_fold/4 documentation.
-spec run_global(HookName :: atom(), Acc :: term(), Args :: [term()]) ->
NewAcc :: term() | stopped.
run_global(HookName, Acc, Args) ->
run_fold(HookName, global, Acc, Args).

%% @doc run hook for the host type, for more details see run_fold/4 documentation.
-spec run_for_host_type(HookName :: atom(),
HostType :: binary(),
Acc :: term(),
Expand Down Expand Up @@ -261,6 +241,18 @@ code_change(_OldVsn, State, _Extra) ->
%%%----------------------------------------------------------------------
%%% Internal functions
%%%----------------------------------------------------------------------

%% @doc Run the handlers of the hook in order.
%% The arguments passed to the hook handler function are: [Acc | Args].
%% The result of a call is used as Acc for the next call.
%% If a call returns 'stop', no more calls are performed and 'stopped' is returned.
%% If a call returns {stop, NewAcc}, no more calls are performed and NewAcc is returned.
%% If hook doesn't need accumulator and doesn't care about the return value. The 'ok'
%% atom can be used as initial Acc value.
%%
%% Note that every hook handler MUST return a valid Acc. if any hook handler is not
%% interested in Acc parameter (or even if Acc is not used for a hook at all), it must
%% return (pass through) an unchanged input accumulator value.
-spec run_fold(HookName :: atom(),
HostType :: global | binary(),
Acc :: term(),
Expand Down
4 changes: 2 additions & 2 deletions src/mongoose_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ auth_failed(Server, Username) ->
Domain :: jid:lserver(),
Result :: ok.
disable_domain(HostType, Domain) ->
ejabberd_hooks:run_global(disable_domain, [HostType, Domain]).
ejabberd_hooks:run_global(disable_domain, ok, [HostType, Domain]).

-spec remove_domain(HostType, Domain) -> Result when
HostType :: binary(),
Domain :: jid:lserver(),
Result :: ok.
remove_domain(HostType, Domain) ->
ejabberd_hooks:run_global(remove_domain, [HostType, Domain]).
ejabberd_hooks:run_global(remove_domain, ok, [HostType, Domain]).

-spec node_cleanup(Node :: node()) -> Acc :: map().
node_cleanup(Node) ->
Expand Down

0 comments on commit 2150d7f

Please sign in to comment.