mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-06-30 21:20:09 +00:00
Add client path for DirectConvo
This commit is contained in:
parent
d30a4f2ed4
commit
a27dfb1a7f
@ -21,10 +21,6 @@ impl DirectV1Convo {
|
|||||||
// have multiple Installations.
|
// have multiple Installations.
|
||||||
pub fn new<S: ExternalServices>(
|
pub fn new<S: ExternalServices>(
|
||||||
cx: &mut ServiceContext<S>,
|
cx: &mut ServiceContext<S>,
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
// Constructor must accept multiple
|
|
||||||
>>>>>>> 206314b (Update DirectV1 to support multiple members)
|
|
||||||
members: &[IdentIdRef],
|
members: &[IdentIdRef],
|
||||||
) -> Result<Self, ChatError> {
|
) -> Result<Self, ChatError> {
|
||||||
let mut inner_group = DelegateGroup::new(cx)?;
|
let mut inner_group = DelegateGroup::new(cx)?;
|
||||||
|
|||||||
@ -185,12 +185,11 @@ impl<'a, S: ExternalServices + 'static> Core<S> {
|
|||||||
self.services.identity.public_key()
|
self.services.identity.public_key()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_private_convo(
|
pub fn create_direct_convo(
|
||||||
&mut self,
|
&mut self,
|
||||||
remote_bundle: &Introduction,
|
members: &[IdentIdRef],
|
||||||
content: &[u8],
|
|
||||||
) -> Result<ConversationId, ChatError> {
|
) -> Result<ConversationId, ChatError> {
|
||||||
self.create_private_convo_v1(remote_bundle, content)
|
self.create_direct_convo_v1(members)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_private_convo_v1(
|
pub fn create_private_convo_v1(
|
||||||
|
|||||||
@ -4,8 +4,8 @@ use std::thread::{self, JoinHandle};
|
|||||||
use components::{EphemeralRegistry, ThreadedWakeupService, WakeupEvent};
|
use components::{EphemeralRegistry, ThreadedWakeupService, WakeupEvent};
|
||||||
use crossbeam_channel::{Receiver, Sender, select};
|
use crossbeam_channel::{Receiver, Sender, select};
|
||||||
use libchat::{
|
use libchat::{
|
||||||
ChatError, ChatStorage, ConversationId, ConvoOutcome, Core, DeliveryService, InboxOutcome,
|
ChatError, ChatStorage, ConversationId, ConvoOutcome, Core, DeliveryService, IdentId,
|
||||||
Introduction, PayloadOutcome, RegistrationService, StorageConfig,
|
IdentIdRef, InboxOutcome, Introduction, PayloadOutcome, RegistrationService, StorageConfig,
|
||||||
};
|
};
|
||||||
use logos_account::TestLogosAccount;
|
use logos_account::TestLogosAccount;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@ -14,6 +14,8 @@ use crate::errors::ClientError;
|
|||||||
use crate::event::Event;
|
use crate::event::Event;
|
||||||
|
|
||||||
type ClientCore<T, R> = Core<(TestLogosAccount, T, R, ThreadedWakeupService, ChatStorage)>;
|
type ClientCore<T, R> = 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
|
/// The transport as the client sees it: a [`DeliveryService`] for outbound
|
||||||
/// publishing plus the inbound payload stream the worker drains. One object owns
|
/// 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)
|
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<ConversationId, ClientError> {
|
||||||
|
let signers = self.signers_from_account(account)?;
|
||||||
|
let signer_refs: Vec<IdentIdRef> = 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
|
/// Parse intro bundle bytes and initiate a private conversation. Outbound
|
||||||
/// envelopes are published by the core. Returns this side's conversation ID.
|
/// 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(
|
pub fn create_conversation(
|
||||||
&mut self,
|
&mut self,
|
||||||
intro_bundle: &[u8],
|
intro_bundle: &[u8],
|
||||||
@ -185,6 +203,15 @@ where
|
|||||||
.send_content(convo_id, content)
|
.send_content(convo_id, content)
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get signers for a given AccountAddress.
|
||||||
|
fn signers_from_account(
|
||||||
|
&self,
|
||||||
|
account: AccountAddressRef,
|
||||||
|
) -> Result<Vec<LocalSignerId>, ClientError> {
|
||||||
|
// Assume Account = LocalSigner until Account is ready
|
||||||
|
Ok(vec![IdentId::new(account.to_string())])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: DeliveryService, R: RegistrationService> Drop for ChatClient<T, R> {
|
impl<T: DeliveryService, R: RegistrationService> Drop for ChatClient<T, R> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user