feat: implemented sync status update function in repository
parent
efe08771b1
commit
f42c708cc6
|
@ -1,4 +1,4 @@
|
||||||
use std::sync::Arc;
|
use std::{collections::HashSet, sync::Arc};
|
||||||
|
|
||||||
use argon2::{Argon2, PasswordHash, PasswordVerifier};
|
use argon2::{Argon2, PasswordHash, PasswordVerifier};
|
||||||
use chrono::{DateTime, TimeDelta, Utc};
|
use chrono::{DateTime, TimeDelta, Utc};
|
||||||
|
@ -100,7 +100,30 @@ impl GpodderRepository {
|
||||||
sync: Vec<Vec<&str>>,
|
sync: Vec<Vec<&str>>,
|
||||||
unsync: Vec<&str>,
|
unsync: Vec<&str>,
|
||||||
) -> Result<(), AuthErr> {
|
) -> 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(
|
pub fn devices_by_sync_group(
|
||||||
|
|
Loading…
Reference in New Issue