From: Simon Tatham Date: Mon, 1 Jan 2024 12:14:17 +0000 (+0000) Subject: Start of View Post Info. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=2357a937893efdfe30b9f6e8a2908196653c624b;p=mastodonochrome.git Start of View Post Info. Currently it just shows the post in the ordinary way, without all the extra detail. But it's plumbed through the menus, which is a start. --- diff --git a/src/activity_stack.rs b/src/activity_stack.rs index 0a78da1..604f3fa 100644 --- a/src/activity_stack.rs +++ b/src/activity_stack.rs @@ -4,6 +4,7 @@ pub enum NonUtilityActivity { HomeTimelineFile, PublicTimelineFile, LocalTimelineFile, + SinglePost(String), } #[derive(PartialEq, Eq, Debug, Clone)] @@ -25,6 +26,7 @@ pub enum UtilityActivity { #[derive(PartialEq, Eq, Debug, Clone)] pub enum OverlayActivity { GetUserToExamine, + GetPostIdToRead, } #[derive(PartialEq, Eq, Debug, Clone)] diff --git a/src/editor.rs b/src/editor.rs index 0e00ee6..87ca60b 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -1,6 +1,6 @@ use unicode_width::UnicodeWidthChar; -use super::activity_stack::UtilityActivity; +use super::activity_stack::{NonUtilityActivity, UtilityActivity}; use super::client::Client; use super::coloured_string::ColouredString; use super::tui::{ @@ -596,3 +596,25 @@ pub fn get_user_to_examine() -> Box { }) )) } + +pub fn get_post_id_to_read() -> Box { + Box::new(BottomLineEditorOverlay::new( + ColouredString::plain("View post with id: "), + Box::new(move |s, client| { + let s = s.trim(); + if s.is_empty() { + LogicalAction::PopOverlaySilent + } else { + match client.status_by_id(s) { + Ok(st) => LogicalAction::Goto( + NonUtilityActivity::SinglePost(st.id).into()), + + // FIXME: it would be nice to discriminate errors + // better here, and maybe return anything worse + // than 'post not found' to the Error Log + Err(_) => LogicalAction::PopOverlayBeep, + } + } + }) + )) +} diff --git a/src/file.rs b/src/file.rs index c9794d7..64e3724 100644 --- a/src/file.rs +++ b/src/file.rs @@ -647,3 +647,27 @@ pub fn examine_user(client: &mut Client, account_id: &str) -> client, SingletonSource::new(ac.id), title)?; Ok(Box::new(file)) } + +struct DetailedStatusFileType {} +impl FileType for DetailedStatusFileType { + type Item = StatusDisplay; + + fn get_from_client(id: &str, client: &mut Client) -> + Result + { + let st = client.status_by_id(&id)?; + Ok(StatusDisplay::new(st.clone(), client)) // FIXME: .set_detailed() + } +} + +pub fn view_single_post(client: &mut Client, status_id: &str) -> + Result, ClientError> +{ + let st = client.status_by_id(status_id)?; + let title = ColouredString::uniform( + &format!("Information about post {}", st.id), 'H'); + + let file = File::::new( + client, SingletonSource::new(st.id), title)?; + Ok(Box::new(file)) +} diff --git a/src/menu.rs b/src/menu.rs index 4bc733f..1143a83 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -198,8 +198,8 @@ pub fn main_menu() -> Box { menu.add_action(Pr('#'), "Timeline for a #hashtag", LogicalAction::NYI); menu.add_blank_line(); - menu.add_action(Pr('I'), "View a post by its ID", - LogicalAction::NYI); + menu.add_action(Pr('I'), "View a post by its ID", LogicalAction::Goto( + OverlayActivity::GetPostIdToRead.into())); menu.add_blank_line(); menu.add_action(Pr('C'), "Compose a post", LogicalAction::NYI); diff --git a/src/tui.rs b/src/tui.rs index 027d742..1be8273 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -443,8 +443,12 @@ fn new_activity_state(activity: Activity, client: &mut Client) -> ego_log(client), Activity::Overlay(OverlayActivity::GetUserToExamine) => Ok(get_user_to_examine()), + Activity::Overlay(OverlayActivity::GetPostIdToRead) => + Ok(get_post_id_to_read()), Activity::Util(UtilityActivity::ExamineUser(ref name)) => examine_user(client, name), + Activity::NonUtil(NonUtilityActivity::SinglePost(ref id)) => + view_single_post(client, id), _ => todo!(), };