From d17d89ea8f66c450e27fe7dc293189d0eabc9fe4 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 20 Apr 2024 12:09:45 +0000 Subject: [PATCH] fix: mark contact request messages as seen on IMAP --- deltachat-rpc-client/tests/test_something.py | 31 +++++++++++++++++++- src/message.rs | 10 ++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 9c53a078d..e6b62c540 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -8,7 +8,7 @@ from unittest.mock import MagicMock import pytest from deltachat_rpc_client import Contact, EventType, Message, events -from deltachat_rpc_client.const import DownloadState +from deltachat_rpc_client.const import DownloadState, MessageState from deltachat_rpc_client.direct_imap import DirectImap from deltachat_rpc_client.rpc import JsonRpcError @@ -584,3 +584,32 @@ def test_download_limit_chat_assignment(acfactory, tmp_path, n_accounts): # # Message may be a private reply, so we assign it to 1:1 chat with Alice. assert snapshot.chat == bob_chat_alice + + +def test_markseen_contact_request(acfactory, tmp_path): + """ + Test that seen status is synchronized for contact request messages + even though read receipt is not sent. + """ + alice, bob = acfactory.get_online_accounts(2) + + # Bob sets up a second device. + bob.export_backup(tmp_path) + files = list(tmp_path.glob("*.tar")) + bob2 = acfactory.get_unconfigured_account() + bob2.import_backup(files[0]) + bob2.start_io() + + alice_chat_bob = alice.create_chat(bob) + alice_chat_bob.send_text("Hello Bob!") + + message = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id) + message2 = bob2.get_message_by_id(bob2.wait_for_incoming_msg_event().msg_id) + assert message2.get_snapshot().state == MessageState.IN_FRESH + + message.mark_seen() + while True: + event = bob2.wait_for_event() + if event.kind == EventType.MSGS_NOTICED: + break + assert message2.get_snapshot().state == MessageState.IN_SEEN diff --git a/src/message.rs b/src/message.rs index 33e3e557a..cdfdb70e7 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1643,9 +1643,7 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec) -> Result<()> _curr_ephemeral_timer, ) in msgs { - if curr_blocked == Blocked::Not - && (curr_state == MessageState::InFresh || curr_state == MessageState::InNoticed) - { + if curr_state == MessageState::InFresh || curr_state == MessageState::InNoticed { update_msg_state(context, id, MessageState::InSeen).await?; info!(context, "Seen message {}.", id); @@ -1657,7 +1655,11 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec) -> Result<()> // "Group left by me", a read receipt will quote "Group left by ", and the name can // be a display name stored in address book rather than the name sent in the From field by // the user. - if curr_param.get_bool(Param::WantsMdn).unwrap_or_default() + // + // We also don't send read receipts for contact requests. + // Read receipts will not be sent even after accepting the chat. + if curr_blocked == Blocked::Not + && curr_param.get_bool(Param::WantsMdn).unwrap_or_default() && curr_param.get_cmd() == SystemMessage::Unknown { let mdns_enabled = context.get_config_bool(Config::MdnsEnabled).await?;