From 8d2d3a6540f9f578c09cb31f006fd3c45eb2ba77 Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Wed, 27 Dec 2023 09:42:22 +0300 Subject: [PATCH] Support XEP-0424 in mod_mam_mnesia --- src/mod_mam_mnesia.erl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mod_mam_mnesia.erl b/src/mod_mam_mnesia.erl index 5cbac5ffb..95c5451d4 100644 --- a/src/mod_mam_mnesia.erl +++ b/src/mod_mam_mnesia.erl @@ -190,7 +190,27 @@ extended_fields() -> []. store(Pkt, _, {LUser, LServer}, Type, Peer, Nick, _Dir, TS, - OriginID, _Retract) -> + OriginID, Retract) -> + case Retract of + {true, RID} -> + mnesia:transaction( + fun () -> + {PUser, PServer, _} = jid:tolower(Peer), + Msgs = mnesia:select( + archive_msg, + ets:fun2ms( + fun(#archive_msg{ + us = US1, + bare_peer = Peer1, + origin_id = OriginID1} = Msg) + when US1 == {LUser, LServer}, + Peer1 == {PUser, PServer, <<>>}, + OriginID1 == RID -> Msg + end)), + lists:foreach(fun mnesia:delete_object/1, Msgs) + end); + false -> ok + end, case {mnesia:table_info(archive_msg, disc_only_copies), mnesia:table_info(archive_msg, memory)} of {[_|_], TableSize} when TableSize > ?TABLE_SIZE_LIMIT ->