chiark / gitweb /
When replying to a post, propagate its spoiler warning.
authorSimon Tatham <anakin@pobox.com>
Sat, 13 Jan 2024 13:37:37 +0000 (13:37 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 13 Jan 2024 13:59:16 +0000 (13:59 +0000)
I forgot this yesterday in discussions of a maths problem, and posted
an answer in cleartext. Happily, it wasn't a very hard problem. But it
would have been better if the default had been to repeat the spoiler
text from the parent post; I could always change it manually, but if I
don't want to think very hard, this would more likely be right.

src/posting.rs

index 28b17b752f4f0b254ef7fa34dfa308efcfca3a9c..a387938c63ac1b91e01ba6e1217b7e50672aec1b 100644 (file)
@@ -95,12 +95,20 @@ impl Post {
 
         let text = userids.map(|acct| format!("@{} ", acct)).collect();
 
+        // Set a default content warning of the same as the post we're
+        // replying to.
+        let content_warning = if !st.sensitive {
+            None
+        } else {
+            Some(st.spoiler_text.clone())
+        };
+
         Ok(Post {
             text,
             m: PostMetadata {
                 in_reply_to_id: Some(id.to_owned()),
                 visibility: st.visibility, // match the existing vis
-                content_warning: None,
+                content_warning,
                 language: default_language(&ac),
             },
         })