fix(account): update sync range and handle all-mode reset

This commit is contained in:
rustmailer
2025-12-31 22:57:20 +08:00
parent a6216c2ce6
commit ef891b20c3
3 changed files with 22 additions and 13 deletions
+7 -12
View File
@@ -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);
}
+10
View File
@@ -121,6 +121,7 @@ pub struct AccountUpdateRequest {
/// - Reducing server load during resyncs
pub date_since: Option<DateSince>,
pub date_before: Option<RelativeDate>,
pub clear_date_range: Option<bool>,
/// 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()?;
}
@@ -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" });
}