-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add device message for imported contacts after configuration #6195
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -768,14 +768,16 @@ impl Imap { | |
&mut self, | ||
context: &Context, | ||
session: &mut Session, | ||
) -> Result<()> { | ||
add_all_recipients_as_contacts(context, session, Config::ConfiguredSentboxFolder) | ||
.await | ||
.context("failed to get recipients from the sentbox")?; | ||
add_all_recipients_as_contacts(context, session, Config::ConfiguredMvboxFolder) | ||
) -> Result<i32> { | ||
let mut created = 0; | ||
created += | ||
add_all_recipients_as_contacts(context, session, Config::ConfiguredSentboxFolder) | ||
.await | ||
.context("failed to get recipients from the sentbox")?; | ||
created += add_all_recipients_as_contacts(context, session, Config::ConfiguredMvboxFolder) | ||
.await | ||
.context("failed to get recipients from the movebox")?; | ||
add_all_recipients_as_contacts(context, session, Config::ConfiguredInboxFolder) | ||
created += add_all_recipients_as_contacts(context, session, Config::ConfiguredInboxFolder) | ||
.await | ||
.context("failed to get recipients from the inbox")?; | ||
|
||
|
@@ -802,7 +804,7 @@ impl Imap { | |
} | ||
|
||
info!(context, "Done fetching existing messages."); | ||
Ok(()) | ||
Ok(created) | ||
} | ||
} | ||
|
||
|
@@ -2479,19 +2481,22 @@ impl std::fmt::Display for UidRange { | |
} | ||
} | ||
} | ||
|
||
/// Add all recipients as contacts. | ||
/// Returns how many contacts were created. | ||
async fn add_all_recipients_as_contacts( | ||
context: &Context, | ||
session: &mut Session, | ||
folder: Config, | ||
) -> Result<()> { | ||
) -> Result<i32> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather say it should be |
||
let mailbox = if let Some(m) = context.get_config(folder).await? { | ||
m | ||
} else { | ||
info!( | ||
context, | ||
"Folder {} is not configured, skipping fetching contacts from it.", folder | ||
); | ||
return Ok(()); | ||
return Ok(0); | ||
}; | ||
session | ||
.select_with_uidvalidity(context, &mailbox) | ||
|
@@ -2504,6 +2509,7 @@ async fn add_all_recipients_as_contacts( | |
.context("could not get recipients")?; | ||
|
||
let mut any_modified = false; | ||
let mut created = 0; | ||
for recipient in recipients { | ||
let recipient_addr = match ContactAddress::new(&recipient.addr) { | ||
Err(err) => { | ||
|
@@ -2528,12 +2534,15 @@ async fn add_all_recipients_as_contacts( | |
if modified != Modifier::None { | ||
any_modified = true; | ||
} | ||
if modified == Modifier::Created { | ||
created += 1; | ||
} | ||
} | ||
if any_modified { | ||
context.emit_event(EventType::ContactsChanged(None)); | ||
} | ||
|
||
Ok(()) | ||
Ok(created) | ||
} | ||
|
||
#[cfg(test)] | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,12 +19,12 @@ use crate::download::{download_msg, DownloadState}; | |||||
use crate::ephemeral::{self, delete_expired_imap_messages}; | ||||||
use crate::events::EventType; | ||||||
use crate::imap::{session::Session, FolderMeaning, Imap}; | ||||||
use crate::location; | ||||||
use crate::log::LogExt; | ||||||
use crate::message::MsgId; | ||||||
use crate::message::{Message, MsgId}; | ||||||
use crate::smtp::{send_smtp_messages, Smtp}; | ||||||
use crate::sql; | ||||||
use crate::tools::{self, duration_to_str, maybe_add_time_based_warnings, time, time_elapsed}; | ||||||
use crate::{chat, location}; | ||||||
|
||||||
pub(crate) mod connectivity; | ||||||
|
||||||
|
@@ -514,8 +514,18 @@ async fn inbox_fetch_idle(ctx: &Context, imap: &mut Imap, mut session: Session) | |||||
warn!(ctx, "Can't set Config::FetchedExistingMsgs: {:#}", err); | ||||||
} | ||||||
|
||||||
if let Err(err) = imap.fetch_existing_msgs(ctx, &mut session).await { | ||||||
warn!(ctx, "Failed to fetch existing messages: {:#}", err); | ||||||
match imap.fetch_existing_msgs(ctx, &mut session).await { | ||||||
Err(err) => { | ||||||
warn!(ctx, "Failed to fetch existing messages: {:#}", err); | ||||||
} | ||||||
Ok(count) => { | ||||||
let mut msg = Message::new_text(format!( | ||||||
"Added {} contacts from outgoing chats", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It seems we don't have the term "outgoing chat", at least i don't see it in the core code / Delta Chat FAQ. |
||||||
count | ||||||
)); | ||||||
Comment on lines
+522
to
+525
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be a translated message |
||||||
|
||||||
chat::add_device_msg(ctx, None, Some(&mut msg)).await?; | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the device message right from this function? Otherwise it's strange that the function returns smth very particular, it's about messages, but returns the number of contacts