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

Creation, querying, and setting base state.

source

pub fn new() -> Self

Create a new, empty MessageBox.

This is the only way it may return true from MessageBox::is_empty.

source

pub fn load(state: UpdateState) -> Self

Create a MessageBox from a previously known update state.

source

pub fn session_state(&self) -> UpdateState

Return the current state in a format that sessions understand.

This should be used for persisting the state.

source

pub fn is_empty(&self) -> bool

Return true if the message box is empty and has no state yet.

source

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.

source

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.

source

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

source

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.

source

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

Getting and applying account difference.

source

pub fn get_difference(&mut self) -> Option<GetDifference>

Return the request that needs to be made to get the difference, if any.

source

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

Getting and applying channel difference.

source

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.

source

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.

source

pub fn end_channel_difference( &mut self, request: &GetChannelDifference, reason: PrematureEndReason )

Trait Implementations§

source§

impl Debug for MessageBox

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.