feat: Make received reactions hidden chat messages as well

Before, received reactions went to the trash chat. Make them hidden chat messages as already done
for sent reactions, just for unification. Incoming received reactions remain `InSeen`, so no changes
are needed to `chat::marknoticed_chat()` et al.
This commit is contained in:
iequidoo
2024-12-13 13:13:35 -03:00
parent 62e22286bb
commit 97b6a03801
3 changed files with 28 additions and 18 deletions

View File

@@ -663,7 +663,8 @@ Here's my footer -- bob@example.net"
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id).await?.len(), 2); assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id).await?.len(), 2);
let bob_reaction_msg = bob.pop_sent_msg().await; let bob_reaction_msg = bob.pop_sent_msg().await;
alice.recv_msg_trash(&bob_reaction_msg).await; let alice_reaction_msg = alice.recv_msg_hidden(&bob_reaction_msg).await;
assert_eq!(alice_reaction_msg.state, MessageState::InSeen);
assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 2); assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 2);
let reactions = get_msg_reactions(&alice, alice_msg.sender_msg_id).await?; let reactions = get_msg_reactions(&alice, alice_msg.sender_msg_id).await?;
@@ -719,7 +720,7 @@ Here's my footer -- bob@example.net"
bob_msg1.chat_id.accept(&bob).await?; bob_msg1.chat_id.accept(&bob).await?;
send_reaction(&bob, bob_msg1.id, "👍").await?; send_reaction(&bob, bob_msg1.id, "👍").await?;
let bob_send_reaction = bob.pop_sent_msg().await; let bob_send_reaction = bob.pop_sent_msg().await;
alice.recv_msg_trash(&bob_send_reaction).await; alice.recv_msg_hidden(&bob_send_reaction).await;
expect_incoming_reactions_event(&alice, alice_msg1.sender_msg_id, alice_bob_id, "👍") expect_incoming_reactions_event(&alice, alice_msg1.sender_msg_id, alice_bob_id, "👍")
.await?; .await?;
expect_no_unwanted_events(&alice).await; expect_no_unwanted_events(&alice).await;
@@ -882,7 +883,7 @@ Here's my footer -- bob@example.net"
let bob_reaction_msg = bob.pop_sent_msg().await; let bob_reaction_msg = bob.pop_sent_msg().await;
// Alice receives a reaction. // Alice receives a reaction.
alice.recv_msg_trash(&bob_reaction_msg).await; alice.recv_msg_hidden(&bob_reaction_msg).await;
let reactions = get_msg_reactions(&alice, alice_msg_id).await?; let reactions = get_msg_reactions(&alice, alice_msg_id).await?;
assert_eq!(reactions.to_string(), "👍1"); assert_eq!(reactions.to_string(), "👍1");
@@ -934,7 +935,7 @@ Here's my footer -- bob@example.net"
{ {
send_reaction(&alice2, alice2_msg.id, "👍").await?; send_reaction(&alice2, alice2_msg.id, "👍").await?;
let msg = alice2.pop_sent_msg().await; let msg = alice2.pop_sent_msg().await;
alice1.recv_msg_trash(&msg).await; alice1.recv_msg_hidden(&msg).await;
} }
// Check that the status is still the same. // Check that the status is still the same.
@@ -956,7 +957,7 @@ Here's my footer -- bob@example.net"
let alice1_msg = alice1.recv_msg(&alice0.pop_sent_msg().await).await; let alice1_msg = alice1.recv_msg(&alice0.pop_sent_msg().await).await;
send_reaction(&alice0, alice0_msg_id, "👀").await?; send_reaction(&alice0, alice0_msg_id, "👀").await?;
alice1.recv_msg_trash(&alice0.pop_sent_msg().await).await; alice1.recv_msg_hidden(&alice0.pop_sent_msg().await).await;
expect_reactions_changed_event(&alice0, chat_id, alice0_msg_id, ContactId::SELF).await?; expect_reactions_changed_event(&alice0, chat_id, alice0_msg_id, ContactId::SELF).await?;
expect_reactions_changed_event(&alice1, alice1_msg.chat_id, alice1_msg.id, ContactId::SELF) expect_reactions_changed_event(&alice1, alice1_msg.chat_id, alice1_msg.id, ContactId::SELF)

