mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
adding auto-copy-blob logic when preparing a message
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
""" The Message object. """
|
""" The Message object. """
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
from . import props
|
from . import props
|
||||||
from .cutil import from_dc_charpointer, as_dc_charpointer
|
from .cutil import from_dc_charpointer, as_dc_charpointer
|
||||||
from .capi import lib, ffi
|
from .capi import lib, ffi
|
||||||
|
|||||||
@@ -453,10 +453,10 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
def send_and_receive_message():
|
def send_and_receive_message():
|
||||||
lp.sec("ac1: prepare and send attachment + text to ac2")
|
lp.sec("ac1: prepare and send attachment + text to ac2")
|
||||||
msg = Message.new_empty(ac1, "file")
|
msg1 = Message.new_empty(ac1, "file")
|
||||||
msg.set_text("withfile")
|
msg1.set_text("withfile")
|
||||||
msg.set_file(p)
|
msg1.set_file(p)
|
||||||
message = chat.prepare_message(msg)
|
message = chat.prepare_message(msg1)
|
||||||
assert message.is_out_preparing()
|
assert message.is_out_preparing()
|
||||||
assert message.text == "withfile"
|
assert message.text == "withfile"
|
||||||
chat.send_prepared(message)
|
chat.send_prepared(message)
|
||||||
@@ -464,7 +464,7 @@ class TestOnlineAccount:
|
|||||||
lp.sec("ac2: receive message")
|
lp.sec("ac2: receive message")
|
||||||
ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] > const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev[2] > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
return ac2.get_message_by_id(ev[1])
|
return ac2.get_message_by_id(ev[2])
|
||||||
|
|
||||||
msg = send_and_receive_message()
|
msg = send_and_receive_message()
|
||||||
assert msg.text == "withfile"
|
assert msg.text == "withfile"
|
||||||
|
|||||||
20
src/chat.rs
20
src/chat.rs
@@ -725,11 +725,21 @@ fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<(), Error> {
|
|||||||
if msg.type_0 == Viewtype::Text {
|
if msg.type_0 == Viewtype::Text {
|
||||||
// the caller should check if the message text is empty
|
// the caller should check if the message text is empty
|
||||||
} else if msgtype_has_file(msg.type_0) {
|
} else if msgtype_has_file(msg.type_0) {
|
||||||
let blob = msg
|
let blob = if let Some(f) = msg.param.get_file(Param::File, context)? {
|
||||||
.param
|
match f {
|
||||||
.get_blob(Param::File, context, !msg.is_increation())?
|
ParamsFile::Blob(blob) => blob,
|
||||||
.ok_or_else(|| format_err!("Attachment missing for message of type #{}", msg.type_0))?;
|
ParamsFile::FsPath(path) => {
|
||||||
msg.param.set(Param::File, blob.as_name());
|
// path is outside the blobdir, let's copy
|
||||||
|
let blob = BlobObject::create_and_copy(context, path)?;
|
||||||
|
msg.param.set(Param::File, blob.as_name());
|
||||||
|
|
||||||
|
blob
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bail!("Attachment missing for message of type #{}", msg.type_0);
|
||||||
|
};
|
||||||
|
|
||||||
if msg.type_0 == Viewtype::File || msg.type_0 == Viewtype::Image {
|
if msg.type_0 == Viewtype::File || msg.type_0 == Viewtype::Image {
|
||||||
// Correct the type, take care not to correct already very special
|
// Correct the type, take care not to correct already very special
|
||||||
// formats as GIF or VOICE.
|
// formats as GIF or VOICE.
|
||||||
|
|||||||
Reference in New Issue
Block a user