mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-02-10 00:43:09 +00:00
Use PayloadData for outbound datatype (#23)
* Add Introductions (#22) * Move to Payload data * compute delivery_address
This commit is contained in:
parent
d40e72be9b
commit
4b1069a4a8
@ -1,6 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crypto::PrekeyBundle;
|
||||
use std::{collections::HashMap, rc::Rc, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
conversation::{ConversationId, ConversationIdOwned, ConversationStore},
|
||||
@ -34,7 +32,7 @@ impl Context {
|
||||
&mut self,
|
||||
remote_bundle: &Introduction,
|
||||
content: String,
|
||||
) -> (ConversationIdOwned, Vec<proto::EncryptedPayload>) {
|
||||
) -> (ConversationIdOwned, Vec<PayloadData>) {
|
||||
let (convo, payloads) = self
|
||||
.inbox
|
||||
.invite_to_private_convo(remote_bundle, content)
|
||||
|
||||
@ -14,7 +14,13 @@ use crate::crypto::{Blake2b128, CopyBytes, Digest, PublicKey, StaticSecret};
|
||||
use crate::identity::Identity;
|
||||
use crate::inbox::handshake::InboxHandshake;
|
||||
use crate::proto::{self};
|
||||
use crate::types::ContentData;
|
||||
use crate::types::{ContentData, PayloadData};
|
||||
|
||||
/// Compute the deterministic Delivery_address for an installation
|
||||
fn delivery_address_for_installation(_: PublicKey) -> String {
|
||||
// TODO: Implement Delivery Address
|
||||
"delivery_address".into()
|
||||
}
|
||||
|
||||
pub struct Inbox {
|
||||
ident: Rc<Identity>,
|
||||
@ -69,7 +75,7 @@ impl Inbox {
|
||||
&self,
|
||||
remote_bundle: &Introduction,
|
||||
initial_message: String,
|
||||
) -> Result<(PrivateV1Convo, Vec<proto::EncryptedPayload>), ChatError> {
|
||||
) -> Result<(PrivateV1Convo, Vec<PayloadData>), ChatError> {
|
||||
let mut rng = OsRng;
|
||||
|
||||
// TODO: Include signature in introduction bundle. Manaully fill for now
|
||||
@ -112,7 +118,16 @@ impl Inbox {
|
||||
};
|
||||
}
|
||||
|
||||
Ok((convo, initial_payloads))
|
||||
// Convert Encrypted Payloads to PayloadData
|
||||
let payload_data = initial_payloads
|
||||
.iter()
|
||||
.map(|p| PayloadData {
|
||||
delivery_address: delivery_address_for_installation(remote_bundle.installation_key),
|
||||
data: p.encode_to_vec(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok((convo, payload_data))
|
||||
}
|
||||
|
||||
fn wrap_in_invite(payload: proto::EncryptedPayload) -> proto::InboxV1Frame {
|
||||
@ -238,12 +253,12 @@ mod tests {
|
||||
.invite_to_private_convo(&bundle.into(), "hello".into())
|
||||
.unwrap();
|
||||
|
||||
let encrypted_payload = payloads
|
||||
let payload = payloads
|
||||
.get(0)
|
||||
.expect("RemoteInbox::invite_to_private_convo did not generate any payloads");
|
||||
|
||||
let mut buf = Vec::new();
|
||||
encrypted_payload.encode(&mut buf).unwrap();
|
||||
payload.data.encode(&mut buf).unwrap();
|
||||
|
||||
// Test handle_frame with valid payload
|
||||
let result = raya_inbox.handle_frame(&buf);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user