Skip to content

Commit abb9405

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 b74ff27 commit abb9405

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ async fn add_parts(
760760
// (of course, the user can add other chats manually later)
761761
let to_id: ContactId;
762762
let state: MessageState;
763-
let mut hidden = false;
763+
let mut hidden = is_reaction;
764764
let mut needs_delete_job = false;
765765
let mut restore_protection = false;
766766

@@ -1232,7 +1232,7 @@ async fn add_parts(
12321232
}
12331233

12341234
let orig_chat_id = chat_id;
1235-
let mut chat_id = if is_mdn || is_reaction {
1235+
let mut chat_id = if is_mdn {
12361236
DC_CHAT_ID_TRASH
12371237
} else {
12381238
chat_id.unwrap_or_else(|| {
@@ -1597,10 +1597,10 @@ RETURNING id
15971597
state,
15981598
is_dc_message,
15991599
if trash { "" } else { msg },
1600-
if trash { None } else { message::normalize_text(msg) },
1601-
if trash { "" } else { &subject },
1600+
if trash || hidden { None } else { message::normalize_text(msg) },
1601+
if trash || hidden { "" } else { &subject },
16021602
// txt_raw might contain invalid utf8
1603-
if trash { "" } else { &txt_raw },
1603+
if trash || hidden { "" } else { &txt_raw },
16041604
if trash {
16051605
"".to_string()
16061606
} else {
@@ -1616,7 +1616,7 @@ RETURNING id
16161616
mime_in_reply_to,
16171617
mime_references,
16181618
save_mime_modified,
1619-
part.error.as_deref().unwrap_or_default(),
1619+
if trash || hidden { "" } else { part.error.as_deref().unwrap_or_default() },
16201620
ephemeral_timer,
16211621
ephemeral_timestamp,
16221622
if is_partial_download.is_some() {
@@ -1626,7 +1626,7 @@ RETURNING id
16261626
} else {
16271627
DownloadState::Done
16281628
},
1629-
mime_parser.hop_info
1629+
if trash || hidden { "" } else { &mime_parser.hop_info },
16301630
],
16311631
|row| {
16321632
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)