mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +03:00
fix: do not return hidden chat from dc_get_chat_id_by_contact_id
This commit is contained in:
13
src/chat.rs
13
src/chat.rs
@@ -215,9 +215,16 @@ impl ChatId {
|
|||||||
context: &Context,
|
context: &Context,
|
||||||
contact_id: ContactId,
|
contact_id: ContactId,
|
||||||
) -> Result<Option<Self>> {
|
) -> Result<Option<Self>> {
|
||||||
ChatIdBlocked::lookup_by_contact(context, contact_id)
|
let Some(chat_id_blocked) = ChatIdBlocked::lookup_by_contact(context, contact_id).await?
|
||||||
.await
|
else {
|
||||||
.map(|lookup| lookup.map(|chat| chat.id))
|
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`.
|
/// Returns the [`ChatId`] for the 1:1 chat with `contact_id`.
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ use tokio::sync::RwLock;
|
|||||||
use tokio::{fs, task};
|
use tokio::{fs, task};
|
||||||
|
|
||||||
use crate::chat::{
|
use crate::chat::{
|
||||||
self, add_to_chat_contacts_table, create_group_chat, Chat, ChatId, MessageListOptions,
|
self, add_to_chat_contacts_table, create_group_chat, Chat, ChatId, ChatIdBlocked,
|
||||||
ProtectionStatus,
|
MessageListOptions, ProtectionStatus,
|
||||||
};
|
};
|
||||||
use crate::chatlist::Chatlist;
|
use crate::chatlist::Chatlist;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
@@ -592,14 +592,17 @@ impl TestContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns 1:1 [`Chat`] with another account. Panics if it doesn't exist.
|
/// 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
|
/// This first creates a contact using the configured details on the other account, then
|
||||||
/// gets the 1:1 chat with this contact.
|
/// gets the 1:1 chat with this contact.
|
||||||
pub async fn get_chat(&self, other: &TestContext) -> Chat {
|
pub async fn get_chat(&self, other: &TestContext) -> Chat {
|
||||||
let contact = self.add_or_lookup_contact(other).await;
|
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
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.map(|chat_id_blocked| chat_id_blocked.id)
|
||||||
.expect(
|
.expect(
|
||||||
"There is no chat with this contact. \
|
"There is no chat with this contact. \
|
||||||
Hint: Use create_chat() instead of get_chat() if this is expected.",
|
Hint: Use create_chat() instead of get_chat() if this is expected.",
|
||||||
|
|||||||
Reference in New Issue
Block a user