Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mod_offline_chatmarkers configurable #3609

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion big_tests/tests/offline_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ config_with_groupchat_modules(Backend) ->
chatmarkers_modules() ->
[{mod_smart_markers, config_parser_helper:default_mod_config(mod_smart_markers)},
{mod_offline, config_with_groupchat_modules(rdbms)},
{mod_offline_chatmarkers, [{store_groupchat_messages, true}]},
{mod_offline_chatmarkers,
mod_config(mod_offline_chatmarkers,
#{store_groupchat_messages => true})},
{mod_muc_light, mod_config(mod_muc_light, #{backend => rdbms})}].

end_per_group(Group, C) when Group =:= chatmarkers;
Expand Down
2 changes: 1 addition & 1 deletion src/config/mongoose_config_parser_toml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ get_spec_for_key(Key, Items) ->
false ->
case maps:find(default, Items) of
{ok, Spec} -> Spec;
error -> error(#{what => unexpected_key, key => Key})
error -> error(#{what => unexpected_key, key => Key, items => Items})
end
end.

Expand Down
1 change: 1 addition & 0 deletions src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ configurable_modules() ->
mod_muc_light,
mod_muc_log,
mod_offline,
mod_offline_chatmarkers,
mod_ping,
mod_privacy,
mod_private,
Expand Down
21 changes: 18 additions & 3 deletions src/offline/mod_offline_chatmarkers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
-export([stop/1]).
-export([deps/2]).
-export([supported_features/0]).
-export([config_spec/0]).

%% Hook handlers
-export([inspect_packet/4,
Expand All @@ -52,6 +53,7 @@

-include("jlib.hrl").
-include_lib("exml/include/exml.hrl").
-include("mongoose_config_spec.hrl").

%% gen_mod callbacks
%% ------------------------------------------------------------------
Expand All @@ -61,7 +63,7 @@ supported_features() ->
[dynamic_domains].

-spec deps(mongooseim:host_type(), gen_mod:module_opts()) -> gen_mod_deps:deps().
deps(_,_)->
deps(_, _)->
[]. %% TODO: this need to be marked as required-to-be-configured
% [{mod_smart_markers, [], hard}].

Expand All @@ -80,17 +82,30 @@ hooks(HostType) ->
{resend_offline_messages_hook, HostType, ?MODULE, pop_offline_messages, 60},
{remove_user, HostType, ?MODULE, remove_user, 50}
],
case gen_mod:get_module_opt(HostType, ?MODULE, store_groupchat_messages, false) of
case gen_mod:get_module_opt(HostType, ?MODULE, store_groupchat_messages) of
true ->
GroupChatHook = {offline_groupchat_message_hook,
HostType, ?MODULE, inspect_packet, 40},
[GroupChatHook | DefaultHooks];
_ -> DefaultHooks
end.

-spec config_spec() -> mongoose_config_spec:config_section().
config_spec() ->
#section{
items = #{<<"backend">> => #option{type = atom,
validate = {module, ?MODULE}},
<<"store_groupchat_messages">> => #option{type = boolean}
},
defaults = #{<<"store_groupchat_messages">> => false,
<<"backend">> => rdbms
},
format_items = map
}.

remove_user(Acc, User, Server) ->
HostType = mongoose_acc:host_type(Acc),
mod_offline_chatmarkers_backend:remove_user(HostType, jid:make(User, Server, <<"">>)),
mod_offline_chatmarkers_backend:remove_user(HostType, jid:make(User, Server, <<>>)),
Acc.

pop_offline_messages(Acc, JID) ->
Expand Down
3 changes: 3 additions & 0 deletions test/common/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,9 @@ default_mod_config(mod_offline) ->
#{backend => mnesia,
access_max_user_messages => max_user_offline_messages,
store_groupchat_messages => false};
default_mod_config(mod_offline_chatmarkers) ->
#{backend => rdbms,
store_groupchat_messages => false};
default_mod_config(mod_privacy) ->
#{backend => mnesia};
default_mod_config(mod_private) ->
Expand Down
16 changes: 14 additions & 2 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ groups() ->
mod_muc_light,
mod_muc_light_config_schema,
mod_offline,
mod_offline_chatmarkers,
mod_ping,
mod_privacy,
mod_private,
Expand Down Expand Up @@ -2534,6 +2535,17 @@ mod_offline(_Config) ->
?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})),
?errh(T(#{<<"riak">> => #{<<"bucket">> => <<"leaky">>}})).

mod_offline_chatmarkers(_Config) ->
check_module_defaults(mod_offline_chatmarkers),
T = fun(Opts) -> #{<<"modules">> => #{<<"mod_offline_chatmarkers">> => Opts}} end,
P = [modules, mod_offline_chatmarkers],
?cfgh(P ++ [backend], rdbms,
T(#{<<"backend">> => <<"rdbms">>})),
?cfgh(P ++ [store_groupchat_messages], true,
T(#{<<"store_groupchat_messages">> => true})),
?errh(T(#{<<"store_groupchat_messages">> => 1})),
?errh(T(#{<<"backend">> => <<"riak_is_the_best">>})).

mod_ping(_Config) ->
T = fun(Opts) -> #{<<"modules">> => #{<<"mod_ping">> => Opts}} end,
P = [modules, mod_ping],
Expand Down Expand Up @@ -3382,10 +3394,10 @@ handle_module_options(V1, V2) ->
?eq(V1, V2).

%% Generic assertions, use the 'F' handler for any custom cases
compare_unordered_lists(L1, L2) ->
compare_unordered_lists(L1, L2) when is_list(L1), is_list(L2) ->
compare_unordered_lists(L1, L2, fun(V1, V2) -> ?eq(V1, V2) end).

compare_unordered_lists(L1, L2, F) ->
compare_unordered_lists(L1, L2, F) when is_list(L1), is_list(L2) ->
SL1 = lists:sort(L1),
SL2 = lists:sort(L2),
compare_ordered_lists(SL1, SL2, F).
Expand Down