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

@@ -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(());
}
}
}
}