Skip to content

Commit

Permalink
Add Chat::from_raw (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin authored Jun 9, 2024
1 parent c8eb83c commit a6a5f9a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/grammers-client/src/client/chats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl Client {
channel_id: chat_id,
}) => chats
.into_iter()
.map(Chat::from_chat)
.map(Chat::from_raw)
.find(|chat| chat.id() == chat_id),
})
}
Expand Down Expand Up @@ -651,7 +651,7 @@ impl Client {
if res.len() != 1 {
panic!("fetching only one chat should exactly return one chat");
}
Chat::from_chat(res.pop().unwrap())
Chat::from_raw(res.pop().unwrap())
}
PackedType::Megagroup | PackedType::Broadcast | PackedType::Gigagroup => {
let mut res = match self
Expand All @@ -669,7 +669,7 @@ impl Client {
if res.len() != 1 {
panic!("fetching only one chat should exactly return one chat");
}
Chat::from_chat(res.pop().unwrap())
Chat::from_raw(res.pop().unwrap())
}
})
}
Expand Down Expand Up @@ -846,7 +846,7 @@ impl Client {
};

match update_chat {
Some(chats) if !chats.is_empty() => Ok(Some(Chat::from_chat(chats[0].clone()))),
Some(chats) if !chats.is_empty() => Ok(Some(Chat::from_raw(chats[0].clone()))),
Some(chats) if chats.is_empty() => Ok(None),
None => Ok(None),
Some(_) => Ok(None),
Expand Down
12 changes: 11 additions & 1 deletion lib/grammers-client/src/types/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Chat {
Self::User(User::from_raw(user))
}

pub(crate) fn from_chat(chat: tl::enums::Chat) -> Self {
fn _from_raw(chat: tl::enums::Chat) -> Self {
use tl::enums::Chat as C;

match chat {
Expand Down Expand Up @@ -205,6 +205,16 @@ impl Chat {
}),
}
}

#[cfg(feature = "unstable_raw")]
pub fn from_raw(chat: tl::enums::Chat) -> Self {
Self::_from_raw(chat)
}

#[cfg(not(feature = "unstable_raw"))]
pub(crate) fn from_raw(chat: tl::enums::Chat) -> Self {
Self::_from_raw(chat)
}
}

impl From<Chat> for PackedChat {
Expand Down
2 changes: 1 addition & 1 deletion lib/grammers-client/src/types/chat_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ChatMap {
map: users
.into_iter()
.map(Chat::from_user)
.chain(chats.into_iter().map(Chat::from_chat))
.chain(chats.into_iter().map(Chat::from_raw))
.map(|chat| ((&chat.pack().to_peer()).into(), chat))
.collect(),
})
Expand Down

0 comments on commit a6a5f9a

Please sign in to comment.