Compare commits

...

2 Commits

Author SHA1 Message Date
Simon Laux
ef8b98e1aa combine width and height into a tuple 2025-02-16 21:30:49 +01:00
Simon Laux
3ab75f1053 feat: jsonrpc: add late_file_message_mediasize 2025-02-16 21:13:44 +01:00
2 changed files with 61 additions and 1 deletions

View File

@@ -49,7 +49,7 @@ use types::chat::FullChat;
use types::contact::{ContactObject, VcardContact};
use types::events::Event;
use types::http::HttpResponse;
use types::message::{MessageData, MessageObject, MessageReadReceipt};
use types::message::{LateFilingMediaSize, MessageData, MessageObject, MessageReadReceipt};
use types::provider_info::ProviderInfo;
use types::reactions::JSONRPCReactions;
use types::webxdc::WebxdcMessageInfo;
@@ -1262,6 +1262,31 @@ impl CommandApi {
MsgId::new(message_id).download_full(&ctx).await
}
/// Late filing information to a message.
/// Changes the message width, height or duration, and stores it into the database.
///
/// Sometimes, the core cannot find out the width, the height or the duration
/// of an image, an audio or a video.
///
/// If, in these cases, the frontend can provide the information, it can save
/// them together with the message object for later usage.
///
/// This function should only be used if `Message.dimensions_width`, `Message.dimensions_height` or `Message.duration`
/// do not provide the expected values.
///
/// To get the stored values later, use `Message.dimensions_width`, `Message.dimensions_height` or `Message.duration`.
async fn late_file_message_mediasize(
&self,
account_id: u32,
message_id: u32,
new_size: LateFilingMediaSize,
) -> Result<()> {
let ctx = self.get_context(account_id).await?;
new_size
.apply_to_message(&ctx, MsgId::new(message_id))
.await
}
/// Search messages containing the given query string.
/// Searching can be done globally (chat_id=None) or in a specified chat only (chat_id set).
///

View File

@@ -712,3 +712,38 @@ impl From<deltachat::ephemeral::Timer> for EphemeralTimer {
}
}
}
#[derive(Deserialize, TypeDef, schemars::JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct LateFilingMediaSize {
// The new width and height to store in the message object. None if you don't want to change the dimensions.
pub wh: Option<(u32, u32)>,
// The new duration to store in the message object. None if you don't want to change it.
pub duration: Option<u32>,
}
impl LateFilingMediaSize {
pub async fn apply_to_message(
&self,
context: &Context,
message_id: MsgId,
) -> anyhow::Result<()> {
let mut message = deltachat::message::Message::load_from_db(context, message_id).await?;
let (width, height) = match self.wh {
Some((w, h)) => (
w.to_i32().context("conversion to i32 failed")?,
h.to_i32().context("conversion to i32 failed")?,
),
None => (0, 0),
};
let duration = self
.duration
.unwrap_or(0)
.to_i32()
.context("conversion to i32 failed")?;
message
.latefiling_mediasize(context, width, height, duration)
.await?;
Ok(())
}
}