Skip to content

Commit 6bbe9e7

Browse files
committed
try to do sth simple
1 parent 4f71c77 commit 6bbe9e7

File tree

5 files changed

+118
-31
lines changed

5 files changed

+118
-31
lines changed

deltachat-rpc-client/tests/test_something.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,43 @@ def test_message(acfactory) -> None:
287287
assert reactions == snapshot.reactions
288288

289289

290+
def test_reaction_seen_on_another_dev(acfactory, tmp_path) -> None:
291+
alice, bob = acfactory.get_online_accounts(2)
292+
alice.export_backup(tmp_path)
293+
files = list(tmp_path.glob("*.tar"))
294+
alice2 = acfactory.get_unconfigured_account()
295+
alice2.import_backup(files[0])
296+
alice2.start_io()
297+
298+
bob_addr = bob.get_config("addr")
299+
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
300+
alice_chat_bob = alice_contact_bob.create_chat()
301+
alice_chat_bob.send_text("Hello!")
302+
303+
event = bob.wait_for_incoming_msg_event()
304+
msg_id = event.msg_id
305+
306+
message = bob.get_message_by_id(msg_id)
307+
snapshot = message.get_snapshot()
308+
snapshot.chat.accept()
309+
message.send_reaction("😎")
310+
for a in [alice, alice2]:
311+
while True:
312+
event = a.wait_for_event()
313+
if event.kind == EventType.INCOMING_REACTION:
314+
break
315+
316+
alice_chat_bob.mark_noticed()
317+
while True:
318+
event = alice2.wait_for_event()
319+
if event.kind == EventType.MSGS_NOTICED:
320+
chat_id = event.chat_id
321+
break
322+
alice2_contact_bob = alice2.get_contact_by_addr(bob_addr)
323+
alice2_chat_bob = alice2_contact_bob.create_chat()
324+
assert chat_id == alice2_chat_bob.id
325+
326+
290327
def test_is_bot(acfactory) -> None:
291328
"""Test that we can recognize messages submitted by bots."""
292329
alice, bob = acfactory.get_online_accounts(2)

src/chat.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use tokio::task;
1818
use crate::aheader::EncryptPreference;
1919
use crate::blob::BlobObject;
2020
use crate::chatlist::Chatlist;
21-
use crate::chatlist_events;
2221
use crate::color::str_to_color;
2322
use crate::config::Config;
2423
use crate::constants::{
@@ -51,6 +50,7 @@ use crate::tools::{
5150
truncate_msg_text, IsNoneOrEmpty, SystemTime,
5251
};
5352
use crate::webxdc::StatusUpdateSerial;
53+
use crate::{chatlist_events, imap};
5454

5555
/// An chat item, such as a message or a marker.
5656
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -3328,7 +3328,7 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()>
33283328
} else {
33293329
start_chat_ephemeral_timers(context, chat_id).await?;
33303330

3331-
if context
3331+
let noticed_msgs_count = context
33323332
.sql
33333333
.execute(
33343334
"UPDATE msgs
@@ -3338,9 +3338,36 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()>
33383338
AND chat_id=?;",
33393339
(MessageState::InNoticed, MessageState::InFresh, chat_id),
33403340
)
3341-
.await?
3342-
== 0
3343-
{
3341+
.await?;
3342+
3343+
// This is to trigger emitting `MsgsNoticed` on other devices when reactions are noticed
3344+
// locally (i.e. when the chat was opened locally).
3345+
let hidden_messages = context
3346+
.sql
3347+
.query_map(
3348+
"SELECT id, rfc724_mid FROM msgs
3349+
WHERE state=?
3350+
AND hidden=1
3351+
AND chat_id=?
3352+
ORDER BY id DESC LIMIT 100", // LIMIT to 100 in order to avoid blocking the UI too long, usually there will be less than 100 messages anyway
3353+
(MessageState::InNoticed, chat_id),
3354+
|row| {
3355+
let msg_id: MsgId = row.get(0)?;
3356+
let rfc724_mid: String = row.get(1)?;
3357+
Ok((msg_id, rfc724_mid))
3358+
},
3359+
|rows| {
3360+
rows.collect::<std::result::Result<Vec<_>, _>>()
3361+
.map_err(Into::into)
3362+
},
3363+
)
3364+
.await?;
3365+
for (msg_id, rfc724_mid) in &hidden_messages {
3366+
message::update_msg_state(context, *msg_id, MessageState::InSeen).await?;
3367+
imap::markseen_on_imap_table(context, rfc724_mid).await?;
3368+
}
3369+
3370+
if noticed_msgs_count == 0 {
33443371
return Ok(());
33453372
}
33463373
}

src/reaction.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ mod tests {
398398
use deltachat_contact_tools::ContactAddress;
399399

400400
use super::*;
401-
use crate::chat::{forward_msgs, get_chat_msgs, send_text_msg};
401+
use crate::chat::{forward_msgs, get_chat_msgs, marknoticed_chat, send_text_msg};
402402
use crate::chatlist::Chatlist;
403403
use crate::config::Config;
404404
use crate::contact::{Contact, Origin};
@@ -667,7 +667,8 @@ Here's my footer -- bob@example.net"
667667
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id).await?.len(), 2);
668668

