diff --git a/src/api_data/conversation_api.rs b/src/api_data/conversation_api.rs index 37afce5..2705d07 100644 --- a/src/api_data/conversation_api.rs +++ b/src/api_data/conversation_api.rs @@ -5,6 +5,7 @@ use serde::{Serialize, Serializer}; use crate::api_data::legacy_api_bool::LegacyBool; use crate::data::conversation::Conversation; +use crate::helpers::calls_helper; /// Special implementation of conversation name (false if none / the name otherwise) struct ConvName(Option); @@ -48,9 +49,9 @@ impl ConversationAPI { members: conv.members.iter().map(|x| x.id()).collect(), canEveryoneAddMembers: conv.can_everyone_add_members, + 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 - can_have_call: false, - can_have_video_call: false, has_call_now: false, } } diff --git a/src/controllers/rtc_relay_controller.rs b/src/controllers/rtc_relay_controller.rs index 39e0ed8..72c0fbd 100644 --- a/src/controllers/rtc_relay_controller.rs +++ b/src/controllers/rtc_relay_controller.rs @@ -99,6 +99,15 @@ fn get_active_connection() -> Option> { conn } +/// Check out whether a relay is currently connected to the API or not +pub fn is_connected() -> bool { + if let Some(conn) = get_active_connection() { + return conn.connected(); + } + + false +} + /// Establish a new connection with the RTC relay /// /// Debug with diff --git a/src/helpers/calls_helper.rs b/src/helpers/calls_helper.rs new file mode 100644 index 0000000..7e5eedd --- /dev/null +++ b/src/helpers/calls_helper.rs @@ -0,0 +1,29 @@ +//! # Calls helper +//! +//! @author Pierre Hubert + +use crate::controllers::rtc_relay_controller; +use crate::data::config::conf; +use crate::data::conversation::Conversation; + +/// Check out whether a conversation can make a call or not +pub fn can_have_call(conv: &Conversation) -> bool { + if let Some(conf) = &conf().rtc_relay { + return conv.members.len() > 1 + && conf.max_users_per_calls >= conv.members.len() as u64 + && rtc_relay_controller::is_connected(); + } + + false +} + +/// Check out whether a conversation is allowed to make video calls or not +pub fn can_have_video_calls(conv: &Conversation) -> bool { + if let Some(conf) = &conf().rtc_relay { + return can_have_call(conv) + && conf.allow_video + && conf.max_users_per_video_calls >= conv.members.len() as u64; + } + + false +} \ No newline at end of file diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs index f78db4c..683f516 100644 --- a/src/helpers/mod.rs +++ b/src/helpers/mod.rs @@ -17,4 +17,5 @@ pub mod comments_helper; pub mod notifications_helper; pub mod webapp_helper; pub mod requests_limit_helper; -pub mod events_helper; \ No newline at end of file +pub mod events_helper; +pub mod calls_helper; \ No newline at end of file