mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-22 18:39:31 +00:00
store: Refactoring to split calendar and addressbook
This commit is contained in:
27
crates/store/src/addressbook/address_object.rs
Normal file
27
crates/store/src/addressbook/address_object.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use crate::Error;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AddressObject {
|
||||
id: String,
|
||||
vcf: String,
|
||||
}
|
||||
|
||||
impl AddressObject {
|
||||
pub fn from_vcf(object_id: String, vcf: String) -> Result<Self, Error> {
|
||||
Ok(Self { id: object_id, vcf })
|
||||
}
|
||||
pub fn get_id(&self) -> &str {
|
||||
&self.id
|
||||
}
|
||||
pub fn get_etag(&self) -> String {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&self.id);
|
||||
hasher.update(self.get_vcf());
|
||||
format!("{:x}", hasher.finalize())
|
||||
}
|
||||
|
||||
pub fn get_vcf(&self) -> &str {
|
||||
&self.vcf
|
||||
}
|
||||
}
|
||||
32
crates/store/src/addressbook/addressbook.rs
Normal file
32
crates/store/src/addressbook/addressbook.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Addressbook {
|
||||
pub id: String,
|
||||
pub principal: String,
|
||||
pub displayname: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub deleted_at: Option<NaiveDateTime>,
|
||||
pub synctoken: i64,
|
||||
}
|
||||
|
||||
impl Addressbook {
|
||||
pub fn format_synctoken(&self) -> String {
|
||||
format_synctoken(self.synctoken)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make nicer
|
||||
const SYNC_NAMESPACE: &str = "github.com/lennart-k/rustical/ns/";
|
||||
|
||||
pub fn format_synctoken(synctoken: i64) -> String {
|
||||
format!("{}{}", SYNC_NAMESPACE, synctoken)
|
||||
}
|
||||
|
||||
pub fn parse_synctoken(synctoken: &str) -> Option<i64> {
|
||||
if !synctoken.starts_with(SYNC_NAMESPACE) {
|
||||
return None;
|
||||
}
|
||||
let (_, synctoken) = synctoken.split_at(SYNC_NAMESPACE.len());
|
||||
synctoken.parse::<i64>().ok()
|
||||
}
|
||||
5
crates/store/src/addressbook/mod.rs
Normal file
5
crates/store/src/addressbook/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
pub mod address_object;
|
||||
pub mod addressbook;
|
||||
|
||||
pub use address_object::*;
|
||||
pub use addressbook::*;
|
||||
Reference in New Issue
Block a user