From 935c78ce7d2aaabca269d81cff3459cef1084fbc Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 31 Dec 2017 04:49:49 -0800 Subject: clean up DM support, add thing to send DMs --- src/display/mod.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/display') diff --git a/src/display/mod.rs b/src/display/mod.rs index 6115472..098bb1c 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -27,7 +27,7 @@ pub enum Infos { TweetWithContext(TweetId, String), Thread(Vec), Event(tw::events::Event), - DM(String), + DM(String, String, String), User(tw::user::User), Text(Vec) } @@ -549,10 +549,8 @@ pub fn paint(tweeter: &::tw::TwitterCache, display_info: &mut DisplayInfo) -> Re }; wrapped.into_iter().rev().collect() }, - Infos::DM(msg) => { - let mut lines = vec![format!("{}{}{} DM:", cursor::Goto(1, height - h), clear::CurrentLine, "from")]; - lines.push(msg); - lines + Infos::DM(msg, from_id, to_id) => { + into_display_lines(render_dm(msg, from_id, to_id, tweeter, display_info, width), width).into_iter().rev().collect() } Infos::User(user) => { vec![ @@ -703,6 +701,17 @@ fn short_display_summary(u: &tw::user::User) -> String { ) } +pub fn render_dm(text: String, from_id: String, to_id: String, tweeter: &tw::TwitterCache, display_info: &mut DisplayInfo, width: u16) -> Vec { + let from_user = tweeter.retrieve_user(&from_id).unwrap().clone(); + let to_user = tweeter.retrieve_user(&to_id).unwrap().clone(); + + let mut lines = pad_lines(into_display_lines(text.split("\n").map(|x| x.to_owned()).collect(), width - 2), " "); + let envelope = format!("DM: {} -> {}", short_display_summary(&from_user), short_display_summary(&to_user)); + + lines.insert(0, envelope); + lines +} + pub fn render_twete(twete_id: &TweetId, tweeter: &tw::TwitterCache, display_info: &mut DisplayInfo, width: Option) -> Vec { let mut lines = render_twete_no_recurse(twete_id, tweeter, display_info, width); match tweeter.retrieve_tweet(twete_id).map(|x| x.clone()) { -- cgit v1.1