View File

@@ -764,7 +764,7 @@ async fn add_parts(
// (of course, the user can add other chats manually later) // (of course, the user can add other chats manually later)
let to_id: ContactId; let to_id: ContactId;
let state: MessageState; let state: MessageState;
let mut hidden = false; let mut hidden = is_reaction;
let mut needs_delete_job = false; let mut needs_delete_job = false;
let mut restore_protection = false; let mut restore_protection = false;
@@ -1235,14 +1235,10 @@ async fn add_parts(
} }
let orig_chat_id = chat_id; let orig_chat_id = chat_id;
let mut chat_id = if is_reaction { let mut chat_id = chat_id.unwrap_or_else(|| {
info!(context, "No chat id for message (TRASH).");
DC_CHAT_ID_TRASH DC_CHAT_ID_TRASH
} else { });
chat_id.unwrap_or_else(|| {
info!(context, "No chat id for message (TRASH).");
DC_CHAT_ID_TRASH
})
};
// Extract ephemeral timer from the message or use the existing timer if the message is not fully downloaded. // Extract ephemeral timer from the message or use the existing timer if the message is not fully downloaded.
let mut ephemeral_timer = if is_partial_download.is_some() { let mut ephemeral_timer = if is_partial_download.is_some() {
@@ -1600,10 +1596,10 @@ RETURNING id
state, state,
is_dc_message, is_dc_message,
if trash { "" } else { msg }, if trash { "" } else { msg },
if trash { None } else { message::normalize_text(msg) }, if trash || hidden { None } else { message::normalize_text(msg) },
if trash { "" } else { &subject }, if trash || hidden { "" } else { &subject },
// txt_raw might contain invalid utf8 // txt_raw might contain invalid utf8
if trash { "" } else { &txt_raw }, if trash || hidden { "" } else { &txt_raw },
if trash { if trash {
"".to_string() "".to_string()
} else { } else {
@@ -1619,7 +1615,7 @@ RETURNING id
mime_in_reply_to, mime_in_reply_to,
mime_references, mime_references,
save_mime_modified, save_mime_modified,
part.error.as_deref().unwrap_or_default(), if trash || hidden { "" } else { part.error.as_deref().unwrap_or_default() },
ephemeral_timer, ephemeral_timer,
ephemeral_timestamp, ephemeral_timestamp,
if is_partial_download.is_some() { if is_partial_download.is_some() {
@@ -1629,7 +1625,7 @@ RETURNING id
} else { } else {
DownloadState::Done DownloadState::Done
}, },
mime_parser.hop_info if trash || hidden { "" } else { &mime_parser.hop_info },
], ],
|row| { |row| {
let msg_id: MsgId = row.get(0)?; let msg_id: MsgId = row.get(0)?;

View File

@@ -606,6 +606,19 @@ impl TestContext {
msg msg
} }
/// Receive a message using the `receive_imf()` pipeline. Panics if it's not hidden.
pub async fn recv_msg_hidden(&self, msg: &SentMessage<'_>) -> Message {
let received = self
.recv_msg_opt(msg)
.await
.expect("receive_imf() seems not to have added a new message to the db");
let msg = Message::load_from_db(self, *received.msg_ids.last().unwrap())
.await
.unwrap();
assert!(msg.hidden);
msg
}
/// Receive a message using the `receive_imf()` pipeline. This is similar /// Receive a message using the `receive_imf()` pipeline. This is similar
/// to `recv_msg()`, but doesn't assume that the message is shown in the chat. /// to `recv_msg()`, but doesn't assume that the message is shown in the chat.
pub async fn recv_msg_opt( pub async fn recv_msg_opt(