669669
let bob_reaction_msg = bob.pop_sent_msg().await;
670-
alice.recv_msg_trash(&bob_reaction_msg).await;
670+
let alice_reaction_msg = alice.recv_msg_hidden(&bob_reaction_msg).await;
671+
assert_eq!(alice_reaction_msg.state, MessageState::InNoticed);
671672
assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 2);
672673

673674
let reactions = get_msg_reactions(&alice, alice_msg.sender_msg_id).await?;
@@ -691,6 +692,20 @@ Here's my footer -- bob@example.net"
691692
.await?;
692693
expect_no_unwanted_events(&alice).await;
693694

695+
marknoticed_chat(&alice, chat_alice.id).await?;
696+
assert_eq!(
697+
alice_reaction_msg.id.get_state(&alice).await?,
698+
MessageState::InSeen
699+
);
700+
// Reactions don't request MDNs.
701+
assert_eq!(
702+
alice
703+
.sql
704+
.count("SELECT COUNT(*) FROM smtp_mdns", ())
705+
.await?,
706+
0
707+
);
708+
694709
// Alice reacts to own message.
695710
send_reaction(&alice, alice_msg.sender_msg_id, "👍 😀")
696711
.await
@@ -730,7 +745,7 @@ Here's my footer -- bob@example.net"
730745
bob_msg1.chat_id.accept(&bob).await?;
731746
send_reaction(&bob, bob_msg1.id, "👍").await?;
732747
let bob_send_reaction = bob.pop_sent_msg().await;
733-
alice.recv_msg_trash(&bob_send_reaction).await;
748+
alice.recv_msg_hidden(&bob_send_reaction).await;
734749
expect_incoming_reactions_event(
735750
&alice,
736751
alice_chat.id,
@@ -899,7 +914,7 @@ Here's my footer -- bob@example.net"
899914
let bob_reaction_msg = bob.pop_sent_msg().await;
900915

901916
// Alice receives a reaction.
902-
alice.recv_msg_trash(&bob_reaction_msg).await;
917+
alice.recv_msg_hidden(&bob_reaction_msg).await;
903918

904919
let reactions = get_msg_reactions(&alice, alice_msg_id).await?;
905920
assert_eq!(reactions.to_string(), "👍1");
@@ -951,7 +966,7 @@ Here's my footer -- bob@example.net"
951966
{
952967
send_reaction(&alice2, alice2_msg.id, "👍").await?;
953968
let msg = alice2.pop_sent_msg().await;
954-
alice1.recv_msg_trash(&msg).await;
969+
alice1.recv_msg_hidden(&msg).await;
955970
}
956971

957972
// Check that the status is still the same.
@@ -973,7 +988,7 @@ Here's my footer -- bob@example.net"
973988
let alice1_msg = alice1.recv_msg(&alice0.pop_sent_msg().await).await;
974989

975990
send_reaction(&alice0, alice0_msg_id, "👀").await?;
976-
alice1.recv_msg_trash(&alice0.pop_sent_msg().await).await;
991+
alice1.recv_msg_hidden(&alice0.pop_sent_msg().await).await;
977992

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

src/receive_imf.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ async fn add_parts(
778778
// (of course, the user can add other chats manually later)
779779
let to_id: ContactId;
780780
let state: MessageState;
781-
let mut hidden = false;
781+
let mut hidden = is_reaction;
782782
let mut needs_delete_job = false;
783783
let mut restore_protection = false;
784784

@@ -1033,13 +1033,12 @@ async fn add_parts(
10331033
}
10341034
}
10351035

1036-
state = if seen
1037-
|| fetching_existing_messages
1038-
|| is_mdn
1039-
|| is_reaction
1040-
|| chat_id_blocked == Blocked::Yes
1036+
state = if seen || fetching_existing_messages || is_mdn || chat_id_blocked == Blocked::Yes
1037+
// No check for `hidden` because only reactions are such and they should be `InFresh`.
10411038
{
10421039
MessageState::InSeen
1040+
} else if is_reaction {
1041+
MessageState::InNoticed
10431042
} else {
10441043
MessageState::InFresh
10451044
};
@@ -1246,14 +1245,10 @@ async fn add_parts(
12461245
}
12471246

12481247
let orig_chat_id = chat_id;
1249-
let mut chat_id = if is_reaction {
1248+
let mut chat_id = chat_id.unwrap_or_else(|| {
1249+
info!(context, "No chat id for message (TRASH).");
12501250
DC_CHAT_ID_TRASH
1251-
} else {
1252-
chat_id.unwrap_or_else(|| {
1253-
info!(context, "No chat id for message (TRASH).");
1254-
DC_CHAT_ID_TRASH
1255-
})
1256-
};
1251+
});
12571252

12581253
// Extract ephemeral timer from the message or use the existing timer if the message is not fully downloaded.
12591254
let mut ephemeral_timer = if is_partial_download.is_some() {
@@ -1602,27 +1597,27 @@ RETURNING id
16021597
replace_msg_id,
16031598
rfc724_mid_orig,
16041599
if trash { DC_CHAT_ID_TRASH } else { chat_id },
1605-
if trash { ContactId::UNDEFINED } else { from_id },
1606-
if trash { ContactId::UNDEFINED } else { to_id },
1600+
if trash || hidden { ContactId::UNDEFINED } else { from_id },
1601+
if trash || hidden { ContactId::UNDEFINED } else { to_id },
16071602
sort_timestamp,
16081603
mime_parser.timestamp_sent,
16091604
mime_parser.timestamp_rcvd,
16101605
typ,
16111606
state,
16121607
is_dc_message,
1613-
if trash { "" } else { msg },
1614-
if trash { None } else { message::normalize_text(msg) },
1615-
if trash { "" } else { &subject },
1608+
if trash || hidden { "" } else { msg },
1609+
if trash || hidden { None } else { message::normalize_text(msg) },
1610+
if trash || hidden { "" } else { &subject },
16161611
// txt_raw might contain invalid utf8
1617-
if trash { "" } else { &txt_raw },
1612+
if trash || hidden { "" } else { &txt_raw },
16181613
if trash {
16191614
"".to_string()
16201615
} else {
16211616
param.to_string()
16221617
},
16231618
hidden,
16241619
part.bytes as isize,
1625-
if (save_mime_headers || save_mime_modified) && !trash {
1620+
if (save_mime_headers || save_mime_modified) && !(trash || hidden) {
16261621
mime_headers.clone()
16271622
} else {
16281623
Vec::new()

src/test_utils.rs

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

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

0 commit comments

Comments
 (0)