From 6f7efebb56d17d78b271508807cea1f304ea0626 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 11 Nov 2024 22:41:03 +0100 Subject: [PATCH] Only delete offline msgs when user has MAM enabled (#4287) --- src/mod_mam.erl | 14 ++++++++++++++ src/mod_offline.erl | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/mod_mam.erl b/src/mod_mam.erl index b20bdbd09..198a33738 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -46,6 +46,7 @@ mod_options/1, remove_mam_for_user_with_peer/3, remove_mam_for_user/2, is_empty_for_user/2, is_empty_for_room/3, check_create_room/4, process_iq/3, store_mam_message/7, make_id/0, wrap_as_mucsub/2, select/7, + is_archiving_enabled/2, get_mam_count/2, webadmin_menu_hostuser/4, webadmin_page_hostuser/4, @@ -1571,6 +1572,19 @@ get_jids(undefined) -> get_jids(Js) -> [jid:tolower(jid:remove_resource(J)) || J <- Js]. +is_archiving_enabled(LUser, LServer) -> + case gen_mod:is_loaded(LServer, mod_mam) of + true -> + case get_prefs(LUser, LServer) of + {ok, #archive_prefs{default = Default}} when Default /= never -> + true; + _ -> + false + end; + false -> + false + end. + get_commands_spec() -> [ #ejabberd_commands{name = get_mam_count, tags = [mam], diff --git a/src/mod_offline.erl b/src/mod_offline.erl index eaba44a34..96b541c59 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -306,7 +306,12 @@ c2s_copy_session(State, _) -> State. c2s_handle_bind2_inline({#{jid := #jid{luser = LUser, lserver = LServer}} = State, Els, Results}) -> - delete_all_msgs(LUser, LServer), + case mod_mam:is_archiving_enabled(LUser, LServer) of + true -> + delete_all_msgs(LUser, LServer); + false -> + ok + end, {State, Els, Results}. -spec handle_offline_query(iq()) -> iq().