diff --git a/src/modules/account/migration.rs b/src/modules/account/migration.rs index e9089dd..002265b 100644 --- a/src/modules/account/migration.rs +++ b/src/modules/account/migration.rs @@ -195,13 +195,6 @@ impl AccountV3 { ErrorCode::ResourceNotFound ) })?; - - // if !account.enabled { - // return Err(raise_error!( - // format!("Account id='{account_id}' is disabled"), - // ErrorCode::AccountDisabled - // )); - // } Ok(account) } @@ -221,11 +214,6 @@ impl AccountV3 { .await } - // /// Saves the current `AccountEntity` by persisting it to storage. - // pub async fn save(&self) -> BichonResult<()> { - // insert_impl(DB_MANAGER.meta_db(), self.to_owned()).await - // } - pub async fn create_account( user_id: u64, request: AccountCreateRequest, @@ -420,6 +408,13 @@ impl AccountV3 { new.date_since = None; } + if let Some(clear_date_range) = request.clear_date_range { + if clear_date_range { + new.date_since = None; + new.date_before = None; + } + } + if let Some(folder_limit) = request.folder_limit { new.folder_limit = Some(folder_limit); } diff --git a/src/modules/account/payload.rs b/src/modules/account/payload.rs index 5be9c83..91f8d1c 100644 --- a/src/modules/account/payload.rs +++ b/src/modules/account/payload.rs @@ -121,6 +121,7 @@ pub struct AccountUpdateRequest { /// - Reducing server load during resyncs pub date_since: Option, pub date_before: Option, + pub clear_date_range: Option, /// Max emails to sync for this folder. /// If not set, sync all emails. /// otherwise sync up to `n` most recent emails (min 10). @@ -165,6 +166,15 @@ impl AccountUpdateRequest { )); } + if self.clear_date_range == Some(true) + && (self.date_since.is_some() || self.date_before.is_some()) + { + return Err(raise_error!( + "clear_date_range cannot be combined with date_since or date_before".into(), + ErrorCode::InvalidParameter + )); + } + if let Some(date_since) = self.date_since.as_ref() { date_since.validate()?; } diff --git a/web/src/features/accounts/components/action-dialog.tsx b/web/src/features/accounts/components/action-dialog.tsx index b7b2183..904d0b1 100644 --- a/web/src/features/accounts/components/action-dialog.tsx +++ b/web/src/features/accounts/components/action-dialog.tsx @@ -290,7 +290,11 @@ export function AccountActionDialog({ currentRow, open, onOpenChange }: Props) { sync_batch_size: data.sync_batch_size, }; if (isEdit) { - updateMutation.mutate(commonData); + const isAllMode = !data.date_since && !data.date_before; + updateMutation.mutate({ + ...commonData, + ...(isAllMode ? { clear_date_range: true } : {}) + }); } else { createMutation.mutate({ ...commonData, account_type: "IMAP" }); }