25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Fix XEP-0425: Message Moderation with SQL storage

Use the correct server name and room JID when removing moderated
messages from SQL.
This commit is contained in:
Holger Weiss 2024-02-24 22:06:36 +01:00
parent a6b10ac4c0
commit 6aaefc663b
3 changed files with 9 additions and 8 deletions

View File

@ -361,9 +361,9 @@ remove_mam_for_user_with_peer(User, Server, Peer) ->
ok | {error, binary()}.
remove_message_from_archive(User, Server, StanzaId) when is_binary(User) ->
remove_message_from_archive({User, Server}, Server, StanzaId);
remove_message_from_archive({User, Host}, Server, StanzaId) ->
remove_message_from_archive({_User, _Host} = UserHost, Server, StanzaId) ->
Mod = gen_mod:db_mod(Server, ?MODULE),
case Mod:remove_from_archive(User, Host, StanzaId) of
case Mod:remove_from_archive(UserHost, Server, StanzaId) of
ok ->
ok;
{error, Bin} when is_binary(Bin) ->

View File

@ -77,14 +77,14 @@ remove_user(LUser, LServer) ->
remove_room(_LServer, LName, LHost) ->
remove_user(LName, LHost).
remove_from_archive(LUser, LServer, none) ->
US = {LUser, LServer},
remove_from_archive(LUser, LHost, Key) when is_binary(LUser) ->
remove_from_archive({LUser, LHost}, LHost, Key);
remove_from_archive(US, _LServer, none) ->
case mnesia:transaction(fun () -> mnesia:delete({archive_msg, US}) end) of
{atomic, _} -> ok;
{aborted, Reason} -> {error, Reason}
end;
remove_from_archive(LUser, LServer, #jid{} = WithJid) ->
US = {LUser, LServer},
remove_from_archive(US, _LServer, #jid{} = WithJid) ->
Peer = jid:remove_resource(jid:split(WithJid)),
F = fun () ->
Msgs = mnesia:select(
@ -99,9 +99,8 @@ remove_from_archive(LUser, LServer, #jid{} = WithJid) ->
{atomic, _} -> ok;
{aborted, Reason} -> {error, Reason}
end;
remove_from_archive(LUser, LServer, StanzaId) ->
remove_from_archive(US, _LServer, StanzaId) ->
Timestamp = misc:usec_to_now(StanzaId),
US = {LUser, LServer},
F = fun () ->
Msgs = mnesia:select(
archive_msg,

View File

@ -163,6 +163,8 @@ remove_room(LServer, LName, LHost) ->
LUser = jid:encode({LName, LHost, <<>>}),
remove_user(LUser, LServer).
remove_from_archive({LUser, LHost}, LServer, Key) ->
remove_from_archive(jid:encode({LUser, LHost, <<>>}), LServer, Key);
remove_from_archive(LUser, LServer, none) ->
case ejabberd_sql:sql_query(LServer,
?SQL("delete from archive where username=%(LUser)s and %(LServer)H")) of