Notify about incoming contact requests

This commit is contained in:
link2xt
2021-09-18 09:49:43 +00:00
parent 47bf67e658
commit 4e8724694a
3 changed files with 40 additions and 26 deletions

View File

@@ -973,7 +973,7 @@ class TestOnlineAccount:
ac1._evtracker.wait_msg_delivered(msg1)
lp.sec("wait for ac2 to receive message")
msg2 = ac2._evtracker.wait_next_messages_changed()
msg2 = ac2._evtracker.wait_next_incoming_message()
assert msg2.text == "message1"
assert not msg2.is_forwarded()
assert msg2.get_sender_contact().display_name == ac1.get_config("displayname")
@@ -1125,7 +1125,7 @@ class TestOnlineAccount:
group1.add_contact(ac2)
group1.send_text("hello")
msg2 = ac2._evtracker.wait_next_messages_changed()
msg2 = ac2._evtracker.wait_next_incoming_message()
group2 = msg2.create_chat()
assert group2.get_name() == group1.get_name()
@@ -1188,7 +1188,7 @@ class TestOnlineAccount:
chat.send_text("message1")
lp.sec("wait for ac2 to receive message")
msg2 = ac2._evtracker.wait_next_messages_changed()
msg2 = ac2._evtracker.wait_next_incoming_message()
assert msg2.text == "message1"
lp.sec("create new chat with contact and send back (encrypted) message")
@@ -1468,7 +1468,7 @@ class TestOnlineAccount:
assert not msg1.is_encrypted()
lp.sec("wait for ac2 to receive message")
msg2 = ac2._evtracker.wait_next_messages_changed()
msg2 = ac2._evtracker.wait_next_incoming_message()
assert msg2.text == "message1"
assert not msg2.is_encrypted()
@@ -1517,7 +1517,7 @@ class TestOnlineAccount:
chat1.send_text("hi")
lp.sec("ac2 receives contact request from ac1")
received_message = ac2._evtracker.wait_next_messages_changed()
received_message = ac2._evtracker.wait_next_incoming_message()
assert received_message.text == "hi"
basename = "attachment.txt"
@@ -1552,7 +1552,7 @@ class TestOnlineAccount:
assert msg_out.get_mime_headers() is None
lp.sec("wait for ac2 to receive message")
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
in_id = ev.data2
mime = ac2.get_message_by_id(in_id).get_mime_headers()
assert mime.get_all("From")
@@ -1851,7 +1851,7 @@ class TestOnlineAccount:
ac1.create_chat(ac2).send_text("with avatar!")
lp.sec("ac2: wait for receiving message and avatar from ac1")
msg2 = ac2._evtracker.wait_next_messages_changed()
msg2 = ac2._evtracker.wait_next_incoming_message()
assert msg2.chat.is_contact_request()
received_path = msg2.get_sender_contact().get_profile_image()
assert open(received_path, "rb").read() == open(p, "rb").read()
@@ -2681,7 +2681,7 @@ class TestOnlineAccount:
lp.sec("receive a message")
ac2.create_group_chat("group name", contacts=[ac1]).send_text("incoming, unencrypted group message")
ac1._evtracker.wait_next_messages_changed()
ac1._evtracker.wait_next_incoming_message()
lp.sec("send out message with bcc to ourselves")
ac1.direct_imap.idle_start()

View File

@@ -6,8 +6,6 @@ import shutil
import pytest
from filecmp import cmp
from deltachat import const
def wait_msg_delivered(account, msg_list):
""" wait for one or more MSG_DELIVERED events to match msg_list contents. """
@@ -102,14 +100,10 @@ class TestOnlineInCreation:
])
lp.sec("wait1 for original or forwarded messages to arrive")
ev1 = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
assert ev1.data1 > const.DC_CHAT_ID_LAST_SPECIAL
received_original = ac2.get_message_by_id(ev1.data2)
received_original = ac2._evtracker.wait_next_incoming_message()
assert cmp(received_original.filename, orig, shallow=False)
lp.sec("wait2 for original or forwarded messages to arrive")
ev2 = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
assert ev2.data1 > const.DC_CHAT_ID_LAST_SPECIAL
assert ev2.data1 != ev1.data1
received_copy = ac2.get_message_by_id(ev2.data2)
received_copy = ac2._evtracker.wait_next_incoming_message()
assert received_copy.id != received_original.id
assert cmp(received_copy.filename, orig, shallow=False)

View File

@@ -813,7 +813,7 @@ async fn add_parts(
if let Some(chat_id) = chat_id {
if Blocked::Not != chat_id_blocked {
chat_id.unblock(context).await?;
chat_id_blocked = Blocked::Not;
// Not assigning `chat_id_blocked = Blocked::Not` to avoid unused_assignments warning.
}
}
}
@@ -1184,15 +1184,13 @@ INSERT INTO msgs
}
// check event to send
if chat_id.is_trash() || *hidden {
*create_event_to_send = None;
*create_event_to_send = if chat_id.is_trash() || *hidden {
None
} else if incoming && state == MessageState::InFresh {
if Blocked::Not != chat_id_blocked {
*create_event_to_send = Some(CreateEvent::MsgsChanged);
} else {
*create_event_to_send = Some(CreateEvent::IncomingMsg);
}
}
Some(CreateEvent::IncomingMsg)
} else {
Some(CreateEvent::MsgsChanged)
};
if !is_mdn {
let mut chat = Chat::load_from_db(context, chat_id).await?;
@@ -4673,4 +4671,26 @@ Reply to all"#,
Ok(())
}
/// Tests that user is notified about new incoming contact requests.
#[async_std::test]
async fn test_incoming_contact_request() -> Result<()> {
let t = TestContext::new_alice().await;
dc_receive_imf(&t, MSGRMSG, "INBOX", 1, false).await?;
let msg = t.get_last_msg().await;
let chat = chat::Chat::load_from_db(&t, msg.chat_id).await?;
assert!(chat.is_contact_request());
let duration = std::time::Duration::from_secs(1);
loop {
let event = async_std::future::timeout(duration, t.evtracker.recv()).await??;
if let EventType::IncomingMsg { chat_id, msg_id } = &event {
assert_eq!(msg.chat_id, *chat_id);
assert_eq!(msg.id, *msg_id);
return Ok(());
}
}
}
}