Receive message do nothing

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

View File

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

View File

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