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),
AlreadyDisconnected,
LostConnection,
CacheUpdate(Reason),
}
#[derive(Debug)]

View File

@ -314,7 +314,7 @@ impl CommandMessage {
// TODO: jid could lose resource by the end
jid: Arc<Mutex<JID>>,
db: Db,
sender: mpsc::Sender<UpdateMessage>,
update_sender: mpsc::Sender<UpdateMessage>,
pending_iqs: Arc<Mutex<HashMap<String, oneshot::Sender<Result<Stanza, Reason>>>>>,
) {
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<Contact> =
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;
}

View File

@ -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<String>,
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum Subscription {
None,
PendingOut,