Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jsonrpc: add late_file_message_mediasize #6428

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion deltachat-jsonrpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this happen that image dimensions are wrong? If UI can determine the the image size, can it just display the image correctly, why does it need to store it back into the database and read back?

///
/// 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).
///
Expand Down
35 changes: 35 additions & 0 deletions deltachat-jsonrpc/src/api/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the unit for duration, seconds, milliseconds?

}

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This converts everything to i32, but then function arguments are u32 everywhere.

Copy link
Collaborator

@iequidoo iequidoo Feb 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u32 is the right type obviously, but Core's Message::latefiling_mediasize() takes i32 args, probably should be fixed there

.context("conversion to i32 failed")?;
message
.latefiling_mediasize(context, width, height, duration)
.await?;
Ok(())
}
}
Loading