mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 22:06:29 +03:00
Move module functions to type methods
This moves the module-level lookup and creation functions to the types, which make the naming more consistent. Now the lookup_* get_* and create_* functions all behave similarly. Peraps even more important the API of the lookup now allows distinguishing failure from not found. This in turn is important to be able to remove reliance on a ChatId with a 0 or "unset" value. The locations where this ChatId(0) is still used is in database queries which should be solved in an independed commit.
This commit is contained in:
@@ -474,10 +474,9 @@ async fn add_parts(
|
||||
}
|
||||
}
|
||||
|
||||
let (test_normal_chat_id, test_normal_chat_id_blocked) =
|
||||
chat::lookup_by_contact_id(context, from_id)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
let test_normal_chat = ChatIdBlocked::lookup_by_contact(context, from_id)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
// get the chat_id - a chat_id here is no indicator that the chat is displayed in the normal list,
|
||||
// it might also be blocked and displayed in the deaddrop as a result
|
||||
@@ -498,17 +497,18 @@ async fn add_parts(
|
||||
if chat_id.is_unset() {
|
||||
// try to create a group
|
||||
|
||||
let create_blocked =
|
||||
if !test_normal_chat_id.is_unset() && test_normal_chat_id_blocked == Blocked::Not {
|
||||
Blocked::Not
|
||||
} else {
|
||||
Blocked::Deaddrop
|
||||
};
|
||||
let create_blocked = match test_normal_chat {
|
||||
Some(ChatIdBlocked {
|
||||
id: _,
|
||||
blocked: Blocked::Not,
|
||||
}) => Blocked::Not,
|
||||
_ => Blocked::Deaddrop,
|
||||
};
|
||||
|
||||
let (new_chat_id, new_chat_id_blocked) = create_or_lookup_group(
|
||||
context,
|
||||
&mut mime_parser,
|
||||
if test_normal_chat_id.is_unset() {
|
||||
if test_normal_chat.is_none() {
|
||||
allow_creation
|
||||
} else {
|
||||
true
|
||||
@@ -600,9 +600,9 @@ async fn add_parts(
|
||||
Blocked::Deaddrop
|
||||
};
|
||||
|
||||
if !test_normal_chat_id.is_unset() {
|
||||
*chat_id = test_normal_chat_id;
|
||||
chat_id_blocked = test_normal_chat_id_blocked;
|
||||
if let Some(chat) = test_normal_chat {
|
||||
*chat_id = chat.id;
|
||||
chat_id_blocked = chat.blocked;
|
||||
} else if allow_creation {
|
||||
if let Ok(chat) = ChatIdBlocked::get_for_contact(context, from_id, create_blocked)
|
||||
.await
|
||||
@@ -2358,7 +2358,7 @@ mod tests {
|
||||
let t = TestContext::new_alice().await;
|
||||
|
||||
let bob_id = Contact::create(&t, "bob", "bob@example.com").await.unwrap();
|
||||
let one2one_id = chat::create_by_contact_id(&t, bob_id).await.unwrap();
|
||||
let one2one_id = ChatId::create_for_contact(&t, bob_id).await.unwrap();
|
||||
one2one_id
|
||||
.set_visibility(&t, ChatVisibility::Archived)
|
||||
.await
|
||||
@@ -2527,7 +2527,7 @@ mod tests {
|
||||
let contact_id = Contact::create(&t, "foobar", "foobar@example.com")
|
||||
.await
|
||||
.unwrap();
|
||||
let chat_id = chat::create_by_contact_id(&t, contact_id).await.unwrap();
|
||||
let chat_id = ChatId::create_for_contact(&t, contact_id).await.unwrap();
|
||||
dc_receive_imf(
|
||||
&t,
|
||||
b"From: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= <foobar@example.com>\n\
|
||||
|
||||
Reference in New Issue
Block a user