Repair errors saved for messages

This commit is contained in:
Hocuri
2020-06-06 17:05:24 +02:00
parent 8350729cbb
commit f0837cfa73
4 changed files with 36 additions and 27 deletions

View File

@@ -2328,6 +2328,7 @@ mod tests {
#[async_std::test]
async fn test_parse_ndn() {
use std::io::Write;
use std::{thread, time};
let t = dummy_context().await;
t.ctx
@@ -2369,25 +2370,17 @@ mod tests {
.await
.unwrap();
thread::sleep(time::Duration::from_millis(1000));
println!("Loading msg {}", msg_id);
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap();
std::io::stdout().flush().unwrap();
thread::sleep(time::Duration::from_millis(1000));
assert_eq!(msg.state, MessageState::OutFailed);
assert_eq!(
msg.param.get(Param::Error),
Some(
r"** Die Adresse wurde nicht gefunden **
Ihre Nachricht wurde nicht an assidhfaaspocwaeofi@gmail.com zugestellt, weil die Adresse nicht gefunden wurde oder keine E-Mails empfangen kann.
Hier erfahren Sie mehr: https://support.google.com/mail/?p=NoSuchUser
Antwort:
550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/?p=NoSuchUser i18sor6261697wrs.38 - gsmtp
"
)
msg.error.as_ref().map(|s| s.as_str()),
Some("Delivery Status Notification (Failure) ** Die Adresse wurde nicht gefunden **\n\nIhre Nachricht wurde nicht an assidhfaaspocwaeofi@gmail.com zugestellt, weil die Adresse nicht gefunden wurde oder keine E-Mails empfangen kann.\n\nHier erfahren Sie mehr: https://support.google.com/mail/?p=NoSuchUser\n\nAntwort:\n\n550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/?p=NoSuchUser i18sor6261697wrs.38 - gsmtp")
)
}
}

View File

@@ -255,6 +255,7 @@ pub struct Message {
pub(crate) starred: bool,
pub(crate) chat_blocked: Blocked,
pub(crate) location_id: u32,
pub(crate) error: Option<String>,
pub(crate) param: Params,
}
@@ -289,6 +290,7 @@ impl Message {
" m.timestamp_rcvd AS timestamp_rcvd,",
" m.type AS type,",
" m.state AS state,",
" m.error AS error,",
" m.msgrmsg AS msgrmsg,",
" m.txt AS txt,",
" m.param AS param,",
@@ -316,6 +318,7 @@ impl Message {
msg.timestamp_rcvd = row.get("timestamp_rcvd")?;
msg.viewtype = row.get("type")?;
msg.state = row.get("state")?;
msg.error = row.get("error")?;
msg.is_dc_message = row.get("msgrmsg")?;
let text;
@@ -937,7 +940,7 @@ pub async fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
}
ret += "\n";
if let Some(err) = msg.param.get(Param::Error) {
if let Some(err) = &msg.error {
ret += &format!("Error: {}", err)
}
@@ -1251,27 +1254,33 @@ pub async fn exists(context: &Context, msg_id: MsgId) -> bool {
pub async fn set_msg_failed(context: &Context, msg_id: MsgId, error: Option<impl AsRef<str>>) {
if let Ok(mut msg) = Message::load_from_db(context, msg_id).await {
let error = error.map(|e| e.as_ref().to_string()).unwrap_or_default();
if msg.state.can_fail() {
msg.state = MessageState::OutFailed;
}
if let Some(error) = error {
msg.param.set(Param::Error, error.as_ref());
warn!(context, "{} failed: {}", msg_id, error.as_ref());
warn!(context, "{} failed: {}", msg_id, error);
} else {
warn!(
context,
"{} seems to have failed ({}), but state is {}", msg_id, error, msg.state
)
}
if context
match context
.sql
.execute(
"UPDATE msgs SET state=?, param=? WHERE id=?;",
paramsv![msg.state, msg.param.to_string(), msg_id],
"UPDATE msgs SET state=?, error=? WHERE id=?;",
paramsv![msg.state, error, msg_id],
)
.await
.is_ok()
{
context.emit_event(Event::MsgFailed {
Ok(_) => context.emit_event(Event::MsgFailed {
chat_id: msg.chat_id,
msg_id,
});
}),
Err(e) => {
error!(context, "{:?}", e);
println!("{:?}", e)
}
}
}
}

View File

@@ -65,9 +65,6 @@ pub enum Param {
/// For Messages
Arg4 = b'H',
/// For Messages
Error = b'L',
/// For Messages
AttachGroupImage = b'A',

View File

@@ -779,6 +779,7 @@ async fn open(
timestamp INTEGER DEFAULT 0, \
type INTEGER DEFAULT 0, \
state INTEGER DEFAULT 0, \
error TEXT DEFAULT '', \
msgrmsg INTEGER DEFAULT 1, \
bytes INTEGER DEFAULT 0, \
txt TEXT DEFAULT '', \
@@ -1241,6 +1242,15 @@ async fn open(
.await?;
sql.set_raw_config_int(context, "dbversion", 63).await?;
}
if dbversion < 64 {
info!(context, "[migration] v63");
sql.execute(
"ALTER TABLE chats ADD COLUMN error TEXT DEFAULT '';",
paramsv![],
)
.await?;
sql.set_raw_config_int(context, "dbversion", 64).await?;
}
// (2) updates that require high-level objects
// (the structure is complete now and all objects are usable)