Skip to content

Commit f5c93da

Browse files
committed
Fix User usages after refactor
1 parent c4c79ff commit f5c93da

File tree

2 files changed

+67
-15
lines changed

2 files changed

+67
-15
lines changed

lib/grammers-client/src/types/chat/mod.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ impl Chat {
105105

106106
pub(crate) fn unpack(packed: PackedChat) -> Self {
107107
match packed.ty {
108-
PackedType::User => {
109-
let mut user = User::from_raw(tl::types::UserEmpty { id: packed.id }.into());
110-
user.raw.access_hash = packed.access_hash;
111-
Chat::User(user)
112-
}
113-
PackedType::Bot => {
114-
let mut user = User::from_raw(tl::types::UserEmpty { id: packed.id }.into());
115-
user.raw.access_hash = packed.access_hash;
116-
user.raw.bot = true;
117-
Chat::User(user)
118-
}
108+
PackedType::User => Chat::User(User::empty_with_hash_and_bot(
109+
packed.id,
110+
packed.access_hash,
111+
false,
112+
)),
113+
PackedType::Bot => Chat::User(User::empty_with_hash_and_bot(
114+
packed.id,
115+
packed.access_hash,
116+
true,
117+
)),
119118
PackedType::Chat => Chat::Group(Group::from_raw(
120119
tl::types::ChatEmpty { id: packed.id }.into(),
121120
)),
@@ -180,9 +179,12 @@ impl Chat {
180179
// is missing).
181180
pub(crate) fn get_min_hash_ref(&mut self) -> Option<(&mut bool, &mut i64)> {
182181
match self {
183-
Self::User(user) => match (&mut user.raw.min, user.raw.access_hash.as_mut()) {
184-
(m @ true, Some(ah)) => Some((m, ah)),
185-
_ => None,
182+
Self::User(user) => match &mut user.raw {
183+
tl::enums::User::User(raw) => match (&mut raw.min, raw.access_hash.as_mut()) {
184+
(m @ true, Some(ah)) => Some((m, ah)),
185+
_ => None,
186+
},
187+
tl::enums::User::Empty(_) => None,
186188
},
187189
// Small group chats don't have an `access_hash` to begin with.
188190
Self::Group(_group) => None,

lib/grammers-client/src/types/chat/user.rs

+51-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,57 @@ impl User {
7777
Self { raw: user }
7878
}
7979

80-
fn user(&self) -> Option<&tl::types::User> {
80+
pub(crate) fn empty_with_hash_and_bot(id: i64, access_hash: Option<i64>, bot: bool) -> Self {
81+
Self {
82+
raw: tl::enums::User::User(tl::types::User {
83+
is_self: false,
84+
contact: false,
85+
mutual_contact: false,
86+
deleted: false,
87+
bot,
88+
bot_chat_history: false,
89+
bot_nochats: false,
90+
verified: false,
91+
restricted: false,
92+
min: false, // not min because the input hash is not a min hash
93+
bot_inline_geo: false,
94+
support: false,
95+
scam: false,
96+
apply_min_photo: false,
97+
fake: false,
98+
bot_attach_menu: false,
99+
premium: false,
100+
attach_menu_enabled: false,
101+
bot_can_edit: false,
102+
close_friend: false,
103+
stories_hidden: false,
104+
stories_unavailable: true,
105+
contact_require_premium: false,
106+
bot_business: false,
107+
bot_has_main_app: false,
108+
id,
109+
access_hash,
110+
first_name: None,
111+
last_name: None,
112+
username: None,
113+
phone: None,
114+
photo: None,
115+
status: None,
116+
bot_info_version: None,
117+
restriction_reason: None,
118+
bot_inline_placeholder: None,
119+
lang_code: None,
120+
emoji_status: None,
121+
usernames: None,
122+
stories_max_id: None,
123+
color: None,
124+
profile_color: None,
125+
bot_active_users: None,
126+
}),
127+
}
128+
}
129+
130+
pub(crate) fn user(&self) -> Option<&tl::types::User> {
81131
match &self.raw {
82132
tl::enums::User::User(u) => Some(u),
83133
tl::enums::User::Empty(_) => None,

0 commit comments

Comments
 (0)