mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
Replace unstable try_trait with a job_try! macro
This commit is contained in:
49
src/job.rs
49
src/job.rs
@@ -49,26 +49,19 @@ pub enum Try {
|
|||||||
RetryLater,
|
RetryLater,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Try for Try {
|
#[macro_export]
|
||||||
type Ok = Try;
|
macro_rules! job_try {
|
||||||
type Error = Error;
|
($expr:expr) => {
|
||||||
|
match $expr {
|
||||||
fn into_result(self) -> std::result::Result<Self::Ok, Self::Error> {
|
::std::result::Result::Ok(val) => val,
|
||||||
match self {
|
::std::result::Result::Err(err) => {
|
||||||
Self::Finished(Ok(())) => Ok(Self::Finished(Ok(()))),
|
return $crate::job::Try::Finished(Err(err.into()));
|
||||||
Self::Finished(Err(err)) => Err(err),
|
}
|
||||||
Self::RetryNow => Ok(Self::RetryNow),
|
|
||||||
Self::RetryLater => Ok(Self::RetryLater),
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
($expr:expr,) => {
|
||||||
fn from_error(e: Self::Error) -> Self {
|
$crate::job_try!($expr)
|
||||||
Self::Finished(Err(e))
|
};
|
||||||
}
|
|
||||||
|
|
||||||
fn from_ok(_: Self::Ok) -> Self {
|
|
||||||
Self::Finished(Ok(()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Thread {
|
impl Default for Thread {
|
||||||
@@ -189,16 +182,16 @@ impl Job {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let filename = self
|
let filename = job_try!(job_try!(self
|
||||||
.param
|
.param
|
||||||
.get_path(Param::File, context)
|
.get_path(Param::File, context)
|
||||||
.map_err(|_| format_err!("Can't get filename"))?
|
.map_err(|_| format_err!("Can't get filename")))
|
||||||
.ok_or_else(|| format_err!("Can't get filename"))?;
|
.ok_or_else(|| format_err!("Can't get filename")));
|
||||||
let body = dc_read_file(context, &filename)?;
|
let body = job_try!(dc_read_file(context, &filename));
|
||||||
let recipients = self.param.get(Param::Recipients).ok_or_else(|| {
|
let recipients = job_try!(self.param.get(Param::Recipients).ok_or_else(|| {
|
||||||
warn!(context, "Missing recipients for job {}", self.job_id);
|
warn!(context, "Missing recipients for job {}", self.job_id);
|
||||||
format_err!("Missing recipients")
|
format_err!("Missing recipients")
|
||||||
})?;
|
}));
|
||||||
|
|
||||||
let recipients_list = recipients
|
let recipients_list = recipients
|
||||||
.split('\x1e')
|
.split('\x1e')
|
||||||
@@ -268,7 +261,7 @@ impl Job {
|
|||||||
fn MoveMsg(&mut self, context: &Context) -> Try {
|
fn MoveMsg(&mut self, context: &Context) -> Try {
|
||||||
let imap_inbox = &context.inbox_thread.read().unwrap().imap;
|
let imap_inbox = &context.inbox_thread.read().unwrap().imap;
|
||||||
|
|
||||||
let msg = Message::load_from_db(context, MsgId::new(self.foreign_id))?;
|
let msg = job_try!(Message::load_from_db(context, MsgId::new(self.foreign_id)));
|
||||||
|
|
||||||
if let Err(err) = imap_inbox.ensure_configured_folders(context, true) {
|
if let Err(err) = imap_inbox.ensure_configured_folders(context, true) {
|
||||||
warn!(context, "could not configure folders: {:?}", err);
|
warn!(context, "could not configure folders: {:?}", err);
|
||||||
@@ -306,7 +299,7 @@ impl Job {
|
|||||||
fn DeleteMsgOnImap(&mut self, context: &Context) -> Try {
|
fn DeleteMsgOnImap(&mut self, context: &Context) -> Try {
|
||||||
let imap_inbox = &context.inbox_thread.read().unwrap().imap;
|
let imap_inbox = &context.inbox_thread.read().unwrap().imap;
|
||||||
|
|
||||||
let mut msg = Message::load_from_db(context, MsgId::new(self.foreign_id))?;
|
let mut msg = job_try!(Message::load_from_db(context, MsgId::new(self.foreign_id)));
|
||||||
|
|
||||||
if !msg.rfc724_mid.is_empty() {
|
if !msg.rfc724_mid.is_empty() {
|
||||||
if message::rfc724_mid_cnt(context, &msg.rfc724_mid) > 1 {
|
if message::rfc724_mid_cnt(context, &msg.rfc724_mid) > 1 {
|
||||||
@@ -354,7 +347,7 @@ impl Job {
|
|||||||
fn MarkseenMsgOnImap(&mut self, context: &Context) -> Try {
|
fn MarkseenMsgOnImap(&mut self, context: &Context) -> Try {
|
||||||
let imap_inbox = &context.inbox_thread.read().unwrap().imap;
|
let imap_inbox = &context.inbox_thread.read().unwrap().imap;
|
||||||
|
|
||||||
let msg = Message::load_from_db(context, MsgId::new(self.foreign_id))?;
|
let msg = job_try!(Message::load_from_db(context, MsgId::new(self.foreign_id)));
|
||||||
|
|
||||||
let folder = msg.server_folder.as_ref().unwrap();
|
let folder = msg.server_folder.as_ref().unwrap();
|
||||||
match imap_inbox.set_seen(context, folder, msg.server_uid) {
|
match imap_inbox.set_seen(context, folder, msg.server_uid) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#![allow(clippy::match_bool)]
|
#![allow(clippy::match_bool)]
|
||||||
#![feature(ptr_wrapping_offset_from)]
|
#![feature(ptr_wrapping_offset_from)]
|
||||||
#![feature(drain_filter)]
|
#![feature(drain_filter)]
|
||||||
#![feature(try_trait)]
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate failure_derive;
|
extern crate failure_derive;
|
||||||
@@ -43,6 +42,7 @@ mod e2ee;
|
|||||||
mod imap;
|
mod imap;
|
||||||
mod imap_client;
|
mod imap_client;
|
||||||
pub mod imex;
|
pub mod imex;
|
||||||
|
#[macro_use]
|
||||||
pub mod job;
|
pub mod job;
|
||||||
mod job_thread;
|
mod job_thread;
|
||||||
pub mod key;
|
pub mod key;
|
||||||
|
|||||||
@@ -640,11 +640,11 @@ pub fn JobMaybeSendLocationsEnded(context: &Context, job: &mut Job) -> Try {
|
|||||||
|
|
||||||
let chat_id = job.foreign_id;
|
let chat_id = job.foreign_id;
|
||||||
|
|
||||||
let (send_begin, send_until) = context.sql.query_row(
|
let (send_begin, send_until) = job_try!(context.sql.query_row(
|
||||||
"SELECT locations_send_begin, locations_send_until FROM chats WHERE id=?",
|
"SELECT locations_send_begin, locations_send_until FROM chats WHERE id=?",
|
||||||
params![chat_id as i32],
|
params![chat_id as i32],
|
||||||
|row| Ok((row.get::<_, i64>(0)?, row.get::<_, i64>(1)?)),
|
|row| Ok((row.get::<_, i64>(0)?, row.get::<_, i64>(1)?)),
|
||||||
)?;
|
));
|
||||||
|
|
||||||
if !(send_begin != 0 && time() <= send_until) {
|
if !(send_begin != 0 && time() <= send_until) {
|
||||||
// still streaming -
|
// still streaming -
|
||||||
@@ -652,10 +652,10 @@ pub fn JobMaybeSendLocationsEnded(context: &Context, job: &mut Job) -> Try {
|
|||||||
// do not un-schedule pending DC_MAYBE_SEND_LOC_ENDED jobs
|
// do not un-schedule pending DC_MAYBE_SEND_LOC_ENDED jobs
|
||||||
if !(send_begin == 0 && send_until == 0) {
|
if !(send_begin == 0 && send_until == 0) {
|
||||||
// not streaming, device-message already sent
|
// not streaming, device-message already sent
|
||||||
context.sql.execute(
|
job_try!(context.sql.execute(
|
||||||
"UPDATE chats SET locations_send_begin=0, locations_send_until=0 WHERE id=?",
|
"UPDATE chats SET locations_send_begin=0, locations_send_until=0 WHERE id=?",
|
||||||
params![chat_id as i32],
|
params![chat_id as i32],
|
||||||
)?;
|
));
|
||||||
|
|
||||||
let stock_str = context.stock_system_msg(StockMessage::MsgLocationDisabled, "", "", 0);
|
let stock_str = context.stock_system_msg(StockMessage::MsgLocationDisabled, "", "", 0);
|
||||||
chat::add_info_msg(context, chat_id, stock_str);
|
chat::add_info_msg(context, chat_id, stock_str);
|
||||||
|
|||||||
Reference in New Issue
Block a user