Receive message do nothing

This commit is contained in:
xmppftw xmppftw 2024-06-03 16:52:32 +02:00
parent a1ec955fdd
commit ba7e9746c1
2 changed files with 21 additions and 15 deletions

View File

@ -21,7 +21,7 @@ mod message;
mod poezio_logs;
mod tab;
mod window;
mod xmpp;
mod xmpp_client;
use message::Message;
use tab::Tab;
@ -52,12 +52,21 @@ fn main() {
let tabs_store = gio::ListStore::new::<Tab>();
let xmpp_receiver = xmpp::client(&username, &password);
let xmpp_receiver = xmpp_client::client(&username, &password);
let tabs_store_copy = tabs_store.clone();
glib::spawn_future_local(async move {
while let Ok(xmpp::ContactReceived(jid)) = xmpp_receiver.recv().await {
let tab = Tab::new(jid.as_str(), jid.as_str());
tabs_store_copy.append(&tab);
while let Ok(event) = xmpp_receiver.recv().await {
match event {
xmpp::Event::ContactAdded(jid) => {
let tab = Tab::new(jid.jid.as_str(), jid.jid.as_str());
tabs_store_copy.append(&tab);
}
xmpp::Event::ChatMessage(_id, _from, _body, _time) => {
// TODO: Insert message into tab history
continue;
}
_ => continue,
}
}
});

View File

@ -4,16 +4,13 @@ use xmpp::{BareJid, ClientBuilder, ClientFeature, Event};
use std::sync::OnceLock;
#[derive(Clone, Debug)]
pub struct ContactReceived(pub BareJid);
fn tokio_runtime() -> &'static Runtime {
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
RUNTIME.get_or_init(|| Runtime::new().expect("Setting up tokio runtime needs to succeed."))
}
pub(crate) fn client(jid: &str, password: &str) -> Receiver<ContactReceived> {
let (event_sender, event_receiver) = async_channel::bounded::<ContactReceived>(1);
pub(crate) fn client(jid: &str, password: &str) -> Receiver<xmpp::Event> {
let (event_sender, event_receiver) = async_channel::bounded::<xmpp::Event>(1);
let jid = jid.to_string();
let password = password.to_string();
@ -27,11 +24,11 @@ pub(crate) fn client(jid: &str, password: &str) -> Receiver<ContactReceived> {
while let Some(events) = client.wait_for_events().await {
for event in events {
match event {
Event::ContactAdded(contact) => {
event_sender
.send(ContactReceived(contact.jid))
.await
.expect("BOOOOOOHOOOO");
Event::ContactAdded(_) => {
event_sender.send(event).await.expect("BOOOOOOHOOOO");
}
Event::ChatMessage(_, _, _, _) => {
event_sender.send(event).await.expect("BOOOHOOOO");
}
_ => {
continue;