fix FFI-behaviour: return default empty messages when asked for special ones

This commit is contained in:
holger krekel
2019-10-30 18:54:42 +01:00
parent 9cdfc3409d
commit b0ccbc36d9
4 changed files with 26 additions and 4 deletions

View File

@@ -1,5 +1,9 @@
# Changelog
## 1.0.0-beta5
- fix dc_get_msg() to return empty messages when asked for special ones
## 1.0.0-beta4
- fix more than one sending of autocrypt setup message

View File

@@ -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)) {
Ok(msg) => msg,
Err(e) => {
warn!(ctx, "Error getting msg #{}: {}", msg_id, e);
return ptr::null_mut();
if msg_id <= constants::DC_MSG_ID_LAST_SPECIAL {
// 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 };

View File

@@ -95,6 +95,13 @@ def test_markseen_invalid_message_ids(acfactory):
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():
provider = lib.dc_provider_new_from_email(cutil.as_dc_charpointer("ex@example.com"))
assert cutil.from_dc_charpointer(

View File

@@ -655,8 +655,6 @@ impl<'a> MimeFactory<'a> {
}
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 chat = Chat::load_from_db(context, msg.chat_id)?;
let mut factory = MimeFactory::new(context, msg);