From 42c7423667a2d6acdebca75250ad30c5d475081b Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Mon, 28 Apr 2025 19:53:11 +0100 Subject: feat: serde --- filamento/src/lib.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'filamento/src/lib.rs') diff --git a/filamento/src/lib.rs b/filamento/src/lib.rs index e06f7c6..18ceb9d 100644 --- a/filamento/src/lib.rs +++ b/filamento/src/lib.rs @@ -70,6 +70,7 @@ pub enum Command { /// get a specific chat by jid GetChat(JID, oneshot::Sender>), /// get message history for chat (does appropriate mam things) + GetMessage(Uuid, oneshot::Sender>), // TODO: paging and filtering GetMessages(JID, oneshot::Sender, DatabaseError>>), /// get message history for chat (does appropriate mam things) @@ -268,8 +269,15 @@ impl Client { } impl Client { - pub async fn connect(&self) -> Result<(), ActorError> { - self.send(CoreClientCommand::Connect).await?; + pub async fn connect(&self) -> Result<(), CommandError> { + let (send, recv) = oneshot::channel::>(); + self.send(CoreClientCommand::Connect(send)) + .await + .map_err(|e| CommandError::Actor(Into::::into(e)))?; + let result = timeout(self.timeout, recv) + .await + .map_err(|e| CommandError::Actor(Into::::into(e)))? + .map_err(|e| CommandError::Actor(Into::::into(e)))??; Ok(()) } @@ -374,6 +382,18 @@ impl Client { Ok(chat) } + pub async fn get_message(&self, id: Uuid) -> Result> { + let (send, recv) = oneshot::channel(); + self.send(CoreClientCommand::Command(Command::GetMessage(id, send))) + .await + .map_err(|e| CommandError::Actor(Into::::into(e)))?; + let message = timeout(self.timeout, recv) + .await + .map_err(|e| CommandError::Actor(Into::::into(e)))? + .map_err(|e| CommandError::Actor(Into::::into(e)))??; + Ok(message) + } + pub async fn get_messages( &self, jid: JID, -- cgit