feat: implemented sync status update function in repository

main
Jef Roosens 2025-03-17 10:27:30 +01:00
parent efe08771b1
commit f42c708cc6
No known key found for this signature in database
GPG Key ID: 21FD3D77D56BAF49
1 changed files with 25 additions and 2 deletions

View File

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{collections::HashSet, sync::Arc};
use argon2::{Argon2, PasswordHash, PasswordVerifier};
use chrono::{DateTime, TimeDelta, Utc};
@ -100,7 +100,30 @@ impl GpodderRepository {
sync: Vec<Vec<&str>>,
unsync: Vec<&str>,
) -> Result<(), AuthErr> {
todo!("perform diff devices to sync and unsync")
let now = Utc::now();
let mut unsync: HashSet<&str> = HashSet::from_iter(unsync);
let original_unsync = unsync.clone();
for group in sync {
// We want to remove devices that are provided in both a sync group and the unsync
// category, as this does not make sense to perform. We use the original unsync array,
// as a device could be provided multiple times in different sync groups.
let (remove, remaining): (Vec<&str>, Vec<&str>) =
group.into_iter().partition(|d| original_unsync.contains(d));
for device_id in remove {
unsync.remove(device_id);
}
let group_id = self.store.merge_sync_groups(user, remaining)?;
self.store.synchronize_sync_group(group_id, now)?;
}
// Finally we unsync the remaining devices
self.store
.remove_from_sync_group(user, unsync.into_iter().collect())?;
Ok(())
}
pub fn devices_by_sync_group(