diff --git a/src/chat.rs b/src/chat.rs index 79d7bb5f3..0a35742d8 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1984,6 +1984,7 @@ pub fn add_device_msg( chat_id = create_or_lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE, Blocked::Not)?.0; let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device"); + msg.try_calc_and_set_dimensions(context).ok(); prepare_msg_blob(context, msg)?; unarchive(context, chat_id)?; diff --git a/src/job.rs b/src/job.rs index fb26878a3..dd4e66561 100644 --- a/src/job.rs +++ b/src/job.rs @@ -605,27 +605,7 @@ fn set_delivered(context: &Context, msg_id: MsgId) { #[allow(non_snake_case)] pub fn job_send_msg(context: &Context, msg_id: MsgId) -> Result<(), Error> { let mut mimefactory = MimeFactory::load_msg(context, msg_id)?; - - if chat::msgtype_has_file(mimefactory.msg.type_0) { - let file_param = mimefactory.msg.param.get_path(Param::File, context)?; - if let Some(pathNfilename) = file_param { - if (mimefactory.msg.type_0 == Viewtype::Image - || mimefactory.msg.type_0 == Viewtype::Gif) - && !mimefactory.msg.param.exists(Param::Width) - { - mimefactory.msg.param.set_int(Param::Width, 0); - mimefactory.msg.param.set_int(Param::Height, 0); - - if let Ok(buf) = dc_read_file(context, pathNfilename) { - if let Ok((width, height)) = dc_get_filemeta(&buf) { - mimefactory.msg.param.set_int(Param::Width, width as i32); - mimefactory.msg.param.set_int(Param::Height, height as i32); - } - } - mimefactory.msg.save_param_to_disk(context); - } - } - } + mimefactory.msg.try_calc_and_set_dimensions(context).ok(); /* create message */ if let Err(msg) = unsafe { mimefactory.render() } { diff --git a/src/message.rs b/src/message.rs index 97c039f50..dccb500ac 100644 --- a/src/message.rs +++ b/src/message.rs @@ -309,6 +309,32 @@ impl Message { self.param.get_path(Param::File, context).unwrap_or(None) } + pub fn try_calc_and_set_dimensions(&mut self, context: &Context) -> Result<(), Error> { + if chat::msgtype_has_file(self.type_0) { + let file_param = self.param.get_path(Param::File, context)?; + if let Some(path_and_filename) = file_param { + if (self.type_0 == Viewtype::Image || self.type_0 == Viewtype::Gif) + && !self.param.exists(Param::Width) + { + self.param.set_int(Param::Width, 0); + self.param.set_int(Param::Height, 0); + + if let Ok(buf) = dc_read_file(context, path_and_filename) { + if let Ok((width, height)) = dc_get_filemeta(&buf) { + self.param.set_int(Param::Width, width as i32); + self.param.set_int(Param::Height, height as i32); + } + } + + if !self.id.is_unset() { + self.save_param_to_disk(context); + } + } + } + } + Ok(()) + } + /// Check if a message has a location bound to it. /// These messages are also returned by dc_get_locations() /// and the UI may decide to display a special icon beside such messages,