diff --git a/src/api_data/conversation_api.rs b/src/api_data/conversation_api.rs index 2705d07..4ac5d7c 100644 --- a/src/api_data/conversation_api.rs +++ b/src/api_data/conversation_api.rs @@ -4,6 +4,7 @@ use serde::{Serialize, Serializer}; use crate::api_data::legacy_api_bool::LegacyBool; +use crate::controllers::calls_controller; use crate::data::conversation::Conversation; use crate::helpers::calls_helper; @@ -51,8 +52,7 @@ impl ConversationAPI { can_have_call: calls_helper::can_have_call(conv), can_have_video_call: calls_helper::can_have_video_calls(conv), - // TODO : update when call system is implemented - has_call_now: false, + has_call_now: calls_controller::is_conversation_having_call(&conv.id), } } diff --git a/src/controllers/calls_controller.rs b/src/controllers/calls_controller.rs index 0f4a338..99d3dd5 100644 --- a/src/controllers/calls_controller.rs +++ b/src/controllers/calls_controller.rs @@ -43,6 +43,25 @@ pub fn get_config(r: &mut UserWsRequestHandler) -> RequestResult { r.internal_error(ExecError::boxed_new("Missing calls configuration!")) } +/// Check out whether a conversation is having a call or not +pub fn is_conversation_having_call(conv_id: &ConvID) -> bool { + let mut found = false; + + let res = user_ws_controller::foreach_connection(|f| { + if found || f.is_having_call_with_conversation(conv_id) { + found = true; + } + + Ok(()) + }); + + if let Err(e) = res { + eprintln!("Failed to check if a conversation is having call! Conversation: {} / Error: {:#?}", conv_id, e); + } + + found +} + /// Join a call pub fn join_call(r: &mut UserWsRequestHandler) -> RequestResult { let conv_id = r.post_conv_id("convID")?;