chiark / gitweb /
Support showing content warnings.
authorSimon Tatham <anakin@pobox.com>
Sun, 7 Jan 2024 21:54:58 +0000 (21:54 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 7 Jan 2024 22:23:21 +0000 (22:23 +0000)
We still don't hide the rest of the post, but this is a start, because
sometimes the poster expects that you've at least _seen_ the warning
text. (For example I saw a post today in which the content warning was
the question part of a joke, and the post body was the punchline.)

TODO.md
src/text.rs

diff --git a/TODO.md b/TODO.md
index f8186400e15d2f98614e1ab87ae4b4ff066e9c29..a5af8a6b821f53b88fe8bd6725db7013232400dc 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -36,16 +36,14 @@ way Mono did it.
 
 ### Sensitive-content markers
 
-Currently we ignore whether a post is marked as sensitive: it doesn't
-show up at all in the UI.
-
-We should _at least_ display the sensitive-content tag, because it's
-not unheard of for people to use it as a post title, and write the
-rest of the toot in the assumption that you saw it, so that it might
-not even make sense without.
-
-Probably better to go all the way, and actually hide the post until
-told otherwise.
+Currently we display sensitive-content tags, but then display the rest
+of the post anyway. It would be better to (at least have the option
+to) hide the post and then be able to show it on demand.
+
+This will probably involve some kind of state object in File which
+maps post IDs to data about them that informs display. Once we have
+that, it could also be used to make the handling of unsubmitted poll
+results less horrible.
 
 ### Scrolling to keep the selection in view
 
index 227934c1b8dbc0ab672f86546af733ebf5cd70cc..2a5fa64c7f97d9a833bed15f6c5fb7d6f456084d 100644 (file)
@@ -1749,6 +1749,7 @@ pub struct StatusDisplay {
     via: Option<UsernameHeader>,
     irt: Option<InReplyToLine>,
     vis: Option<VisibilityLine>,
+    warning: Option<Paragraph>,
     content: Html,
     media: Vec<Media>,
     poll: Option<Poll>,
@@ -1787,6 +1788,16 @@ impl StatusDisplay {
             vis => Some(VisibilityLine::new(vis)),
         };
 
+        let warning = if st.sensitive {
+            let mut para = Paragraph::new();
+            para = para.add(&ColouredString::uniform("Content note:", 'r'));
+            para.end_word();
+            para = para.add(&ColouredString::plain(&st.spoiler_text));
+            Some(para)
+        } else {
+            None
+        };
+
         let content = Html::new(&st.content);
 
         let media = st.media_attachments.iter().map(|m| {
@@ -1853,6 +1864,7 @@ impl StatusDisplay {
             via,
             irt,
             vis,
+            warning,
             content,
             media,
             poll,
@@ -1897,6 +1909,7 @@ impl TextFragment for StatusDisplay {
         push_fragment(&mut lines, self.vis.render(width));
         push_fragment(&mut lines, self.irt.render(width));
         push_fragment(&mut lines, self.blank.render(width));
+        push_fragment_opt_highlight(&mut lines, self.warning.render(width));
         let rendered_content = self.content.render(width);
         let content_empty = rendered_content.is_empty();
         push_fragment_opt_highlight(&mut lines, rendered_content);