mirror of
https://github.com/chatmail/core.git
synced 2026-05-21 07:46:31 +03:00
Reduce number of generic impl AsRef
This commit is contained in:
@@ -1919,7 +1919,7 @@ pub unsafe extern "C" fn dc_get_contacts(
|
|||||||
let query = to_opt_string_lossy(query);
|
let query = to_opt_string_lossy(query);
|
||||||
|
|
||||||
block_on(async move {
|
block_on(async move {
|
||||||
match Contact::get_all(ctx, flags, query).await {
|
match Contact::get_all(ctx, flags, query.as_deref()).await {
|
||||||
Ok(contacts) => Box::into_raw(Box::new(dc_array_t::from(
|
Ok(contacts) => Box::into_raw(Box::new(dc_array_t::from(
|
||||||
contacts.iter().map(|id| id.to_u32()).collect::<Vec<u32>>(),
|
contacts.iter().map(|id| id.to_u32()).collect::<Vec<u32>>(),
|
||||||
))),
|
))),
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ impl Contact {
|
|||||||
pub async fn get_all(
|
pub async fn get_all(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
listflags: u32,
|
listflags: u32,
|
||||||
query: Option<impl AsRef<str>>,
|
query: Option<&str>,
|
||||||
) -> Result<Vec<ContactId>> {
|
) -> Result<Vec<ContactId>> {
|
||||||
let self_addrs = context.get_all_self_addrs().await?;
|
let self_addrs = context.get_all_self_addrs().await?;
|
||||||
let mut add_self = false;
|
let mut add_self = false;
|
||||||
@@ -695,7 +695,7 @@ impl Contact {
|
|||||||
let flag_add_self = (listflags & DC_GCL_ADD_SELF) != 0;
|
let flag_add_self = (listflags & DC_GCL_ADD_SELF) != 0;
|
||||||
|
|
||||||
if flag_verified_only || query.is_some() {
|
if flag_verified_only || query.is_some() {
|
||||||
let s3str_like_cmd = format!("%{}%", query.as_ref().map(|s| s.as_ref()).unwrap_or(""));
|
let s3str_like_cmd = format!("%{}%", query.unwrap_or(""));
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.query_map(
|
.query_map(
|
||||||
@@ -739,9 +739,9 @@ impl Contact {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let self_name2 = stock_str::self_msg(context);
|
let self_name2 = stock_str::self_msg(context);
|
||||||
|
|
||||||
if self_addr.contains(query.as_ref())
|
if self_addr.contains(query)
|
||||||
|| self_name.contains(query.as_ref())
|
|| self_name.contains(query)
|
||||||
|| self_name2.await.contains(query.as_ref())
|
|| self_name2.await.contains(query)
|
||||||
{
|
{
|
||||||
add_self = true;
|
add_self = true;
|
||||||
}
|
}
|
||||||
@@ -1396,27 +1396,23 @@ pub fn normalize_name(full_name: &str) -> String {
|
|||||||
fn cat_fingerprint(
|
fn cat_fingerprint(
|
||||||
ret: &mut String,
|
ret: &mut String,
|
||||||
addr: &str,
|
addr: &str,
|
||||||
fingerprint_verified: impl AsRef<str>,
|
fingerprint_verified: &str,
|
||||||
fingerprint_unverified: impl AsRef<str>,
|
fingerprint_unverified: &str,
|
||||||
) {
|
) {
|
||||||
*ret += &format!(
|
*ret += &format!(
|
||||||
"\n\n{}:\n{}",
|
"\n\n{}:\n{}",
|
||||||
addr,
|
addr,
|
||||||
if !fingerprint_verified.as_ref().is_empty() {
|
if !fingerprint_verified.is_empty() {
|
||||||
fingerprint_verified.as_ref()
|
fingerprint_verified
|
||||||
} else {
|
} else {
|
||||||
fingerprint_unverified.as_ref()
|
fingerprint_unverified
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if !fingerprint_verified.as_ref().is_empty()
|
if !fingerprint_verified.is_empty()
|
||||||
&& !fingerprint_unverified.as_ref().is_empty()
|
&& !fingerprint_unverified.is_empty()
|
||||||
&& fingerprint_verified.as_ref() != fingerprint_unverified.as_ref()
|
&& fingerprint_verified != fingerprint_unverified
|
||||||
{
|
{
|
||||||
*ret += &format!(
|
*ret += &format!("\n\n{} (alternative):\n{}", addr, fingerprint_unverified);
|
||||||
"\n\n{} (alternative):\n{}",
|
|
||||||
addr,
|
|
||||||
fingerprint_unverified.as_ref()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2920,7 +2920,7 @@ mod tests {
|
|||||||
|
|
||||||
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await?;
|
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await?;
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
let contacts = Contact::get_all(&t.ctx, 0, None as Option<String>).await?;
|
let contacts = Contact::get_all(&t.ctx, 0, None).await?;
|
||||||
assert_eq!(contacts.len(), 0); // mailing list recipients and senders do not count as "known contacts"
|
assert_eq!(contacts.len(), 0); // mailing list recipients and senders do not count as "known contacts"
|
||||||
|
|
||||||
let msg1 = get_chat_msg(&t, chat_id, 0, 2).await;
|
let msg1 = get_chat_msg(&t, chat_id, 0, 2).await;
|
||||||
|
|||||||
@@ -150,8 +150,7 @@ impl LoginParam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Read the login parameters from the database.
|
/// Read the login parameters from the database.
|
||||||
async fn from_database(context: &Context, prefix: impl AsRef<str>) -> Result<Self> {
|
async fn from_database(context: &Context, prefix: &str) -> Result<Self> {
|
||||||
let prefix = prefix.as_ref();
|
|
||||||
let sql = &context.sql;
|
let sql = &context.sql;
|
||||||
|
|
||||||
let key = format!("{}addr", prefix);
|
let key = format!("{}addr", prefix);
|
||||||
|
|||||||
Reference in New Issue
Block a user