Private
Public Access
1
0

daemon: implements post office

This commit is contained in:
2025-05-02 14:22:43 -07:00
parent 07b55f8615
commit 2519bc05ad
13 changed files with 234 additions and 48 deletions

View File

@@ -227,7 +227,7 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
async fn send_message(
&mut self,
outgoing_message: OutgoingMessage,
outgoing_message: &OutgoingMessage,
) -> Result<Message, Self::Error> {
let message: Message = self.request_with_body(
"sendMessage",

View File

@@ -15,10 +15,11 @@ pub mod event_socket;
pub use event_socket::EventSocket;
use self::http_client::Credentials;
use std::fmt::Debug;
#[async_trait]
pub trait APIInterface {
type Error;
type Error: Debug;
// (GET) /version
async fn get_version(&mut self) -> Result<String, Self::Error>;
@@ -38,7 +39,7 @@ pub trait APIInterface {
// (POST) /sendMessage
async fn send_message(
&mut self,
outgoing_message: OutgoingMessage,
outgoing_message: &OutgoingMessage,
) -> Result<Message, Self::Error>;
// (POST) /authenticate

View File

@@ -1,8 +1,12 @@
use serde::Serialize;
use super::conversation::ConversationID;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize)]
pub struct OutgoingMessage {
#[serde(skip)]
pub guid: Uuid,
#[serde(rename = "body")]
pub text: String,
@@ -21,6 +25,7 @@ impl OutgoingMessage {
#[derive(Default)]
pub struct OutgoingMessageBuilder {
guid: Option<Uuid>,
text: Option<String>,
conversation_id: Option<ConversationID>,
file_transfer_guids: Option<Vec<String>>,
@@ -31,6 +36,11 @@ impl OutgoingMessageBuilder {
Self::default()
}
pub fn guid(mut self, guid: Uuid) -> Self {
self.guid = Some(guid);
self
}
pub fn text(mut self, text: String) -> Self {
self.text = Some(text);
self
@@ -48,6 +58,7 @@ impl OutgoingMessageBuilder {
pub fn build(self) -> OutgoingMessage {
OutgoingMessage {
guid: self.guid.unwrap_or_else(|| Uuid::new_v4()),
text: self.text.unwrap(),
conversation_id: self.conversation_id.unwrap(),
file_transfer_guids: self.file_transfer_guids.unwrap_or_default(),

View File

@@ -93,15 +93,15 @@ impl APIInterface for TestClient {
async fn send_message(
&mut self,
outgoing_message: OutgoingMessage,
outgoing_message: &OutgoingMessage,
) -> Result<Message, Self::Error> {
let message = Message::builder()
.guid(Uuid::new_v4().to_string())
.text(outgoing_message.text)
.text(outgoing_message.text.clone())
.date(OffsetDateTime::now_utc())
.build();
self.messages.entry(outgoing_message.conversation_id).or_insert(vec![]).push(message.clone());
self.messages.entry(outgoing_message.conversation_id.clone()).or_insert(vec![]).push(message.clone());
Ok(message)
}