mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Can get the list of members of a call
This commit is contained in:
parent
2e5cdca850
commit
3c696bde5f
23
src/api_data/call_member_info.rs
Normal file
23
src/api_data/call_member_info.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//! # Call member information
|
||||||
|
//!
|
||||||
|
//! @author Pierre Hubert
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::data::user::UserID;
|
||||||
|
use crate::data::user_ws_connection::ActiveCall;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub struct CallMemberInfo {
|
||||||
|
userID: u64,
|
||||||
|
ready: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CallMemberInfo {
|
||||||
|
pub fn new(user_id: &UserID, call: &ActiveCall) -> Self {
|
||||||
|
Self {
|
||||||
|
userID: user_id.id(),
|
||||||
|
ready: call.ready,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -58,4 +58,5 @@ pub mod account_image_settings_api;
|
|||||||
pub mod res_create_custom_emoji;
|
pub mod res_create_custom_emoji;
|
||||||
pub mod res_get_ws_token;
|
pub mod res_get_ws_token;
|
||||||
pub mod user_calls_config;
|
pub mod user_calls_config;
|
||||||
pub mod joined_call_message;
|
pub mod joined_call_message;
|
||||||
|
pub mod call_member_info;
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::api_data::call_member_info::CallMemberInfo;
|
||||||
use crate::api_data::joined_call_message::JoinedCallMessage;
|
use crate::api_data::joined_call_message::JoinedCallMessage;
|
||||||
use crate::api_data::user_calls_config::UserCallsConfig;
|
use crate::api_data::user_calls_config::UserCallsConfig;
|
||||||
use crate::controllers::routes::RequestResult;
|
use crate::controllers::routes::RequestResult;
|
||||||
@ -61,6 +62,23 @@ pub fn join_call(r: &mut UserWsRequestHandler) -> RequestResult {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the list of members of a call
|
||||||
|
pub fn get_members_list(r: &mut UserWsRequestHandler) -> RequestResult {
|
||||||
|
let conv_id = r.post_call_id("callID")?;
|
||||||
|
let mut list = vec![];
|
||||||
|
|
||||||
|
user_ws_controller::foreach_connection(|conn| {
|
||||||
|
if conn.is_having_call_with_conversation(&conv_id) {
|
||||||
|
list.push(CallMemberInfo::new(&conn.user_id, &conn.active_call.as_ref().unwrap()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
|
||||||
|
r.set_response(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Events handler
|
/// Events handler
|
||||||
pub fn handle_event(e: &events_helper::Event) -> Res {
|
pub fn handle_event(e: &events_helper::Event) -> Res {
|
||||||
match e {
|
match e {
|
||||||
|
@ -560,6 +560,16 @@ pub fn disconnect_user_from_all_sockets(user_id: &UserID) -> Res {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Do something with all active connections
|
||||||
|
pub fn foreach_connection<F>(mut f: F) -> Res
|
||||||
|
where F: FnMut(&UserWsConnection) -> Res {
|
||||||
|
for conn in get_ws_connections_list().lock().unwrap().iter() {
|
||||||
|
f(conn)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Events handler
|
/// Events handler
|
||||||
pub fn handle_event(e: &events_helper::Event) -> Res {
|
pub fn handle_event(e: &events_helper::Event) -> Res {
|
||||||
match e {
|
match e {
|
||||||
|
@ -40,6 +40,7 @@ pub fn get_user_ws_routes() -> Vec<UserWsRoute> {
|
|||||||
// Calls controller
|
// Calls controller
|
||||||
UserWsRoute::new("calls/config", calls_controller::get_config),
|
UserWsRoute::new("calls/config", calls_controller::get_config),
|
||||||
UserWsRoute::new("calls/join", calls_controller::join_call),
|
UserWsRoute::new("calls/join", calls_controller::join_call),
|
||||||
|
UserWsRoute::new("calls/members", calls_controller::get_members_list),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ use serde::Serialize;
|
|||||||
use crate::api_data::http_error::HttpError;
|
use crate::api_data::http_error::HttpError;
|
||||||
use crate::controllers::routes::RequestResult;
|
use crate::controllers::routes::RequestResult;
|
||||||
use crate::data::base_request_handler::{BaseRequestHandler, RequestValue};
|
use crate::data::base_request_handler::{BaseRequestHandler, RequestValue};
|
||||||
use crate::data::error::ResultBoxError;
|
use crate::data::conversation::ConvID;
|
||||||
|
use crate::data::error::{Res, ResultBoxError};
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::data::user_ws_connection::UserWsConnection;
|
use crate::data::user_ws_connection::UserWsConnection;
|
||||||
|
|
||||||
@ -56,6 +57,17 @@ impl UserWsRequestHandler {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the ID of a call included in a WebSocket request
|
||||||
|
pub fn post_call_id(&mut self, name: &str) -> Res<ConvID> {
|
||||||
|
let conv_id = self.post_u64(name)?;
|
||||||
|
|
||||||
|
if !self.connection.is_having_call_with_conversation(&conv_id) {
|
||||||
|
self.forbidden("You do not belong to this call!".to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(conv_id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BaseRequestHandler for UserWsRequestHandler {
|
impl BaseRequestHandler for UserWsRequestHandler {
|
||||||
|
Loading…
Reference in New Issue
Block a user