From 7b3ed73184f375004af6db62654af0e69e7d14d3 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Mon, 19 May 2025 11:39:15 +0100 Subject: feat(filamento): read_chat_and_user() --- filamento/src/lib.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'filamento/src/lib.rs') diff --git a/filamento/src/lib.rs b/filamento/src/lib.rs index 8b27441..068bfe8 100644 --- a/filamento/src/lib.rs +++ b/filamento/src/lib.rs @@ -69,6 +69,8 @@ pub enum Command { ), /// get a specific chat by jid GetChat(JID, oneshot::Sender>), + /// get a specific chat and user by jid + GetChatAndUser(JID, oneshot::Sender>), /// get message history for chat (does appropriate mam things) GetMessage(Uuid, oneshot::Sender>), // TODO: paging and filtering @@ -269,8 +271,9 @@ impl Client { } impl Client { - pub async fn connect(&self) -> Result<(), CommandError> { - let (send, recv) = oneshot::channel::>(); + /// returns the resource + pub async fn connect(&self) -> Result> { + let (send, recv) = oneshot::channel::>(); self.send(CoreClientCommand::Connect(send)) .await .map_err(|e| CommandError::Actor(Into::::into(e)))?; @@ -278,7 +281,7 @@ impl Client { .await .map_err(|e| CommandError::Actor(Into::::into(e)))? .map_err(|e| CommandError::Actor(Into::::into(e)))??; - Ok(()) + Ok(result) } pub async fn disconnect(&self, offline: Offline) -> Result<(), ActorError> { @@ -382,6 +385,18 @@ impl Client { Ok(chat) } + pub async fn get_chat_and_user(&self, jid: JID) -> Result<(Chat, User), CommandError> { + let (send, recv) = oneshot::channel(); + self.send(CoreClientCommand::Command(Command::GetChatAndUser(jid, 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(result) + } + pub async fn get_message(&self, id: Uuid) -> Result> { let (send, recv) = oneshot::channel(); self.send(CoreClientCommand::Command(Command::GetMessage(id, send))) -- cgit