Introduce a ContactId newtype

This makes the contact ID its own newtype instead of being a plain
u32.  The change purposefully does not yet try and reap any benefits
from this yet, instead aiming for a boring change that's easy to
review.  Only exception is the ToSql/FromSql as not doing that yet
would also have created churn in the database code and it is easier to
go straight for the right solution here.
This commit is contained in:
Floris Bruynooghe
2022-03-02 22:06:48 +01:00
parent f28fcec81d
commit 438940219e
20 changed files with 372 additions and 261 deletions

View File

@@ -8,6 +8,7 @@ use quick_xml::events::{BytesEnd, BytesStart, BytesText};
use crate::chat::{self, ChatId};
use crate::config::Config;
use crate::constants::{Viewtype, DC_CONTACT_ID_SELF};
use crate::contact::ContactId;
use crate::context::Context;
use crate::dc_tools::time;
use crate::events::EventType;
@@ -25,7 +26,7 @@ pub struct Location {
pub longitude: f64,
pub accuracy: f64,
pub timestamp: i64,
pub contact_id: u32,
pub contact_id: ContactId,
pub msg_id: u32,
pub chat_id: ChatId,
pub marker: Option<String>,
@@ -558,7 +559,7 @@ pub async fn set_msg_location_id(context: &Context, msg_id: MsgId, location_id:
pub(crate) async fn save(
context: &Context,
chat_id: ChatId,
contact_id: u32,
contact_id: ContactId,
locations: &[Location],
independent: bool,
) -> Result<Option<u32>> {
@@ -585,12 +586,12 @@ pub(crate) async fn save(
conn.prepare_cached("SELECT id FROM locations WHERE timestamp=? AND from_id=?")?;
let mut stmt_insert = conn.prepare_cached(stmt_insert)?;
let exists = stmt_test.exists(paramsv![timestamp, contact_id as i32])?;
let exists = stmt_test.exists(paramsv![timestamp, contact_id])?;
if independent || !exists {
stmt_insert.execute(paramsv![
timestamp,
contact_id as i32,
contact_id,
chat_id,
latitude,
longitude,