mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
refactor: put duplicate code into lookup_chat_or_create_adhoc_group
This commit is contained in:
@@ -840,34 +840,23 @@ async fn add_parts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if chat_id.is_none() {
|
if chat_id.is_none() {
|
||||||
// try to assign to a chat based on In-Reply-To/References:
|
if let Some((new_chat_id, new_chat_id_blocked)) = lookup_chat_or_create_adhoc_group(
|
||||||
|
context,
|
||||||
if let Some((new_chat_id, new_chat_id_blocked)) =
|
mime_parser,
|
||||||
lookup_chat_by_reply(context, mime_parser, &parent, to_ids, from_id).await?
|
&parent,
|
||||||
|
to_ids,
|
||||||
|
from_id,
|
||||||
|
allow_creation || test_normal_chat.is_some(),
|
||||||
|
create_blocked,
|
||||||
|
is_partial_download.is_some(),
|
||||||
|
)
|
||||||
|
.await?
|
||||||
{
|
{
|
||||||
chat_id = Some(new_chat_id);
|
chat_id = Some(new_chat_id);
|
||||||
chat_id_blocked = new_chat_id_blocked;
|
chat_id_blocked = new_chat_id_blocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if chat_id.is_none() && (allow_creation || test_normal_chat.is_some()) {
|
|
||||||
// Try to create an ad hoc group.
|
|
||||||
if let Some(new_chat_id) = create_adhoc_group(
|
|
||||||
context,
|
|
||||||
mime_parser,
|
|
||||||
create_blocked,
|
|
||||||
from_id,
|
|
||||||
to_ids,
|
|
||||||
is_partial_download.is_some(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.context("Could not create ad hoc group")?
|
|
||||||
{
|
|
||||||
chat_id = Some(new_chat_id);
|
|
||||||
chat_id_blocked = create_blocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the chat is somehow blocked but we want to create a non-blocked chat,
|
// if the chat is somehow blocked but we want to create a non-blocked chat,
|
||||||
// unblock the chat
|
// unblock the chat
|
||||||
if chat_id_blocked != Blocked::Not && create_blocked != Blocked::Yes {
|
if chat_id_blocked != Blocked::Not && create_blocked != Blocked::Yes {
|
||||||
@@ -1087,17 +1076,6 @@ async fn add_parts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if chat_id.is_none() {
|
|
||||||
// try to assign to a chat based on In-Reply-To/References:
|
|
||||||
|
|
||||||
if let Some((new_chat_id, new_chat_id_blocked)) =
|
|
||||||
lookup_chat_by_reply(context, mime_parser, &parent, to_ids, from_id).await?
|
|
||||||
{
|
|
||||||
chat_id = Some(new_chat_id);
|
|
||||||
chat_id_blocked = new_chat_id_blocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if mime_parser.decrypting_failed && !fetching_existing_messages {
|
if mime_parser.decrypting_failed && !fetching_existing_messages {
|
||||||
if chat_id.is_none() {
|
if chat_id.is_none() {
|
||||||
chat_id = Some(DC_CHAT_ID_TRASH);
|
chat_id = Some(DC_CHAT_ID_TRASH);
|
||||||
@@ -1129,20 +1107,21 @@ async fn add_parts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if chat_id.is_none() && allow_creation {
|
if chat_id.is_none() {
|
||||||
if let Some(new_chat_id) = create_adhoc_group(
|
if let Some((new_chat_id, new_chat_id_blocked)) = lookup_chat_or_create_adhoc_group(
|
||||||
context,
|
context,
|
||||||
mime_parser,
|
mime_parser,
|
||||||
Blocked::Not,
|
&parent,
|
||||||
from_id,
|
|
||||||
to_ids,
|
to_ids,
|
||||||
|
from_id,
|
||||||
|
allow_creation,
|
||||||
|
Blocked::Not,
|
||||||
is_partial_download.is_some(),
|
is_partial_download.is_some(),
|
||||||
)
|
)
|
||||||
.await
|
.await?
|
||||||
.context("Could not create ad hoc group")?
|
|
||||||
{
|
{
|
||||||
chat_id = Some(new_chat_id);
|
chat_id = Some(new_chat_id);
|
||||||
chat_id_blocked = Blocked::Not;
|
chat_id_blocked = new_chat_id_blocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1811,6 +1790,44 @@ async fn lookup_chat_by_reply(
|
|||||||
Ok(Some((parent_chat.id, parent_chat.blocked)))
|
Ok(Some((parent_chat.id, parent_chat.blocked)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
async fn lookup_chat_or_create_adhoc_group(
|
||||||
|
context: &Context,
|
||||||
|
mime_parser: &MimeMessage,
|
||||||
|
parent: &Option<Message>,
|
||||||
|
to_ids: &[ContactId],
|
||||||
|
from_id: ContactId,
|
||||||
|
allow_creation: bool,
|
||||||
|
create_blocked: Blocked,
|
||||||
|
is_partial_download: bool,
|
||||||
|
) -> Result<Option<(ChatId, Blocked)>> {
|
||||||
|
if let Some((new_chat_id, new_chat_id_blocked)) =
|
||||||
|
// Try to assign to a chat based on In-Reply-To/References.
|
||||||
|
lookup_chat_by_reply(context, mime_parser, parent, to_ids, from_id).await?
|
||||||
|
{
|
||||||
|
Ok(Some((new_chat_id, new_chat_id_blocked)))
|
||||||
|
} else if allow_creation {
|
||||||
|
// Try to create an ad hoc group.
|
||||||
|
if let Some(new_chat_id) = create_adhoc_group(
|
||||||
|
context,
|
||||||
|
mime_parser,
|
||||||
|
create_blocked,
|
||||||
|
from_id,
|
||||||
|
to_ids,
|
||||||
|
is_partial_download,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.context("Could not create ad hoc group")?
|
||||||
|
{
|
||||||
|
Ok(Some((new_chat_id, create_blocked)))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If this method returns true, the message shall be assigned to the 1:1 chat with the sender.
|
/// If this method returns true, the message shall be assigned to the 1:1 chat with the sender.
|
||||||
/// If it returns false, it shall be assigned to the parent chat.
|
/// If it returns false, it shall be assigned to the parent chat.
|
||||||
async fn is_probably_private_reply(
|
async fn is_probably_private_reply(
|
||||||
|
|||||||
Reference in New Issue
Block a user