Skip to content

Commit 3ab75f1

Browse files
committed
feat: jsonrpc: add late_file_message_mediasize
1 parent 4f71c77 commit 3ab75f1

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;
@@ -1262,6 +1262,31 @@ impl CommandApi {
12621262
MsgId::new(message_id).download_full(&ctx).await
12631263
}
12641264

1265+
/// Late filing information to a message.
1266+
/// Changes the message width, height or duration, and stores it into the database.
1267+
///
1268+
/// Sometimes, the core cannot find out the width, the height or the duration
1269+
/// of an image, an audio or a video.
1270+
///
1271+
/// If, in these cases, the frontend can provide the information, it can save
1272+
/// them together with the message object for later usage.
1273+
///
1274+
/// This function should only be used if `Message.dimensions_width`, `Message.dimensions_height` or `Message.duration`
1275+
/// do not provide the expected values.
1276+
///
1277+
/// To get the stored values later, use `Message.dimensions_width`, `Message.dimensions_height` or `Message.duration`.
1278+
async fn late_file_message_mediasize(
1279+
&self,
1280+
account_id: u32,
1281+
message_id: u32,
1282+
new_size: LateFilingMediaSize,
1283+
) -> Result<()> {
1284+
let ctx = self.get_context(account_id).await?;
1285+
new_size
1286+
.apply_to_message(&ctx, MsgId::new(message_id))
1287+
.await
1288+
}
1289+
12651290
/// Search messages containing the given query string.
12661291
/// Searching can be done globally (chat_id=None) or in a specified chat only (chat_id set).
12671292
///

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

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

0 commit comments

Comments
 (0)