Skip to content

Commit f3170d0

Browse files
committed
fix: stop notifying about messages in contact request chats
1 parent 2ada3cd commit f3170d0

File tree

8 files changed

+110
-45
lines changed

8 files changed

+110
-45
lines changed

deltachat-rpc-client/tests/test_calls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_no_contact_request_call(acfactory) -> None:
103103
# There should be no incoming call notification.
104104
assert event.kind != EventType.INCOMING_CALL
105105

106-
if event.kind == EventType.INCOMING_MSG:
106+
if event.kind == EventType.MSGS_CHANGED:
107107
msg = bob.get_message_by_id(event.msg_id)
108-
assert msg.get_snapshot().text == "Hello!"
109-
break
108+
if msg.get_snapshot().text == "Hello!":
109+
break

deltachat-rpc-client/tests/test_chatlist_events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def test_imap_sync_seen_msgs(acfactory: ACFactory) -> None:
169169
"""
170170
alice, alice_second_device, bob, alice_chat_bob = get_multi_account_test_setup(acfactory)
171171

172+
bob.create_chat(alice)
173+
172174
alice_chat_bob.send_text("hello")
173175

174176
msg = bob.wait_for_incoming_msg()

deltachat-rpc-client/tests/test_iroh_webxdc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ def test_advertisement_after_chatting(acfactory, path_to_webxdc):
214214
ac1_ac2_chat = ac1.create_chat(ac2)
215215
ac1_webxdc_msg = ac1_ac2_chat.send_message(text="WebXDC", file=path_to_webxdc)
216216
ac2_webxdc_msg = ac2.wait_for_incoming_msg()
217-
assert ac2_webxdc_msg.get_snapshot().text == "WebXDC"
217+
ac2_webxdc_msg_snapshot = ac2_webxdc_msg.get_snapshot()
218+
assert ac2_webxdc_msg_snapshot.text == "WebXDC"
219+
ac2_webxdc_msg_snapshot.chat.accept()
218220

219221
ac1_ac2_chat.send_text("Hello!")
220222
ac2_hello_msg = ac2.wait_for_incoming_msg()

deltachat-rpc-client/tests/test_something.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ def test_receive_imf_failure(acfactory) -> None:
347347
assert snapshot.download_state == DownloadState.AVAILABLE
348348
assert snapshot.error is not None
349349
assert snapshot.show_padlock
350+
snapshot.chat.accept()
350351

351352
# The failed message doesn't break the IMAP loop.
352353
bob.set_config("fail_on_receiving_full_msg", "0")
@@ -888,10 +889,12 @@ def test_rename_group(acfactory):
888889
bob_msg = bob.wait_for_incoming_msg()
889890
bob_chat = bob_msg.get_snapshot().chat
890891
assert bob_chat.get_basic_snapshot().name == "Test group"
892+
bob.wait_for_event(EventType.CHATLIST_ITEM_CHANGED)
891893

892894
for name in ["Baz", "Foo bar", "Xyzzy"]:
893895
alice_group.set_name(name)
894-
bob.wait_for_incoming_msg_event()
896+
bob.wait_for_event(EventType.CHATLIST_ITEM_CHANGED)
897+
bob.wait_for_event(EventType.CHATLIST_ITEM_CHANGED)
895898
assert bob_chat.get_basic_snapshot().name == name
896899

897900

deltachat-rpc-client/tests/test_vcard.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
def test_vcard(acfactory) -> None:
22
alice, bob, fiona = acfactory.get_online_accounts(3)
33

4+
bob.create_chat(alice)
45
alice_contact_bob = alice.create_contact(bob, "Bob")
56
alice_contact_charlie = alice.create_contact("[email protected]", "Charlie")
67
alice_contact_charlie_snapshot = alice_contact_charlie.get_snapshot()

python/tests/test_1_online.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def test_forward_own_message(acfactory, lp):
460460

461461
def test_resend_message(acfactory, lp):
462462
ac1, ac2 = acfactory.get_online_accounts(2)
463-
chat1 = ac1.create_chat(ac2)
463+
chat1 = acfactory.get_accepted_chat(ac1, ac2)
464464

465465
lp.sec("ac1: send message to ac2")
466466
chat1.send_text("message")

src/receive_imf.rs

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,9 @@ pub(crate) async fn receive_imf_inner(
715715
mark_recipients_as_verified(context, from_id, &mime_parser).await?;
716716
}
717717

718+
let is_old_contact_request;
718719
let received_msg = if let Some(received_msg) = received_msg {
720+
is_old_contact_request = false;
719721
received_msg
720722
} else {
721723
let is_dc_message = if mime_parser.has_chat_version() {
@@ -754,9 +756,9 @@ pub(crate) async fn receive_imf_inner(
754756
to_ids.first().copied().flatten().unwrap_or(ContactId::SELF)
755757
};
756758

757-
let (chat_id, chat_id_blocked) = do_chat_assignment(
759+
let (chat_id, chat_id_blocked, is_created) = do_chat_assignment(
758760
context,
759-
chat_assignment,
761+
&chat_assignment,
760762
from_id,
761763
&to_ids,
762764
&past_ids,
@@ -767,6 +769,7 @@ pub(crate) async fn receive_imf_inner(
767769
parent_message,
768770
)
769771
.await?;
772+
is_old_contact_request = chat_id_blocked == Blocked::Request && !is_created;
770773

771774
// Add parts
772775
add_parts(
@@ -984,8 +987,9 @@ pub(crate) async fn receive_imf_inner(
984987
let fresh = received_msg.state == MessageState::InFresh
985988
&& mime_parser.is_system_message != SystemMessage::CallAccepted
986989
&& mime_parser.is_system_message != SystemMessage::CallEnded;
990+
let important = mime_parser.incoming && fresh && !is_old_contact_request;
987991
for msg_id in &received_msg.msg_ids {
988-
chat_id.emit_msg_event(context, *msg_id, mime_parser.incoming && fresh);
992+
chat_id.emit_msg_event(context, *msg_id, important);
989993
}
990994
}
991995
context.new_msgs_notify.notify_one();
@@ -1279,10 +1283,15 @@ async fn decide_chat_assignment(
12791283
/// Assigns the message to a chat.
12801284
///
12811285
/// Creates a new chat if necessary.
1286+
///
1287+
/// Returns the chat ID,
1288+
/// whether it is blocked
1289+
/// and if the chat was created by this function
1290+
/// (as opposed to being looked up among existing chats).
12821291
#[expect(clippy::too_many_arguments)]
12831292
async fn do_chat_assignment(
12841293
context: &Context,
1285-
chat_assignment: ChatAssignment,
1294+
chat_assignment: &ChatAssignment,
12861295
from_id: ContactId,
12871296
to_ids: &[Option<ContactId>],
12881297
past_ids: &[Option<ContactId>],
@@ -1291,11 +1300,12 @@ async fn do_chat_assignment(
12911300
mime_parser: &mut MimeMessage,
12921301
is_partial_download: Option<u32>,
12931302
parent_message: Option<Message>,
1294-
) -> Result<(ChatId, Blocked)> {
1303+
) -> Result<(ChatId, Blocked, bool)> {
12951304
let is_bot = context.get_config_bool(Config::Bot).await?;
12961305

12971306
let mut chat_id = None;
12981307
let mut chat_id_blocked = Blocked::Not;
1308+
let mut chat_created = false;
12991309

13001310
if mime_parser.incoming {
13011311
let test_normal_chat = ChatIdBlocked::lookup_by_contact(context, from_id).await?;
@@ -1350,12 +1360,13 @@ async fn do_chat_assignment(
13501360
{
13511361
chat_id = Some(new_chat_id);
13521362
chat_id_blocked = new_chat_id_blocked;
1363+
chat_created = true;
13531364
}
13541365
}
13551366
}
13561367
ChatAssignment::MailingListOrBroadcast => {
13571368
if let Some(mailinglist_header) = mime_parser.get_mailinglist_header() {
1358-
if let Some((new_chat_id, new_chat_id_blocked)) =
1369+
if let Some((new_chat_id, new_chat_id_blocked, new_chat_created)) =
13591370
create_or_lookup_mailinglist_or_broadcast(
13601371
context,
13611372
allow_creation,
@@ -1367,6 +1378,7 @@ async fn do_chat_assignment(
13671378
{
13681379
chat_id = Some(new_chat_id);
13691380
chat_id_blocked = new_chat_id_blocked;
1381+
chat_created = new_chat_created;
13701382

13711383
apply_mailinglist_changes(context, mime_parser, new_chat_id).await?;
13721384
}
@@ -1380,18 +1392,20 @@ async fn do_chat_assignment(
13801392
chat_id_blocked = *new_chat_id_blocked;
13811393
}
13821394
ChatAssignment::AdHocGroup => {
1383-
if let Some((new_chat_id, new_chat_id_blocked)) = lookup_or_create_adhoc_group(
1384-
context,
1385-
mime_parser,
1386-
to_ids,
1387-
allow_creation || test_normal_chat.is_some(),
1388-
create_blocked,
1389-
is_partial_download.is_some(),
1390-
)
1391-
.await?
1395+
if let Some((new_chat_id, new_chat_id_blocked, new_created)) =
1396+
lookup_or_create_adhoc_group(
1397+
context,
1398+
mime_parser,
1399+
to_ids,
1400+
allow_creation || test_normal_chat.is_some(),
1401+
create_blocked,
1402+
is_partial_download.is_some(),
1403+
)
1404+
.await?
13921405
{
13931406
chat_id = Some(new_chat_id);
13941407
chat_id_blocked = new_chat_id_blocked;
1408+
chat_created = new_created;
13951409
}
13961410
}
13971411
ChatAssignment::OneOneChat => {}
@@ -1427,6 +1441,7 @@ async fn do_chat_assignment(
14271441
.context("Failed to get (new) chat for contact")?;
14281442
chat_id = Some(chat.id);
14291443
chat_id_blocked = chat.blocked;
1444+
chat_created = true;
14301445
}
14311446

14321447
if let Some(chat_id) = chat_id {
@@ -1479,6 +1494,7 @@ async fn do_chat_assignment(
14791494
{
14801495
chat_id = Some(new_chat_id);
14811496
chat_id_blocked = new_chat_id_blocked;
1497+
chat_created = true;
14821498
}
14831499
}
14841500
}
@@ -1499,6 +1515,7 @@ async fn do_chat_assignment(
14991515
{
15001516
id
15011517
} else {
1518+
chat_created = true;
15021519
let name =
15031520
compute_mailinglist_name(mailinglist_header, &listid, mime_parser);
15041521
chat::create_broadcast_ex(context, Nosync, listid, name).await?
@@ -1507,18 +1524,20 @@ async fn do_chat_assignment(
15071524
}
15081525
}
15091526
ChatAssignment::AdHocGroup => {
1510-
if let Some((new_chat_id, new_chat_id_blocked)) = lookup_or_create_adhoc_group(
1511-
context,
1512-
mime_parser,
1513-
to_ids,
1514-
allow_creation,
1515-
Blocked::Not,
1516-
is_partial_download.is_some(),
1517-
)
1518-
.await?
1527+
if let Some((new_chat_id, new_chat_id_blocked, new_chat_created)) =
1528+
lookup_or_create_adhoc_group(
1529+
context,
1530+
mime_parser,
1531+
to_ids,
1532+
allow_creation,
1533+
Blocked::Not,
1534+
is_partial_download.is_some(),
1535+
)
1536+
.await?
15191537
{
15201538
chat_id = Some(new_chat_id);
15211539
chat_id_blocked = new_chat_id_blocked;
1540+
chat_created = new_chat_created;
15221541
}
15231542
}
15241543
ChatAssignment::OneOneChat => {}
@@ -1538,6 +1557,7 @@ async fn do_chat_assignment(
15381557
let chat = ChatIdBlocked::get_for_contact(context, to_id, Blocked::Not).await?;
15391558
chat_id = Some(chat.id);
15401559
chat_id_blocked = chat.blocked;
1560+
chat_created = true;
15411561
}
15421562
}
15431563
if chat_id.is_none() && mime_parser.has_chat_version() {
@@ -1575,7 +1595,7 @@ async fn do_chat_assignment(
15751595
info!(context, "No chat id for message (TRASH).");
15761596
DC_CHAT_ID_TRASH
15771597
});
1578-
Ok((chat_id, chat_id_blocked))
1598+
Ok((chat_id, chat_id_blocked, chat_created))
15791599
}
15801600

15811601
/// Creates a `ReceivedMsg` from given parts which might consist of
@@ -2402,7 +2422,7 @@ async fn lookup_or_create_adhoc_group(
24022422
allow_creation: bool,
24032423
create_blocked: Blocked,
24042424
is_partial_download: bool,
2405-
) -> Result<Option<(ChatId, Blocked)>> {
2425+
) -> Result<Option<(ChatId, Blocked, bool)>> {
24062426
// Partial download may be an encrypted message with protected Subject header. We do not want to
24072427
// create a group with "..." or "Encrypted message" as a subject. The same is for undecipherable
24082428
// messages. Instead, assign the message to 1:1 chat with the sender.
@@ -2492,12 +2512,12 @@ async fn lookup_or_create_adhoc_group(
24922512
context,
24932513
"Assigning message to ad-hoc group {chat_id} with matching name and members."
24942514
);
2495-
return Ok(Some((chat_id, blocked)));
2515+
return Ok(Some((chat_id, blocked, false)));
24962516
}
24972517
if !allow_creation {
24982518
return Ok(None);
24992519
}
2500-
create_adhoc_group(
2520+
Ok(create_adhoc_group(
25012521
context,
25022522
mime_parser,
25032523
create_blocked,
@@ -2506,7 +2526,8 @@ async fn lookup_or_create_adhoc_group(
25062526
&grpname,
25072527
)
25082528
.await
2509-
.context("Could not create ad hoc group")
2529+
.context("Could not create ad hoc group")?
2530+
.map(|(chat_id, blocked)| (chat_id, blocked, true)))
25102531
}
25112532

25122533
/// If this method returns true, the message shall be assigned to the 1:1 chat with the sender.
@@ -3146,17 +3167,22 @@ fn mailinglist_header_listid(list_id_header: &str) -> Result<String> {
31463167
///
31473168
/// `mime_parser` is the corresponding message
31483169
/// and is used to figure out the mailing list name from different header fields.
3170+
///
3171+
/// Returns the chat ID,
3172+
/// whether it is blocked
3173+
/// and if the chat was created by this function
3174+
/// (as opposed to being looked up among existing chats).
31493175
async fn create_or_lookup_mailinglist_or_broadcast(
31503176
context: &Context,
31513177
allow_creation: bool,
31523178
list_id_header: &str,
31533179
from_id: ContactId,
31543180
mime_parser: &MimeMessage,
3155-
) -> Result<Option<(ChatId, Blocked)>> {
3181+
) -> Result<Option<(ChatId, Blocked, bool)>> {
31563182
let listid = mailinglist_header_listid(list_id_header)?;
31573183

31583184
if let Some((chat_id, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
3159-
return Ok(Some((chat_id, blocked)));
3185+
return Ok(Some((chat_id, blocked, false)));
31603186
}
31613187

31623188
let chattype = if mime_parser.was_encrypted() {
@@ -3220,7 +3246,7 @@ async fn create_or_lookup_mailinglist_or_broadcast(
32203246
)
32213247
.await?;
32223248
}
3223-
Ok(Some((chat_id, blocked)))
3249+
Ok(Some((chat_id, blocked, true)))
32243250
} else {
32253251
info!(context, "Creating list forbidden by caller.");
32263252
Ok(None)

0 commit comments

Comments
 (0)