JMAP for Contacts implementation (part 2)
This commit is contained in:
1
crates/groupware/src/cache/mod.rs
vendored
1
crates/groupware/src/cache/mod.rs
vendored
@@ -327,6 +327,7 @@ impl GroupwareCache for Server {
|
||||
.await?;
|
||||
AddressBook {
|
||||
name: name.clone(),
|
||||
is_default: true,
|
||||
preferences: vec![AddressBookPreferences {
|
||||
account_id,
|
||||
name: format!(
|
||||
|
||||
@@ -169,17 +169,21 @@ impl Calendar {
|
||||
}
|
||||
|
||||
pub fn preferences_mut(&mut self, access_token: &AccessToken) -> &mut CalendarPreferences {
|
||||
if self.preferences.len() == 1 {
|
||||
&mut self.preferences[0]
|
||||
let account_id = access_token.primary_id();
|
||||
let idx = if let Some(idx) = self
|
||||
.preferences
|
||||
.iter()
|
||||
.position(|p| p.account_id == account_id)
|
||||
{
|
||||
idx
|
||||
} else {
|
||||
let account_id = access_token.primary_id();
|
||||
let idx = self
|
||||
.preferences
|
||||
.iter()
|
||||
.position(|p| p.account_id == account_id)
|
||||
.unwrap_or(0);
|
||||
&mut self.preferences[idx]
|
||||
}
|
||||
let mut preferences = self.preferences[0].clone();
|
||||
preferences.account_id = account_id;
|
||||
self.preferences.push(preferences);
|
||||
self.preferences.len() - 1
|
||||
};
|
||||
|
||||
&mut self.preferences[idx]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ pub struct AddressBook {
|
||||
pub name: String,
|
||||
pub preferences: Vec<AddressBookPreferences>,
|
||||
pub subscribers: Vec<u32>,
|
||||
pub is_default: bool,
|
||||
pub dead_properties: DeadProperty,
|
||||
pub acls: Vec<AclGrant>,
|
||||
pub created: i64,
|
||||
@@ -35,7 +36,6 @@ pub struct AddressBookPreferences {
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub sort_order: u32,
|
||||
pub is_default: bool,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
@@ -66,17 +66,21 @@ impl AddressBook {
|
||||
}
|
||||
|
||||
pub fn preferences_mut(&mut self, access_token: &AccessToken) -> &mut AddressBookPreferences {
|
||||
if self.preferences.len() == 1 {
|
||||
&mut self.preferences[0]
|
||||
let account_id = access_token.primary_id();
|
||||
let idx = if let Some(idx) = self
|
||||
.preferences
|
||||
.iter()
|
||||
.position(|p| p.account_id == account_id)
|
||||
{
|
||||
idx
|
||||
} else {
|
||||
let account_id = access_token.primary_id();
|
||||
let idx = self
|
||||
.preferences
|
||||
.iter()
|
||||
.position(|p| p.account_id == account_id)
|
||||
.unwrap_or(0);
|
||||
&mut self.preferences[idx]
|
||||
}
|
||||
let mut preferences = self.preferences[0].clone();
|
||||
preferences.account_id = account_id;
|
||||
self.preferences.push(preferences);
|
||||
self.preferences.len() - 1
|
||||
};
|
||||
|
||||
&mut self.preferences[idx]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,3 +98,36 @@ impl ArchivedAddressBook {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ContactCard {
|
||||
pub fn added_addressbook_ids(
|
||||
&self,
|
||||
prev_data: &ArchivedContactCard,
|
||||
) -> impl Iterator<Item = u32> {
|
||||
self.names
|
||||
.iter()
|
||||
.filter(|m| prev_data.names.iter().all(|pm| pm.parent_id != m.parent_id))
|
||||
.map(|m| m.parent_id)
|
||||
}
|
||||
|
||||
pub fn removed_addressbook_ids(
|
||||
&self,
|
||||
prev_data: &ArchivedContactCard,
|
||||
) -> impl Iterator<Item = u32> {
|
||||
prev_data
|
||||
.names
|
||||
.iter()
|
||||
.filter(|m| self.names.iter().all(|pm| pm.parent_id != m.parent_id))
|
||||
.map(|m| m.parent_id.to_native())
|
||||
}
|
||||
|
||||
pub fn unchanged_addressbook_ids(
|
||||
&self,
|
||||
prev_data: &ArchivedContactCard,
|
||||
) -> impl Iterator<Item = u32> {
|
||||
self.names
|
||||
.iter()
|
||||
.filter(|m| prev_data.names.iter().any(|pm| pm.parent_id == m.parent_id))
|
||||
.map(|m| m.parent_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,4 +246,26 @@ impl DestroyArchive<Archive<&ArchivedContactCard>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_all(
|
||||
self,
|
||||
access_token: &AccessToken,
|
||||
account_id: u32,
|
||||
document_id: u32,
|
||||
batch: &mut BatchBuilder,
|
||||
) -> trc::Result<()> {
|
||||
batch
|
||||
.with_account_id(account_id)
|
||||
.with_collection(Collection::ContactCard)
|
||||
.delete_document(document_id)
|
||||
.custom(
|
||||
ObjectIndexBuilder::<_, ()>::new()
|
||||
.with_tenant_id(access_token)
|
||||
.with_current(self.0),
|
||||
)
|
||||
.caused_by(trc::location!())
|
||||
.map(|b| {
|
||||
b.commit_point();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user