use std::collections::HashSet; use jid::JID; pub struct ContactUpdate { pub name: Option, pub groups: HashSet, } #[derive(Debug, Clone)] pub struct Contact { // jid is the id used to reference everything, but not the primary key pub user_jid: JID, pub subscription: Subscription, /// client user defined name pub name: Option, // TODO: avatar, nickname /// nickname picked by contact // nickname: Option, pub groups: HashSet, } #[derive(Debug, Clone)] pub enum Subscription { None, PendingOut, PendingIn, PendingInPendingOut, OnlyOut, OnlyIn, OutPendingIn, InPendingOut, Buddy, // TODO: perhaps don't need, just emit event to remove contact // Remove, } // none // > // >> // < // << // >< // >>< // ><< // >><< impl From for Contact { fn from(value: stanza::roster::Item) -> Self { let subscription = match value.ask { true => match value.subscription { Some(s) => match s { stanza::roster::Subscription::Both => Subscription::Buddy, stanza::roster::Subscription::From => Subscription::InPendingOut, stanza::roster::Subscription::None => Subscription::PendingOut, stanza::roster::Subscription::Remove => Subscription::PendingOut, stanza::roster::Subscription::To => Subscription::OnlyOut, }, None => Subscription::PendingOut, }, false => match value.subscription { Some(s) => match s { stanza::roster::Subscription::Both => Subscription::Buddy, stanza::roster::Subscription::From => Subscription::OnlyIn, stanza::roster::Subscription::None => Subscription::None, stanza::roster::Subscription::Remove => Subscription::None, stanza::roster::Subscription::To => Subscription::OnlyOut, }, None => Subscription::None, }, }; Contact { user_jid: value.jid, subscription, name: value.name, groups: HashSet::from_iter(value.groups.into_iter().filter_map(|group| group.0)), } } }