Skip to content

Commit

Permalink
Merge pull request #3554 from esl/module-opts-map-time
Browse files Browse the repository at this point in the history
Module opts map time
  • Loading branch information
chrzaszcz authored Mar 1, 2022
2 parents a151c29 + 3686ab5 commit efd6bec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion big_tests/tests/mod_time_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ suite() ->
%%--------------------------------------------------------------------

init_per_suite(Config) ->
dynamic_modules:start(domain_helper:host_type(), mod_time, []),
dynamic_modules:start(domain_helper:host_type(), mod_time, config_parser_helper:default_mod_config(mod_time)),
escalus:init_per_suite(Config).

end_per_suite(Config) ->
Expand Down
11 changes: 7 additions & 4 deletions src/mod_time.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
-xep([{xep, 202}, {version, "2.0"}]).
-xep([{xep, 82}, {version, "1.1"}]).

start(HostType, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
-spec start(HostType :: mongooseim:host_type(), gen_mod:module_opts()) -> ok | {error, atom()}.
start(HostType, #{iqdisc := IQDisc}) ->
gen_iq_handler:add_iq_handler_for_domain(HostType, ?NS_TIME, ejabberd_local,
fun ?MODULE:process_local_iq/5, #{}, IQDisc).


-spec stop(HostType :: mongooseim:host_type()) -> ok | {error, not_registered}.
stop(HostType) ->
gen_iq_handler:remove_iq_handler_for_domain(HostType, ?NS_TIME, ejabberd_local).

Expand All @@ -40,7 +40,10 @@ supported_features() ->
-spec config_spec() -> mongoose_config_spec:config_section().
config_spec() ->
#section{
items = #{<<"iqdisc">> => mongoose_config_spec:iqdisc()}}.
items = #{<<"iqdisc">> => mongoose_config_spec:iqdisc()},
defaults = #{<<"iqdisc">> => one_queue},
format_items = map
}.

process_local_iq(Acc, _From, _To, #iq{type = set, sub_el = SubEl} = IQ, _Extra) ->
{Acc, IQ#iq{type = error, sub_el = [SubEl, mongoose_xmpp_errors:not_allowed()]}};
Expand Down
2 changes: 2 additions & 0 deletions test/common/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,8 @@ default_mod_config(mod_inbox) ->
iqdisc => no_queue};
default_mod_config(mod_private) ->
#{iqdisc => one_queue, backend => rdbms};
default_mod_config(mod_time) ->
#{iqdisc => one_queue};
default_mod_config(mod_vcard) ->
#{iqdisc => parallel,
host => {prefix, <<"vjud.">>},
Expand Down
4 changes: 2 additions & 2 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2923,8 +2923,8 @@ mod_stream_management_stale_h(_Config) ->
?errh(T(#{<<"geriatric">> => <<"one">>})).

mod_time(_Config) ->
check_iqdisc(mod_time),
?cfgh(modopts(mod_time, []), #{<<"modules">> => #{<<"mod_time">> => #{}}}).
check_iqdisc_map(mod_time),
check_module_defaults(mod_time).

mod_vcard(_Config) ->
check_module_defaults(mod_vcard),
Expand Down

0 comments on commit efd6bec

Please sign in to comment.