mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 18:36:30 +03:00
add dc_has_device_msg()
This commit is contained in:
36
src/chat.rs
36
src/chat.rs
@@ -2021,12 +2021,7 @@ fn add_device_msg_maybe_labelled(
|
||||
}
|
||||
|
||||
pub fn skip_device_msg(context: &Context, label: &str) -> Result<(), Error> {
|
||||
ensure!(!label.is_empty(), "cannot skip empty label");
|
||||
if let Ok(()) = context.sql.query_row(
|
||||
"SELECT label FROM devmsglabels WHERE label=?",
|
||||
params![label],
|
||||
|_| Ok(()),
|
||||
) {
|
||||
if has_device_msg(context, label)? {
|
||||
info!(context, "device-message {} already added", label);
|
||||
return Ok(());
|
||||
}
|
||||
@@ -2039,6 +2034,19 @@ pub fn skip_device_msg(context: &Context, label: &str) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn has_device_msg(context: &Context, label: &str) -> Result<bool, Error> {
|
||||
ensure!(!label.is_empty(), "empty label");
|
||||
if let Ok(()) = context.sql.query_row(
|
||||
"SELECT label FROM devmsglabels WHERE label=?",
|
||||
params![label],
|
||||
|_| Ok(()),
|
||||
) {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub fn add_info_msg(context: &Context, chat_id: u32, text: impl AsRef<str>) {
|
||||
let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device");
|
||||
|
||||
@@ -2251,6 +2259,22 @@ mod tests {
|
||||
assert!(!msg_id.as_ref().unwrap().is_unset());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_device_msg() {
|
||||
let t = test_context(Some(Box::new(logging_cb)));
|
||||
skip_device_msg(&t.ctx, "some-label").ok();
|
||||
assert!(has_device_msg(&t.ctx, "some-label").unwrap());
|
||||
|
||||
let mut msg = Message::new(Viewtype::Text);
|
||||
msg.text = Some("message text".to_string());
|
||||
add_device_msg_once(&t.ctx, "another-label", &mut msg).ok();
|
||||
assert!(has_device_msg(&t.ctx, "another-label").unwrap());
|
||||
|
||||
assert!(!has_device_msg(&t.ctx, "unused-label").unwrap());
|
||||
|
||||
assert!(has_device_msg(&t.ctx, "").is_err());
|
||||
}
|
||||
|
||||
fn chatlist_len(ctx: &Context, listflags: usize) -> usize {
|
||||
Chatlist::try_load(ctx, listflags, None, None)
|
||||
.unwrap()
|
||||
|
||||
Reference in New Issue
Block a user