From 1c984f442cb52dcec50d48a3013b9a83d03441dd Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Sat, 20 Jun 2026 09:44:27 -0700 Subject: [PATCH] Add client path for DirectConvo (#140) * Add PrivateV2Convo * Rename to DirectV1 * Update DirectV1 to support multiple members * Add client path for DirectConvo --- core/conversations/src/core.rs | 7 +++---- crates/client/src/client.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/conversations/src/core.rs b/core/conversations/src/core.rs index d88a4a8..37fbe71 100644 --- a/core/conversations/src/core.rs +++ b/core/conversations/src/core.rs @@ -185,12 +185,11 @@ impl<'a, S: ExternalServices + 'static> Core { self.services.identity.public_key() } - pub fn create_private_convo( + pub fn create_direct_convo( &mut self, - remote_bundle: &Introduction, - content: &[u8], + members: &[IdentIdRef], ) -> Result { - self.create_private_convo_v1(remote_bundle, content) + self.create_direct_convo_v1(members) } pub fn create_private_convo_v1( diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 170030a..4337bf9 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -4,8 +4,8 @@ use std::thread::{self, JoinHandle}; use components::{EphemeralRegistry, ThreadedWakeupService, WakeupEvent}; use crossbeam_channel::{Receiver, Sender, select}; use libchat::{ - ChatError, ChatStorage, ConversationId, ConvoOutcome, Core, DeliveryService, InboxOutcome, - Introduction, PayloadOutcome, RegistrationService, StorageConfig, + ChatError, ChatStorage, ConversationId, ConvoOutcome, Core, DeliveryService, IdentId, + IdentIdRef, InboxOutcome, Introduction, PayloadOutcome, RegistrationService, StorageConfig, }; use logos_account::TestLogosAccount; use parking_lot::Mutex; @@ -14,6 +14,8 @@ use crate::errors::ClientError; use crate::event::Event; type ClientCore = Core<(TestLogosAccount, T, R, ThreadedWakeupService, ChatStorage)>; +type AccountAddressRef<'a> = &'a str; +type LocalSignerId = IdentId; /// The transport as the client sees it: a [`DeliveryService`] for outbound /// publishing plus the inbound payload stream the worker drains. One object owns @@ -158,8 +160,24 @@ where self.core.lock().create_intro_bundle().map_err(Into::into) } + // Creates a conversation between two Accounts. + pub fn create_direct_conversation( + &mut self, + account: AccountAddressRef, + ) -> Result { + let signers = self.signers_from_account(account)?; + let signer_refs: Vec = signers.iter().collect(); + + self.core + .lock() + .create_direct_convo(&signer_refs) + .map_err(Into::into) + } + /// Parse intro bundle bytes and initiate a private conversation. Outbound /// envelopes are published by the core. Returns this side's conversation ID. + /// + /// This function will be deprecated in the future. Use `create_direct_conversation` pub fn create_conversation( &mut self, intro_bundle: &[u8], @@ -185,6 +203,15 @@ where .send_content(convo_id, content) .map_err(Into::into) } + + // Get signers for a given AccountAddress. + fn signers_from_account( + &self, + account: AccountAddressRef, + ) -> Result, ClientError> { + // Assume Account = LocalSigner until Account is ready + Ok(vec![IdentId::new(account.to_string())]) + } } impl Drop for ChatClient {