let verb = if enable {"reblog"} else {"unreblog"};
self.fave_boost_post(id, verb)
}
+
+ pub fn status_context(&mut self, id: &str) -> Result<Context, ClientError>
+ {
+ let (url, req) = self.api_request(Req::get(
+ &format!("v1/statuses/{id}/context")))?;
+ let rsp = req.send()?;
+ let rspstatus = rsp.status();
+ let ctx: Context = if !rspstatus.is_success() {
+ Err(ClientError::UrlError(url.clone(), rspstatus.to_string()))
+ } else {
+ match serde_json::from_str(&rsp.text()?) {
+ Ok(st) => Ok(st),
+ Err(e) => {
+ Err(ClientError::UrlError(url.clone(), e.to_string()))
+ }
+ }
+ }?;
+ for st in &ctx.ancestors {
+ self.cache_status(st);
+ }
+ for st in &ctx.descendants {
+ self.cache_status(st);
+ }
+ Ok(ctx)
+ }
}
StatusInfo,
Favourite,
Boost,
+ Thread,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Err(_) => LogicalAction::Beep,
}
}
+ SelectionPurpose::Thread => LogicalAction::Goto(
+ UtilityActivity::ThreadFile(id, alt).into()),
}
} else {
LogicalAction::Beep
fs.add(Space, "Boost", 98)
}
}
+ SelectionPurpose::Thread => {
+ fs.add(Space, "Thread Context", 98)
+ .add(Pr('F'), "Full Thread", 97)
+ }
};
fs.add(Pr('+'), "Down", 99)
.add(Pr('-'), "Up", 99)
}
}
+ Pr('t') | Pr('T') => {
+ if Type::Item::can_highlight(HighlightType::Status) {
+ self.start_selection(HighlightType::Status,
+ SelectionPurpose::Thread,
+ client)
+ } else {
+ LogicalAction::Nothing
+ }
+ }
+
_ => LogicalAction::Nothing,
}
UIMode::Select(_, purpose) => match key {
self.complete_selection(client, true),
_ => LogicalAction::Nothing,
}
+ Pr('f') | Pr('F') => match purpose {
+ SelectionPurpose::Thread =>
+ self.complete_selection(client, true),
+ _ => LogicalAction::Nothing,
+ }
Pr('-') | Up => self.selection_up(client),
Pr('+') | Down => self.selection_down(client),
Pr('q') | Pr('Q') => self.abort_selection(),
client, StaticSource::singleton(st.id), title)?;
Ok(Box::new(file))
}
+
+pub fn view_thread(client: &mut Client, start_id: &str, full: bool) ->
+ Result<Box<dyn ActivityState>, ClientError>
+{
+ let mut make_vec = |id: &str| -> Result<Vec<String>, ClientError> {
+ let ctx = client.status_context(id)?;
+ let mut v = Vec::new();
+ for st in &ctx.ancestors {
+ v.push(st.id.to_owned());
+ }
+ v.push(id.to_owned());
+ for st in &ctx.descendants {
+ v.push(st.id.to_owned());
+ }
+ Ok(v)
+ };
+
+ let ids = make_vec(start_id)?;
+ let is_full = ids[0] == start_id;
+ let (ids, is_full) = if full && !is_full {
+ (make_vec(&ids[0])?, true)
+ } else {
+ (ids, is_full)
+ };
+
+ let title = if is_full {
+ format!("Full thread of post {}", start_id)
+ } else {
+ format!("Thread context of post {}", start_id)
+ };
+ let title = ColouredString::uniform(&title, 'H');
+
+ let file = File::<StatusFeedType, _>::new(
+ client, StaticSource::vector(ids), title)?;
+ Ok(Box::new(file))
+}