From ba276d9b005570081b53d169376cd32dba127e8a Mon Sep 17 00:00:00 2001 From: xmppftw Date: Mon, 3 Jun 2024 16:52:32 +0200 Subject: [PATCH] Receive message do nothing --- src/main.rs | 19 ++++++++++++++----- src/{xmpp.rs => xmpp_client.rs} | 17 +++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) rename src/{xmpp.rs => xmpp_client.rs} (71%) diff --git a/src/main.rs b/src/main.rs index 7b5812d..3a4f258 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::(); - 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, + } } }); diff --git a/src/xmpp.rs b/src/xmpp_client.rs similarity index 71% rename from src/xmpp.rs rename to src/xmpp_client.rs index 4eade70..e196d54 100644 --- a/src/xmpp.rs +++ b/src/xmpp_client.rs @@ -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 = 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 { - let (event_sender, event_receiver) = async_channel::bounded::(1); +pub(crate) fn client(jid: &str, password: &str) -> Receiver { + let (event_sender, event_receiver) = async_channel::bounded::(1); let jid = jid.to_string(); let password = password.to_string(); @@ -27,11 +24,11 @@ pub(crate) fn client(jid: &str, password: &str) -> Receiver { 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;