mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 14:26:30 +03:00
rename has_device_msg() to was_device_msg_ever_added() what describes better what the function is doing
This commit is contained in:
@@ -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,
|
* @return 1=A message with this label was added at some point,
|
||||||
* 0=A message with this label was never added.
|
* 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);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -842,18 +842,19 @@ pub unsafe extern "C" fn dc_add_device_msg(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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,
|
context: *mut dc_context_t,
|
||||||
label: *const libc::c_char,
|
label: *const libc::c_char,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
if context.is_null() || label.is_null() {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
let ffi_context = &mut *context;
|
let ffi_context = &mut *context;
|
||||||
ffi_context
|
ffi_context
|
||||||
.with_inner(|ctx| {
|
.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)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/chat.rs
14
src/chat.rs
@@ -1966,7 +1966,7 @@ pub fn add_device_msg(
|
|||||||
let mut msg_id = MsgId::new_unset();
|
let mut msg_id = MsgId::new_unset();
|
||||||
|
|
||||||
if let Some(label) = label {
|
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);
|
info!(context, "device-message {} already added", label);
|
||||||
return Ok(msg_id);
|
return Ok(msg_id);
|
||||||
}
|
}
|
||||||
@@ -2011,7 +2011,7 @@ pub fn add_device_msg(
|
|||||||
Ok(msg_id)
|
Ok(msg_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_device_msg(context: &Context, label: &str) -> Result<bool, Error> {
|
pub fn was_device_msg_ever_added(context: &Context, label: &str) -> Result<bool, Error> {
|
||||||
ensure!(!label.is_empty(), "empty label");
|
ensure!(!label.is_empty(), "empty label");
|
||||||
if let Ok(()) = context.sql.query_row(
|
if let Ok(()) = context.sql.query_row(
|
||||||
"SELECT label FROM devmsglabels WHERE label=?",
|
"SELECT label FROM devmsglabels WHERE label=?",
|
||||||
@@ -2237,19 +2237,19 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_has_device_msg() {
|
fn test_was_device_msg_ever_added() {
|
||||||
let t = test_context(Some(Box::new(logging_cb)));
|
let t = test_context(Some(Box::new(logging_cb)));
|
||||||
add_device_msg(&t.ctx, Some("some-label"), None).ok();
|
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);
|
let mut msg = Message::new(Viewtype::Text);
|
||||||
msg.text = Some("message text".to_string());
|
msg.text = Some("message text".to_string());
|
||||||
add_device_msg(&t.ctx, Some("another-label"), Some(&mut msg)).ok();
|
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 {
|
fn chatlist_len(ctx: &Context, listflags: usize) -> usize {
|
||||||
|
|||||||
Reference in New Issue
Block a user