Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not store message sent to yourself #3859

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions big_tests/tests/mam_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) ->
Expand Down
9 changes: 8 additions & 1 deletion src/mam/mod_mam_pm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand Down