mirror of
https://github.com/chatmail/core.git
synced 2026-05-23 00:36:32 +03:00
@link2xt's review
This commit is contained in:
@@ -1638,12 +1638,12 @@ pub(crate) async fn handle_ndn(
|
|||||||
context: &Context,
|
context: &Context,
|
||||||
failed: &FailureReport,
|
failed: &FailureReport,
|
||||||
error: Option<impl AsRef<str>>,
|
error: Option<impl AsRef<str>>,
|
||||||
) {
|
) -> anyhow::Result<()> {
|
||||||
if failed.rfc724_mid.is_empty() {
|
if failed.rfc724_mid.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let res: Result<Vec<_>, _> = context
|
let msgs: Result<Vec<_>, _> = context
|
||||||
.sql
|
.sql
|
||||||
.query_map(
|
.query_map(
|
||||||
concat!(
|
concat!(
|
||||||
@@ -1664,23 +1664,20 @@ pub(crate) async fn handle_ndn(
|
|||||||
},
|
},
|
||||||
|rows| Ok(rows.collect::<Vec<_>>()),
|
|rows| Ok(rows.collect::<Vec<_>>()),
|
||||||
)
|
)
|
||||||
.await;
|
.await?;
|
||||||
|
|
||||||
if let Err(ref err) = res {
|
for msg in msgs.iter() {
|
||||||
info!(context, "Failed to select NDN {:?}", err);
|
let (msg_id, chat_id, chat_type) = msg?;
|
||||||
|
set_msg_failed(context, *msg_id, error.as_ref()).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(msgs) = res {
|
if let Some(msg) = msgs.last() {
|
||||||
for msg in msgs.iter() {
|
let (msg_id, chat_id, chat_type) = msg?;
|
||||||
match msg {
|
// Add only one info msg for all failed messages
|
||||||
Ok((msg_id, chat_id, chat_type)) => {
|
ndn_maybe_add_info_msg(context, failed, chat_id, chat_type).await?;
|
||||||
set_msg_failed(context, *msg_id, error.as_ref()).await;
|
|
||||||
ndn_maybe_add_info_msg(context, failed, *chat_id, *chat_type).await;
|
|
||||||
}
|
|
||||||
Err(e) => warn!(context, "ndn error: {}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ndn_maybe_add_info_msg(
|
async fn ndn_maybe_add_info_msg(
|
||||||
@@ -1688,28 +1685,28 @@ async fn ndn_maybe_add_info_msg(
|
|||||||
failed: &FailureReport,
|
failed: &FailureReport,
|
||||||
chat_id: ChatId,
|
chat_id: ChatId,
|
||||||
chat_type: Chattype,
|
chat_type: Chattype,
|
||||||
) {
|
) -> anyhow::Result<()> {
|
||||||
if chat_type == Chattype::Group {
|
if chat_type == Chattype::Group {
|
||||||
if let Some(failed_recipient) = &failed.failed_recipient {
|
if let Some(failed_recipient) = &failed.failed_recipient {
|
||||||
let contact_id =
|
let contact_id =
|
||||||
Contact::lookup_id_by_addr(context, failed_recipient, Origin::Unknown).await;
|
Contact::lookup_id_by_addr(context, failed_recipient, Origin::Unknown).await;
|
||||||
if let Ok(contact) = Contact::load_from_db(context, contact_id).await {
|
let contact = Contact::load_from_db(context, contact_id).await?;
|
||||||
// Tell the user which of the recipients failed if we know that (because in a group, this might otherwise be unclear)
|
// Tell the user which of the recipients failed if we know that (because in a group, this might otherwise be unclear)
|
||||||
chat::add_info_msg(
|
chat::add_info_msg(
|
||||||
context,
|
context,
|
||||||
chat_id,
|
chat_id,
|
||||||
context
|
context
|
||||||
.stock_string_repl_str(
|
.stock_string_repl_str(
|
||||||
StockMessage::FailedSendingTo,
|
StockMessage::FailedSendingTo,
|
||||||
contact.get_display_name(),
|
contact.get_display_name(),
|
||||||
)
|
)
|
||||||
.await,
|
.await,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
context.emit_event(EventType::ChatModified(chat_id));
|
context.emit_event(EventType::ChatModified(chat_id));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The number of messages assigned to real chat (!=deaddrop, !=trash)
|
/// The number of messages assigned to real chat (!=deaddrop, !=trash)
|
||||||
|
|||||||
@@ -1071,7 +1071,9 @@ impl MimeMessage {
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|p| p.typ == Viewtype::Text)
|
.find(|p| p.typ == Viewtype::Text)
|
||||||
.map(|p| p.msg.clone());
|
.map(|p| p.msg.clone());
|
||||||
message::handle_ndn(context, failure_report, error).await
|
if let Err(e) = message::handle_ndn(context, failure_report, error).await {
|
||||||
|
warn!(context, "Could not handle ndn: {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user