Struct egg_mode::direct::Timeline
[−]
[src]
pub struct Timeline<'a> { pub count: i32, pub max_id: Option<u64>, pub min_id: Option<u64>, // some fields omitted }
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, &handle) .with_page_size(10); for dm in &core.run(timeline.start()).unwrap() { 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 &core.run(timeline.older(None)).unwrap() { 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, &handle) .with_page_size(10); core.run(timeline.start()).unwrap(); //keep the max_id for later let reload_id = timeline.max_id.unwrap(); //simulate scrolling down a little bit core.run(timeline.older(None)).unwrap(); core.run(timeline.older(None)).unwrap(); //reload the timeline with only what's new timeline.reset(); core.run(timeline.older(Some(reload_id))).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: i32
The 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<'a> Timeline<'a>
[src]
fn reset(&mut self)
[src]
Clear the saved IDs on this timeline.
fn start<'s>(&'s mut self) -> TimelineFuture<'s, 'a>
[src]
Clear the saved IDs on this timeline, and return the most recent set of messages.
fn older<'s>(&'s mut self, since_id: Option<u64>) -> TimelineFuture<'s, 'a>
[src]
Return the set of DMs older than the last set pulled, optionally placing a minimum DM ID to bound with.
fn newer<'s>(&'s mut self, max_id: Option<u64>) -> TimelineFuture<'s, 'a>
[src]
Return the set of DMs newer than the last set pulled, optionally placing a maximum DM ID to bound with.
fn call(
&self,
since_id: Option<u64>,
max_id: Option<u64>
) -> FutureResponse<'a, Vec<DirectMessage>>
[src]
&self,
since_id: Option<u64>,
max_id: Option<u64>
) -> FutureResponse<'a, Vec<DirectMessage>>
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.
fn with_page_size(self, page_size: i32) -> Self
[src]
Helper builder function to set the page size.