mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-08-25 23:21:10 +00:00
Update Context to accept External Identity Provider. (#127)
* rename .account_id() to .id() * Create logos-traits crate * Remove AccountId references * external IdentityProvider for Context * Fix compile errors from merge * Update logos-traits to shared-traits * format fixes * warnings cleanup * clippy fix * Remove rebase artifact
This commit is contained in:
@@ -8,9 +8,10 @@ edition = "2024"
|
||||
|
||||
[dev-dependencies]
|
||||
# Workspace dependencies (sorted)
|
||||
chat-sqlite = { workspace = true }
|
||||
components = { workspace = true }
|
||||
libchat = { workspace = true }
|
||||
chat-sqlite = { workspace = true }
|
||||
logos-account = { workspace = true , features = ["dev"]}
|
||||
storage = { workspace = true }
|
||||
|
||||
# External dependencies (sorted)
|
||||
|
||||
@@ -8,13 +8,25 @@ use std::ops::{Deref, DerefMut};
|
||||
|
||||
use components::{EphemeralRegistry, LocalBroadcaster, MemStore};
|
||||
use libchat::{Core, MissingMessage};
|
||||
|
||||
use logos_account::TestLogosAccount;
|
||||
struct Client {
|
||||
inner: Core<(LocalBroadcaster, EphemeralRegistry, MemStore)>,
|
||||
inner: Core<(
|
||||
TestLogosAccount,
|
||||
LocalBroadcaster,
|
||||
EphemeralRegistry,
|
||||
MemStore,
|
||||
)>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
fn init(core: Core<(LocalBroadcaster, EphemeralRegistry, MemStore)>) -> Self {
|
||||
fn init(
|
||||
core: Core<(
|
||||
TestLogosAccount,
|
||||
LocalBroadcaster,
|
||||
EphemeralRegistry,
|
||||
MemStore,
|
||||
)>,
|
||||
) -> Self {
|
||||
Client { inner: core }
|
||||
}
|
||||
|
||||
@@ -38,7 +50,12 @@ impl Client {
|
||||
}
|
||||
|
||||
impl Deref for Client {
|
||||
type Target = Core<(LocalBroadcaster, EphemeralRegistry, MemStore)>;
|
||||
type Target = Core<(
|
||||
TestLogosAccount,
|
||||
LocalBroadcaster,
|
||||
EphemeralRegistry,
|
||||
MemStore,
|
||||
)>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
@@ -55,16 +72,19 @@ fn missing_group_message_is_detected() {
|
||||
let ds = LocalBroadcaster::new();
|
||||
let rs = EphemeralRegistry::new();
|
||||
|
||||
let saro_account = TestLogosAccount::new("saro");
|
||||
let saro_ctx =
|
||||
Core::new_with_name("saro", ds.new_consumer(), rs.clone(), MemStore::new()).unwrap();
|
||||
Core::new_with_name(saro_account, ds.new_consumer(), rs.clone(), MemStore::new()).unwrap();
|
||||
|
||||
let raya_ctx = Core::new_with_name("raya", ds.clone(), rs.clone(), MemStore::new()).unwrap();
|
||||
let raya_account = TestLogosAccount::new("raya");
|
||||
let raya_ctx =
|
||||
Core::new_with_name(raya_account, ds.clone(), rs.clone(), MemStore::new()).unwrap();
|
||||
|
||||
let mut saro = Client::init(saro_ctx);
|
||||
let mut raya = Client::init(raya_ctx);
|
||||
|
||||
// Saro creates a group with Raya.
|
||||
let raya_id = raya.account_id().clone();
|
||||
let raya_id = raya.ident_id().clone();
|
||||
let convo_id = saro.create_group_convo(&[&raya_id]).unwrap().to_string();
|
||||
|
||||
// Raya joins (processes the Welcome + commit).
|
||||
@@ -95,7 +115,7 @@ fn missing_group_message_is_detected() {
|
||||
);
|
||||
assert_eq!(
|
||||
missing[0].frontier.sender_id(),
|
||||
saro.account_id().as_str(),
|
||||
saro.ident_id().as_str(),
|
||||
"missing-message sender hint should attribute to Saro"
|
||||
);
|
||||
|
||||
|
||||
@@ -4,12 +4,18 @@ use components::{EphemeralRegistry, LocalBroadcaster, MemStore};
|
||||
use libchat::{
|
||||
Content, ConversationClass, ConvoOutcome, Core, NewConversation, PayloadOutcome, hex_trunc,
|
||||
};
|
||||
use logos_account::TestLogosAccount;
|
||||
|
||||
type ResultCallback = Box<dyn Fn(&PayloadOutcome)>;
|
||||
|
||||
// Simple client Functionality for testing
|
||||
struct Client {
|
||||
inner: Core<(LocalBroadcaster, EphemeralRegistry, MemStore)>,
|
||||
inner: Core<(
|
||||
TestLogosAccount,
|
||||
LocalBroadcaster,
|
||||
EphemeralRegistry,
|
||||
MemStore,
|
||||
)>,
|
||||
on_result: Option<ResultCallback>,
|
||||
new_conversations: Vec<NewConversation>,
|
||||
received_messages: Vec<(libchat::ConversationId, Content)>,
|
||||
@@ -17,7 +23,12 @@ struct Client {
|
||||
|
||||
impl Client {
|
||||
fn init(
|
||||
core: Core<(LocalBroadcaster, EphemeralRegistry, MemStore)>,
|
||||
core: Core<(
|
||||
TestLogosAccount,
|
||||
LocalBroadcaster,
|
||||
EphemeralRegistry,
|
||||
MemStore,
|
||||
)>,
|
||||
cb: Option<impl Fn(&PayloadOutcome) + 'static>,
|
||||
) -> Self {
|
||||
Client {
|
||||
@@ -60,7 +71,12 @@ impl Client {
|
||||
}
|
||||
|
||||
impl Deref for Client {
|
||||
type Target = Core<(LocalBroadcaster, EphemeralRegistry, MemStore)>;
|
||||
type Target = Core<(
|
||||
TestLogosAccount,
|
||||
LocalBroadcaster,
|
||||
EphemeralRegistry,
|
||||
MemStore,
|
||||
)>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
@@ -111,19 +127,22 @@ fn create_group() {
|
||||
let ds = LocalBroadcaster::new();
|
||||
let rs = EphemeralRegistry::new();
|
||||
|
||||
let saro_ctx =
|
||||
Core::new_with_name("saro", ds.new_consumer(), rs.clone(), MemStore::new()).unwrap();
|
||||
let raya_ctx = Core::new_with_name("raya", ds.clone(), rs.clone(), MemStore::new()).unwrap();
|
||||
let saro_ident = TestLogosAccount::new("saro");
|
||||
let saro =
|
||||
Core::new_with_name(saro_ident, ds.new_consumer(), rs.clone(), MemStore::new()).unwrap();
|
||||
|
||||
let raya_ident = TestLogosAccount::new("raya");
|
||||
let raya = Core::new_with_name(raya_ident, ds.clone(), rs.clone(), MemStore::new()).unwrap();
|
||||
|
||||
let mut clients = vec![
|
||||
Client::init(saro_ctx, Some(pretty_print(" Saro "))),
|
||||
Client::init(raya_ctx, Some(pretty_print(" Raya "))),
|
||||
Client::init(saro, Some(pretty_print(" Saro "))),
|
||||
Client::init(raya, Some(pretty_print(" Raya "))),
|
||||
];
|
||||
|
||||
const SARO: usize = 0;
|
||||
const RAYA: usize = 1;
|
||||
|
||||
let raya_id = clients[RAYA].account_id().clone();
|
||||
let raya_id = clients[RAYA].ident_id().clone();
|
||||
let convo_id = clients[SARO]
|
||||
.create_group_convo(&[&raya_id])
|
||||
.unwrap()
|
||||
@@ -157,11 +176,12 @@ fn create_group() {
|
||||
|
||||
process(&mut clients);
|
||||
|
||||
let pax_ctx = Core::new_with_name("pax", ds, rs, MemStore::new()).unwrap();
|
||||
clients.push(Client::init(pax_ctx, Some(pretty_print(" Pax"))));
|
||||
let pax_ident = TestLogosAccount::new("pax");
|
||||
let pax = Core::new_with_name(pax_ident, ds, rs, MemStore::new()).unwrap();
|
||||
clients.push(Client::init(pax, Some(pretty_print(" Pax"))));
|
||||
const PAX: usize = 2;
|
||||
|
||||
let pax_id = clients[PAX].account_id().clone();
|
||||
let pax_id = clients[PAX].ident_id().clone();
|
||||
clients[SARO]
|
||||
.group_add_member(&convo_id, &[&pax_id])
|
||||
.unwrap();
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
use chat_sqlite::{ChatStorage, StorageConfig};
|
||||
use libchat::{ConversationClass, Core, Introduction, PayloadOutcome};
|
||||
use logos_account::TestLogosAccount;
|
||||
use storage::{ConversationStore, IdentityStore};
|
||||
use tempfile::tempdir;
|
||||
|
||||
use components::{EphemeralRegistry, LocalBroadcaster};
|
||||
|
||||
type PrivateCore = Core<(LocalBroadcaster, EphemeralRegistry, ChatStorage)>;
|
||||
type PrivateCore = Core<(
|
||||
TestLogosAccount,
|
||||
LocalBroadcaster,
|
||||
EphemeralRegistry,
|
||||
ChatStorage,
|
||||
)>;
|
||||
|
||||
/// Drains everything published to `receiver`'s delivery service and feeds each
|
||||
/// payload back through `handle_payload`, returning the observed outcomes.
|
||||
@@ -49,9 +55,16 @@ fn ctx_integration() {
|
||||
let ds = LocalBroadcaster::new();
|
||||
let rs = EphemeralRegistry::new();
|
||||
|
||||
let mut saro =
|
||||
Core::new_with_name("saro", ds.clone(), rs.clone(), ChatStorage::in_memory()).unwrap();
|
||||
let mut raya = Core::new_with_name("raya", ds, rs, ChatStorage::in_memory()).unwrap();
|
||||
let saro_account = TestLogosAccount::new("saro");
|
||||
let mut saro = Core::new_with_name(
|
||||
saro_account,
|
||||
ds.clone(),
|
||||
rs.clone(),
|
||||
ChatStorage::in_memory(),
|
||||
)
|
||||
.unwrap();
|
||||
let raya_account = TestLogosAccount::new("raya");
|
||||
let mut raya = Core::new_with_name(raya_account, ds, rs, ChatStorage::in_memory()).unwrap();
|
||||
|
||||
// Raya creates intro bundle and sends to Saro
|
||||
let bundle = raya.create_intro_bundle().unwrap();
|
||||
@@ -93,7 +106,8 @@ fn identity_persistence() {
|
||||
let ds = LocalBroadcaster::new();
|
||||
let rs = EphemeralRegistry::new();
|
||||
let store1 = ChatStorage::new(StorageConfig::InMemory).unwrap();
|
||||
let ctx1 = Core::new_with_name("alice", ds, rs, store1).unwrap();
|
||||
let alice_account = TestLogosAccount::new("alice");
|
||||
let ctx1 = Core::new_with_name(alice_account, ds, rs, store1).unwrap();
|
||||
let pubkey1 = ctx1.identity().public_key();
|
||||
let name1 = ctx1.installation_name().to_string();
|
||||
|
||||
@@ -112,7 +126,8 @@ fn open_persists_new_identity() {
|
||||
let ds = LocalBroadcaster::new();
|
||||
let rs = EphemeralRegistry::new();
|
||||
let store = ChatStorage::new(StorageConfig::File(db_path.clone())).unwrap();
|
||||
let core = Core::new_from_store("alice", ds, rs, store).unwrap();
|
||||
let alice_account = TestLogosAccount::new("alice");
|
||||
let core = Core::new_from_store(alice_account, ds, rs, store).unwrap();
|
||||
let pubkey = core.identity().public_key();
|
||||
drop(core);
|
||||
|
||||
@@ -127,9 +142,16 @@ fn open_persists_new_identity() {
|
||||
fn conversation_metadata_persistence() {
|
||||
let ds = LocalBroadcaster::new();
|
||||
let rs = EphemeralRegistry::new();
|
||||
let mut alice =
|
||||
Core::new_with_name("alice", ds.clone(), rs.clone(), ChatStorage::in_memory()).unwrap();
|
||||
let mut bob = Core::new_with_name("bob", ds, rs, ChatStorage::in_memory()).unwrap();
|
||||
let alice_account = TestLogosAccount::new("alice");
|
||||
let mut alice = Core::new_with_name(
|
||||
alice_account,
|
||||
ds.clone(),
|
||||
rs.clone(),
|
||||
ChatStorage::in_memory(),
|
||||
)
|
||||
.unwrap();
|
||||
let bob_account = TestLogosAccount::new("bob");
|
||||
let mut bob = Core::new_with_name(bob_account, ds, rs, ChatStorage::in_memory()).unwrap();
|
||||
|
||||
let bundle = alice.create_intro_bundle().unwrap();
|
||||
let intro = Introduction::try_from(bundle.as_slice()).unwrap();
|
||||
@@ -153,9 +175,16 @@ fn conversation_metadata_persistence() {
|
||||
fn conversation_full_flow() {
|
||||
let ds = LocalBroadcaster::new();
|
||||
let rs = EphemeralRegistry::new();
|
||||
let mut alice =
|
||||
Core::new_with_name("alice", ds.clone(), rs.clone(), ChatStorage::in_memory()).unwrap();
|
||||
let mut bob = Core::new_with_name("bob", ds, rs, ChatStorage::in_memory()).unwrap();
|
||||
let alice_account = TestLogosAccount::new("alice");
|
||||
let mut alice = Core::new_with_name(
|
||||
alice_account,
|
||||
ds.clone(),
|
||||
rs.clone(),
|
||||
ChatStorage::in_memory(),
|
||||
)
|
||||
.unwrap();
|
||||
let bob_account = TestLogosAccount::new("bob");
|
||||
let mut bob = Core::new_with_name(bob_account, ds, rs, ChatStorage::in_memory()).unwrap();
|
||||
|
||||
let bundle = alice.create_intro_bundle().unwrap();
|
||||
let intro = Introduction::try_from(bundle.as_slice()).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user