Timeline

Struct Timeline 

Source
pub struct Timeline {
    pub count: u32,
    pub next_cursor: Option<String>,
    pub loaded: bool,
    /* private fields */
}
Expand description

Helper struct to navigate collections of direct messages by tracking the status of Twitter’s cursor references.

The API of the Direct Message Timeline differs from the Tweet Timeline, in that Twitter returns a “cursor” ID instead of paging through results by asking for messages before or after a certain ID. It’s not a strict CursorIter, though, in that there is no “previous cursor” ID given by Twitter; messages are loaded one-way, from newest to oldest.

To start using a Timeline, call list to set one up. Before starting, you can call with_page_size to set how many messages to ask for at once. Then use start and next_page to load messages one page at a time.

let timeline = egg_mode::direct::list(&token).with_page_size(50);
let mut messages = timeline.start().await.unwrap();

while timeline.next_cursor.is_some() {
    let next_page = timeline.next_page().await.unwrap();
    messages.extend(next_page.response);
}

An adapter is provided which converts a Timeline into a futures::stream::Stream which yields one message at a time and lazily loads each page as needed. As the stream’s Item is a Result which can express the error caused by loading the next page, it also implements futures::stream::TryStream as well. The previous example can also be expressed like this:

use egg_mode::Response;
use egg_mode::direct::DirectMessage;
use futures::stream::TryStreamExt;
let timeline = egg_mode::direct::list(&token).with_page_size(50);
let messages = timeline.into_stream()
                       .try_collect::<Vec<Response<DirectMessage>>>()
                       .await
                       .unwrap();

In addition, an adapter is available which loads all available messages and sorts them into “conversations” between the authenticated user and other users. The into_conversations adapter loads all available messages and returns a DMConversations map after sorting them.

Fields§

§count: u32

The number of messages to request in a single page. The default is 20; the maximum is 50.

§next_cursor: Option<String>

The string ID that can be used to load the next page of results. A value of None indicates that either no messages have been loaded yet, or that the most recently loaded page is the last page of messages available.

§loaded: bool

Whether this Timeline has been called yet.

Implementations§

Source§

impl Timeline

Source

pub fn with_page_size(self, count: u32) -> Self

Builder function to set the page size. The default value for the page size is 20; the maximum allowed is 50.

Source

pub fn reset(&mut self)

Clears the saved cursor information on this Timeline.

Source

pub fn start( &mut self, ) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>> + '_

Clear the saved cursor information on this timeline, then return the most recent set of messages.

Source

pub fn next_page( &mut self, ) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>> + '_

Loads the next page of messages, setting the next_cursor to the one received from Twitter.

Source

pub fn into_stream( self, ) -> impl Stream<Item = Result<Response<DirectMessage>, Error>>

Converts this Timeline into a Stream of direct messages, which automatically loads the next page as needed.

Source

pub async fn into_conversations(self) -> Result<DMConversations, Error>

Loads all the direct messages from this Timeline and sorts them into a DMConversations map.

This adapter is a convenient way to sort all of a user’s messages (from the last 30 days) into a familiar user-interface pattern of a list of conversations between the authenticated user and a specific other user. This function first pulls all the available messages, then sorts them into a set of threads by matching them against which user the authenticated user is messaging.

If there are more messages available than can be loaded without hitting the rate limit (15 calls to the list endpoint per 15 minutes), then this function will stop once it receives a rate-limit error and sort the messages it received.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more