aboutsummaryrefslogtreecommitdiff
path: root/src/display/mod.rs
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-12-31 04:49:49 -0800
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-12-31 04:49:49 -0800
commitf03dc86b2af24b133bc85f05941c9819ce6cd83b (patch)
tree9b4ade0ad1d036df2c5f50016720d48355f50e5e /src/display/mod.rs
parent27bf6925db5fed3936e03a197bf256ac3e860a0b (diff)
clean up DM support, add thing to send DMsdm-fixup
Diffstat (limited to 'src/display/mod.rs')
-rw-r--r--src/display/mod.rs19
1 files changed, 14 insertions, 5 deletions
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<TweetId>),
Event(tw::events::Event),
- DM(String),
+ DM(String, String, String),
User(tw::user::User),
Text(Vec<String>)
}
@@ -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<String> {
+ 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<u16>) -> Vec<String> {
let mut lines = render_twete_no_recurse(twete_id, tweeter, display_info, width);
match tweeter.retrieve_tweet(twete_id).map(|x| x.clone()) {