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
|
pub enum LossyUsername {
Username(String),
NoUsername(String, String),
Unknown,
}
impl LossyUsername {
pub fn from_user_ref(from: &paperplane::types::User) -> Self {
if from.username.len() > 0 {
LossyUsername::Username(from.username.clone())
} else {
LossyUsername::NoUsername(from.first_name.clone(), from.last_name.clone())
}
}
}
impl std::fmt::Display for LossyUsername {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
LossyUsername::Username(username) => write!(f, "@{}", username),
LossyUsername::NoUsername(first, last) => {
if last.len() > 0 {
write!(f, "{} {}", first, last)
} else {
write!(f, "{}", first)
}
}
LossyUsername::Unknown => write!(f, "unknown"),
}
}
}
pub enum LossyChatTitle {
Title(String),
Unknown,
}
impl LossyChatTitle {
pub fn from_chat_ref(from: &paperplane::types::Chat) -> Self {
Self::Title(from.title.clone())
}
}
impl std::fmt::Display for LossyChatTitle {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
LossyChatTitle::Title(title) => write!(f, "{}", title),
LossyChatTitle::Unknown => write!(f, "unknown"),
}
}
}
|