Skip to content

Commit

Permalink
Merge pull request #3575 from esl/mu-mod-muc-map-opts
Browse files Browse the repository at this point in the history
Use maps as options in mod_muc
  • Loading branch information
chrzaszcz authored Mar 9, 2022
2 parents 30368d7 + e24caa4 commit 7aff549
Show file tree
Hide file tree
Showing 12 changed files with 480 additions and 430 deletions.
3 changes: 2 additions & 1 deletion big_tests/tests/domain_removal_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ group_to_modules(muc_light_removal) ->
[{mod_muc_light, [{backend, rdbms}, {host, MucHost}]}];
group_to_modules(muc_removal) ->
MucHost = subhost_pattern(muc_helper:muc_host_pattern()),
[{mod_muc, [{backend, rdbms}, {host, MucHost}]}];
Opts = #{backend => rdbms, host => MucHost},
[{mod_muc, muc_helper:make_opts(Opts)}];
group_to_modules(inbox_removal) ->
[{mod_inbox, inbox_helper:inbox_opts()}];
group_to_modules(private_removal) ->
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,13 @@ mam_required_modules(CN, Backend) when CN =:= retrieve_mam_muc_private_msg;
[{mod_mam_meta, mam_helper:config_opts(#{backend => Backend,
pm => #{},
muc => #{host => HostPattern}})},
{mod_muc, [{host, HostPattern}]}];
{mod_muc, muc_helper:make_opts(#{host => HostPattern})}];
mam_required_modules(retrieve_mam_muc_store_pm, Backend) ->
HostPattern = subhost_pattern(muc_helper:muc_host_pattern()),
[{mod_mam_meta, mam_helper:config_opts(#{backend => Backend,
pm => #{archive_groupchats => true},
muc => #{host => HostPattern}})},
{mod_muc, [{host, HostPattern}]}].
{mod_muc, muc_helper:make_opts(#{host => HostPattern})}].

pick_enabled_backend() ->
BackendsList = [
Expand Down
15 changes: 7 additions & 8 deletions big_tests/tests/muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,13 @@ init_per_group(_GroupName, Config) ->

required_modules(http_auth) ->
MucHostPattern = ct:get_config({hosts, mim, muc_service_pattern}),
[{mod_muc, [
{host, subhost_pattern(MucHostPattern)},
{access, muc},
{access_create, muc_create},
{http_auth_pool, muc_http_auth_test},
{default_room_options, [{password_protected, true}]}
]}
].
DefRoomOpts = config_parser_helper:default_room_opts(),
Opts = #{host => subhost_pattern(MucHostPattern),
access => muc,
access_create => muc_create,
http_auth_pool => muc_http_auth_test,
default_room => DefRoomOpts#{password_protected => true}},
[{mod_muc, muc_helper:make_opts(Opts)}].

handle_http_auth(Req) ->
Qs = cowboy_req:parse_qs(Req),
Expand Down
26 changes: 15 additions & 11 deletions big_tests/tests/muc_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

-export_type([verify_fun/0]).

%% Extend default opts with new ExtraOpts
make_opts(ExtraOpts) ->
config_parser_helper:mod_config(mod_muc, ExtraOpts).

make_log_opts(ExtraOpts) ->
config_parser_helper:mod_config(mod_muc_log, ExtraOpts).

-spec foreach_occupant(
Users :: [escalus:client()], Stanza :: #xmlel{}, VerifyFun :: verify_fun()) -> ok.
foreach_occupant(Users, Stanza, VerifyFun) ->
Expand Down Expand Up @@ -50,17 +57,14 @@ load_muc() ->
HostType = domain_helper:host_type(),
MucHostPattern = ct:get_config({hosts, mim, muc_service_pattern}),
ct:log("Starting MUC for ~p", [HostType]),
dynamic_modules:start(HostType, mod_muc,
[{host, subhost_pattern(MucHostPattern)},
{backend, Backend},
{hibernate_timeout, 2000},
{hibernated_room_check_interval, 1000},
{hibernated_room_timeout, 2000},
{access, muc},
{access_create, muc_create}]),
dynamic_modules:start(HostType, mod_muc_log,
[{outdir, "/tmp/muclogs"},
{access_log, muc}]).
Opts = #{host => subhost_pattern(MucHostPattern), backend => Backend,
hibernate_timeout => 2000,
hibernated_room_check_interval => 1000,
hibernated_room_timeout => 2000,
access => muc, access_create => muc_create},
LogOpts = #{outdir => "/tmp/muclogs", access_log => muc},
dynamic_modules:start(HostType, mod_muc, make_opts(Opts)),
dynamic_modules:start(HostType, mod_muc_log, make_log_opts(LogOpts)).

unload_muc() ->
HostType = domain_helper:host_type(),
Expand Down
7 changes: 7 additions & 0 deletions src/config/mongoose_config_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
%% It's for generic functions.
-module(mongoose_config_utils).
-export([exit_or_halt/1]).
-export([section_to_defaults/1]).
-ignore_xref([section_to_defaults/1]).

-include("mongoose_config_spec.hrl").

%% @doc If MongooseIM isn't yet running in this node, then halt the node
-spec exit_or_halt(ExitText :: string()) -> none().
Expand All @@ -14,3 +18,6 @@ exit_or_halt(ExitText) ->
[_] ->
exit(ExitText)
end.

section_to_defaults(#section{defaults = Defaults}) ->
Defaults.
8 changes: 1 addition & 7 deletions src/inbox/mod_inbox.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ process_entry(#{remote_jid := RemJID,
-spec deps(jid:lserver(), list()) -> gen_mod_deps:deps().
deps(_Host, Opts) ->
Groupchats = gen_mod:get_opt(groupchat, Opts),
muclight_dep(Groupchats) ++ muc_dep(Groupchats).
muclight_dep(Groupchats).

-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
start(HostType, #{iqdisc := IQDisc, groupchat := MucTypes} = Opts) ->
Expand Down Expand Up @@ -553,12 +553,6 @@ muclight_dep(List) ->
false -> []
end.

muc_dep(List) ->
case lists:member(muc, List) of
true -> [{mod_muc, [], hard}];
false -> []
end.

-spec muclight_enabled(HostType :: mongooseim:host_type()) -> boolean().
muclight_enabled(HostType) ->
Groupchats = get_groupchat_types(HostType),
Expand Down
Loading

0 comments on commit 7aff549

Please sign in to comment.