From 2c23433185c8247d1ca28924b3c449163d4247f4 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Sat, 13 Jun 2020 19:45:59 +0200 Subject: [PATCH] Make it work Add a mutex to prevent a race condition when a "your pw is wrong" warning is sent, resulting in multiple messeges being sent. Do not mute the device chat but "only" send MsgsChanged event when no notification shall be shown. More logging. --- src/chat.rs | 13 +++++-------- src/context.rs | 3 +++ src/imap/mod.rs | 20 ++++++++++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 11184b5cd..fd4a2807c 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2698,14 +2698,7 @@ pub async fn add_device_msg_with_importance( let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device"); msg.try_calc_and_set_dimensions(context).await.ok(); prepare_msg_blob(context, msg).await?; - chat_id.unarchive(context).await?; - let muted = if important { - MuteDuration::NotMuted - } else { - MuteDuration::Forever - }; - set_muted(context, chat_id, muted).await?; context.sql.execute( "INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,param,rfc724_mid) \ @@ -2741,7 +2734,11 @@ pub async fn add_device_msg_with_importance( } if !msg_id.is_unset() { - context.emit_event(Event::IncomingMsg { chat_id, msg_id }); + if important { + context.emit_event(Event::IncomingMsg { chat_id, msg_id }); + } else { + context.emit_event(Event::MsgsChanged { chat_id, msg_id }); + } } Ok(msg_id) diff --git a/src/context.rs b/src/context.rs index 016c27d4f..5458282bf 100644 --- a/src/context.rs +++ b/src/context.rs @@ -53,6 +53,8 @@ pub struct InnerContext { pub(crate) generating_key_mutex: Mutex<()>, /// Mutex to enforce only a single running oauth2 is running. pub(crate) oauth2_mutex: Mutex<()>, + /// Mutex to prevent a race condition when a "your pw is wrong" warning is sent, resulting in multiple messeges being sent. + pub(crate) wrong_pw_warning_mutex: Mutex<()>, pub(crate) translated_stockstrings: RwLock>, pub(crate) events: Events, @@ -120,6 +122,7 @@ impl Context { last_smeared_timestamp: RwLock::new(0), generating_key_mutex: Mutex::new(()), oauth2_mutex: Mutex::new(()), + wrong_pw_warning_mutex: Mutex::new(()), translated_stockstrings: RwLock::new(HashMap::new()), events: Events::default(), scheduler: RwLock::new(Scheduler::Stopped), diff --git a/src/imap/mod.rs b/src/imap/mod.rs index 85cf92a85..e515d31a4 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -308,17 +308,29 @@ impl Imap { .stock_string_repl_str(StockMessage::CannotLogin, &imap_user) .await; + warn!(context, "{} ({})", message, err); error!(context, "{}", message); + + let lock = context.wrong_pw_warning_mutex.lock().await; if self.login_failed_once - && self.fetch && !context.get_config_bool(Config::WarnedAboutWrongPw).await { - context + if let Err(e) = context .set_config(Config::WarnedAboutWrongPw, Some("1")) - .await; + .await + { + warn!(context, "{}", e); + } + drop(lock); + let mut msg = Message::new(Viewtype::Text); msg.text = Some(message); - chat::add_device_msg_with_importance(context, None, Some(&mut msg), true).await; + if let Err(e) = + chat::add_device_msg_with_importance(context, None, Some(&mut msg), true) + .await + { + warn!(context, "{}", e); + } } else { self.login_failed_once = true; }