[−][src]Struct egg_mode::direct::ConversationTimeline
Helper struct to load both sent and received direct messages, pre-sorting them into conversations by their recipient.
This timeline loader is meant to get around a limitation of the direct message API endpoints:
Twitter only gives endpoints to load all the messages sent by the authenticated user, or all
the messages received by the authenticated user. However, the common user interface for DMs
is to separate them by the other account in the conversation. This loader is a higher-level
wrapper over the direct sent and received calls to achieve this interface without library
users having to implement it themselves.
Much like Timeline, simply receiving a ConversationTimeline from conversations does not
load any messages on its own. This is to allow setting the page size before loading the first
batch of messages.
ConversationTimeline keeps a cache of all the messages its loaded, and updates this during
calls to Twitter. Any calls on this timeline that generate a ConversationFuture will take
ownership of the ConversationTimeline so that it can update this cache. The Future will
return the ConversationTimeline on success. To view the current cache, use the
conversations field.
There are two methods to load messages, and they operate by extending the cache by loading messages either older or newer than the extent of the cache.
NOTE: Twitter has different API limitations for sent versus received messages. You can only load the most recent 200 received messages through the public API, but you can load up to 800 sent messages. This can create some strange user-interface if a user has some old conversations, as they can only see their own side of the conversation this way. If you'd like to load as many messages as possible, both API endpoints have a per-call limit of 200. Setting the page size to 200 prior to loading messages allows you to use one function call to load a fairly-complete view of the user's conversations.
Example
let mut conversations = egg_mode::direct::conversations(&token); // newest() and oldest() consume the Timeline and give it back on success, so assign it back // when it's done conversations = conversations.newest().await.unwrap(); for (id, convo) in &conversations.conversations { let user = egg_mode::user::show(*id, &token).await.unwrap(); println!("Conversation with @{}", user.screen_name); for msg in convo { println!("<@{}> {}", msg.sender_screen_name, msg.text); } }
Fields
last_sent: Option<u64>The message ID of the most recent sent message in the current conversation set.
last_received: Option<u64>The message ID of the most recent received message in the current conversation set.
first_sent: Option<u64>The message ID of the oldest sent message in the current conversation set.
first_received: Option<u64>The message ID of the oldest received message in the current conversation set.
count: u32The number of messages loaded per API call.
conversations: DMConversationsThe conversation threads that have been loaded so far.
Methods
impl ConversationTimeline[src]
pub fn with_page_size(self, page_size: u32) -> ConversationTimeline[src]
Builder function to set the number of messages pulled in a single request.
pub async fn newest(self) -> Result<ConversationTimeline, Error>[src]
Load messages newer than the currently-loaded set, or the newset set if no messages have
been loaded yet. The complete conversation set can be viewed from the ConversationTimeline
after it is finished loading.
pub fn next(self) -> impl Future<Output = Result<ConversationTimeline, Error>>[src]
Load messages older than the currently-loaded set, or the newest set if no messages have
been loaded. The complete conversation set can be viewed from the ConversationTimeline
after it is finished loading.
Auto Trait Implementations
impl RefUnwindSafe for ConversationTimeline
impl Send for ConversationTimeline
impl Sync for ConversationTimeline
impl Unpin for ConversationTimeline
impl UnwindSafe for ConversationTimeline
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>,