1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
use std::collections::HashSet;
use jid::JID;
pub struct ContactUpdate {
pub name: Option<String>,
pub groups: HashSet<String>,
}
#[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<String>,
// TODO: avatar, nickname
/// nickname picked by contact
// nickname: Option<String>,
pub groups: HashSet<String>,
}
#[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<stanza::roster::Item> 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)),
}
}
}
|