Private
Public Access
1
0

client: implements event/updates websocket

This commit is contained in:
2025-05-01 18:07:18 -07:00
parent 13a78ccd47
commit f6ac3b5a58
14 changed files with 561 additions and 67 deletions

View File

@@ -4,8 +4,12 @@ use std::collections::HashMap;
pub use crate::APIInterface;
use crate::{
api::http_client::Credentials,
model::{Conversation, ConversationID, JwtToken, Message, MessageID}
};
model::{Conversation, ConversationID, JwtToken, Message, MessageID, UpdateItem, Event},
api::event_socket::EventSocket,
};
use futures_util::StreamExt;
use futures_util::stream::BoxStream;
pub struct TestClient {
pub version: &'static str,
@@ -28,6 +32,32 @@ impl TestClient {
}
}
pub struct TestEventSocket {
pub events: Vec<Event>,
}
impl TestEventSocket {
pub fn new() -> Self {
Self { events: vec![] }
}
}
#[async_trait]
impl EventSocket for TestEventSocket {
type Error = TestError;
type EventStream = BoxStream<'static, Result<Event, TestError>>;
type UpdateStream = BoxStream<'static, Result<Vec<UpdateItem>, TestError>>;
async fn events(self) -> Self::EventStream {
futures_util::stream::iter(self.events.into_iter().map(Ok)).boxed()
}
async fn raw_updates(self) -> Self::UpdateStream {
let results: Vec<Result<Vec<UpdateItem>, TestError>> = vec![];
futures_util::stream::iter(results.into_iter()).boxed()
}
}
#[async_trait]
impl APIInterface for TestClient {
type Error = TestError;
@@ -57,4 +87,10 @@ impl APIInterface for TestClient {
Err(TestError::ConversationNotFound)
}
async fn open_event_socket(&mut self) -> Result<impl EventSocket, Self::Error> {
Ok(TestEventSocket::new())
}
}