Skip to main content

ferogram/client/
settings.rs

1// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
2//
3// ferogram: async Telegram MTProto client in Rust
4// https://github.com/ankit-chaubey/ferogram
5//
6// Licensed under either the MIT License or the Apache License 2.0.
7// See the LICENSE-MIT or LICENSE-APACHE file in this repository:
8// https://github.com/ankit-chaubey/ferogram
9//
10// Feel free to use, modify, and share this code.
11// Please keep this notice when redistributing.
12
13use crate::*;
14#[allow(unused_imports)]
15use crate::{
16    InputMessage, InvocationError, PeerRef,
17    dialog::{Dialog, DialogIter, MessageIter},
18    inline_iter, media, participants, search, update,
19};
20use ferogram_tl_types::{Cursor, Deserializable};
21
22impl Client {
23    /// Mark all unread reactions in a chat as read.
24    pub async fn read_reactions(&self, peer: impl Into<PeerRef>) -> Result<(), InvocationError> {
25        let peer = peer.into().resolve(self).await?;
26        let input_peer = self.inner.peer_cache.read().await.peer_to_input(&peer)?;
27        let req = tl::functions::messages::ReadReactions {
28            peer: input_peer,
29            top_msg_id: None,
30            saved_peer_id: None,
31        };
32        self.rpc_write(&req).await
33    }
34
35    /// Clear the recent reactions list shown in the reaction picker.
36    pub async fn clear_recent_reactions(&self) -> Result<(), InvocationError> {
37        let req = tl::functions::messages::ClearRecentReactions {};
38        self.rpc_write(&req).await
39    }
40
41    /// Get the approximate number of online members in a group or channel.
42    pub async fn get_online_count(&self, peer: impl Into<PeerRef>) -> Result<i32, InvocationError> {
43        let peer = peer.into().resolve(self).await?;
44        let input_peer = self.inner.peer_cache.read().await.peer_to_input(&peer)?;
45        let req = tl::functions::messages::GetOnlines { peer: input_peer };
46        let body: Vec<u8> = self.rpc_call_raw(&req).await?;
47        let mut cur = Cursor::from_slice(&body);
48        let tl::enums::ChatOnlines::ChatOnlines(result) =
49            tl::enums::ChatOnlines::deserialize(&mut cur)?;
50        Ok(result.onlines)
51    }
52}