From f2c1e5c6e559d7254ed7732777083f9521d24f65 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sun, 3 Apr 2022 15:29:05 +0200 Subject: [PATCH] Replace some ContactId::new() calls with constants --- src/chat.rs | 5 ++--- src/contact.rs | 3 +-- src/dc_receive_imf.rs | 12 ++++++------ src/ephemeral.rs | 4 ++-- src/qr.rs | 6 +++--- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 54ea9065e..29de1fc71 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3904,7 +3904,6 @@ mod tests { async fn test_self_talk() -> Result<()> { let t = TestContext::new_alice().await; let chat = &t.get_self_chat().await; - assert_eq!(ContactId::SELF, ContactId::new(1)); assert!(!chat.id.is_special()); assert!(chat.is_self_talk()); assert!(chat.visibility == ChatVisibility::Normal); @@ -4321,7 +4320,7 @@ mod tests { let contact1 = Contact::create(&context.ctx, "bob", "bob@mail.de") .await .unwrap(); - assert_ne!(contact1, ContactId::new(0)); + assert_ne!(contact1, ContactId::UNDEFINED); let chat_id = ChatId::create_for_contact(&context.ctx, contact1) .await @@ -4526,7 +4525,7 @@ mod tests { // create contact, then unblocked chat let contact_id = Contact::create(&ctx, "", "bob@foo.de").await.unwrap(); - assert_ne!(contact_id, ContactId::new(0)); + assert_ne!(contact_id, ContactId::UNDEFINED); let found = ChatId::lookup_by_contact(&ctx, contact_id).await.unwrap(); assert!(found.is_none()); diff --git a/src/contact.rs b/src/contact.rs index a84e2fe5f..4c4eb3058 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1542,7 +1542,7 @@ mod tests { Origin::IncomingReplyTo, ) .await?; - assert_ne!(id, ContactId::new(0)); + assert_ne!(id, ContactId::UNDEFINED); let contact = Contact::load_from_db(&context.ctx, id).await.unwrap(); assert_eq!(contact.get_name(), ""); @@ -1697,7 +1697,6 @@ mod tests { // check SELF let contact = Contact::load_from_db(&t, ContactId::SELF).await.unwrap(); - assert_eq!(ContactId::SELF, ContactId::new(1)); assert_eq!(contact.get_name(), stock_str::self_msg(&t).await); assert_eq!(contact.get_addr(), ""); // we're not configured assert!(!contact.is_blocked()); diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index cfeae1180..75a650926 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -277,7 +277,7 @@ pub(crate) async fn dc_receive_imf_inner( } if let Some(avatar_action) = &mime_parser.user_avatar { - if from_id != ContactId::new(0) + if from_id != ContactId::UNDEFINED && context .update_contacts_timestamp(from_id, Param::AvatarTimestamp, sent_timestamp) .await? @@ -305,7 +305,7 @@ pub(crate) async fn dc_receive_imf_inner( // Ignore MDNs though, as they never contain the signature even if user has set it. if mime_parser.mdn_reports.is_empty() && is_partial_download.is_none() - && from_id != ContactId::new(0) + && from_id != ContactId::UNDEFINED && context .update_contacts_timestamp(from_id, Param::StatusTimestamp, sent_timestamp) .await? @@ -417,7 +417,7 @@ pub async fn from_field_to_contact_id( "mail has an empty From header: {:?}", from_address_list ); - Ok((ContactId::new(0), false, Origin::Unknown)) + Ok((ContactId::UNDEFINED, false, Origin::Unknown)) } } @@ -524,7 +524,7 @@ async fn add_parts( securejoin_seen = false; } - let test_normal_chat = if from_id == ContactId::new(0) { + let test_normal_chat = if from_id == ContactId::UNDEFINED { Default::default() } else { ChatIdBlocked::lookup_by_contact(context, from_id).await? @@ -1144,8 +1144,8 @@ INSERT INTO msgs stmt.execute(paramsv![ rfc724_mid, chat_id, - if trash { ContactId::new(0) } else { from_id }, - if trash { ContactId::new(0) } else { to_id }, + if trash { ContactId::UNDEFINED } else { from_id }, + if trash { ContactId::UNDEFINED } else { to_id }, sort_timestamp, sent_timestamp, rcvd_timestamp, diff --git a/src/ephemeral.rs b/src/ephemeral.rs index f5cd25330..5eec7ef9e 100644 --- a/src/ephemeral.rs +++ b/src/ephemeral.rs @@ -855,8 +855,8 @@ mod tests { // Check that if there is a message left, the text and metadata are gone if let Ok(msg) = Message::load_from_db(t, msg_id).await { - assert_eq!(msg.from_id, ContactId::new(0)); - assert_eq!(msg.to_id, ContactId::new(0)); + assert_eq!(msg.from_id, ContactId::UNDEFINED); + assert_eq!(msg.to_id, ContactId::UNDEFINED); assert!(msg.text.is_none_or_empty(), "{:?}", msg.text); let rawtxt: Option = t .sql diff --git a/src/qr.rs b/src/qr.rs index 5edbd9588..6046049fa 100644 --- a/src/qr.rs +++ b/src/qr.rs @@ -711,7 +711,7 @@ mod tests { .. } = qr { - assert_ne!(contact_id, ContactId::new(0)); + assert_ne!(contact_id, ContactId::UNDEFINED); assert_eq!(grpname, "test ? test !"); } else { bail!("Wrong QR code type"); @@ -729,7 +729,7 @@ mod tests { .. } = qr { - assert_ne!(contact_id, ContactId::new(0)); + assert_ne!(contact_id, ContactId::UNDEFINED); assert_eq!(grpname, "test ? test !"); let contact = Contact::get_by_id(&ctx.ctx, contact_id).await?; @@ -751,7 +751,7 @@ mod tests { ).await?; if let Qr::AskVerifyContact { contact_id, .. } = qr { - assert_ne!(contact_id, ContactId::new(0)); + assert_ne!(contact_id, ContactId::UNDEFINED); } else { bail!("Wrong QR code type"); }