mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +03:00
Add factory method MimeFactory::new
* src/dc_mimefactory.rs(new): add factory method to have verbose initialization of all (more than 10) MimeFactory fields only in one place. * src/dc_mimefactory.rc(dc_mimefactory_load_msg, dc_mimefactory_load_mdn): simplify code (and reduce linecount) using Mimefactory::new
This commit is contained in:
committed by
holger krekel
parent
4b45be7cda
commit
7dd3bad8bd
@@ -58,6 +58,33 @@ pub struct MimeFactory<'a> {
|
||||
pub context: &'a Context,
|
||||
}
|
||||
|
||||
impl<'a> MimeFactory<'a> {
|
||||
fn new(context: &'a Context, msg: Message) -> Self {
|
||||
MimeFactory {
|
||||
from_addr: ptr::null_mut(),
|
||||
from_displayname: ptr::null_mut(),
|
||||
selfstatus: None,
|
||||
recipients_names: clist_new(),
|
||||
recipients_addr: clist_new(),
|
||||
timestamp: 0,
|
||||
rfc724_mid: String::default(),
|
||||
loaded: Loaded::Nothing,
|
||||
msg,
|
||||
chat: None,
|
||||
increation: false,
|
||||
in_reply_to: ptr::null_mut(),
|
||||
references: ptr::null_mut(),
|
||||
req_mdn: 0,
|
||||
out: ptr::null_mut(),
|
||||
out_encrypted: false,
|
||||
out_gossiped: false,
|
||||
out_last_added_location_id: 0,
|
||||
error: ptr::null_mut(),
|
||||
context,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for MimeFactory<'a> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
@@ -90,28 +117,8 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
|
||||
let msg = dc_msg_load_from_db(context, msg_id)?;
|
||||
let chat = Chat::load_from_db(context, msg.chat_id)?;
|
||||
let mut factory = MimeFactory {
|
||||
from_addr: ptr::null_mut(),
|
||||
from_displayname: ptr::null_mut(),
|
||||
selfstatus: None,
|
||||
recipients_names: clist_new(),
|
||||
recipients_addr: clist_new(),
|
||||
timestamp: 0,
|
||||
rfc724_mid: String::default(),
|
||||
loaded: Loaded::Nothing,
|
||||
msg,
|
||||
chat: Some(chat),
|
||||
increation: false,
|
||||
in_reply_to: ptr::null_mut(),
|
||||
references: ptr::null_mut(),
|
||||
req_mdn: 0,
|
||||
out: ptr::null_mut(),
|
||||
out_encrypted: false,
|
||||
out_gossiped: false,
|
||||
out_last_added_location_id: 0,
|
||||
error: ptr::null_mut(),
|
||||
context,
|
||||
};
|
||||
let mut factory = MimeFactory::new(context, msg);
|
||||
factory.chat = Some(chat);
|
||||
|
||||
load_from(&mut factory);
|
||||
|
||||
@@ -279,30 +286,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
||||
}
|
||||
|
||||
let msg = dc_msg_load_from_db(context, msg_id)?;
|
||||
|
||||
let mut factory = MimeFactory {
|
||||
from_addr: ptr::null_mut(),
|
||||
from_displayname: ptr::null_mut(),
|
||||
selfstatus: None,
|
||||
recipients_names: clist_new(),
|
||||
recipients_addr: clist_new(),
|
||||
timestamp: 0,
|
||||
rfc724_mid: String::default(),
|
||||
loaded: Loaded::Nothing,
|
||||
msg,
|
||||
chat: None,
|
||||
increation: false,
|
||||
in_reply_to: ptr::null_mut(),
|
||||
references: ptr::null_mut(),
|
||||
req_mdn: 0,
|
||||
out: ptr::null_mut(),
|
||||
out_encrypted: false,
|
||||
out_gossiped: false,
|
||||
out_last_added_location_id: 0,
|
||||
error: ptr::null_mut(),
|
||||
context,
|
||||
};
|
||||
|
||||
let mut factory = MimeFactory::new(context, msg);
|
||||
let contact = Contact::load_from_db(factory.context, factory.msg.from_id)?;
|
||||
|
||||
// Do not send MDNs trash etc.; chats.blocked is already checked by the caller
|
||||
|
||||
Reference in New Issue
Block a user