From 775f7062f0e6df1d8b59b7bcde651bc1b970bdd8 Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Wed, 16 Nov 2022 11:19:25 +0100 Subject: [PATCH] Do not store message sent to yourself --- big_tests/tests/mam_SUITE.erl | 16 ++++++++++++++++ src/mam/mod_mam_pm.erl | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index e01478545dd..84089080301 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -36,6 +36,7 @@ muc_service_discovery/1, easy_archive_request/1, easy_archive_request_for_the_receiver/1, + message_sent_to_yourself/1, text_search_query_fails_if_disabled/1, pagination_simple_enforced/1, text_search_is_not_available/1, @@ -383,6 +384,7 @@ mam_cases() -> [mam_service_discovery, easy_archive_request, easy_archive_request_for_the_receiver, + message_sent_to_yourself, range_archive_request, range_archive_request_not_empty, limit_archive_request, @@ -1226,6 +1228,20 @@ easy_archive_request_for_the_receiver(Config) -> end, escalus_fresh:story(Config, [{alice, 1}, {bob, 1}], F). +message_sent_to_yourself(Config) -> + P = ?config(props, Config), + F = fun(Alice) -> + escalus:send(Alice, escalus_stanza:chat_to(Alice, <<"OH, HAI!">>)), + escalus:wait_for_stanza(Alice), %% Receive that message + mam_helper:wait_for_archive_size(Alice, 1), + escalus:send(Alice, stanza_archive_request(P, <<"q1">>)), + Res = wait_archive_respond(Alice), + assert_respond_size(1, Res), + assert_respond_query_id(P, <<"q1">>, parse_result_iq(Res)), + ok + end, + escalus_fresh:story(Config, [{alice, 1}], F). + text_search_is_not_available(Config) -> P = ?config(props, Config), F = fun(Alice) -> diff --git a/src/mam/mod_mam_pm.erl b/src/mam/mod_mam_pm.erl index 6610236b8d3..0e0bd94f962 100644 --- a/src/mam/mod_mam_pm.erl +++ b/src/mam/mod_mam_pm.erl @@ -449,7 +449,8 @@ handle_package(Dir, ReturnMessID, LocJID = #jid{}, RemJID = #jid{}, SrcJID = #jid{}, Packet, Acc) -> HostType = acc_to_host_type(Acc), case is_archivable_message(HostType, Dir, Packet) - andalso should_archive_if_groupchat(HostType, exml_query:attr(Packet, <<"type">>)) of + andalso should_archive_if_groupchat(HostType, exml_query:attr(Packet, <<"type">>)) + andalso should_archive_if_sent_to_yourself(LocJID, RemJID, Dir) of true -> ArcID = archive_id_int(HostType, LocJID), OriginID = mod_mam_utils:get_origin_id(Packet), @@ -479,6 +480,12 @@ should_archive_if_groupchat(HostType, <<"groupchat">>) -> should_archive_if_groupchat(_, _) -> true. +%% Only store messages sent to yourself in user_send_packet. +should_archive_if_sent_to_yourself(LocJID, RemJID, incoming) -> + not jid:are_bare_equal(LocJID, RemJID); +should_archive_if_sent_to_yourself(LocJID, RemJID, _Dir) -> + true. + -spec return_external_message_id_if_ok(ReturnMessID :: boolean(), ArchivingResult :: ok | any(), MessID :: integer()) -> binary() | undefined.