chiark / gitweb /
Start of View Post Info.
authorSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 12:14:17 +0000 (12:14 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 12:14:17 +0000 (12:14 +0000)
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.

src/activity_stack.rs
src/editor.rs
src/file.rs
src/menu.rs
src/tui.rs

index 0a78da14ccd68964320e99910e1acea2df247e04..604f3fa55bcad59cc7c3ce2f9222f33642307ee1 100644 (file)
@@ -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)]
index 0e00ee63d19dbd619b4a6332a9e368e506163560..87ca60b484f0fa6088242b95dd1c3850bcd9fa69 100644 (file)
@@ -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<dyn ActivityState> {
         })
     ))
 }
+
+pub fn get_post_id_to_read() -> Box<dyn ActivityState> {
+    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,
+                }
+            }
+        })
+    ))
+}
index c9794d75155f7b5bd83c2cf2039eebe830db6293..64e3724c44dc31639c91b9da1c5077bdee4a7ef5 100644 (file)
@@ -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<Self::Item, ClientError>
+    {
+        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<Box<dyn ActivityState>, ClientError>
+{
+    let st = client.status_by_id(status_id)?;
+    let title = ColouredString::uniform(
+        &format!("Information about post {}", st.id), 'H');
+
+    let file = File::<DetailedStatusFileType, _>::new(
+        client, SingletonSource::new(st.id), title)?;
+    Ok(Box::new(file))
+}
index 4bc733f0e3e433838724fc169df8d6f5a02d86bc..1143a830bfd2327c97aa1be00afc8dc4c4a0b690 100644 (file)
@@ -198,8 +198,8 @@ pub fn main_menu() -> Box<dyn ActivityState> {
     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);
index 027d742afb601ceaddb06a0561fa0529f62d469b..1be8273579a6ded9522d23270cb5994e1c71b207 100644 (file)
@@ -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!(),
     };