Skip to content

Commit

Permalink
Only delete offline msgs when user has MAM enabled (4287)
Browse files Browse the repository at this point in the history
  • Loading branch information
badlop committed Nov 12, 2024
1 parent 27b277f commit fc5010d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/mod_mam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down
7 changes: 6 additions & 1 deletion src/mod_offline.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit fc5010d

Please sign in to comment.