chiark / gitweb /
UNTESTED: go to Read Mentions if user is mentioned.
authorSimon Tatham <anakin@pobox.com>
Sun, 31 Dec 2023 13:38:24 +0000 (13:38 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 31 Dec 2023 14:06:18 +0000 (14:06 +0000)
Annoyingly, I can't test this on the dev instance, because its
streaming API doesn't work!

src/activity_stack.rs
src/tui.rs

index 9f442239051abae6885b6aed61d1c38b3ae16b33..7136ba416c9f0cbcda312268263bb553f4690c31 100644 (file)
@@ -41,6 +41,16 @@ pub struct ActivityStack {
     util: Option<UtilityActivity>,
 }
 
+impl Activity {
+    pub fn throw_into_mentions(&self) -> bool {
+        // ReadMentions itself doesn't count. This will have to return
+        // false for post-editing activities.
+        match self {
+            _ => true,
+        }
+    }
+}
+
 impl ActivityStack {
     pub fn new() -> Self {
         ActivityStack {
index 6f78573033b27d288a232d8f0103c244ba98f3f4..5a17b816431e87fbbd8a43df9350fedfec57acae 100644 (file)
@@ -344,9 +344,24 @@ impl Tui {
                 },
                 Ok(SubthreadEvent::StreamEv(update)) => {
                     match self.client.process_stream_update(update) {
-                        Ok(feeds_updated) =>
-                            state.handle_feed_updates(feeds_updated,
-                                                      &mut self.client),
+                        Ok(feeds_updated) => {
+                            match state.handle_feed_updates(feeds_updated,
+                                                            &mut self.client) {
+                                PhysicalAction::Beep => {
+                                    Self::beep()?
+                                },
+
+                                PhysicalAction::Exit => {
+                                    break 'outer Ok(());
+                                },
+
+                                PhysicalAction::Error(err) => {
+                                    break 'outer Err(err);
+                                },
+
+                                PhysicalAction::Nothing => (),
+                            }
+                        },
 
                         // FIXME: errors here should go in the Error Log
                         _ => (),
@@ -501,12 +516,20 @@ impl TuiLogicalState {
     }
 
     fn handle_feed_updates(&mut self, feeds_updated: HashSet<FeedId>,
-                           client: &mut Client) {
-        // FIXME: if the mentions feed is updated, we may need to
-        // actually change the activity stack to throw the user into
-        // Read Messages.
-
+                           client: &mut Client)  -> PhysicalAction {
         self.activity_state.handle_feed_updates(&feeds_updated, client);
+
+        if feeds_updated.contains(&FeedId::Mentions) {
+            if self.activity_stack.top().throw_into_mentions() {
+                self.activity_stack.goto(UtilityActivity::ReadMentions.into());
+                self.changed_activity(client);
+            }
+
+            // FIXME: we'd quite like a double-beep if you're in the composer
+            PhysicalAction::Beep
+        } else {
+            PhysicalAction::Nothing
+        }
     }
 
     fn changed_activity(&mut self, client: &mut Client) {