From 89b9e25588018e9c332745679283697a25b32be1 Mon Sep 17 00:00:00 2001 From: Christoph Scholz Date: Sun, 13 Jan 2019 10:35:03 +0100 Subject: [PATCH] option to prevent archive removal on room destroy --- src/mod_mam.erl | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/mod_mam.erl b/src/mod_mam.erl index 294d4f401..b104e0f97 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -113,8 +113,6 @@ start(Host, Opts) -> disco_sm_features, 50), ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 50), - ejabberd_hooks:add(remove_room, Host, ?MODULE, - remove_room, 50), ejabberd_hooks:add(get_room_config, Host, ?MODULE, get_room_config, 50), ejabberd_hooks:add(set_room_option, Host, ?MODULE, @@ -126,11 +124,21 @@ start(Host, Opts) -> false -> ok end, + case gen_mod:get_opt(clear_archive_on_room_destroy, Opts) of + true -> + ejabberd_hooks:add(remove_room, Host, ?MODULE, + remove_room, 50); + false -> + ok + end, ejabberd_commands:register_commands(get_commands_spec()); Err -> Err end. + + + use_cache(Mod, Host) -> case erlang:function_exported(Mod, use_cache, 2) of true -> Mod:use_cache(Host); @@ -180,8 +188,6 @@ stop(Host) -> disco_sm_features, 50), ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50), - ejabberd_hooks:delete(remove_room, Host, ?MODULE, - remove_room, 50), ejabberd_hooks:delete(get_room_config, Host, ?MODULE, get_room_config, 50), ejabberd_hooks:delete(set_room_option, Host, ?MODULE, @@ -193,6 +199,13 @@ stop(Host) -> false -> ok end, + case gen_mod:get_module_opt(Host, ?MODULE, clear_archive_on_room_destroy) of + true -> + ejabberd_hooks:delete(remove_room, Host, ?MODULE, + remove_room, 50); + false -> + ok + end, case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of false -> ejabberd_commands:unregister_commands(get_commands_spec()); @@ -1211,6 +1224,8 @@ mod_opt_type(default) -> (roster) -> roster end; mod_opt_type(request_activates_archiving) -> + fun (B) when is_boolean(B) -> B end; +mod_opt_type(clear_archive_on_room_destroy) -> fun (B) when is_boolean(B) -> B end. mod_options(Host) -> @@ -1218,6 +1233,7 @@ mod_options(Host) -> {default, never}, {request_activates_archiving, false}, {compress_xml, false}, + {clear_archive_on_room_destroy, true}, {db_type, ejabberd_config:default_db(Host, ?MODULE)}, {use_cache, ejabberd_config:use_cache(Host)}, {cache_size, ejabberd_config:cache_size(Host)}, -- 2.40.0