Can update client last usage

This commit is contained in:
2025-01-30 21:53:51 +01:00
parent 08f535c15c
commit 501520a9df
2 changed files with 23 additions and 2 deletions

View File

@@ -80,6 +80,10 @@ impl APIClient {
pub fn fmt_used(&self) -> String {
format_time(self.used).unwrap_or_default()
}
pub fn need_update_last_used(&self) -> bool {
self.used + 60 * 15 < curr_time().unwrap()
}
}
impl APIClient {
@@ -97,7 +101,7 @@ impl APIClient {
}
}
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(serde::Serialize, serde::Deserialize, Clone)]
pub struct UserConfig {
/// Target user ID
pub user_id: UserID,
@@ -211,4 +215,9 @@ impl UserConfig {
pub fn find_client_by_id(&self, id: &APIClientID) -> Option<&APIClient> {
self.clients.iter().find(|c| &c.id == id)
}
/// Find a client by its id and get a mutable reference
pub fn find_client_by_id_mut(&mut self, id: &APIClientID) -> Option<&mut APIClient> {
self.clients.iter_mut().find(|c| &c.id == id)
}
}