1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Can join call

This commit is contained in:
2021-02-10 17:16:52 +01:00
parent 8cfd10c21c
commit 2e5cdca850
10 changed files with 140 additions and 38 deletions

View File

@ -36,4 +36,5 @@ pub mod general_settings;
pub mod lang_settings;
pub mod security_settings;
pub mod new_custom_emoji;
pub mod user_ws_message;
pub mod user_ws_message;
pub mod user_ws_connection;

View File

@ -0,0 +1,36 @@
use std::collections::HashSet;
use crate::controllers::user_ws_controller::WsSession;
use crate::data::conversation::ConvID;
use crate::data::post::PostID;
use crate::data::user::UserID;
#[derive(Clone, Debug)]
pub struct ActiveCall {
pub conv_id: ConvID,
pub ready: bool,
}
/// This structure contains information about an active connection
#[derive(Clone, Debug)]
pub struct UserWsConnection {
pub user_id: UserID,
pub client_id: u32,
pub remote_ip: String,
pub session: actix::Addr<WsSession>,
pub incognito: bool,
pub conversations: HashSet<ConvID>,
pub posts: HashSet<PostID>,
pub active_call: Option<ActiveCall>,
}
impl UserWsConnection {
/// Check out whether a connection is being used to make a call in a specific conversation or not
pub fn is_having_call_with_conversation(&self, conv_id: &ConvID) -> bool {
if let Some(call_info) = &self.active_call {
return &call_info.conv_id == conv_id;
}
false
}
}

View File

@ -6,10 +6,10 @@ use serde::Serialize;
use crate::api_data::http_error::HttpError;
use crate::controllers::routes::RequestResult;
use crate::controllers::user_ws_controller::WsConnection;
use crate::data::base_request_handler::{BaseRequestHandler, RequestValue};
use crate::data::error::ResultBoxError;
use crate::data::user::UserID;
use crate::data::user_ws_connection::UserWsConnection;
pub enum UserWsResponseType {
SUCCESS,
@ -22,13 +22,13 @@ pub struct UserWsResponse {
}
pub struct UserWsRequestHandler {
connection: WsConnection,
connection: UserWsConnection,
args: HashMap<String, RequestValue>,
response: Option<UserWsResponse>,
}
impl UserWsRequestHandler {
pub fn new(connection: &WsConnection, args: HashMap<String, String>) -> UserWsRequestHandler {
pub fn new(connection: &UserWsConnection, args: HashMap<String, String>) -> UserWsRequestHandler {
UserWsRequestHandler {
connection: connection.clone(),
args: args.into_iter().map(|f| (f.0, RequestValue::String(f.1))).collect(),
@ -51,7 +51,7 @@ impl UserWsRequestHandler {
}
/// Update information about the WebSocket connection
pub fn update_conn<H>(&mut self, do_updates: H) -> ResultBoxError where H: FnOnce(&mut WsConnection) {
pub fn update_conn<H>(&mut self, do_updates: H) -> ResultBoxError where H: FnOnce(&mut UserWsConnection) {
self.connection = self.connection.clone().replace(do_updates);
Ok(())