Skip to content

Commit 97b6a03

Browse files
committed
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.
1 parent 62e2228 commit 97b6a03

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

src/reaction.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ Here's my footer -- [email protected]"
663663
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id).await?.len(), 2);
664664

665665
let bob_reaction_msg = bob.pop_sent_msg().await;
666-
alice.recv_msg_trash(&bob_reaction_msg).await;
666+
let alice_reaction_msg = alice.recv_msg_hidden(&bob_reaction_msg).await;
667+
assert_eq!(alice_reaction_msg.state, MessageState::InSeen);
667668
assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 2);
668669

669670
let reactions = get_msg_reactions(&alice, alice_msg.sender_msg_id).await?;
@@ -719,7 +720,7 @@ Here's my footer -- [email protected]"
719720
bob_msg1.chat_id.accept(&bob).await?;
720721
send_reaction(&bob, bob_msg1.id, "👍").await?;
721722
let bob_send_reaction = bob.pop_sent_msg().await;
722-
alice.recv_msg_trash(&bob_send_reaction).await;
723+
alice.recv_msg_hidden(&bob_send_reaction).await;
723724
expect_incoming_reactions_event(&alice, alice_msg1.sender_msg_id, alice_bob_id, "👍")
724725
.await?;
725726
expect_no_unwanted_events(&alice).await;
@@ -882,7 +883,7 @@ Here's my footer -- [email protected]"
882883
let bob_reaction_msg = bob.pop_sent_msg().await;
883884

884885
// Alice receives a reaction.
885-
alice.recv_msg_trash(&bob_reaction_msg).await;
886+
alice.recv_msg_hidden(&bob_reaction_msg).await;
886887

887888
let reactions = get_msg_reactions(&alice, alice_msg_id).await?;
888889
assert_eq!(reactions.to_string(), "👍1");
@@ -934,7 +935,7 @@ Here's my footer -- [email protected]"
934935
{
935936
send_reaction(&alice2, alice2_msg.id, "👍").await?;
936937
let msg = alice2.pop_sent_msg().await;
937-
alice1.recv_msg_trash(&msg).await;
938+
alice1.recv_msg_hidden(&msg).await;
938939
}
939940

940941
// Check that the status is still the same.
@@ -956,7 +957,7 @@ Here's my footer -- [email protected]"
956957
let alice1_msg = alice1.recv_msg(&alice0.pop_sent_msg().await).await;
957958

958959
send_reaction(&alice0, alice0_msg_id, "👀").await?;
959-
alice1.recv_msg_trash(&alice0.pop_sent_msg().await).await;
960+
alice1.recv_msg_hidden(&alice0.pop_sent_msg().await).await;
960961

961962
expect_reactions_changed_event(&alice0, chat_id, alice0_msg_id, ContactId::SELF).await?;
962963
expect_reactions_changed_event(&alice1, alice1_msg.chat_id, alice1_msg.id, ContactId::SELF)

src/receive_imf.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ async fn add_parts(
764764
// (of course, the user can add other chats manually later)
765765
let to_id: ContactId;
766766
let state: MessageState;
767-
let mut hidden = false;
767+
let mut hidden = is_reaction;
768768
let mut needs_delete_job = false;
769769
let mut restore_protection = false;
770770

@@ -1235,14 +1235,10 @@ async fn add_parts(
12351235
}
12361236

12371237
let orig_chat_id = chat_id;
1238-
let mut chat_id = if is_reaction {
1238+
let mut chat_id = chat_id.unwrap_or_else(|| {
1239+
info!(context, "No chat id for message (TRASH).");
12391240
DC_CHAT_ID_TRASH
1240-
} else {
1241-
chat_id.unwrap_or_else(|| {
1242-
info!(context, "No chat id for message (TRASH).");
1243-
DC_CHAT_ID_TRASH
1244-
})
1245-
};
1241+
});
12461242

12471243
// Extract ephemeral timer from the message or use the existing timer if the message is not fully downloaded.
12481244
let mut ephemeral_timer = if is_partial_download.is_some() {
@@ -1600,10 +1596,10 @@ RETURNING id
16001596
state,
16011597
is_dc_message,
16021598
if trash { "" } else { msg },
1603-
if trash { None } else { message::normalize_text(msg) },
1604-
if trash { "" } else { &subject },
1599+
if trash || hidden { None } else { message::normalize_text(msg) },
1600+
if trash || hidden { "" } else { &subject },
16051601
// txt_raw might contain invalid utf8
1606-
if trash { "" } else { &txt_raw },
1602+
if trash || hidden { "" } else { &txt_raw },
16071603
if trash {
16081604
"".to_string()
16091605
} else {
@@ -1619,7 +1615,7 @@ RETURNING id
16191615
mime_in_reply_to,
16201616
mime_references,
16211617
save_mime_modified,
1622-
part.error.as_deref().unwrap_or_default(),
1618+
if trash || hidden { "" } else { part.error.as_deref().unwrap_or_default() },
16231619
ephemeral_timer,
16241620
ephemeral_timestamp,
16251621
if is_partial_download.is_some() {
@@ -1629,7 +1625,7 @@ RETURNING id
16291625
} else {
16301626
DownloadState::Done
16311627
},
1632-
mime_parser.hop_info
1628+
if trash || hidden { "" } else { &mime_parser.hop_info },
16331629
],
16341630
|row| {
16351631
let msg_id: MsgId = row.get(0)?;

src/test_utils.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,19 @@ impl TestContext {
606606
msg
607607
}
608608

609+
/// Receive a message using the `receive_imf()` pipeline. Panics if it's not hidden.
610+
pub async fn recv_msg_hidden(&self, msg: &SentMessage<'_>) -> Message {
611+
let received = self
612+
.recv_msg_opt(msg)
613+
.await
614+
.expect("receive_imf() seems not to have added a new message to the db");
615+
let msg = Message::load_from_db(self, *received.msg_ids.last().unwrap())
616+
.await
617+
.unwrap();
618+
assert!(msg.hidden);
619+
msg
620+
}
621+
609622
/// Receive a message using the `receive_imf()` pipeline. This is similar
610623
/// to `recv_msg()`, but doesn't assume that the message is shown in the chat.
611624
pub async fn recv_msg_opt(

0 commit comments

Comments
 (0)