mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 18:12:27 +00:00
frontend: Add basic information about collections
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{Error, addressbook::Addressbook};
|
||||
use crate::{CollectionMetadata, Error, addressbook::Addressbook};
|
||||
use async_trait::async_trait;
|
||||
use rustical_ical::AddressObject;
|
||||
|
||||
@@ -35,6 +35,12 @@ pub trait AddressbookStore: Send + Sync + 'static {
|
||||
synctoken: i64,
|
||||
) -> Result<(Vec<AddressObject>, Vec<String>, i64), Error>;
|
||||
|
||||
async fn addressbook_metadata(
|
||||
&self,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
) -> Result<CollectionMetadata, Error>;
|
||||
|
||||
async fn get_objects(
|
||||
&self,
|
||||
principal: &str,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Calendar, error::Error};
|
||||
use crate::{Calendar, CollectionMetadata, error::Error};
|
||||
use async_trait::async_trait;
|
||||
use chrono::NaiveDate;
|
||||
use rustical_ical::CalendarObject;
|
||||
@@ -53,6 +53,12 @@ pub trait CalendarStore: Send + Sync + 'static {
|
||||
self.get_objects(principal, cal_id).await
|
||||
}
|
||||
|
||||
async fn calendar_metadata(
|
||||
&self,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
) -> Result<CollectionMetadata, Error>;
|
||||
|
||||
async fn get_objects(
|
||||
&self,
|
||||
principal: &str,
|
||||
|
||||
@@ -135,6 +135,20 @@ impl<CS: CalendarStore, BS: CalendarStore> CalendarStore for CombinedCalendarSto
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn calendar_metadata(
|
||||
&self,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
) -> Result<crate::CollectionMetadata, Error> {
|
||||
if cal_id.starts_with(BIRTHDAYS_PREFIX) {
|
||||
self.birthday_store
|
||||
.calendar_metadata(principal, cal_id)
|
||||
.await
|
||||
} else {
|
||||
self.cal_store.calendar_metadata(principal, cal_id).await
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
async fn get_objects(
|
||||
&self,
|
||||
|
||||
@@ -16,7 +16,7 @@ fn birthday_calendar(addressbook: Addressbook) -> Calendar {
|
||||
id: format!("{}{}", BIRTHDAYS_PREFIX, addressbook.id),
|
||||
displayname: addressbook
|
||||
.displayname
|
||||
.map(|name| format!("{} birthdays", name)),
|
||||
.map(|name| format!("{name} birthdays")),
|
||||
order: 0,
|
||||
description: None,
|
||||
color: None,
|
||||
@@ -104,6 +104,17 @@ impl<AS: AddressbookStore> CalendarStore for ContactBirthdayStore<AS> {
|
||||
Ok((objects, deleted_objects, new_synctoken))
|
||||
}
|
||||
|
||||
async fn calendar_metadata(
|
||||
&self,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
) -> Result<crate::CollectionMetadata, Error> {
|
||||
let cal_id = cal_id
|
||||
.strip_prefix(BIRTHDAYS_PREFIX)
|
||||
.ok_or(Error::NotFound)?;
|
||||
self.0.addressbook_metadata(principal, cal_id).await
|
||||
}
|
||||
|
||||
async fn get_objects(
|
||||
&self,
|
||||
principal: &str,
|
||||
|
||||
@@ -37,3 +37,11 @@ pub struct CollectionOperation {
|
||||
pub topic: String,
|
||||
pub data: CollectionOperationInfo,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct CollectionMetadata {
|
||||
pub len: usize,
|
||||
pub deleted_len: usize,
|
||||
pub size: u64,
|
||||
pub deleted_size: u64,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const SYNC_NAMESPACE: &str = "github.com/lennart-k/rustical/ns/";
|
||||
|
||||
pub fn format_synctoken(synctoken: i64) -> String {
|
||||
format!("{}{}", SYNC_NAMESPACE, synctoken)
|
||||
format!("{SYNC_NAMESPACE}{synctoken}")
|
||||
}
|
||||
|
||||
pub fn parse_synctoken(synctoken: &str) -> Option<i64> {
|
||||
|
||||
Reference in New Issue
Block a user