From 54eb8edee4959883cd186e302c04a4f4402c8c72 Mon Sep 17 00:00:00 2001 From: kaichaosun Date: Thu, 9 Apr 2026 11:58:32 +0800 Subject: [PATCH] chore: params postion --- core/conversations/src/context.rs | 24 +++++++++---------- .../src/conversation/privatev1.rs | 10 ++++---- core/conversations/src/inbox/handler.rs | 10 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/core/conversations/src/context.rs b/core/conversations/src/context.rs index f1aa1a6..761101c 100644 --- a/core/conversations/src/context.rs +++ b/core/conversations/src/context.rs @@ -17,18 +17,18 @@ pub use crate::inbox::Introduction; // This is the main entry point to the conversations api. // Ctx manages lifetimes of objects to process and generate payloads. -pub struct Context { +pub struct Context { _identity: Rc, - inbox: Inbox, - store: Rc>, + inbox: Inbox, + store: Rc>, } -impl Context { +impl Context { /// Opens or creates a Context with the given storage configuration. /// /// If an identity exists in storage, it will be restored. /// Otherwise, a new identity will be created with the given name and saved. - pub fn new_from_store(name: impl Into, store: T) -> Result { + pub fn new_from_store(name: impl Into, store: S) -> Result { let name = name.into(); let store = Rc::new(RefCell::new(store)); @@ -42,7 +42,7 @@ impl Context { }; let identity = Rc::new(identity); - let inbox = Inbox::new(Rc::clone(&identity), Rc::clone(&store)); + let inbox = Inbox::new(Rc::clone(&store), Rc::clone(&identity)); Ok(Self { _identity: identity, @@ -54,7 +54,7 @@ impl Context { /// Creates a new in-memory Context (for testing). /// /// Uses in-memory SQLite database. Each call creates a new isolated database. - pub fn new_with_name(name: impl Into, chat_store: T) -> Self { + pub fn new_with_name(name: impl Into, chat_store: S) -> Self { let name = name.into(); let identity = Identity::new(&name); let chat_store = Rc::new(RefCell::new(chat_store)); @@ -64,7 +64,7 @@ impl Context { .expect("in-memory storage should not fail"); let identity = Rc::new(identity); - let inbox = Inbox::new(Rc::clone(&identity), Rc::clone(&chat_store)); + let inbox = Inbox::new(Rc::clone(&chat_store), Rc::clone(&identity)); Self { _identity: identity, @@ -87,7 +87,7 @@ impl Context { .invite_to_private_convo(remote_bundle, content, Rc::clone(&self.store)) .unwrap_or_else(|_| todo!("Log/Surface Error")); - let remote_id = Inbox::::inbox_identifier_for_key(*remote_bundle.installation_key()); + let remote_id = Inbox::::inbox_identifier_for_key(*remote_bundle.installation_key()); let payload_bytes = payloads .into_iter() .map(|p| p.into_envelope(remote_id.clone())) @@ -144,7 +144,7 @@ impl Context { &mut self, enc_payload: EncryptedPayload, ) -> Result, ChatError> { - let public_key_hex = Inbox::::extract_ephemeral_key_hex(&enc_payload)?; + let public_key_hex = Inbox::::extract_ephemeral_key_hex(&enc_payload)?; let (convo, content) = self.inbox .handle_frame(enc_payload, &public_key_hex, Rc::clone(&self.store))?; @@ -181,7 +181,7 @@ impl Context { } /// Loads a conversation from DB by constructing it from metadata. - fn load_convo(&self, convo_id: ConversationId) -> Result, ChatError> { + fn load_convo(&self, convo_id: ConversationId) -> Result, ChatError> { let record = self .store .borrow() @@ -191,9 +191,9 @@ impl Context { match record.kind { ConversationKind::PrivateV1 => { let private_convo = PrivateV1Convo::new( + self.store.clone(), record.local_convo_id, record.remote_convo_id, - self.store.clone(), )?; Ok(Conversation::Private(private_convo)) } diff --git a/core/conversations/src/conversation/privatev1.rs b/core/conversations/src/conversation/privatev1.rs index 83ac3a5..b7736d8 100644 --- a/core/conversations/src/conversation/privatev1.rs +++ b/core/conversations/src/conversation/privatev1.rs @@ -66,9 +66,9 @@ pub struct PrivateV1Convo { impl PrivateV1Convo { /// Reconstructs a PrivateV1Convo from persisted metadata and ratchet state. pub fn new( + store: Rc>, local_convo_id: String, remote_convo_id: String, - store: Rc>, ) -> Result { let dr_record = store.borrow().load_ratchet_state(&local_convo_id)?; let skipped_keys = store.borrow().load_skipped_keys(&local_convo_id)?; @@ -83,9 +83,9 @@ impl PrivateV1Convo { } pub fn new_initiator( + store: Rc>, seed_key: SymmetricKey32, remote: PublicKey, - store: Rc>, ) -> Self { let base_convo_id = BaseConvoId::new(&seed_key); let local_convo_id = base_convo_id.id_for_participant(Role::Initiator); @@ -106,9 +106,9 @@ impl PrivateV1Convo { } pub fn new_responder( + store: Rc>, seed_key: SymmetricKey32, dh_self: &PrivateKey, - store: Rc>, ) -> Self { let base_convo_id = BaseConvoId::new(&seed_key); let local_convo_id = base_convo_id.id_for_participant(Role::Responder); @@ -305,8 +305,8 @@ mod tests { let seed_key_saro = SymmetricKey32::from(seed_key); let seed_key_raya = SymmetricKey32::from(seed_key); let send_content_bytes = vec![0, 2, 4, 6, 8]; - let mut sr_convo = PrivateV1Convo::new_initiator(seed_key_saro, pub_raya, saro_storage); - let mut rs_convo = PrivateV1Convo::new_responder(seed_key_raya, &raya, raya_storage); + let mut sr_convo = PrivateV1Convo::new_initiator(saro_storage, seed_key_saro, pub_raya); + let mut rs_convo = PrivateV1Convo::new_responder(raya_storage, seed_key_raya, &raya); let send_frame = PrivateV1Frame { conversation_id: "_".into(), diff --git a/core/conversations/src/inbox/handler.rs b/core/conversations/src/inbox/handler.rs index 8e8df24..9b90ac3 100644 --- a/core/conversations/src/inbox/handler.rs +++ b/core/conversations/src/inbox/handler.rs @@ -39,7 +39,7 @@ impl std::fmt::Debug for Inbox { } impl Inbox { - pub fn new(ident: Rc, store: Rc>) -> Self { + pub fn new(store: Rc>, ident: Rc) -> Self { let local_convo_id = Self::inbox_identifier_for_key(ident.public_key()); Self { ident, @@ -83,7 +83,7 @@ impl Inbox { InboxHandshake::perform_as_initiator(self.ident.secret(), &pkb, &mut rng); let mut convo = - PrivateV1Convo::new_initiator(seed_key, *remote_bundle.ephemeral_key(), private_store); + PrivateV1Convo::new_initiator(private_store, seed_key, *remote_bundle.ephemeral_key()); let mut payloads = convo.send_message(initial_message)?; @@ -146,7 +146,7 @@ impl Inbox { match frame.frame_type.unwrap() { proto::inbox_v1_frame::FrameType::InvitePrivateV1(_invite_private_v1) => { let mut convo = - PrivateV1Convo::new_responder(seed_key, &ephemeral_key, private_store); + PrivateV1Convo::new_responder(private_store, seed_key, &ephemeral_key); let Some(enc_payload) = _invite_private_v1.initial_message else { return Err(ChatError::Protocol("missing initial encpayload".into())); @@ -272,10 +272,10 @@ mod tests { )); let saro_ident = Identity::new("saro"); - let saro_inbox = Inbox::new(saro_ident.into(), Rc::clone(&saro_storage)); + let saro_inbox = Inbox::new(Rc::clone(&saro_storage), saro_ident.into()); let raya_ident = Identity::new("raya"); - let raya_inbox = Inbox::new(raya_ident.into(), Rc::clone(&raya_storage)); + let raya_inbox = Inbox::new(Rc::clone(&raya_storage), raya_ident.into()); let bundle = raya_inbox.create_intro_bundle().unwrap();