diff --git a/examples/arsnova-client-tui.rs b/examples/arsnova-client-tui.rs index 432c2a5..b160396 100644 --- a/examples/arsnova-client-tui.rs +++ b/examples/arsnova-client-tui.rs @@ -78,7 +78,11 @@ async fn main() -> Result<(), ()> { let l1 = client.on_feedback_changed(&cli.room, FeedbackHandler::SenderReceiver(in_tx, out_rx)); let room_info = client.get_room_info(&cli.room).await.map_err(|_| ())?; - let title = format!("Live Feedback: {} ({})", room_info.name, room_info.short_id); + let room_stats = client.get_room_stats(&cli.room).await.map_err(|_| ())?; + let title = format!( + "Live Feedback: {} ({}) - 👥: {}", + room_info.name, room_info.short_id, room_stats.room_user_count + ); let l2 = create_ui(&mut terminal, &title, in_rx); diff --git a/src/client.rs b/src/client.rs index 301abdd..b3c6ac8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -182,6 +182,21 @@ pub struct RoomInfo { pub description: String, } +#[derive(Deserialize, Clone, Debug)] +pub struct SummaryResponse { + pub stats: RoomStats, +} + +#[derive(Deserialize, Clone, Debug)] +pub struct RoomStats { + #[serde(rename = "contentCount")] + pub content_count: usize, + #[serde(rename = "ackCommentCount")] + pub ack_comment_count: usize, + #[serde(rename = "roomUserCount")] + pub room_user_count: usize, +} + #[derive(Debug, Clone)] pub struct Feedback { pub very_good: u16, @@ -427,6 +442,36 @@ impl Client { } } + /// Requests `RoomStats` for given 8-digit room ID + /// + /// This method fails on connection or response errors and if + /// no room is available with given room ID. + pub async fn get_room_stats(&self, short_id: &str) -> Result { + let room_info = self.get_room_info(short_id).await?; + + match self + .http_client + .get(format!( + "{}/_view/room/summary?ids={}", + self.api_url, room_info.id + )) + .bearer_auth(self.token.as_ref().unwrap_or(&"".to_string()).to_string()) + .send() + .await + { + Ok(res) => match res.status() { + StatusCode::OK => Ok(res + .json::>() + .await + .map_err(|err| ParserError(err.to_string())) + .map(|summary_response| summary_response.first().unwrap().stats.clone()))?, + StatusCode::NOT_FOUND => Err(RoomNotFoundError(short_id.into())), + _ => Err(ConnectionError), + }, + Err(_) => Err(ConnectionError), + } + } + /// Register feedback channel receiver and send incoming feedback to service /// /// This method fails on connection or response errors and if