(feat): call crypto migration
This commit is contained in:
parent
1c89e71606
commit
9323daa34a
6 changed files with 329 additions and 49 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use crate::anonymous_clients::anonymous_manager;
|
||||
use crate::calls::{call_manager, call_util};
|
||||
use crate::calls::{call_group::call_invite_secret_from_cv, call_manager, call_util};
|
||||
use crate::omega::omega_connection::get_omega_connection;
|
||||
use crate::rho::connection::GeneralConnection;
|
||||
use crate::rho::{rho_connection::RhoConnection, rho_manager};
|
||||
|
|
@ -354,18 +354,29 @@ impl ClientConnection {
|
|||
}
|
||||
};
|
||||
|
||||
let secret = cv
|
||||
.get_data(DataType::CallSecret)
|
||||
.as_str()
|
||||
.map(|s| s.to_string());
|
||||
let secret = match call_invite_secret_from_cv(&cv) {
|
||||
Some(secret) => secret,
|
||||
None => {
|
||||
self.send_error_response(cv.get_id(), CommunicationType::BadRequest)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let invited =
|
||||
call_manager::add_invite(call_id, self.user_id, receiver_id as u64, secret).await;
|
||||
call_manager::add_invite(call_id, self.user_id, receiver_id as u64, secret.clone())
|
||||
.await;
|
||||
if !invited {
|
||||
self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidCallId)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
if !call_manager::should_forward_invite(self.user_id, receiver_id as u64) {
|
||||
let response = CommunicationValue::new(CommunicationType::Success).with_id(cv.get_id());
|
||||
self.send_message(&response).await;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find target RhoConnection
|
||||
let target_rho = match rho_manager::get_rho_con_for_user(receiver_id as i64).await {
|
||||
Some(rho) => rho,
|
||||
|
|
@ -410,10 +421,7 @@ impl ClientConnection {
|
|||
let forward = CommunicationValue::new(CommunicationType::CallInvite)
|
||||
.with_receiver(receiver_id as u64)
|
||||
.with_sender(sender_id as u64)
|
||||
.add_typed_default(
|
||||
DataType::CallSecret,
|
||||
cv.get_data(DataType::CallSecret).clone(),
|
||||
)
|
||||
.add_typed_default(DataType::CallSecret, secret.to_data_value())
|
||||
.add_typed_default(DataType::CallId, DataValue::Str(call_id.to_string()))
|
||||
.add_typed_default(
|
||||
DataType::ReceiverId,
|
||||
|
|
|
|||
|
|
@ -207,7 +207,16 @@ impl GeneralConnection {
|
|||
);
|
||||
}
|
||||
|
||||
// Add to global calls (without contact-specific secret)
|
||||
if let Some(secret) =
|
||||
call.get_secret_for_user(user_id as u64).await
|
||||
{
|
||||
base_call_map.insert(
|
||||
DataType::CallSecret.to_id(&tm),
|
||||
secret.to_data_value(),
|
||||
);
|
||||
}
|
||||
|
||||
// Add to global calls with only this user's recipient-specific secret.
|
||||
global_calls.push(DataValue::container_from_map(
|
||||
&base_call_map,
|
||||
));
|
||||
|
|
@ -218,19 +227,7 @@ impl GeneralConnection {
|
|||
continue;
|
||||
}
|
||||
|
||||
let mut contact_call_map = base_call_map.clone();
|
||||
|
||||
if let Some(secret) = call
|
||||
.secrets
|
||||
.read()
|
||||
.await
|
||||
.get(&(member_id, user_id as u64))
|
||||
{
|
||||
contact_call_map.insert(
|
||||
DataType::CallSecret.to_id(&tm),
|
||||
DataValue::Str(secret.clone()),
|
||||
);
|
||||
}
|
||||
let contact_call_map = base_call_map.clone();
|
||||
|
||||
invites
|
||||
.entry(member_id as i64)
|
||||
|
|
|
|||
|
|
@ -433,7 +433,11 @@ impl IotaConnection {
|
|||
base_call_map.insert(DataType::HasAdmin.to_id(&tm), DataValue::Bool(true));
|
||||
}
|
||||
|
||||
// Add to global calls (without contact-specific secret)
|
||||
if let Some(secret) = call.get_secret_for_user(user_id).await {
|
||||
base_call_map.insert(DataType::CallSecret.to_id(&tm), secret.to_data_value());
|
||||
}
|
||||
|
||||
// Add to global calls with only this user's recipient-specific secret.
|
||||
global_calls.push(DataValue::container_from_map(&base_call_map));
|
||||
|
||||
// Attach this call to EVERY member of the call (other than ourselves)
|
||||
|
|
@ -443,15 +447,7 @@ impl IotaConnection {
|
|||
continue;
|
||||
}
|
||||
|
||||
let mut contact_call_map = base_call_map.clone();
|
||||
|
||||
// Add secret if it exists for this pairing
|
||||
if let Some(secret) = call.secrets.read().await.get(&(member_id, user_id)) {
|
||||
contact_call_map.insert(
|
||||
DataType::CallSecret.to_id(&tm),
|
||||
DataValue::Str(secret.clone()),
|
||||
);
|
||||
}
|
||||
let contact_call_map = base_call_map.clone();
|
||||
|
||||
invites
|
||||
.entry(member_id as i64)
|
||||
|
|
|
|||
Loading…
Reference in a new issue