mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
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.
This commit is contained in:
13
src/chat.rs
13
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)
|
||||
|
||||
@@ -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<HashMap<usize, String>>,
|
||||
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),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user