mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
First try for notification
This commit is contained in:
18
src/chat.rs
18
src/chat.rs
@@ -2670,10 +2670,11 @@ pub(crate) async fn get_chat_id_by_grpid(
|
|||||||
/// Adds a message to device chat.
|
/// Adds a message to device chat.
|
||||||
///
|
///
|
||||||
/// Optional `label` can be provided to ensure that message is added only once.
|
/// Optional `label` can be provided to ensure that message is added only once.
|
||||||
pub async fn add_device_msg(
|
pub async fn add_device_msg_with_importance(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
label: Option<&str>,
|
label: Option<&str>,
|
||||||
msg: Option<&mut Message>,
|
msg: Option<&mut Message>,
|
||||||
|
important: bool,
|
||||||
) -> Result<MsgId, Error> {
|
) -> Result<MsgId, Error> {
|
||||||
ensure!(
|
ensure!(
|
||||||
label.is_some() || msg.is_some(),
|
label.is_some() || msg.is_some(),
|
||||||
@@ -2697,7 +2698,14 @@ pub async fn add_device_msg(
|
|||||||
let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device");
|
let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device");
|
||||||
msg.try_calc_and_set_dimensions(context).await.ok();
|
msg.try_calc_and_set_dimensions(context).await.ok();
|
||||||
prepare_msg_blob(context, msg).await?;
|
prepare_msg_blob(context, msg).await?;
|
||||||
|
|
||||||
chat_id.unarchive(context).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(
|
context.sql.execute(
|
||||||
"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,param,rfc724_mid) \
|
"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,param,rfc724_mid) \
|
||||||
@@ -2739,6 +2747,14 @@ pub async fn add_device_msg(
|
|||||||
Ok(msg_id)
|
Ok(msg_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn add_device_msg(
|
||||||
|
context: &Context,
|
||||||
|
label: Option<&str>,
|
||||||
|
msg: Option<&mut Message>,
|
||||||
|
) -> Result<MsgId, Error> {
|
||||||
|
add_device_msg_with_importance(context, label, msg, false).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn was_device_msg_ever_added(context: &Context, label: &str) -> Result<bool, Error> {
|
pub async fn was_device_msg_ever_added(context: &Context, label: &str) -> Result<bool, Error> {
|
||||||
ensure!(!label.is_empty(), "empty label");
|
ensure!(!label.is_empty(), "empty label");
|
||||||
if let Ok(()) = context
|
if let Ok(()) = context
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ pub enum Config {
|
|||||||
|
|
||||||
#[strum(serialize = "sys.config_keys")]
|
#[strum(serialize = "sys.config_keys")]
|
||||||
SysConfigKeys,
|
SysConfigKeys,
|
||||||
|
|
||||||
|
#[strum(props(default = "0"))]
|
||||||
|
WarnedAboutWrongPw,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ impl Context {
|
|||||||
|
|
||||||
match success {
|
match success {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
self.set_config(Config::WarnedAboutWrongPw, None).await?;
|
||||||
progress!(self, 1000);
|
progress!(self, 1000);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use crate::mimeparser;
|
|||||||
use crate::oauth2::dc_get_oauth2_access_token;
|
use crate::oauth2::dc_get_oauth2_access_token;
|
||||||
use crate::param::Params;
|
use crate::param::Params;
|
||||||
use crate::provider::get_provider_info;
|
use crate::provider::get_provider_info;
|
||||||
use crate::{scheduler::InterruptInfo, stock::StockMessage};
|
use crate::{chat, scheduler::InterruptInfo, stock::StockMessage};
|
||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
mod idle;
|
mod idle;
|
||||||
@@ -38,6 +38,7 @@ pub mod select_folder;
|
|||||||
mod session;
|
mod session;
|
||||||
|
|
||||||
use client::Client;
|
use client::Client;
|
||||||
|
use message::Message;
|
||||||
use session::Session;
|
use session::Session;
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -118,6 +119,7 @@ pub struct Imap {
|
|||||||
connected: bool,
|
connected: bool,
|
||||||
interrupt: Option<stop_token::StopSource>,
|
interrupt: Option<stop_token::StopSource>,
|
||||||
should_reconnect: bool,
|
should_reconnect: bool,
|
||||||
|
login_failed_once: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -191,6 +193,7 @@ impl Imap {
|
|||||||
connected: Default::default(),
|
connected: Default::default(),
|
||||||
interrupt: Default::default(),
|
interrupt: Default::default(),
|
||||||
should_reconnect: Default::default(),
|
should_reconnect: Default::default(),
|
||||||
|
login_failed_once: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,8 +298,10 @@ impl Imap {
|
|||||||
// needs to be set here to ensure it is set on reconnects.
|
// needs to be set here to ensure it is set on reconnects.
|
||||||
self.connected = true;
|
self.connected = true;
|
||||||
self.session = Some(session);
|
self.session = Some(session);
|
||||||
|
self.login_failed_once = false;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
Err((err, _)) => {
|
Err((err, _)) => {
|
||||||
let imap_user = self.config.imap_user.to_owned();
|
let imap_user = self.config.imap_user.to_owned();
|
||||||
let message = context
|
let message = context
|
||||||
@@ -304,6 +309,19 @@ impl Imap {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
error!(context, "{}", message);
|
error!(context, "{}", message);
|
||||||
|
if self.login_failed_once
|
||||||
|
&& self.fetch
|
||||||
|
&& !context.get_config_bool(Config::WarnedAboutWrongPw).await
|
||||||
|
{
|
||||||
|
context
|
||||||
|
.set_config(Config::WarnedAboutWrongPw, Some("1"))
|
||||||
|
.await;
|
||||||
|
let mut msg = Message::new(Viewtype::Text);
|
||||||
|
msg.text = Some(message);
|
||||||
|
chat::add_device_msg_with_importance(context, None, Some(&mut msg), true).await;
|
||||||
|
} else {
|
||||||
|
self.login_failed_once = true;
|
||||||
|
}
|
||||||
|
|
||||||
self.trigger_reconnect();
|
self.trigger_reconnect();
|
||||||
Err(Error::LoginFailed(format!("cannot login as {}", imap_user)))
|
Err(Error::LoginFailed(format!("cannot login as {}", imap_user)))
|
||||||
|
|||||||
Reference in New Issue
Block a user