mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +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,
|
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> {
|
impl<'a> Drop for MimeFactory<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -90,28 +117,8 @@ pub unsafe fn dc_mimefactory_load_msg(
|
|||||||
|
|
||||||
let msg = dc_msg_load_from_db(context, msg_id)?;
|
let msg = dc_msg_load_from_db(context, msg_id)?;
|
||||||
let chat = Chat::load_from_db(context, msg.chat_id)?;
|
let chat = Chat::load_from_db(context, msg.chat_id)?;
|
||||||
let mut factory = MimeFactory {
|
let mut factory = MimeFactory::new(context, msg);
|
||||||
from_addr: ptr::null_mut(),
|
factory.chat = Some(chat);
|
||||||
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,
|
|
||||||
};
|
|
||||||
|
|
||||||
load_from(&mut factory);
|
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 msg = dc_msg_load_from_db(context, msg_id)?;
|
||||||
|
let mut factory = MimeFactory::new(context, msg);
|
||||||
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 contact = Contact::load_from_db(factory.context, factory.msg.from_id)?;
|
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
|
// Do not send MDNs trash etc.; chats.blocked is already checked by the caller
|
||||||
|
|||||||
Reference in New Issue
Block a user