Skip to content

Commit ffd59c6

Browse files
committed
try to do sth simple
1 parent fc06351 commit ffd59c6

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)]
@@ -3332,7 +3332,7 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()>
33323332
} else {
33333333
start_chat_ephemeral_timers(context, chat_id).await?;
33343334

3335-
if context
3335+
let noticed_msgs_count = context
33363336
.sql
33373337
.execute(
33383338
"UPDATE msgs
@@ -3342,9 +3342,36 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()>
33423342
AND chat_id=?;",
33433343
(MessageState::InNoticed, MessageState::InFresh, chat_id),
33443344
)
3345-
.await?
3346-
== 0
3347-
{
3345+
.await?;
3346+
3347+
// This is to trigger emitting `MsgsNoticed` on other devices when reactions are noticed
3348+
// locally (i.e. when the chat was opened locally).
3349+
let hidden_messages = context
3350+
.sql
3351+
.query_map(
3352+
"SELECT id, rfc724_mid FROM msgs
3353+
WHERE state=?
3354+
AND hidden=1
3355+
AND chat_id=?
3356+
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
3357+
(MessageState::InNoticed, chat_id),
3358+
|row| {
3359+
let msg_id: MsgId = row.get(0)?;
3360+
let rfc724_mid: String = row.get(1)?;
3361+
Ok((msg_id, rfc724_mid))
3362+
},
3363+
|rows| {
3364+
rows.collect::<std::result::Result<Vec<_>, _>>()
3365+
.map_err(Into::into)
3366+
},
3367+
)
3368+
.await?;
3369+
for (msg_id, rfc724_mid) in &hidden_messages {
3370+
message::update_msg_state(context, *msg_id, MessageState::InSeen).await?;
3371+
imap::markseen_on_imap_table(context, rfc724_mid).await?;
3372+
}
3373+
3374+
if noticed_msgs_count == 0 {
33483375
return Ok(());
33493376
}
33503377
}

src/reaction.rs

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

399399
use super::*;
400-
use crate::chat::{forward_msgs, get_chat_msgs, send_text_msg};
400+
use crate::chat::{forward_msgs, get_chat_msgs, marknoticed_chat, send_text_msg};
401401
use crate::chatlist::Chatlist;
402402
use crate::config::Config;
403403
use crate::contact::{Contact, Origin};
@@ -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::InNoticed);
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?;
@@ -680,6 +681,20 @@ Here's my footer -- [email protected]"
680681
expect_incoming_reactions_event(&alice, alice_msg.sender_msg_id, *bob_id, "👍").await?;
681682
expect_no_unwanted_events(&alice).await;
682683

684+
marknoticed_chat(&alice, chat_alice.id).await?;
685+
assert_eq!(
686+
alice_reaction_msg.id.get_state(&alice).await?,
687+
MessageState::InSeen
688+
);
689+
// Reactions don't request MDNs.
690+
assert_eq!(
691+
alice
692+
.sql
693+
.count("SELECT COUNT(*) FROM smtp_mdns", ())
694+
.await?,
695+
0
696+
);
697+
683698
// Alice reacts to own message.
684699
send_reaction(&alice, alice_msg.sender_msg_id, "👍 😀")
685700
.await
@@ -719,7 +734,7 @@ Here's my footer -- [email protected]"
719734
bob_msg1.chat_id.accept(&bob).await?;
720735
send_reaction(&bob, bob_msg1.id, "👍").await?;
721736
let bob_send_reaction = bob.pop_sent_msg().await;
722-
alice.recv_msg_trash(&bob_send_reaction).await;
737+
alice.recv_msg_hidden(&bob_send_reaction).await;
723738
expect_incoming_reactions_event(&alice, alice_msg1.sender_msg_id, alice_bob_id, "👍")
724739
.await?;
725740
expect_no_unwanted_events(&alice).await;
@@ -882,7 +897,7 @@ Here's my footer -- [email protected]"
882897
let bob_reaction_msg = bob.pop_sent_msg().await;
883898

884899
// Alice receives a reaction.
885-
alice.recv_msg_trash(&bob_reaction_msg).await;
900+
alice.recv_msg_hidden(&bob_reaction_msg).await;
886901

887902
let reactions = get_msg_reactions(&alice, alice_msg_id).await?;
888903
assert_eq!(reactions.to_string(), "👍1");
@@ -934,7 +949,7 @@ Here's my footer -- [email protected]"
934949
{
935950
send_reaction(&alice2, alice2_msg.id, "👍").await?;
936951
let msg = alice2.pop_sent_msg().await;
937-
alice1.recv_msg_trash(&msg).await;
952+
alice1.recv_msg_hidden(&msg).await;
938953
}
939954

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

958973
send_reaction(&alice0, alice0_msg_id, "👀").await?;
959-
alice1.recv_msg_trash(&alice0.pop_sent_msg().await).await;
974+
alice1.recv_msg_hidden(&alice0.pop_sent_msg().await).await;
960975

961976
expect_reactions_changed_event(&alice0, chat_id, alice0_msg_id, ContactId::SELF).await?;
962977
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)