chiark / gitweb /
Post menu: separate 'sensitive' from 'spoiler text'.
authorSimon Tatham <anakin@pobox.com>
Sat, 13 Jan 2024 13:11:55 +0000 (13:11 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 13 Jan 2024 13:15:23 +0000 (13:15 +0000)
Alas, it _is_ possible to tag a post as sensitive but not provide any
spoiler text. I don't think I should make it actually impossible
through the UI of this client, so here's a change to permit it.

But I'm discouraging it as much as possible, by focusing into the
content-warning editor as soon as you mark a post as sensitive. That
way, if you really want an absence of warning, you have to
deliberately refuse to type one and press Return.

src/posting.rs

index 5419524e9bcd4a15ef21055ed6399dc2384a7516..ccb26cbf23843edc3a2caafa3a38db75921a3f6e 100644 (file)
@@ -92,6 +92,7 @@ struct PostMenu {
     ml_cancel: MenuKeypressLine,
     ml_edit: MenuKeypressLine,
     cl_vis: CyclingMenuLine<Visibility>,
+    cl_sensitive: CyclingMenuLine<bool>,
     el_content_warning: EditableMenuLine<Option<String>>,
     el_language: EditableMenuLine<String>,
 }
@@ -127,8 +128,13 @@ impl PostMenu {
                     "direct (only @mentioned users can see it)",
                     "rrrrrr                                   ")),
             ], post.m.visibility);
+        let cl_sensitive = CyclingMenuLine::new(
+            Pr('S'), ColouredString::plain("Mark post as sensitive: "),
+            &[(false, ColouredString::plain("no")),
+              (true, ColouredString::uniform("yes", 'r'))],
+            post.m.content_warning.is_some());
         let el_content_warning = EditableMenuLine::new(
-            Pr('W'), ColouredString::plain("Content warning: "),
+            Pr('W'), ColouredString::plain("  Content warning: "),
             post.m.content_warning.clone());
         let el_language = EditableMenuLine::new(
             Pr('L'), ColouredString::plain("Language: "),
@@ -143,6 +149,7 @@ impl PostMenu {
             ml_cancel,
             ml_edit,
             cl_vis,
+            cl_sensitive,
             el_content_warning,
             el_language,
         };
@@ -157,6 +164,7 @@ impl PostMenu {
         self.ml_cancel.check_widths(&mut lmaxwid, &mut rmaxwid);
         self.ml_edit.check_widths(&mut lmaxwid, &mut rmaxwid);
         self.cl_vis.check_widths(&mut lmaxwid, &mut rmaxwid);
+        self.cl_sensitive.check_widths(&mut lmaxwid, &mut rmaxwid);
         self.el_content_warning.check_widths(&mut lmaxwid, &mut rmaxwid);
         self.el_language.check_widths(&mut lmaxwid, &mut rmaxwid);
 
@@ -164,6 +172,7 @@ impl PostMenu {
         self.ml_cancel.reset_widths();
         self.ml_edit.reset_widths();
         self.cl_vis.reset_widths();
+        self.cl_sensitive.reset_widths();
         self.el_content_warning.reset_widths();
         self.el_language.reset_widths();
 
@@ -171,6 +180,7 @@ impl PostMenu {
         self.ml_cancel.ensure_widths(lmaxwid, rmaxwid);
         self.ml_edit.ensure_widths(lmaxwid, rmaxwid);
         self.cl_vis.ensure_widths(lmaxwid, rmaxwid);
+        self.cl_sensitive.ensure_widths(lmaxwid, rmaxwid);
         self.el_content_warning.ensure_widths(lmaxwid, rmaxwid);
         self.el_language.ensure_widths(lmaxwid, rmaxwid);
 
@@ -179,8 +189,12 @@ impl PostMenu {
 
     fn post(&mut self, client: &mut Client) -> LogicalAction {
         self.post.m.visibility = self.cl_vis.get_value();
-        self.post.m.content_warning =
-            self.el_content_warning.get_data().clone();
+        self.post.m.content_warning = if self.cl_sensitive.get_value() {
+            self.el_content_warning.get_data().clone()
+                .or_else(|| Some("".to_owned()))
+        } else {
+            None
+        };
         self.post.m.language = self.el_language.get_data().clone();
 
         match client.post_status(&self.post) {
@@ -202,6 +216,7 @@ impl ActivityState for PostMenu {
         lines.extend_from_slice(&self.ml_edit.render(w));
         lines.extend_from_slice(&BlankLine::render_static());
         lines.extend_from_slice(&self.cl_vis.render(w));
+        lines.extend_from_slice(&self.cl_sensitive.render(w));
         lines.push(self.el_content_warning.render(
             w, &mut cursorpos, lines.len()));
         lines.push(self.el_language.render(
@@ -239,7 +254,27 @@ impl ActivityState for PostMenu {
             Pr('a') | Pr('A') => LogicalAction::PostReEdit(
                 self.post.clone()),
             Pr('v') | Pr('V') => self.cl_vis.cycle(),
-            Pr('w') | Pr('W') => self.el_content_warning.start_editing(),
+            Pr('s') | Pr('S') => {
+                let action = self.cl_sensitive.cycle();
+                if self.cl_sensitive.get_value() &&
+                    self.el_content_warning.get_data().is_none()
+                {
+                    // Encourage the user to write a content warning,
+                    // by automatically focusing into the content
+                    // warning editor.
+                    self.el_content_warning.start_editing()
+                } else {
+                    action
+                }
+            }
+            Pr('w') | Pr('W') => {
+                // If the user wants to write a content warning, mark
+                // the post as sensitive too, to prevent accidents.
+                if !self.cl_sensitive.get_value() {
+                    self.cl_sensitive.cycle();
+                }
+                self.el_content_warning.start_editing()
+            }
             Pr('l') | Pr('L') => self.el_language.start_editing(),
             _ => LogicalAction::Nothing,
         }