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 1 commit 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 @@ -1248,6 +1248,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).
///
Expand Down
39 changes: 39 additions & 0 deletions deltachat-jsonrpc/src/api/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,3 +708,42 @@ impl From<deltachat::ephemeral::Timer> for EphemeralTimer {
}
}
}

#[derive(Deserialize, TypeDef, schemars::JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct LateFilingMediaSize {
// The new width to store in the message object. None if you don't want to change the width.
pub width: 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.

Maybe replace these with pub wh: Option<(u32, u32)>,? Because if width == None, the height isn't updated by the core too, the same otherwise. Or at least document this in the comments.

// The new height to store in the message object. None if you don't want to change the height.
pub height: Option<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?;
message
.latefiling_mediasize(
context,
self.width
.unwrap_or(0)
.to_i32()
.context("conversion to i32 failed")?,
self.height
.unwrap_or(0)
.to_i32()
.context("conversion to i32 failed")?,
self.duration
.unwrap_or(0)
.to_i32()
.context("conversion to i32 failed")?,
)
.await?;
Ok(())
}
}
Loading