Struct grammers_session::MessageBox
source · pub struct MessageBox { /* private fields */ }
Expand description
Represents a “message box” (event pts
for a specific entry).
See https://core.telegram.org/api/updates#message-related-event-sequences.
Implementations§
source§impl MessageBox
impl MessageBox
Creation, querying, and setting base state.
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty MessageBox
.
This is the only way it may return true
from MessageBox::is_empty
.
sourcepub fn load(state: UpdateState) -> Self
pub fn load(state: UpdateState) -> Self
Create a MessageBox
from a previously known update state.
sourcepub fn session_state(&self) -> UpdateState
pub fn session_state(&self) -> UpdateState
Return the current state in a format that sessions understand.
This should be used for persisting the state.
sourcepub fn check_deadlines(&mut self) -> Instant
pub fn check_deadlines(&mut self) -> Instant
Return the next deadline when receiving updates should timeout.
If a deadline expired, the corresponding entries will be marked as needing to get its difference. While there are entries pending of getting their difference, this method returns the current instant.
sourcepub fn set_state(&mut self, state: State)
pub fn set_state(&mut self, state: State)
Sets the update state.
Should be called right after login if MessageBox::new
was used, otherwise undesirable
updates will be fetched.
sourcepub fn try_set_channel_state(&mut self, id: i64, pts: i32)
pub fn try_set_channel_state(&mut self, id: i64, pts: i32)
Like MessageBox::set_state
, but for channels. Useful when getting dialogs.
The update state will only be updated if no entry was known previously.
source§impl MessageBox
impl MessageBox
sourcepub fn ensure_known_peer_hashes(
&mut self,
updates: &Updates,
chat_hashes: &mut ChatHashCache
) -> Result<(), Gap>
pub fn ensure_known_peer_hashes( &mut self, updates: &Updates, chat_hashes: &mut ChatHashCache ) -> Result<(), Gap>
Make sure all peer hashes contained in the update are known by the client (either by checking if they were already known, or by extending the hash cache with those that were not known).
If a peer is found, but it doesn’t contain a non-min
hash and no hash for it
is known, it is treated as a gap.
sourcepub fn process_updates(
&mut self,
updates: Updates,
chat_hashes: &ChatHashCache
) -> Result<(Vec<Update>, Vec<User>, Vec<Chat>), Gap>
pub fn process_updates( &mut self, updates: Updates, chat_hashes: &ChatHashCache ) -> Result<(Vec<Update>, Vec<User>, Vec<Chat>), Gap>
Process an update and return what should be done with it.
Updates corresponding to entries for which their difference is currently being fetched will be ignored. While according to the updates’ documentation:
Implementations [have] to postpone updates received via the socket while filling gaps in the event and
Update
sequences, as well as avoid filling gaps in the same sequence.
In practice, these updates should have also been retrieved through getting difference.
source§impl MessageBox
impl MessageBox
Getting and applying account difference.
sourcepub fn get_difference(&mut self) -> Option<GetDifference>
pub fn get_difference(&mut self) -> Option<GetDifference>
Return the request that needs to be made to get the difference, if any.
sourcepub fn apply_difference(
&mut self,
difference: Difference,
chat_hashes: &mut ChatHashCache
) -> (Vec<Update>, Vec<User>, Vec<Chat>)
pub fn apply_difference( &mut self, difference: Difference, chat_hashes: &mut ChatHashCache ) -> (Vec<Update>, Vec<User>, Vec<Chat>)
Similar to MessageBox::process_updates
, but using the result from getting difference.
source§impl MessageBox
impl MessageBox
Getting and applying channel difference.
sourcepub fn get_channel_difference(
&mut self,
chat_hashes: &ChatHashCache
) -> Option<GetChannelDifference>
pub fn get_channel_difference( &mut self, chat_hashes: &ChatHashCache ) -> Option<GetChannelDifference>
Return the request that needs to be made to get a channel’s difference, if any.
sourcepub fn apply_channel_difference(
&mut self,
request: GetChannelDifference,
difference: ChannelDifference,
chat_hashes: &mut ChatHashCache
) -> (Vec<Update>, Vec<User>, Vec<Chat>)
pub fn apply_channel_difference( &mut self, request: GetChannelDifference, difference: ChannelDifference, chat_hashes: &mut ChatHashCache ) -> (Vec<Update>, Vec<User>, Vec<Chat>)
Similar to MessageBox::process_updates
, but using the result from getting difference.