Move check for blocked contact from mimefactory to SendMdn job

This commit is contained in:
Alexander Krotov
2020-01-17 01:29:26 +03:00
parent b40ad7e87e
commit 79bc34ed76
2 changed files with 9 additions and 5 deletions

View File

@@ -15,6 +15,7 @@ use crate::chat;
use crate::config::Config;
use crate::configure::*;
use crate::constants::*;
use crate::contact::Contact;
use crate::context::{Context, PerformJobsNeeded};
use crate::dc_tools::*;
use crate::error::{Error, Result};
@@ -261,6 +262,12 @@ impl Job {
return Status::Finished(Err(format_err!("MDNs are disabled")));
}
let contact_id = self.foreign_id;
let contact = job_try!(Contact::load_from_db(context, contact_id));
if contact.is_blocked() {
return Status::Finished(Err(format_err!("Contact is blocked")));
}
let msg_id = if let Some(msg_id) = self.param.get_msg_id() {
msg_id
} else {

View File

@@ -159,13 +159,10 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
}
pub fn from_mdn(context: &'a Context, msg: &'b Message) -> Result<Self, Error> {
let contact = Contact::load_from_db(context, msg.from_id)?;
// Do not send MDNs trash etc.; chats.blocked is already checked by the caller
// in dc_markseen_msgs()
ensure!(!contact.is_blocked(), "Contact blocked");
ensure!(msg.chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat id");
let contact = Contact::load_from_db(context, msg.from_id)?;
Ok(MimeFactory {
context,
from_addr: context