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: Deduplicate blob files in the JsonRPC API #6470

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 7 additions & 3 deletions deltachat-jsonrpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ impl CommandApi {
let ctx = self.get_context(account_id).await?;

let mut msg = Message::new(Viewtype::Sticker);
msg.set_file(&sticker_path, None);
msg.set_file_and_deduplicate(&ctx, Path::new(&sticker_path), None, None)?;

// JSON-rpc does not need heuristics to turn [Viewtype::Sticker] into [Viewtype::Image]
msg.force_sticker();
Expand Down Expand Up @@ -2157,12 +2157,14 @@ impl CommandApi {

// mimics the old desktop call, will get replaced with something better in the composer rewrite,
// the better version will just be sending the current draft, though there will be probably something similar with more options to this for the corner cases like setting a marker on the map
#[allow(clippy::too_many_arguments)]
Hocuri marked this conversation as resolved.
Show resolved Hide resolved
async fn misc_send_msg(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure whether it's necessary to change this function and misc_set_draft() since it's going to be replaced anyway?

Is this function and misc_set_draft() still in use in the Desktop UI?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently it is still used, did a quick grep for miscSetDraft.

&self,
account_id: u32,
chat_id: u32,
text: Option<String>,
file: Option<String>,
filename: Option<String>,
location: Option<(f64, f64)>,
quoted_message_id: Option<u32>,
) -> Result<(u32, MessageObject)> {
Expand All @@ -2174,7 +2176,7 @@ impl CommandApi {
});
message.set_text(text.unwrap_or_default());
if let Some(file) = file {
message.set_file(file, None);
message.set_file_and_deduplicate(&ctx, Path::new(&file), filename.as_deref(), None)?;
}
if let Some((latitude, longitude)) = location {
message.set_location(latitude, longitude);
Expand Down Expand Up @@ -2202,12 +2204,14 @@ impl CommandApi {
// the better version should support:
// - changing viewtype to enable/disable compression
// - keeping same message id as long as attachment does not change for webxdc messages
#[allow(clippy::too_many_arguments)]
Hocuri marked this conversation as resolved.
Show resolved Hide resolved
async fn misc_set_draft(
&self,
account_id: u32,
chat_id: u32,
text: Option<String>,
file: Option<String>,
filename: Option<String>,
quoted_message_id: Option<u32>,
view_type: Option<MessageViewtype>,
) -> Result<()> {
Expand All @@ -2224,7 +2228,7 @@ impl CommandApi {
));
draft.set_text(text.unwrap_or_default());
if let Some(file) = file {
draft.set_file(file, None);
draft.set_file_and_deduplicate(&ctx, Path::new(&file), filename.as_deref(), None)?;
}
if let Some(id) = quoted_message_id {
draft
Expand Down
10 changes: 9 additions & 1 deletion deltachat-jsonrpc/src/api/types/message.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::Path;

use crate::api::VcardContact;
use anyhow::{Context as _, Result};
use deltachat::chat::Chat;
Expand Down Expand Up @@ -589,6 +591,7 @@ pub struct MessageData {
pub html: Option<String>,
pub viewtype: Option<MessageViewtype>,
pub file: Option<String>,
pub filename: Option<String>,
pub location: Option<(f64, f64)>,
pub override_sender_name: Option<String>,
/// Quoted message id. Takes preference over `quoted_text` (see below).
Expand All @@ -613,7 +616,12 @@ impl MessageData {
message.set_override_sender_name(self.override_sender_name);
}
if let Some(file) = self.file {
message.set_file(file, None);
message.set_file_and_deduplicate(
context,
Path::new(&file),
self.filename.as_deref(),
None,
)?;
}
if let Some((latitude, longitude)) = self.location {
message.set_location(latitude, longitude);
Expand Down
5 changes: 4 additions & 1 deletion deltachat-rpc-client/src/deltachat_rpc_client/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def send_message(
html: Optional[str] = None,
viewtype: Optional[ViewType] = None,
file: Optional[str] = None,
filename: Optional[str] = None,
location: Optional[tuple[float, float]] = None,
override_sender_name: Optional[str] = None,
quoted_msg: Optional[Union[int, Message]] = None,
Expand All @@ -137,6 +138,7 @@ def send_message(
"html": html,
"viewtype": viewtype,
"file": file,
"filename": filename,
"location": location,
"overrideSenderName": override_sender_name,
"quotedMessageId": quoted_msg,
Expand Down Expand Up @@ -172,13 +174,14 @@ def set_draft(
self,
text: Optional[str] = None,
file: Optional[str] = None,
filename: Optional[str] = None,
quoted_msg: Optional[int] = None,
viewtype: Optional[str] = None,
) -> None:
"""Set draft message."""
if isinstance(quoted_msg, Message):
quoted_msg = quoted_msg.id
self._rpc.misc_set_draft(self.account.id, self.id, text, file, quoted_msg, viewtype)
self._rpc.misc_set_draft(self.account.id, self.id, text, file, filename, quoted_msg, viewtype)

def remove_draft(self) -> None:
"""Remove draft message."""
Expand Down
Loading