Split web and xmpp parts into different tasks

Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
pep 2024-11-21 17:11:43 +01:00
commit d16ead8bc9
No known key found for this signature in database
GPG key ID: DEDA74AEECA9D0F2
2 changed files with 40 additions and 28 deletions

View file

@ -20,6 +20,7 @@ use xmpp::jid::{BareJid, Jid};
use xmpp::parsers::message::MessageType;
use xmpp::tokio_xmpp::connect::StartTlsServerConnector;
use xmpp::{Agent, ClientBuilder, ClientFeature, ClientType, Event};
use tokio::sync::mpsc;
pub struct XmppClient {
is_online: bool,
@ -75,8 +76,22 @@ impl XmppClient {
}
}
pub async fn receive(&mut self, mut rx: mpsc::UnboundedReceiver<Hook>) {
loop {
tokio::select! {
_ = self.next() => (),
wh = rx.recv() => {
if let Some(hook) = wh {
debug!("XMPP Bot Received Hook");
self.hook(hook).await
}
}
}
}
}
pub async fn hook(&mut self, wh: Hook) {
debug!("Received Hook");
debug!("XMPP Bot Processing Hook");
if let Some(display) = format_hook(&wh) {
debug!("Hook: {}", display);
for room in &self.rooms {
@ -89,6 +104,7 @@ impl XmppClient {
)
.await
}
debug!("XMPP Bot Processed Hook");
}
}
}