1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-29 16:56:28 +00:00

Check out whether a conversations can be used for calls or not

This commit is contained in:
Pierre HUBERT 2021-02-08 18:14:15 +01:00
parent a2b2fc89cf
commit 01b83dfa8f
4 changed files with 43 additions and 3 deletions

View File

@ -5,6 +5,7 @@ use serde::{Serialize, Serializer};
use crate::api_data::legacy_api_bool::LegacyBool; use crate::api_data::legacy_api_bool::LegacyBool;
use crate::data::conversation::Conversation; use crate::data::conversation::Conversation;
use crate::helpers::calls_helper;
/// Special implementation of conversation name (false if none / the name otherwise) /// Special implementation of conversation name (false if none / the name otherwise)
struct ConvName(Option<String>); struct ConvName(Option<String>);
@ -48,9 +49,9 @@ impl ConversationAPI {
members: conv.members.iter().map(|x| x.id()).collect(), members: conv.members.iter().map(|x| x.id()).collect(),
canEveryoneAddMembers: conv.can_everyone_add_members, 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 // TODO : update when call system is implemented
can_have_call: false,
can_have_video_call: false,
has_call_now: false, has_call_now: false,
} }
} }

View File

@ -99,6 +99,15 @@ fn get_active_connection() -> Option<Addr<RtcRelayActor>> {
conn 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 /// Establish a new connection with the RTC relay
/// ///
/// Debug with /// Debug with

View File

@ -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
}

View File

@ -18,3 +18,4 @@ pub mod notifications_helper;
pub mod webapp_helper; pub mod webapp_helper;
pub mod requests_limit_helper; pub mod requests_limit_helper;
pub mod events_helper; pub mod events_helper;
pub mod calls_helper;