From cdc1063d838c6422624362916140cd2fa4ad6314 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 21 Mar 2021 17:42:56 +0300 Subject: [PATCH] Do not reset user status after receiving a read receipt Read receipts never contain the signature, so previously receiving it cleared the status. --- python/tests/test_account.py | 22 +++++++++++++++++++--- src/dc_receive_imf.rs | 20 ++++++++++++-------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index e293f4426..e0f91c6ac 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -2187,9 +2187,25 @@ class TestOnlineAccount: chat12 = acfactory.get_accepted_chat(ac1, ac2) ac1.set_config("selfstatus", "New status") chat12.send_text("hi") - msg = ac2._evtracker.wait_next_incoming_message() - assert msg.text == "hi" - assert msg.get_sender_contact().status == "New status" + msg_received = ac2._evtracker.wait_next_incoming_message() + assert msg_received.text == "hi" + assert msg_received.get_sender_contact().status == "New status" + + # Send a reply from ac2 to ac1 so ac1 can send a read receipt. + reply_msg = msg_received.chat.send_text("reply") + reply_msg_received = ac1._evtracker.wait_next_incoming_message() + assert reply_msg_received.text == "reply" + + # Send read receipt from ac1 to ac2. + # It does not contain the signature. + ac1.mark_seen_messages([reply_msg_received]) + ev = ac2._evtracker.get_matching("DC_EVENT_MSG_READ") + assert ev.data1 == reply_msg.chat.id + assert ev.data2 == reply_msg.id + assert reply_msg.is_out_mdn_received() + + # Test that the status is not cleared as a result of receiving a read receipt. + assert msg_received.get_sender_contact().status == "New status" ac1.set_config("selfstatus", "") chat12.send_text("hello") diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 40cc491a3..550c22a73 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -237,14 +237,18 @@ pub(crate) async fn dc_receive_imf_inner( } // Always update the status, even if there is no footer, to allow removing the status. - if let Err(err) = contact::set_status( - context, - from_id, - mime_parser.footer.clone().unwrap_or_default(), - ) - .await - { - warn!(context, "cannot update contact status: {}", err); + // + // Ignore MDNs though, as they never contain the signature even if user has set it. + if mime_parser.mdn_reports.is_empty() { + if let Err(err) = contact::set_status( + context, + from_id, + mime_parser.footer.clone().unwrap_or_default(), + ) + .await + { + warn!(context, "cannot update contact status: {}", err); + } } // Get user-configured server deletion