fix: do not return hidden chat from dc_get_chat_id_by_contact_id

This commit is contained in:
link2xt
2023-11-09 03:59:01 +00:00
parent 0b664e75cb
commit d4d6ced957
2 changed files with 16 additions and 6 deletions

View File

@@ -215,9 +215,16 @@ impl ChatId {
context: &Context,
contact_id: ContactId,
) -> Result<Option<Self>> {
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`.

View File

@@ -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.",