chiark / gitweb /
Fill in the rest of View Post Info.
authorSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 13:04:35 +0000 (13:04 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 13:04:35 +0000 (13:04 +0000)
src/file.rs
src/text.rs

index 64e3724c44dc31639c91b9da1c5077bdee4a7ef5..a0116afedd74993e7eb7081970a59558386d8241 100644 (file)
@@ -650,13 +650,13 @@ pub fn examine_user(client: &mut Client, account_id: &str) ->
 
 struct DetailedStatusFileType {}
 impl FileType for DetailedStatusFileType {
-    type Item = StatusDisplay;
+    type Item = DetailedStatusDisplay;
 
     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()
+        Ok(DetailedStatusDisplay::new(st.clone(), client))
     }
 }
 
index fefb89dcd1a9f5142df7847411e2185a19befcef..2bc84362fd795e9fae4740e4a99dca681ddee7ee 100644 (file)
@@ -1478,6 +1478,191 @@ impl TextFragment for StatusDisplay {
     }
 }
 
+pub struct DetailedStatusDisplay {
+    sd: StatusDisplay,
+    id: Paragraph,
+    webstatus: Option<Paragraph>,
+    creation: Paragraph,
+    lastedit: Paragraph,
+    reply_to: Paragraph,
+    reply_to_user: Paragraph,
+    language: Paragraph,
+    visibility: Paragraph,
+    sensitive: Paragraph,
+    spoiler: Paragraph,
+    replies: Paragraph,
+    boosts: Paragraph,
+    favourites: Paragraph,
+    mentions: Vec<Paragraph>,
+    client_name: Paragraph,
+    client_url: Paragraph,
+    sep: SeparatorLine,
+    blank: BlankLine,
+}
+
+impl DetailedStatusDisplay {
+    pub fn new(st: Status, client: &mut Client) -> Self {
+        let id = Paragraph::new()
+            .add(&ColouredString::plain("Post id: "))
+            .add(&ColouredString::plain(&st.id));
+        let webstatus = st.url.as_ref().map(
+            |s| Paragraph::new()
+                .add(&ColouredString::plain("On the web: "))
+                .add(&ColouredString::uniform(&client.fq(s), 'u')));
+
+        let creation = Paragraph::new()
+            .add(&ColouredString::plain("Creation time: "))
+            .add(&ColouredString::plain(&format_date(st.created_at)));
+        let lastedit = Paragraph::new()
+            .add(&ColouredString::plain("Last edit time: "))
+            .add(&st.edited_at.map_or_else(
+                || ColouredString::uniform("none", '0'),
+                |date| ColouredString::plain(&format_date(date))));
+        let reply_to = Paragraph::new()
+            .add(&ColouredString::plain("Reply to post: "))
+            .add(&st.in_reply_to_id.as_ref().map_or_else(
+                || ColouredString::uniform("none", '0'),
+                |s| ColouredString::plain(s)));
+        let reply_to_user = Paragraph::new()
+            .add(&ColouredString::plain("Reply to account: "))
+            .add(&st.in_reply_to_account_id.as_ref().map_or_else(
+                || ColouredString::uniform("none", '0'),
+                |s| ColouredString::plain(s)));
+
+        let language = Paragraph::new()
+            .add(&ColouredString::plain("Language: "))
+            .add(&st.language.as_ref().map_or_else(
+                || ColouredString::uniform("none", '0'),
+                |s| ColouredString::plain(s)));
+        let vis_str = match st.visibility {
+            Visibility::Public => ColouredString::uniform("public", 'f'),
+            Visibility::Unlisted => ColouredString::uniform("unlisted", 'r'),
+            Visibility::Private => ColouredString::uniform("private", 'r'),
+            Visibility::Direct => ColouredString::uniform("direct", 'r'),
+        };
+        let visibility = Paragraph::new()
+            .add(&ColouredString::plain("Visibility: "))
+            .add(&vis_str);
+        let sens_str = match st.sensitive {
+            false => ColouredString::uniform("no", 'f'),
+            true => ColouredString::uniform("yes", 'r'),
+        };
+        let sensitive = Paragraph::new()
+            .add(&ColouredString::plain("Sensitive: "))
+            .add(&sens_str);
+        let opt_spoiler = if st.spoiler_text.is_empty() {
+            None
+        } else {
+            Some(&st.spoiler_text)
+        };
+        let spoiler = Paragraph::new().set_indent(0, 2)
+            .add(&ColouredString::plain("Spoiler text: "))
+            .add(&opt_spoiler.as_ref().map_or_else(
+                || ColouredString::uniform("none", '0'),
+                |s| ColouredString::plain(s)));
+
+        let replies = Paragraph::new()
+            .add(&ColouredString::plain(
+                &format!("Replies: {}", st.replies_count)));
+        let boosts = Paragraph::new()
+            .add(&ColouredString::plain(
+                &format!("Boosts: {}", st.reblogs_count)));
+        let favourites = Paragraph::new()
+            .add(&ColouredString::plain(
+                &format!("Favourites: {}", st.favourites_count)));
+
+        let mut mentions: Vec<_> = st.mentions.iter().map(|m| {
+            Paragraph::new().set_indent(2, 2)
+                .add(&ColouredString::uniform(&client.fq(&m.acct), 'f'))
+        }).collect();
+        if !mentions.is_empty() {
+            mentions.insert(0, Paragraph::new().add(
+                &ColouredString::plain("Mentioned users:")));
+        }
+
+        let client_name = Paragraph::new()
+            .add(&ColouredString::plain("Client name: "))
+            .add(&st.application.as_ref().map_or_else(
+                || ColouredString::uniform("none", '0'),
+                |app| ColouredString::plain(&app.name)));
+        let client_url = Paragraph::new()
+            .add(&ColouredString::plain("Client website: "))
+            .add(&st.application.as_ref()
+                 .map_or(None, |app| app.website.as_ref())
+                 .map_or_else(
+                     || ColouredString::uniform("none", '0'),
+                     |url| ColouredString::uniform(&url, 'u')));
+
+        DetailedStatusDisplay {
+            sd: StatusDisplay::new(st, client),
+            id,
+            webstatus,
+            creation,
+            lastedit,
+            reply_to,
+            reply_to_user,
+            language,
+            visibility,
+            sensitive,
+            spoiler,
+            replies,
+            boosts,
+            favourites,
+            mentions,
+            client_name,
+            client_url,
+            sep: SeparatorLine::new(None, false, false),
+            blank: BlankLine::new(),
+        }
+    }
+}
+
+impl TextFragment for DetailedStatusDisplay {
+    fn render(&self, width: usize) -> Vec<ColouredString> {
+        let mut lines = Vec::new();
+
+        push_fragment(&mut lines, self.sd.render(width));
+        push_fragment(&mut lines, self.sep.render(width));
+        push_fragment(&mut lines, self.blank.render(width));
+
+        push_fragment(&mut lines, self.id.render(width));
+        if let Some(webstatus) = &self.webstatus {
+            push_fragment(&mut lines, webstatus.render(width));
+        }
+        push_fragment(&mut lines, self.blank.render(width));
+
+        push_fragment(&mut lines, self.creation.render(width));
+        push_fragment(&mut lines, self.lastedit.render(width));
+        push_fragment(&mut lines, self.reply_to.render(width));
+        push_fragment(&mut lines, self.reply_to_user.render(width));
+        push_fragment(&mut lines, self.blank.render(width));
+
+        push_fragment(&mut lines, self.language.render(width));
+        push_fragment(&mut lines, self.visibility.render(width));
+        push_fragment(&mut lines, self.sensitive.render(width));
+        push_fragment(&mut lines, self.spoiler.render(width));
+        push_fragment(&mut lines, self.blank.render(width));
+
+        push_fragment(&mut lines, self.replies.render(width));
+        push_fragment(&mut lines, self.boosts.render(width));
+        push_fragment(&mut lines, self.favourites.render(width));
+        push_fragment(&mut lines, self.blank.render(width));
+
+        if !self.mentions.is_empty() {
+            for para in &self.mentions {
+                push_fragment(&mut lines, para.render(width));
+            }
+            push_fragment(&mut lines, self.blank.render(width));
+        }
+
+        push_fragment(&mut lines, self.client_name.render(width));
+        push_fragment(&mut lines, self.client_url.render(width));
+        push_fragment(&mut lines, self.blank.render(width));
+
+        lines
+    }
+}
+
 pub struct ExamineUserDisplay {
     name: Paragraph,
     webaccount: Paragraph,