From e4e6a00fe4d041c25d927a474a10d929e85d0bc8 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 19 Nov 2019 13:21:02 +0100 Subject: [PATCH] rename has_device_msg() to was_device_msg_ever_added() what describes better what the function is doing --- deltachat-ffi/deltachat.h | 2 +- deltachat-ffi/src/lib.rs | 7 ++++--- src/chat.rs | 14 +++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index e9980296c..3b405bb39 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -1149,7 +1149,7 @@ uint32_t dc_add_device_msg (dc_context_t* context, const char* * @return 1=A message with this label was added at some point, * 0=A message with this label was never added. */ -int dc_has_device_msg (dc_context_t* context, const char* label); +int dc_was_device_msg_ever_added (dc_context_t* context, const char* label); /** diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index b68d408e6..c5362761a 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -842,18 +842,19 @@ pub unsafe extern "C" fn dc_add_device_msg( } #[no_mangle] -pub unsafe extern "C" fn dc_has_device_msg( +pub unsafe extern "C" fn dc_was_device_msg_ever_added( context: *mut dc_context_t, label: *const libc::c_char, ) -> libc::c_int { if context.is_null() || label.is_null() { - eprintln!("ignoring careless call to dc_has_device_msg()"); + eprintln!("ignoring careless call to dc_was_device_msg_ever_added()"); return 0; } let ffi_context = &mut *context; ffi_context .with_inner(|ctx| { - chat::has_device_msg(ctx, &to_string_lossy(label)).unwrap_or(false) as libc::c_int + chat::was_device_msg_ever_added(ctx, &to_string_lossy(label)).unwrap_or(false) + as libc::c_int }) .unwrap_or(0) } diff --git a/src/chat.rs b/src/chat.rs index ab2fdaed4..31f54ebc2 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1966,7 +1966,7 @@ pub fn add_device_msg( let mut msg_id = MsgId::new_unset(); if let Some(label) = label { - if has_device_msg(context, label)? { + if was_device_msg_ever_added(context, label)? { info!(context, "device-message {} already added", label); return Ok(msg_id); } @@ -2011,7 +2011,7 @@ pub fn add_device_msg( Ok(msg_id) } -pub fn has_device_msg(context: &Context, label: &str) -> Result { +pub fn was_device_msg_ever_added(context: &Context, label: &str) -> Result { ensure!(!label.is_empty(), "empty label"); if let Ok(()) = context.sql.query_row( "SELECT label FROM devmsglabels WHERE label=?", @@ -2237,19 +2237,19 @@ mod tests { } #[test] - fn test_has_device_msg() { + fn test_was_device_msg_ever_added() { let t = test_context(Some(Box::new(logging_cb))); add_device_msg(&t.ctx, Some("some-label"), None).ok(); - assert!(has_device_msg(&t.ctx, "some-label").unwrap()); + assert!(was_device_msg_ever_added(&t.ctx, "some-label").unwrap()); let mut msg = Message::new(Viewtype::Text); msg.text = Some("message text".to_string()); add_device_msg(&t.ctx, Some("another-label"), Some(&mut msg)).ok(); - assert!(has_device_msg(&t.ctx, "another-label").unwrap()); + assert!(was_device_msg_ever_added(&t.ctx, "another-label").unwrap()); - assert!(!has_device_msg(&t.ctx, "unused-label").unwrap()); + assert!(!was_device_msg_ever_added(&t.ctx, "unused-label").unwrap()); - assert!(has_device_msg(&t.ctx, "").is_err()); + assert!(was_device_msg_ever_added(&t.ctx, "").is_err()); } fn chatlist_len(ctx: &Context, listflags: usize) -> usize {