use std::collections::BTreeSet;
use std::path::Path;
use super::presence::Presence;
use super::tools::{self, Tool};
use super::{CLIENTS, Client};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClientRow {
pub client: String,
pub present: bool,
pub tools: Vec<Tool>,
pub last_seen: Option<i64>,
}
pub fn roster(state_root: &Path, presence: &Presence, workspace: &str) -> Vec<ClientRow> {
let live = presence.live();
names(state_root)
.into_iter()
.filter_map(|name| Client::parse(&name).ok())
.filter(|client| super::registered(state_root, client).contains(workspace))
.map(|client| ClientRow {
present: live.contains(&client.name()),
tools: tools::read(state_root, &client),
last_seen: super::seen::read(state_root, &client),
client: client.name(),
})
.collect()
}
fn names(state_root: &Path) -> BTreeSet<String> {
let Ok(entries) = std::fs::read_dir(state_root.join(CLIENTS)) else {
return BTreeSet::new();
};
entries
.flatten()
.map(|e| e.file_name().to_string_lossy().into_owned())
.collect()
}
#[cfg(test)]
mod tests;