rwho: render --json response as dict

This commit is contained in:
2026-07-21 18:06:00 +09:00
parent 6ee0723d07
commit f1f8b8d0d1
2 changed files with 47 additions and 26 deletions
+10 -10
View File
@@ -1,4 +1,4 @@
use std::{os::fd::OwnedFd, time::Duration};
use std::{collections::HashMap, os::fd::OwnedFd, time::Duration};
use anyhow::Context;
use futures_util::stream;
@@ -66,7 +66,7 @@ pub enum VarlinkRwhodClientResponse {
Ruptime(VarlinkRuptimeResponse),
}
pub type VarlinkRwhoResponse = Vec<(String, WhodUserEntry)>;
pub type VarlinkRwhoResponse = HashMap<String, Vec<WhodUserEntry>>;
pub type VarlinkRuptimeResponse = Vec<WhodStatusUpdate>;
#[derive(Debug, Clone, PartialEq, ReplyError)]
@@ -180,19 +180,19 @@ impl VarlinkRoowhoo2ClientServer {
tracing::debug!(?max_idle_time, "Handling Rwho request");
let store = self.whod_status_store.read().await;
let mut all_user_entries = Vec::with_capacity(store.len());
for status_update in store.values() {
all_user_entries.extend(
status_update
store
.values()
.filter_map(|status_update| {
let users: Vec<WhodUserEntry> = status_update
.users
.iter()
.filter(|user| max_idle_time.is_none_or(|max| user.idle_time < max))
.cloned()
.map(|user| (status_update.hostname.clone(), user)),
);
}
.collect();
all_user_entries
(!users.is_empty()).then(|| (status_update.hostname.clone(), users))
})
.collect()
}
async fn handle_ruptime_request(