chiark / gitweb /
Jump to new mentions even if we're already in mentions.
authorSimon Tatham <anakin@pobox.com>
Thu, 25 Jan 2024 08:56:52 +0000 (08:56 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 25 Jan 2024 09:01:51 +0000 (09:01 +0000)
I noticed this because of the bug fixed in the previous commit - I
_wasn't_ already in my mentions feed, and got thrown into it by an
incoming message, but the file position didn't update.

If the ReadMentions activity state had been properly GCed and
recreated, it would have jumped automatically to the new message. But
it _ought_ to be doing that even if I were in Read Mentions already,
which is a rarer occurrence. So the previous bug gave me the
opportunity to spot and fix this one too, before it hit for real!

src/file.rs
src/tui.rs

index a525e09f1dcf09b509df83ce53a47deb6314b674..5fd8785839be5f752607aa0518e7334599e35087 100644 (file)
@@ -77,6 +77,10 @@ trait FileDataSource {
     fn single_id(&self) -> String {
         panic!("Should only call this if the FileType sets CAN_LIST, CAN_GET_POSTS or IS_EXAMINE_USER");
     }
+
+    fn want_to_jump_to_new_content(&self) -> bool {
+        false
+    }
 }
 
 struct FeedSource {
@@ -112,6 +116,10 @@ impl FileDataSource for FeedSource {
     fn extendable(&self) -> bool {
         true
     }
+
+    fn want_to_jump_to_new_content(&self) -> bool {
+        self.id == FeedId::Mentions
+    }
 }
 
 struct StaticSource {
@@ -1750,6 +1758,17 @@ impl<Type: FileType, Source: FileDataSource> ActivityState
             Err(..) => LogicalAction::Beep,
         }
     }
+
+    fn show_new_content(&mut self, client: &mut Client) {
+        self.contents.update_items(client);
+        if let Some(index) = self.latest_read_index {
+            if self.contents.last_index() > index {
+                self.pos = FilePosition::item_top(index + 1);
+                self.ensure_enough_rendered();
+                self.after_setting_pos();
+            }
+        }
+    }
 }
 
 pub fn home_timeline(
index 253caf463600451b4da060661fab2ad3a1ca8283..dfe2ddd530b94f6f4a7d607b4566122e56969ef0 100644 (file)
@@ -637,6 +637,7 @@ pub trait ActivityState {
     fn save_file_position(&self) -> Option<(FeedId, SavedFilePos)> {
         None
     }
+    fn show_new_content(&mut self, _client: &mut Client) {}
     fn got_search_expression(
         &mut self,
         _dir: SearchDirection,
@@ -917,7 +918,9 @@ impl TuiLogicalState {
         post: Option<Post>,
         is_interrupt: bool,
     ) {
-        if !self.activity_states.contains_key(&act) {
+        if let Some(ref mut state) = self.activity_states.get_mut(&act) {
+            state.show_new_content(client);
+        } else {
             self.activity_states.insert(
                 act.clone(),
                 self.new_activity_state(act, client, post, is_interrupt),