anonymous calls

This commit is contained in:
Alex-Emmet 2026-01-20 21:45:05 +01:00
commit 8747657999
12 changed files with 712 additions and 39 deletions

View file

@ -1,15 +1,20 @@
use std::sync::Arc;
use json::JsonValue;
use std::{env, sync::Arc, time::Duration};
use tokio::sync::RwLock;
use uuid::Uuid;
use crate::calls::caller::Caller;
use crate::{
calls::{call_util, caller::Caller},
data::communication::{CommunicationType, CommunicationValue, DataTypes},
omega::omega_connection::get_omega_connection,
};
pub struct CallGroup {
pub call_id: Uuid,
pub members: RwLock<Vec<Arc<Caller>>>,
pub show: RwLock<bool>,
pub anonymous_joining: RwLock<bool>,
pub short_link: RwLock<Option<String>>,
}
impl CallGroup {
@ -19,6 +24,7 @@ impl CallGroup {
members: RwLock::new(vec![user]),
show: RwLock::new(true),
anonymous_joining: RwLock::new(false),
short_link: RwLock::new(None),
}
}
@ -31,8 +37,54 @@ impl CallGroup {
.cloned()
}
pub async fn is_anonymous(&self) -> bool {
*self.anonymous_joining.read().await
}
pub async fn set_anonymous_joining(&self, enable: bool) {
*self.anonymous_joining.write().await = enable;
if self.short_link.read().await.is_none() {
let long_link = format!(
"https://app.tensamin.net/call/anonymous?call_id={}&omikron_id={}",
self.call_id,
env::var("ID")
.unwrap_or("0".to_string())
.parse::<i64>()
.unwrap_or(0),
);
let response_cv = get_omega_connection()
.await_response(
&CommunicationValue::new(CommunicationType::shorten_link)
.add_data(DataTypes::link, JsonValue::from(long_link)),
Some(Duration::from_secs(20)),
)
.await;
if let Ok(response) = response_cv {
*self.short_link.write().await = Some(
response
.get_data(DataTypes::link)
.unwrap()
.as_str()
.unwrap()
.to_string(),
);
log::info!(
"Shortened link for call {} is {}",
self.call_id,
self.short_link.read().await.as_ref().unwrap()
);
}
}
}
pub async fn create_anonymous_token(&self, user_id: i64) -> Option<String> {
if self.is_anonymous().await {
if let Ok(token) = call_util::create_token(user_id, self.call_id, false) {
return Some(token);
}
}
None
}
pub async fn remove_caller(&self, user_id: i64) {
@ -41,4 +93,8 @@ impl CallGroup {
.await
.retain(|caller| caller.user_id != user_id);
}
pub async fn get_short_link(self: Arc<Self>) -> Option<String> {
self.short_link.read().await.clone()
}
}

View file

@ -50,6 +50,9 @@ pub async fn get_call_token(user_id: i64, call_id: Uuid) -> Option<String> {
}
return Some(member.create_token());
}
if cg.is_anonymous().await {
return cg.create_anonymous_token(user_id).await;
}
return None;
}

View file

@ -1,7 +1,4 @@
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::sync::RwLock;
use uuid::Uuid;