mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Implement helper method to easily check if a bit flag is inside
listflags. Make Contact::get_all use it Add method documentation and tests
This commit is contained in:
@@ -52,7 +52,7 @@ pub const DC_GCL_ADD_ALLDONE_HINT: usize = 0x04;
|
||||
|
||||
const DC_GCM_ADDDAYMARKER: usize = 0x01;
|
||||
|
||||
const DC_GCL_VERIFIED_ONLY: usize = 0x01;
|
||||
pub const DC_GCL_VERIFIED_ONLY: usize = 0x01;
|
||||
pub const DC_GCL_ADD_SELF: usize = 0x02;
|
||||
|
||||
/// param1 is a directory where the keys are written to
|
||||
|
||||
@@ -18,8 +18,6 @@ use crate::sql;
|
||||
use crate::stock::StockMessage;
|
||||
use crate::types::*;
|
||||
|
||||
const DC_GCL_VERIFIED_ONLY: u32 = 0x01;
|
||||
|
||||
/// Contacts with at least this origin value are shown in the contact list.
|
||||
const DC_ORIGIN_MIN_CONTACT_LIST: i32 = 0x100;
|
||||
|
||||
@@ -479,8 +477,10 @@ impl<'a> Contact<'a> {
|
||||
|
||||
let mut add_self = false;
|
||||
let mut ret = Vec::new();
|
||||
let flag_verified_only = listflags_has(listflags, DC_GCL_VERIFIED_ONLY);
|
||||
let flag_add_self = listflags_has(listflags, DC_GCL_ADD_SELF);
|
||||
|
||||
if (listflags & DC_GCL_VERIFIED_ONLY) > 0 || query.is_some() {
|
||||
if flag_verified_only || query.is_some() {
|
||||
let s3str_like_cmd = format!(
|
||||
"%{}%",
|
||||
query
|
||||
@@ -504,7 +504,7 @@ impl<'a> Contact<'a> {
|
||||
0x100,
|
||||
&s3str_like_cmd,
|
||||
&s3str_like_cmd,
|
||||
if 0 != listflags & 0x1 { 0 } else { 1 },
|
||||
if flag_verified_only { 0 } else { 1 },
|
||||
],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| {
|
||||
@@ -544,7 +544,7 @@ impl<'a> Contact<'a> {
|
||||
)?;
|
||||
}
|
||||
|
||||
if 0 != listflags & DC_GCL_ADD_SELF as u32 && add_self {
|
||||
if flag_add_self && add_self {
|
||||
ret.push(DC_CONTACT_ID_SELF);
|
||||
}
|
||||
|
||||
|
||||
@@ -1383,6 +1383,32 @@ impl FromStr for EmailAddress {
|
||||
}
|
||||
}
|
||||
|
||||
/// Utility to check if a in the binary represantion of listflags
|
||||
/// the bit at position bitindex is 1.
|
||||
///
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::convert::TryInto;
|
||||
/// use deltachat::dc_tools::listflags_has;
|
||||
/// use deltachat::constants::{DC_GCL_ADD_SELF, DC_GCL_VERIFIED_ONLY};
|
||||
/// let listflags: u32 = 0x1101;
|
||||
/// assert!(listflags_has(listflags, 0x1) == true);
|
||||
/// assert!(listflags_has(listflags, 0x10) == false);
|
||||
/// assert!(listflags_has(listflags, 0x100) == true);
|
||||
/// assert!(listflags_has(listflags, 0x1000) == true);
|
||||
/// let listflags: u32 = (DC_GCL_ADD_SELF | DC_GCL_VERIFIED_ONLY).try_into().unwrap();
|
||||
/// assert!(listflags_has(listflags, DC_GCL_VERIFIED_ONLY) == true);
|
||||
/// assert!(listflags_has(listflags, DC_GCL_ADD_SELF) == true);
|
||||
/// let listflags: u32 = DC_GCL_VERIFIED_ONLY.try_into().unwrap();
|
||||
/// assert!(listflags_has(listflags, DC_GCL_ADD_SELF) == false);
|
||||
/// ```
|
||||
pub fn listflags_has(listflags: u32, bitindex: usize) -> bool {
|
||||
let listflags = listflags as usize;
|
||||
(listflags & bitindex) == bitindex
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user