Remove dc_tools::listflags_has

It was not even doing what the documentation says: the implementation
worked correctly only for bitindex=1 and bitindex=2.
This commit is contained in:
link2xt
2021-02-12 20:57:46 +03:00
committed by link2xt
parent 374ee7c1fe
commit 57a6f27c87
4 changed files with 7 additions and 30 deletions

View File

@@ -1018,9 +1018,9 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let contacts = Contact::get_all(
&context,
if arg0 == "listverified" {
0x1 | 0x2
DC_GCL_VERIFIED_ONLY | DC_GCL_ADD_SELF
} else {
0x2
DC_GCL_ADD_SELF
},
Some(arg1),
)

View File

@@ -101,8 +101,8 @@ pub const DC_GCL_FOR_FORWARDING: usize = 0x08;
pub const DC_GCM_ADDDAYMARKER: u32 = 0x01;
pub const DC_GCM_INFO_ONLY: u32 = 0x02;
pub const DC_GCL_VERIFIED_ONLY: usize = 0x01;
pub const DC_GCL_ADD_SELF: usize = 0x02;
pub const DC_GCL_VERIFIED_ONLY: u32 = 0x01;
pub const DC_GCL_ADD_SELF: u32 = 0x02;
// unchanged user avatars are resent to the recipients every some days
pub const DC_RESEND_USER_AVATAR_DAYS: i64 = 14;

View File

@@ -16,7 +16,7 @@ use crate::constants::{
DC_CONTACT_ID_LAST_SPECIAL, DC_CONTACT_ID_SELF, DC_GCL_ADD_SELF, DC_GCL_VERIFIED_ONLY,
};
use crate::context::Context;
use crate::dc_tools::{dc_get_abs_path, improve_single_line_input, listflags_has, EmailAddress};
use crate::dc_tools::{dc_get_abs_path, improve_single_line_input, EmailAddress};
use crate::events::EventType;
use crate::key::{DcKey, SignedPublicKey};
use crate::login_param::LoginParam;
@@ -586,8 +586,8 @@ impl Contact {
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);
let flag_verified_only = (listflags & DC_GCL_VERIFIED_ONLY) != 0;
let flag_add_self = (listflags & DC_GCL_ADD_SELF) != 0;
if flag_verified_only || query.is_some() {
let s3str_like_cmd = format!(

View File

@@ -642,13 +642,6 @@ impl rusqlite::types::ToSql for EmailAddress {
}
}
/// Utility to check if a in the binary represantion of listflags
/// the bit at position bitindex is 1.
pub(crate) fn listflags_has(listflags: u32, bitindex: usize) -> bool {
let listflags = listflags as usize;
(listflags & bitindex) == bitindex
}
/// Makes sure that a user input that is not supposed to contain newlines does not contain newlines.
pub(crate) fn improve_single_line_input(input: impl AsRef<str>) -> String {
input
@@ -676,9 +669,7 @@ mod tests {
#![allow(clippy::indexing_slicing)]
use super::*;
use std::convert::TryInto;
use crate::constants::{DC_GCL_ADD_SELF, DC_GCL_VERIFIED_ONLY};
use crate::test_utils::TestContext;
#[test]
@@ -930,20 +921,6 @@ mod tests {
assert!(!dc_file_exist!(context, &fn0).await);
}
#[test]
fn test_listflags_has() {
let listflags: u32 = 0x1101;
assert!(listflags_has(listflags, 0x1));
assert!(!listflags_has(listflags, 0x10));
assert!(listflags_has(listflags, 0x100));
assert!(listflags_has(listflags, 0x1000));
let listflags: u32 = (DC_GCL_ADD_SELF | DC_GCL_VERIFIED_ONLY).try_into().unwrap();
assert!(listflags_has(listflags, DC_GCL_VERIFIED_ONLY));
assert!(listflags_has(listflags, DC_GCL_ADD_SELF));
let listflags: u32 = DC_GCL_VERIFIED_ONLY.try_into().unwrap();
assert!(!listflags_has(listflags, DC_GCL_ADD_SELF));
}
#[async_std::test]
async fn test_create_smeared_timestamp() {
let t = TestContext::new().await;