WIP: roster retrieval

This commit is contained in:
cel 🌸 2025-02-18 06:19:54 +00:00
parent 5dd488550f
commit 945f140616
3 changed files with 14 additions and 8 deletions

View File

@ -11,6 +11,7 @@ pub enum Error {
SendMessage(Reason), SendMessage(Reason),
AlreadyDisconnected, AlreadyDisconnected,
LostConnection, LostConnection,
CacheUpdate(Reason),
} }
#[derive(Debug)] #[derive(Debug)]

View File

@ -314,7 +314,7 @@ impl CommandMessage {
// TODO: jid could lose resource by the end // TODO: jid could lose resource by the end
jid: Arc<Mutex<JID>>, jid: Arc<Mutex<JID>>,
db: Db, db: Db,
sender: mpsc::Sender<UpdateMessage>, update_sender: mpsc::Sender<UpdateMessage>,
pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>, pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>,
) { ) {
match self { match self {
@ -367,16 +367,21 @@ impl CommandMessage {
match iq_recv.await { match iq_recv.await {
Ok(Ok(stanza)) => match stanza { Ok(Ok(stanza)) => match stanza {
Stanza::Iq(Iq { Stanza::Iq(Iq {
from, from: _,
id, id,
to, to: _,
r#type, r#type,
lang, lang: _,
query: Some(iq::Query::Roster(stanza::roster::Query { ver, items })), query: Some(iq::Query::Roster(stanza::roster::Query { ver: _, items })),
errors, errors: _,
}) if id == iq_id && r#type == IqType::Result => { }) if id == iq_id && r#type == IqType::Result => {
let contacts: Vec<Contact> = let contacts: Vec<Contact> =
items.into_iter().map(|item| item.into()).collect(); 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)); result_sender.send(Ok(contacts));
return; return;
} }

View File

@ -9,7 +9,7 @@ pub enum ContactUpdate {
RemoveFromGroup(String), RemoveFromGroup(String),
} }
#[derive(Debug, sqlx::FromRow)] #[derive(Debug, sqlx::FromRow, Clone)]
pub struct Contact { pub struct Contact {
// jid is the id used to reference everything, but not the primary key // jid is the id used to reference everything, but not the primary key
pub user_jid: JID, pub user_jid: JID,
@ -23,7 +23,7 @@ pub struct Contact {
pub groups: HashSet<String>, pub groups: HashSet<String>,
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub enum Subscription { pub enum Subscription {
None, None,
PendingOut, PendingOut,