diff --git a/src/chat.rs b/src/chat.rs index 054218674..a5f05df97 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -215,9 +215,16 @@ impl ChatId { context: &Context, contact_id: ContactId, ) -> Result> { - ChatIdBlocked::lookup_by_contact(context, contact_id) - .await - .map(|lookup| lookup.map(|chat| chat.id)) + let Some(chat_id_blocked) = ChatIdBlocked::lookup_by_contact(context, contact_id).await? + else { + return Ok(None); + }; + + let chat_id = match chat_id_blocked.blocked { + Blocked::Not | Blocked::Request => Some(chat_id_blocked.id), + Blocked::Yes => None, + }; + Ok(chat_id) } /// Returns the [`ChatId`] for the 1:1 chat with `contact_id`. diff --git a/src/test_utils.rs b/src/test_utils.rs index 5980ca41c..9cc6fd5f0 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -22,8 +22,8 @@ use tokio::sync::RwLock; use tokio::{fs, task}; use crate::chat::{ - self, add_to_chat_contacts_table, create_group_chat, Chat, ChatId, MessageListOptions, - ProtectionStatus, + self, add_to_chat_contacts_table, create_group_chat, Chat, ChatId, ChatIdBlocked, + MessageListOptions, ProtectionStatus, }; use crate::chatlist::Chatlist; use crate::config::Config; @@ -592,14 +592,17 @@ impl TestContext { } /// Returns 1:1 [`Chat`] with another account. Panics if it doesn't exist. + /// May return a blocked chat. /// /// This first creates a contact using the configured details on the other account, then /// gets the 1:1 chat with this contact. pub async fn get_chat(&self, other: &TestContext) -> Chat { let contact = self.add_or_lookup_contact(other).await; - let chat_id = ChatId::lookup_by_contact(&self.ctx, contact.id) + + let chat_id = ChatIdBlocked::lookup_by_contact(&self.ctx, contact.id) .await .unwrap() + .map(|chat_id_blocked| chat_id_blocked.id) .expect( "There is no chat with this contact. \ Hint: Use create_chat() instead of get_chat() if this is expected.",