mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
fix FFI-behaviour: return default empty messages when asked for special ones
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.0.0-beta5
|
||||||
|
|
||||||
|
- fix dc_get_msg() to return empty messages when asked for special ones
|
||||||
|
|
||||||
## 1.0.0-beta4
|
## 1.0.0-beta4
|
||||||
|
|
||||||
- fix more than one sending of autocrypt setup message
|
- fix more than one sending of autocrypt setup message
|
||||||
|
|||||||
@@ -1382,8 +1382,21 @@ pub unsafe extern "C" fn dc_get_msg(context: *mut dc_context_t, msg_id: u32) ->
|
|||||||
let message = match message::Message::load_from_db(ctx, MsgId::new(msg_id)) {
|
let message = match message::Message::load_from_db(ctx, MsgId::new(msg_id)) {
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!(ctx, "Error getting msg #{}: {}", msg_id, e);
|
if msg_id <= constants::DC_MSG_ID_LAST_SPECIAL {
|
||||||
return ptr::null_mut();
|
// C-core API returns empty messages, do the same
|
||||||
|
warn!(
|
||||||
|
ctx,
|
||||||
|
"dc_get_msg called with special msg_id={}, returning empty msg",
|
||||||
|
msg_id
|
||||||
|
);
|
||||||
|
message::Message::default()
|
||||||
|
} else {
|
||||||
|
error!(
|
||||||
|
ctx,
|
||||||
|
"dc_get_msg could not retrieve msg_id {}: {}", msg_id, e
|
||||||
|
);
|
||||||
|
return ptr::null_mut();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let ffi_msg = MessageWrapper { context, message };
|
let ffi_msg = MessageWrapper { context, message };
|
||||||
|
|||||||
@@ -95,6 +95,13 @@ def test_markseen_invalid_message_ids(acfactory):
|
|||||||
ac1._evlogger.ensure_event_not_queued("DC_EVENT_WARNING|DC_EVENT_ERROR")
|
ac1._evlogger.ensure_event_not_queued("DC_EVENT_WARNING|DC_EVENT_ERROR")
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_special_message_id_returns_empty_message(acfactory):
|
||||||
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
|
for i in range(1, 10):
|
||||||
|
msg = ac1.get_message_by_id(i)
|
||||||
|
assert msg.id == 0
|
||||||
|
|
||||||
|
|
||||||
def test_provider_info():
|
def test_provider_info():
|
||||||
provider = lib.dc_provider_new_from_email(cutil.as_dc_charpointer("ex@example.com"))
|
provider = lib.dc_provider_new_from_email(cutil.as_dc_charpointer("ex@example.com"))
|
||||||
assert cutil.from_dc_charpointer(
|
assert cutil.from_dc_charpointer(
|
||||||
|
|||||||
@@ -655,8 +655,6 @@ impl<'a> MimeFactory<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_msg(context: &Context, msg_id: MsgId) -> Result<MimeFactory, Error> {
|
pub fn load_msg(context: &Context, msg_id: MsgId) -> Result<MimeFactory, Error> {
|
||||||
ensure!(!msg_id.is_special(), "Invalid chat id");
|
|
||||||
|
|
||||||
let msg = Message::load_from_db(context, msg_id)?;
|
let msg = Message::load_from_db(context, msg_id)?;
|
||||||
let chat = Chat::load_from_db(context, msg.chat_id)?;
|
let chat = Chat::load_from_db(context, msg.chat_id)?;
|
||||||
let mut factory = MimeFactory::new(context, msg);
|
let mut factory = MimeFactory::new(context, msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user