Skip to content

Commit 0d5c3ad

Browse files
committed
feat: Deduplicate blob files in the JsonRPC API
1 parent 8435f40 commit 0d5c3ad

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

deltachat-jsonrpc/src/api.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ impl CommandApi {
19371937
let ctx = self.get_context(account_id).await?;
19381938

19391939
let mut msg = Message::new(Viewtype::Sticker);
1940-
msg.set_file(&sticker_path, None);
1940+
msg.set_file_and_deduplicate(ctx, &sticker_path, None, None);
19411941

19421942
// JSON-rpc does not need heuristics to turn [Viewtype::Sticker] into [Viewtype::Image]
19431943
msg.force_sticker();
@@ -2163,6 +2163,7 @@ impl CommandApi {
21632163
chat_id: u32,
21642164
text: Option<String>,
21652165
file: Option<String>,
2166+
filename: Option<String>,
21662167
location: Option<(f64, f64)>,
21672168
quoted_message_id: Option<u32>,
21682169
) -> Result<(u32, MessageObject)> {
@@ -2174,7 +2175,7 @@ impl CommandApi {
21742175
});
21752176
message.set_text(text.unwrap_or_default());
21762177
if let Some(file) = file {
2177-
message.set_file(file, None);
2178+
message.set_file_and_deduplicate(&ctx, file, filename, None);
21782179
}
21792180
if let Some((latitude, longitude)) = location {
21802181
message.set_location(latitude, longitude);
@@ -2208,6 +2209,7 @@ impl CommandApi {
22082209
chat_id: u32,
22092210
text: Option<String>,
22102211
file: Option<String>,
2212+
filename: Option<String>,
22112213
quoted_message_id: Option<u32>,
22122214
view_type: Option<MessageViewtype>,
22132215
) -> Result<()> {
@@ -2224,7 +2226,7 @@ impl CommandApi {
22242226
));
22252227
draft.set_text(text.unwrap_or_default());
22262228
if let Some(file) = file {
2227-
draft.set_file(file, None);
2229+
draft.set_file_and_deduplicate(&ctx, file, filename, None);
22282230
}
22292231
if let Some(id) = quoted_message_id {
22302232
draft

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ pub struct MessageData {
589589
pub html: Option<String>,
590590
pub viewtype: Option<MessageViewtype>,
591591
pub file: Option<String>,
592+
pub filename: Option<String>,
592593
pub location: Option<(f64, f64)>,
593594
pub override_sender_name: Option<String>,
594595
/// Quoted message id. Takes preference over `quoted_text` (see below).
@@ -613,7 +614,7 @@ impl MessageData {
613614
message.set_override_sender_name(self.override_sender_name);
614615
}
615616
if let Some(file) = self.file {
616-
message.set_file(file, None);
617+
message.set_file_and_deduplicate(context, file, filename, None);
617618
}
618619
if let Some((latitude, longitude)) = self.location {
619620
message.set_location(latitude, longitude);

0 commit comments

Comments
 (0)