Skip to content

Commit 96e65f9

Browse files
committed
feat: jsonrpc: add late_file_message_mediasize
1 parent 187274d commit 96e65f9

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

deltachat-jsonrpc/src/api.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use types::chat::FullChat;
4949
use types::contact::{ContactObject, VcardContact};
5050
use types::events::Event;
5151
use types::http::HttpResponse;
52-
use types::message::{MessageData, MessageObject, MessageReadReceipt};
52+
use types::message::{LateFilingMediaSize, MessageData, MessageObject, MessageReadReceipt};
5353
use types::provider_info::ProviderInfo;
5454
use types::reactions::JSONRPCReactions;
5555
use types::webxdc::WebxdcMessageInfo;
@@ -1248,6 +1248,31 @@ impl CommandApi {
12481248
MsgId::new(message_id).download_full(&ctx).await
12491249
}
12501250

1251+
/// Late filing information to a message.
1252+
/// Changes the message width, height or duration, and stores it into the database.
1253+
///
1254+
/// Sometimes, the core cannot find out the width, the height or the duration
1255+
/// of an image, an audio or a video.
1256+
///
1257+
/// If, in these cases, the frontend can provide the information, it can save
1258+
/// them together with the message object for later usage.
1259+
///
1260+
/// This function should only be used if `Message.dimensions_width`, `Message.dimensions_height` or `Message.duration`
1261+
/// do not provide the expected values.
1262+
///
1263+
/// To get the stored values later, use `Message.dimensions_width`, `Message.dimensions_height` or `Message.duration`.
1264+
async fn late_file_message_mediasize(
1265+
&self,
1266+
account_id: u32,
1267+
message_id: u32,
1268+
new_size: LateFilingMediaSize,
1269+
) -> Result<()> {
1270+
let ctx = self.get_context(account_id).await?;
1271+
new_size
1272+
.apply_to_message(&ctx, MsgId::new(message_id))
1273+
.await
1274+
}
1275+
12511276
/// Search messages containing the given query string.
12521277
/// Searching can be done globally (chat_id=None) or in a specified chat only (chat_id set).
12531278
///

deltachat-jsonrpc/src/api/types/message.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,3 +708,42 @@ impl From<deltachat::ephemeral::Timer> for EphemeralTimer {
708708
}
709709
}
710710
}
711+
712+
#[derive(Deserialize, TypeDef, schemars::JsonSchema)]
713+
#[serde(rename_all = "camelCase")]
714+
pub struct LateFilingMediaSize {
715+
// The new width to store in the message object. None if you don't want to change the width.
716+
pub width: Option<u32>,
717+
// The new height to store in the message object. None if you don't want to change the height.
718+
pub height: Option<u32>,
719+
// The new duration to store in the message object. None if you don't want to change it.
720+
pub duration: Option<u32>,
721+
}
722+
723+
impl LateFilingMediaSize {
724+
pub async fn apply_to_message(
725+
&self,
726+
context: &Context,
727+
message_id: MsgId,
728+
) -> anyhow::Result<()> {
729+
let mut message = deltachat::message::Message::load_from_db(context, message_id).await?;
730+
message
731+
.latefiling_mediasize(
732+
context,
733+
self.width
734+
.unwrap_or(0)
735+
.to_i32()
736+
.context("conversion to i32 failed")?,
737+
self.height
738+
.unwrap_or(0)
739+
.to_i32()
740+
.context("conversion to i32 failed")?,
741+
self.duration
742+
.unwrap_or(0)
743+
.to_i32()
744+
.context("conversion to i32 failed")?,
745+
)
746+
.await?;
747+
Ok(())
748+
}
749+
}

0 commit comments

Comments
 (0)