Completed Calling Structure (Needs testing)

This commit is contained in:
Alex Emmet 2025-11-25 08:10:14 +01:00
commit a5e63dcdfd

View file

@ -7,14 +7,12 @@ use async_tungstenite::WebSocketReceiver;
use async_tungstenite::WebSocketSender; use async_tungstenite::WebSocketSender;
use async_tungstenite::tungstenite::Message; use async_tungstenite::tungstenite::Message;
use json::JsonValue; use json::JsonValue;
use json::parse;
use std::{ use std::{
collections::HashMap, collections::HashMap,
sync::{Arc, Weak}, sync::{Arc, Weak},
}; };
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tokio_util::compat::Compat; use tokio_util::compat::Compat;
use tower::retry::backoff::InvalidBackoff;
use tungstenite::Utf8Bytes; use tungstenite::Utf8Bytes;
use uuid::Uuid; use uuid::Uuid;
@ -285,36 +283,37 @@ impl IotaConnection {
let mut interested_ids: Vec<Uuid> = Vec::new(); let mut interested_ids: Vec<Uuid> = Vec::new();
let calls: Vec<Arc<CallGroup>> = call_manager::get_call_groups(receiver_id).await; let calls: Vec<Arc<CallGroup>> = call_manager::get_call_groups(receiver_id).await;
let mut invites: HashMap<Uuid, Vec<Uuid>> = HashMap::new(); let mut invites: HashMap<Uuid, Vec<JsonValue>> = HashMap::new();
for call in calls { for call in calls {
for inviter in call.members.read().await.iter() { for inviter in call.members.read().await.iter() {
let inviter_id = inviter.user_id; let inviter_id = inviter.user_id;
if let Some(call_ids) = invites.get_mut(&inviter_id) { if let Some(call_ids) = invites.get_mut(&inviter_id) {
call_ids.push(call.call_id); call_ids.push(JsonValue::String(call.call_id.to_string()));
} else { } else {
invites.insert(inviter_id, vec![call.call_id]); invites.insert(
inviter_id,
vec![JsonValue::String(call.call_id.to_string())],
);
} }
} }
} }
// Process contacts and add call information // Process contacts and add call information
// Enriched Contacts data:
// [{"user_id": "uuid", "calls": ["call_id"]}, {"user_id": "uuid"}]
let mut enriched_contacts = JsonValue::new_array(); let mut enriched_contacts = JsonValue::new_array();
// Contacts data:
// [{"user_id": "uuid"}, {"user_id": "uuid"}]
if let Some(contacts_data) = cv.get_data(DataTypes::user_ids) { if let Some(contacts_data) = cv.get_data(DataTypes::user_ids) {
if let JsonValue::Array(user_ids) = contacts_data { if let JsonValue::Array(user_ids) = contacts_data {
for user_id in user_ids { for user_json in user_ids {
if let JsonValue::String(user_id_str) = user_id { let user_id_str = user_json["user_id"].as_str().unwrap_or("");
if let Ok(user_id) = Uuid::parse_str(user_id_str) { if let Ok(user_id) = Uuid::parse_str(&user_id_str) {
interested_ids.push(user_id); interested_ids.push(user_id);
let mut enriched_contact = JsonValue::new_object(); let mut enriched_contact = JsonValue::new_object();
let _ = enriched_contact.insert("user_id", user_id.to_string()); let _ = enriched_contact.insert("user_id", user_id.to_string());
let _ = enriched_contact.insert("calls", JsonValue::new_array()); let _ = enriched_contact.insert(
let _ = enriched_contacts.push(enriched_contact); "calls",
} JsonValue::Array(invites.get(&user_id).unwrap_or(&vec![]).clone()),
);
let _ = enriched_contacts.push(enriched_contact);
} }
} }
} else { } else {