From c396b8a8f9f9235f3037c6b111649e0a2ebe0529 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 4 Jan 2024 20:41:12 +0000 Subject: [PATCH] Show visibility of posts with an extra header. Also, changed my mind: 'unlisted' doesn't deserve to be alarming red. Boring grey is enough. --- src/posting.rs | 2 +- src/text.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/posting.rs b/src/posting.rs index ca98ac1..b872b50 100644 --- a/src/posting.rs +++ b/src/posting.rs @@ -183,7 +183,7 @@ impl PostMenu { " ffffff"), Visibility::Unlisted => ColouredString::general( "Visibility: unlisted (anyone can see it, but feeds omit it)", - " rrrrrrrr "), + " "), Visibility::Private => ColouredString::general( "Visibility: private (followees and @mentioned users can see it)", " rrrrrrr "), diff --git a/src/text.rs b/src/text.rs index cbcfa10..0c3976b 100644 --- a/src/text.rs +++ b/src/text.rs @@ -970,6 +970,35 @@ fn test_in_reply_to() { }); } +pub struct VisibilityLine { + vis: Visibility, +} + +impl VisibilityLine { + pub fn new(vis: Visibility) -> Self { VisibilityLine { vis } } +} + +impl TextFragment for VisibilityLine { + fn render_highlighted(&self, width: usize, _highlight: Option) + -> Vec + { + let line = match self.vis { + Visibility::Public => ColouredString::general( + "Visibility: public", + " ffffff"), + Visibility::Unlisted => ColouredString::plain( + "Visibility: unlisted"), + Visibility::Private => ColouredString::general( + "Visibility: private", + " rrrrrrr"), + Visibility::Direct => ColouredString::general( + "Visibility: direct", + " rrrrrr"), + }; + vec! { line.truncate(width).to_owned() } + } +} + pub struct NotificationLog { timestamp: DateTime, account_desc: String, @@ -1670,6 +1699,7 @@ pub struct StatusDisplay { from: UsernameHeader, via: Option, irt: Option, + vis: Option, content: Html, media: Vec, blank: BlankLine, @@ -1704,6 +1734,11 @@ impl StatusDisplay { Some(id) => Some(InReplyToLine::from_id(id, client)), }; + let vis = match st.visibility { + Visibility::Public => None, + vis => Some(VisibilityLine::new(vis)), + }; + let content = Html::new(&st.content); let media = st.media_attachments.iter().map(|m| { @@ -1719,6 +1754,7 @@ impl StatusDisplay { from, via, irt, + vis, content, media, blank: BlankLine::new(), @@ -1756,6 +1792,7 @@ impl TextFragment for StatusDisplay { width, &mut highlight)); push_fragment(&mut lines, self.via.render_highlighted_update( width, &mut highlight)); + push_fragment(&mut lines, self.vis.render(width)); push_fragment(&mut lines, self.irt.render(width)); push_fragment(&mut lines, self.blank.render(width)); let rendered_content = self.content.render(width); -- 2.30.2