1
0
mirror of https://github.com/pcvolkmer/arsnova-client.git synced 2025-04-19 19:16:51 +00:00

feat: add method to request room statistics

This commit is contained in:
Paul-Christian Volkmer 2024-03-31 15:18:13 +02:00
parent 6ea04c7860
commit 9b50fed24b
2 changed files with 50 additions and 1 deletions

View File

@ -78,7 +78,11 @@ async fn main() -> Result<(), ()> {
let l1 = client.on_feedback_changed(&cli.room, FeedbackHandler::SenderReceiver(in_tx, out_rx)); 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 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); let l2 = create_ui(&mut terminal, &title, in_rx);

View File

@ -182,6 +182,21 @@ pub struct RoomInfo {
pub description: String, 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)] #[derive(Debug, Clone)]
pub struct Feedback { pub struct Feedback {
pub very_good: u16, pub very_good: u16,
@ -427,6 +442,36 @@ impl Client<LoggedIn> {
} }
} }
/// 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<RoomStats, ClientError> {
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::<Vec<SummaryResponse>>()
.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 /// Register feedback channel receiver and send incoming feedback to service
/// ///
/// This method fails on connection or response errors and if /// This method fails on connection or response errors and if