Assisted CalDAV/CardDAV shared resource discovery (closes #1691)
This commit is contained in:
17
crates/groupware/src/cache/calcard.rs
vendored
17
crates/groupware/src/cache/calcard.rs
vendored
@@ -53,14 +53,20 @@ pub(super) async fn build_calcard_resources(
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
.unwrap_or_default();
|
||||
let name = server
|
||||
.store()
|
||||
.get_principal_name(account_id)
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
.unwrap_or_else(|| format!("_{account_id}"));
|
||||
if container_ids.is_empty() {
|
||||
if is_calendar {
|
||||
server
|
||||
.create_default_calendar(access_token, account_id)
|
||||
.create_default_calendar(access_token, account_id, &name)
|
||||
.await?;
|
||||
} else {
|
||||
server
|
||||
.create_default_addressbook(access_token, account_id)
|
||||
.create_default_addressbook(access_token, account_id, &name)
|
||||
.await?;
|
||||
}
|
||||
last_change_id = server
|
||||
@@ -84,13 +90,6 @@ pub(super) async fn build_calcard_resources(
|
||||
.caused_by(trc::location!())?
|
||||
.unwrap_or_default();
|
||||
|
||||
let name = server
|
||||
.store()
|
||||
.get_principal_name(account_id)
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
.unwrap_or_else(|| format!("_{account_id}"));
|
||||
|
||||
let mut cache = DavResources {
|
||||
base_path: format!(
|
||||
"{}/{}/",
|
||||
|
||||
25
crates/groupware/src/cache/mod.rs
vendored
25
crates/groupware/src/cache/mod.rs
vendored
@@ -44,18 +44,21 @@ pub trait GroupwareCache: Sync + Send {
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
account_id: u32,
|
||||
account_name: &str,
|
||||
) -> impl Future<Output = trc::Result<Option<u32>>> + Send;
|
||||
|
||||
fn create_default_calendar(
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
account_id: u32,
|
||||
account_name: &str,
|
||||
) -> impl Future<Output = trc::Result<Option<u32>>> + Send;
|
||||
|
||||
fn get_or_create_default_calendar(
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
account_id: u32,
|
||||
account_name: &str,
|
||||
) -> impl Future<Output = trc::Result<Option<u32>>> + Send;
|
||||
|
||||
fn cached_dav_resources(
|
||||
@@ -337,6 +340,7 @@ impl GroupwareCache for Server {
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
account_id: u32,
|
||||
account_name: &str,
|
||||
) -> trc::Result<Option<u32>> {
|
||||
if let Some(name) = &self.core.groupware.default_addressbook_name {
|
||||
let mut batch = BatchBuilder::new();
|
||||
@@ -346,7 +350,12 @@ impl GroupwareCache for Server {
|
||||
.await?;
|
||||
AddressBook {
|
||||
name: name.clone(),
|
||||
display_name: self.core.groupware.default_addressbook_display_name.clone(),
|
||||
display_name: self
|
||||
.core
|
||||
.groupware
|
||||
.default_addressbook_display_name
|
||||
.as_ref()
|
||||
.map(|display| format!("{display} ({account_name})")),
|
||||
is_default: true,
|
||||
..Default::default()
|
||||
}
|
||||
@@ -362,6 +371,7 @@ impl GroupwareCache for Server {
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
account_id: u32,
|
||||
account_name: &str,
|
||||
) -> trc::Result<Option<u32>> {
|
||||
if let Some(name) = &self.core.groupware.default_calendar_name {
|
||||
let mut batch = BatchBuilder::new();
|
||||
@@ -377,8 +387,11 @@ impl GroupwareCache for Server {
|
||||
.core
|
||||
.groupware
|
||||
.default_calendar_display_name
|
||||
.clone()
|
||||
.unwrap_or_else(|| name.clone()),
|
||||
.as_ref()
|
||||
.map_or_else(
|
||||
|| name.clone(),
|
||||
|display| format!("{display} ({account_name})",),
|
||||
),
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
@@ -395,13 +408,17 @@ impl GroupwareCache for Server {
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
account_id: u32,
|
||||
account_name: &str,
|
||||
) -> trc::Result<Option<u32>> {
|
||||
match self
|
||||
.get_document_ids(account_id, Collection::Calendar)
|
||||
.await
|
||||
{
|
||||
Ok(Some(ids)) if !ids.is_empty() => Ok(ids.iter().next()),
|
||||
_ => self.create_default_calendar(access_token, account_id).await,
|
||||
_ => {
|
||||
self.create_default_calendar(access_token, account_id, account_name)
|
||||
.await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ impl ItipIngest for Server {
|
||||
|
||||
// Obtain parent calendar
|
||||
let Some(parent_id) = self
|
||||
.get_or_create_default_calendar(access_token, account_id)
|
||||
.get_or_create_default_calendar(access_token, account_id, &access_token.name)
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user