aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-04-03 03:41:38 +0100
committerLibravatar cel 🌸 <cel@bunny.garden>2025-04-03 03:41:38 +0100
commit91f1994af940085d5d475a97820900ebbf0eb553 (patch)
tree6aab872f71d17a785d3d9286742fef38983d274c /filamento/src/lib.rs
parent9ce3827a7d25714d17f266f0f50bb29f41090175 (diff)
downloadluz-91f1994af940085d5d475a97820900ebbf0eb553.tar.gz
luz-91f1994af940085d5d475a97820900ebbf0eb553.tar.bz2
luz-91f1994af940085d5d475a97820900ebbf0eb553.zip
feat: better message handling, pep publish, xep_0172: nick
Diffstat (limited to 'filamento/src/lib.rs')
-rw-r--r--filamento/src/lib.rs93
1 files changed, 68 insertions, 25 deletions
diff --git a/filamento/src/lib.rs b/filamento/src/lib.rs
index 4d852e2..6118f75 100644
--- a/filamento/src/lib.rs
+++ b/filamento/src/lib.rs
@@ -6,13 +6,13 @@ use std::{
time::Duration,
};
-use chat::{Body, Chat, Message};
+use chat::{Body, Chat, Delivery, Message};
use chrono::Utc;
use db::Db;
use disco::{Info, Items};
use error::{
- ConnectionJobError, DatabaseError, DiscoError, Error, IqError, MessageRecvError, PresenceError,
- RosterError, StatusError,
+ ConnectionJobError, DatabaseError, DiscoError, Error, IqError, MessageRecvError, NickError,
+ PresenceError, PublishError, RosterError, StatusError, SubscribeError,
};
use futures::FutureExt;
use jid::JID;
@@ -40,6 +40,7 @@ pub mod db;
pub mod disco;
pub mod error;
mod logic;
+pub mod pep;
pub mod presence;
pub mod roster;
pub mod user;
@@ -68,13 +69,13 @@ pub enum Command {
/// add a contact to your roster, with a status of none, no subscriptions.
AddContact(JID, oneshot::Sender<Result<(), RosterError>>),
/// send a friend request i.e. a subscription request with a subscription pre-approval. if not already added to roster server adds to roster.
- BuddyRequest(JID, oneshot::Sender<Result<(), WriteError>>),
+ BuddyRequest(JID, oneshot::Sender<Result<(), SubscribeError>>),
/// send a subscription request, without pre-approval. if not already added to roster server adds to roster.
- SubscriptionRequest(JID, oneshot::Sender<Result<(), WriteError>>),
+ SubscriptionRequest(JID, oneshot::Sender<Result<(), SubscribeError>>),
/// accept a friend request by accepting a pending subscription and sending a subscription request back. if not already added to roster adds to roster.
- AcceptBuddyRequest(JID, oneshot::Sender<Result<(), WriteError>>),
+ AcceptBuddyRequest(JID, oneshot::Sender<Result<(), SubscribeError>>),
/// accept a pending subscription and doesn't send a subscription request back. if not already added to roster adds to roster.
- AcceptSubscriptionRequest(JID, oneshot::Sender<Result<(), WriteError>>),
+ AcceptSubscriptionRequest(JID, oneshot::Sender<Result<(), SubscribeError>>),
/// unsubscribe to a contact, but don't remove their subscription.
UnsubscribeFromContact(JID, oneshot::Sender<Result<(), WriteError>>),
/// stop a contact from being subscribed, but stay subscribed to the contact.
@@ -98,7 +99,9 @@ pub enum Command {
// TODO: should probably make it so people can add non-contact auto presence sharing in the client (most likely through setting an internal setting)
/// send a message to a jid (any kind of jid that can receive a message, e.g. a user or a
/// chatroom). if disconnected, will be cached so when client connects, message will be sent.
- SendMessage(JID, Body, oneshot::Sender<Result<(), WriteError>>),
+ SendMessage(JID, Body),
+ // TODO: resend failed messages
+ // ResendMessage(Uuid),
/// disco info query
DiscoInfo(
Option<JID>,
@@ -111,6 +114,14 @@ pub enum Command {
Option<String>,
oneshot::Sender<Result<disco::Items, DiscoError>>,
),
+ /// publish item to a pep node, specified or default according to item.
+ Publish {
+ item: pep::Item,
+ node: String,
+ sender: oneshot::Sender<Result<(), PublishError>>,
+ },
+ /// change user nickname
+ ChangeNick(String, oneshot::Sender<Result<(), NickError>>),
}
#[derive(Debug, Clone)]
@@ -134,7 +145,15 @@ pub enum UpdateMessage {
to: JID,
message: Message,
},
+ MessageDelivery {
+ id: Uuid,
+ delivery: Delivery,
+ },
SubscriptionRequest(jid::JID),
+ NickChanged {
+ jid: JID,
+ nick: String,
+ },
}
/// an xmpp client that is suited for a chat client use case
@@ -192,7 +211,7 @@ impl Client {
timeout: Duration::from_secs(10),
};
- let logic = ClientLogic::new(client.clone(), db, update_send);
+ let logic = ClientLogic::new(client.clone(), jid.as_bare(), db, update_send);
let actor: CoreClient<ClientLogic> =
CoreClient::new(jid, password, command_receiver, None, sup_recv, logic);
@@ -328,7 +347,7 @@ impl Client {
Ok(result)
}
- pub async fn buddy_request(&self, jid: JID) -> Result<(), CommandError<WriteError>> {
+ pub async fn buddy_request(&self, jid: JID) -> Result<(), CommandError<SubscribeError>> {
let (send, recv) = oneshot::channel();
self.send(CoreClientCommand::Command(Command::BuddyRequest(jid, send)))
.await
@@ -340,7 +359,7 @@ impl Client {
Ok(result)
}
- pub async fn subscription_request(&self, jid: JID) -> Result<(), CommandError<WriteError>> {
+ pub async fn subscription_request(&self, jid: JID) -> Result<(), CommandError<SubscribeError>> {
let (send, recv) = oneshot::channel();
self.send(CoreClientCommand::Command(Command::SubscriptionRequest(
jid, send,
@@ -354,7 +373,7 @@ impl Client {
Ok(result)
}
- pub async fn accept_buddy_request(&self, jid: JID) -> Result<(), CommandError<WriteError>> {
+ pub async fn accept_buddy_request(&self, jid: JID) -> Result<(), CommandError<SubscribeError>> {
let (send, recv) = oneshot::channel();
self.send(CoreClientCommand::Command(Command::AcceptBuddyRequest(
jid, send,
@@ -371,7 +390,7 @@ impl Client {
pub async fn accept_subscription_request(
&self,
jid: JID,
- ) -> Result<(), CommandError<WriteError>> {
+ ) -> Result<(), CommandError<SubscribeError>> {
let (send, recv) = oneshot::channel();
self.send(CoreClientCommand::Command(
Command::AcceptSubscriptionRequest(jid, send),
@@ -471,18 +490,10 @@ impl Client {
Ok(result)
}
- pub async fn send_message(&self, jid: JID, body: Body) -> Result<(), CommandError<WriteError>> {
- let (send, recv) = oneshot::channel();
- self.send(CoreClientCommand::Command(Command::SendMessage(
- jid, body, send,
- )))
- .await
- .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))?;
- let result = timeout(self.timeout, recv)
- .await
- .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))?
- .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))??;
- Ok(result)
+ pub async fn send_message(&self, jid: JID, body: Body) -> Result<(), ActorError> {
+ self.send(CoreClientCommand::Command(Command::SendMessage(jid, body)))
+ .await?;
+ Ok(())
}
pub async fn disco_info(
@@ -520,6 +531,38 @@ impl Client {
.map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))??;
Ok(result)
}
+
+ pub async fn publish(
+ &self,
+ item: pep::Item,
+ node: String,
+ ) -> Result<(), CommandError<PublishError>> {
+ let (send, recv) = oneshot::channel();
+ self.send(CoreClientCommand::Command(Command::Publish {
+ item,
+ node,
+ sender: send,
+ }))
+ .await
+ .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))?;
+ let result = timeout(self.timeout, recv)
+ .await
+ .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))?
+ .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))??;
+ Ok(result)
+ }
+
+ pub async fn change_nick(&self, nick: String) -> Result<(), CommandError<NickError>> {
+ let (send, recv) = oneshot::channel();
+ self.send(CoreClientCommand::Command(Command::ChangeNick(nick, send)))
+ .await
+ .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))?;
+ let result = timeout(self.timeout, recv)
+ .await
+ .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))?
+ .map_err(|e| CommandError::Actor(Into::<ActorError>::into(e)))??;
+ Ok(result)
+ }
}
impl From<Command> for CoreClientCommand<Command> {