From: Simon Tatham Date: Sun, 7 Jan 2024 21:54:58 +0000 (+0000) Subject: Support showing content warnings. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=9485062c5cf107ff8891d50407934ba08ec1bc8f;p=mastodonochrome.git Support showing content warnings. 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.) --- diff --git a/TODO.md b/TODO.md index f818640..a5af8a6 100644 --- 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 diff --git a/src/text.rs b/src/text.rs index 227934c..2a5fa64 100644 --- a/src/text.rs +++ b/src/text.rs @@ -1749,6 +1749,7 @@ pub struct StatusDisplay { via: Option, irt: Option, vis: Option, + warning: Option, content: Html, media: Vec, poll: Option, @@ -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);