From 945f1406165aa58414c0374a1ba984a1d6d896c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cel=20=F0=9F=8C=B8?= Date: Tue, 18 Feb 2025 06:19:54 +0000 Subject: [PATCH] WIP: roster retrieval --- luz/src/error.rs | 1 + luz/src/lib.rs | 17 +++++++++++------ luz/src/roster.rs | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/luz/src/error.rs b/luz/src/error.rs index b9a6487..7bf7bac 100644 --- a/luz/src/error.rs +++ b/luz/src/error.rs @@ -11,6 +11,7 @@ pub enum Error { SendMessage(Reason), AlreadyDisconnected, LostConnection, + CacheUpdate(Reason), } #[derive(Debug)] diff --git a/luz/src/lib.rs b/luz/src/lib.rs index c14bae6..1ed6c03 100644 --- a/luz/src/lib.rs +++ b/luz/src/lib.rs @@ -314,7 +314,7 @@ impl CommandMessage { // TODO: jid could lose resource by the end jid: Arc>, db: Db, - sender: mpsc::Sender, + update_sender: mpsc::Sender, pending_iqs: Arc>>>>, ) { match self { @@ -367,16 +367,21 @@ impl CommandMessage { match iq_recv.await { Ok(Ok(stanza)) => match stanza { Stanza::Iq(Iq { - from, + from: _, id, - to, + to: _, r#type, - lang, - query: Some(iq::Query::Roster(stanza::roster::Query { ver, items })), - errors, + lang: _, + query: Some(iq::Query::Roster(stanza::roster::Query { ver: _, items })), + errors: _, }) if id == iq_id && r#type == IqType::Result => { let contacts: Vec = items.into_iter().map(|item| item.into()).collect(); + if let Err(e) = db.replace_cached_roster(contacts.clone()).await { + update_sender + .send(UpdateMessage::Error(Error::CacheUpdate(e.into()))) + .await; + }; result_sender.send(Ok(contacts)); return; } diff --git a/luz/src/roster.rs b/luz/src/roster.rs index 2e3de7e..90bf436 100644 --- a/luz/src/roster.rs +++ b/luz/src/roster.rs @@ -9,7 +9,7 @@ pub enum ContactUpdate { RemoveFromGroup(String), } -#[derive(Debug, sqlx::FromRow)] +#[derive(Debug, sqlx::FromRow, Clone)] pub struct Contact { // jid is the id used to reference everything, but not the primary key pub user_jid: JID, @@ -23,7 +23,7 @@ pub struct Contact { pub groups: HashSet, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum Subscription { None, PendingOut,