mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 22:36:30 +03:00
Notify about incoming contact requests
This commit is contained in:
@@ -973,7 +973,7 @@ class TestOnlineAccount:
|
|||||||
ac1._evtracker.wait_msg_delivered(msg1)
|
ac1._evtracker.wait_msg_delivered(msg1)
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
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 msg2.text == "message1"
|
||||||
assert not msg2.is_forwarded()
|
assert not msg2.is_forwarded()
|
||||||
assert msg2.get_sender_contact().display_name == ac1.get_config("displayname")
|
assert msg2.get_sender_contact().display_name == ac1.get_config("displayname")
|
||||||
@@ -1125,7 +1125,7 @@ class TestOnlineAccount:
|
|||||||
group1.add_contact(ac2)
|
group1.add_contact(ac2)
|
||||||
group1.send_text("hello")
|
group1.send_text("hello")
|
||||||
|
|
||||||
msg2 = ac2._evtracker.wait_next_messages_changed()
|
msg2 = ac2._evtracker.wait_next_incoming_message()
|
||||||
group2 = msg2.create_chat()
|
group2 = msg2.create_chat()
|
||||||
assert group2.get_name() == group1.get_name()
|
assert group2.get_name() == group1.get_name()
|
||||||
|
|
||||||
@@ -1188,7 +1188,7 @@ class TestOnlineAccount:
|
|||||||
chat.send_text("message1")
|
chat.send_text("message1")
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
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 msg2.text == "message1"
|
||||||
|
|
||||||
lp.sec("create new chat with contact and send back (encrypted) message")
|
lp.sec("create new chat with contact and send back (encrypted) message")
|
||||||
@@ -1468,7 +1468,7 @@ class TestOnlineAccount:
|
|||||||
assert not msg1.is_encrypted()
|
assert not msg1.is_encrypted()
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
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 msg2.text == "message1"
|
||||||
assert not msg2.is_encrypted()
|
assert not msg2.is_encrypted()
|
||||||
|
|
||||||
@@ -1517,7 +1517,7 @@ class TestOnlineAccount:
|
|||||||
chat1.send_text("hi")
|
chat1.send_text("hi")
|
||||||
|
|
||||||
lp.sec("ac2 receives contact request from ac1")
|
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"
|
assert received_message.text == "hi"
|
||||||
|
|
||||||
basename = "attachment.txt"
|
basename = "attachment.txt"
|
||||||
@@ -1552,7 +1552,7 @@ class TestOnlineAccount:
|
|||||||
assert msg_out.get_mime_headers() is None
|
assert msg_out.get_mime_headers() is None
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
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
|
in_id = ev.data2
|
||||||
mime = ac2.get_message_by_id(in_id).get_mime_headers()
|
mime = ac2.get_message_by_id(in_id).get_mime_headers()
|
||||||
assert mime.get_all("From")
|
assert mime.get_all("From")
|
||||||
@@ -1851,7 +1851,7 @@ class TestOnlineAccount:
|
|||||||
ac1.create_chat(ac2).send_text("with avatar!")
|
ac1.create_chat(ac2).send_text("with avatar!")
|
||||||
|
|
||||||
lp.sec("ac2: wait for receiving message and avatar from ac1")
|
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()
|
assert msg2.chat.is_contact_request()
|
||||||
received_path = msg2.get_sender_contact().get_profile_image()
|
received_path = msg2.get_sender_contact().get_profile_image()
|
||||||
assert open(received_path, "rb").read() == open(p, "rb").read()
|
assert open(received_path, "rb").read() == open(p, "rb").read()
|
||||||
@@ -2681,7 +2681,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("receive a message")
|
lp.sec("receive a message")
|
||||||
ac2.create_group_chat("group name", contacts=[ac1]).send_text("incoming, unencrypted group 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")
|
lp.sec("send out message with bcc to ourselves")
|
||||||
ac1.direct_imap.idle_start()
|
ac1.direct_imap.idle_start()
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import shutil
|
|||||||
import pytest
|
import pytest
|
||||||
from filecmp import cmp
|
from filecmp import cmp
|
||||||
|
|
||||||
from deltachat import const
|
|
||||||
|
|
||||||
|
|
||||||
def wait_msg_delivered(account, msg_list):
|
def wait_msg_delivered(account, msg_list):
|
||||||
""" wait for one or more MSG_DELIVERED events to match msg_list contents. """
|
""" 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")
|
lp.sec("wait1 for original or forwarded messages to arrive")
|
||||||
ev1 = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
received_original = ac2._evtracker.wait_next_incoming_message()
|
||||||
assert ev1.data1 > const.DC_CHAT_ID_LAST_SPECIAL
|
|
||||||
received_original = ac2.get_message_by_id(ev1.data2)
|
|
||||||
assert cmp(received_original.filename, orig, shallow=False)
|
assert cmp(received_original.filename, orig, shallow=False)
|
||||||
|
|
||||||
lp.sec("wait2 for original or forwarded messages to arrive")
|
lp.sec("wait2 for original or forwarded messages to arrive")
|
||||||
ev2 = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
received_copy = ac2._evtracker.wait_next_incoming_message()
|
||||||
assert ev2.data1 > const.DC_CHAT_ID_LAST_SPECIAL
|
assert received_copy.id != received_original.id
|
||||||
assert ev2.data1 != ev1.data1
|
|
||||||
received_copy = ac2.get_message_by_id(ev2.data2)
|
|
||||||
assert cmp(received_copy.filename, orig, shallow=False)
|
assert cmp(received_copy.filename, orig, shallow=False)
|
||||||
|
|||||||
@@ -813,7 +813,7 @@ async fn add_parts(
|
|||||||
if let Some(chat_id) = chat_id {
|
if let Some(chat_id) = chat_id {
|
||||||
if Blocked::Not != chat_id_blocked {
|
if Blocked::Not != chat_id_blocked {
|
||||||
chat_id.unblock(context).await?;
|
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
|
// check event to send
|
||||||
if chat_id.is_trash() || *hidden {
|
*create_event_to_send = if chat_id.is_trash() || *hidden {
|
||||||
*create_event_to_send = None;
|
None
|
||||||
} else if incoming && state == MessageState::InFresh {
|
} else if incoming && state == MessageState::InFresh {
|
||||||
if Blocked::Not != chat_id_blocked {
|
Some(CreateEvent::IncomingMsg)
|
||||||
*create_event_to_send = Some(CreateEvent::MsgsChanged);
|
} else {
|
||||||
} else {
|
Some(CreateEvent::MsgsChanged)
|
||||||
*create_event_to_send = Some(CreateEvent::IncomingMsg);
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_mdn {
|
if !is_mdn {
|
||||||
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
@@ -4673,4 +4671,26 @@ Reply to all"#,
|
|||||||
|
|
||||||
Ok(())
|
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(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user