[−][src]Struct egg_mode::direct::Timeline
Helper struct to navigate collections of direct messages by requesting DMs older or newer than certain IDs.
Using a Timeline to navigate collections of DMs allows you to efficiently cursor through a collection and only load in the messages you need.
To begin, call a method that returns a Timeline, optionally set the page size, and call
start to load the first page of results:
let mut timeline = egg_mode::direct::received(&token) .with_page_size(10); for dm in timeline.start().await.unwrap().iter() { println!("<@{}> {}", dm.sender_screen_name, dm.text); }
If you need to load the next set of messages, call older, which will automatically update the
IDs it tracks:
for dm in timeline.older(None).await.unwrap().iter() { println!("<@{}> {}", dm.sender_screen_name, dm.text); }
...and similarly for newer, which operates in a similar fashion.
If you want to start afresh and reload the newest set of DMs again, you can call start again,
which will clear the tracked IDs before loading the newest set of messages. However, if you've
been storing these messages as you go, and already know the newest ID you have on hand, you can
load only those messages you need like this:
let mut timeline = egg_mode::direct::received(&token) .with_page_size(10); timeline.start().await.unwrap(); //keep the max_id for later let reload_id = timeline.max_id.unwrap(); //simulate scrolling down a little bit timeline.older(None).await.unwrap(); timeline.older(None).await.unwrap(); //reload the timeline with only what's new timeline.reset(); timeline.older(Some(reload_id)).await.unwrap();
Here, the argument to older means "older than what I just returned, but newer than the given
ID". Since we cleared the tracked IDs with reset, that turns into "the newest DMs available
that were sent after the given ID". The earlier invocations of older with None do not place
a bound on the DMs it loads. newer operates in a similar fashion with its argument, saying
"newer than what I just returned, but not newer than this given ID". When called like this,
it's possible for these methods to return nothing, which will also clear the Timeline's
tracked IDs.
If you want to manually pull messages between certain IDs, the baseline call function can do
that for you. Keep in mind, though, that call doesn't update the min_id or max_id fields,
so you'll have to set those yourself if you want to follow up with older or newer.
Fields
count: i32The maximum number of messages to return in a single call. Twitter doesn't guarantee returning exactly this number, as suspended or deleted content is removed after retrieving the initial collection of messages.
max_id: Option<u64>The largest/most recent DM ID returned in the last call to start, older, or newer.
min_id: Option<u64>The smallest/oldest DM ID returned in the last call to start, older, or newer.
Methods
impl Timeline[src]
pub fn reset(&mut self)[src]
Clear the saved IDs on this timeline.
pub fn start<'s>(
&'s mut self
) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>> + 's[src]
&'s mut self
) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>> + 's
Clear the saved IDs on this timeline, and return the most recent set of messages.
pub fn older<'s>(
&'s mut self,
since_id: Option<u64>
) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>> + 's[src]
&'s mut self,
since_id: Option<u64>
) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>> + 's
Return the set of DMs older than the last set pulled, optionally placing a minimum DM ID to bound with.
pub fn newer<'s>(
&'s mut self,
max_id: Option<u64>
) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>> + 's[src]
&'s mut self,
max_id: Option<u64>
) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>> + 's
Return the set of DMs newer than the last set pulled, optionally placing a maximum DM ID to bound with.
pub fn call(
&self,
since_id: Option<u64>,
max_id: Option<u64>
) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>>[src]
&self,
since_id: Option<u64>,
max_id: Option<u64>
) -> impl Future<Output = Result<Response<Vec<DirectMessage>>, Error>>
Return the set of DMs between the IDs given.
Note that the range is not fully inclusive; the message ID given by since_id will not be
returned, but the message with max_id will be returned.
If the range of DMs given by the IDs would return more than self.count, the newest set
of messages will be returned.
pub fn with_page_size(self, page_size: i32) -> Self[src]
Helper builder function to set the page size.
Auto Trait Implementations
impl RefUnwindSafe for Timeline
impl Send for Timeline
impl Sync for Timeline
impl Unpin for Timeline
impl UnwindSafe for Timeline
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,