chiark / gitweb /
Add an initial_pos to the File constructor.
authorSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 11:58:51 +0000 (11:58 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 12:14:51 +0000 (12:14 +0000)
src/file.rs

index 28413784f73f7a1f9e4d4154a540165dff81a0c7..9ef42c3639369abb9b5624bbf1b7640d5aef2514 100644 (file)
@@ -257,7 +257,8 @@ struct File<Type: FileType, Source: FileDataSource> {
 }
 
 impl<Type: FileType, Source: FileDataSource> File<Type, Source> {
-    fn new(client: &mut Client, source: Source, desc: ColouredString) ->
+    fn new(client: &mut Client, source: Source, desc: ColouredString,
+           initial_pos: Option<FilePosition>) ->
         Result<Self, ClientError>
     {
         source.init(client)?;
@@ -279,8 +280,13 @@ impl<Type: FileType, Source: FileDataSource> File<Type, Source> {
         contents.update_items(client);
 
         // FIXME: once we have an LDB, that's where initial pos comes from
-        let initial_pos = FilePosition::item_bottom(
-            contents.last_index() as isize);
+        let mut initial_pos = initial_pos.unwrap_or_else(
+            || FilePosition::item_bottom(isize::MAX));
+
+        initial_pos.item = max(initial_pos.item, contents.first_index());
+        initial_pos.item = min(initial_pos.item, contents.last_index());
+
+        dbg!(initial_pos);
 
         let ff = File {
             contents,
@@ -1089,7 +1095,7 @@ pub fn home_timeline(client: &mut Client) ->
     let file = File::<StatusFeedType, _>::new(
         client, FeedSource::new(FeedId::Home), ColouredString::general(
             "Home timeline   <H>",
-            "HHHHHHHHHHHHHHHHHKH"))?;
+            "HHHHHHHHHHHHHHHHHKH"), None)?;
     Ok(Box::new(file))
 }
 
@@ -1099,7 +1105,7 @@ pub fn local_timeline(client: &mut Client) ->
     let file = File::<StatusFeedType, _>::new(
         client, FeedSource::new(FeedId::Local), ColouredString::general(
             "Local public timeline   <L>",
-            "HHHHHHHHHHHHHHHHHHHHHHHHHKH"))?;
+            "HHHHHHHHHHHHHHHHHHHHHHHHHKH"), None)?;
     Ok(Box::new(file))
 }
 
@@ -1109,7 +1115,7 @@ pub fn public_timeline(client: &mut Client) ->
     let file = File::<StatusFeedType, _>::new(
         client, FeedSource::new(FeedId::Public), ColouredString::general(
             "Public timeline   <P>",
-            "HHHHHHHHHHHHHHHHHHHKH"))?;
+            "HHHHHHHHHHHHHHHHHHHKH"), None)?;
     Ok(Box::new(file))
 }
 
@@ -1119,7 +1125,7 @@ pub fn mentions(client: &mut Client) ->
     let file = File::<NotificationStatusFeedType, _>::new(
         client, FeedSource::new(FeedId::Mentions), ColouredString::general(
             "Mentions   [ESC][R]",
-            "HHHHHHHHHHHHKKKHHKH"))?;
+            "HHHHHHHHHHHHKKKHHKH"), None)?;
     Ok(Box::new(file))
 }
 
@@ -1129,7 +1135,7 @@ pub fn ego_log(client: &mut Client) ->
     let file = File::<EgoNotificationFeedType, _>::new(
         client, FeedSource::new(FeedId::Ego), ColouredString::general(
             "Ego Log   [ESC][L][L][E]",
-            "HHHHHHHHHHHKKKHHKHHKHHKH"))?;
+            "HHHHHHHHHHHKKKHHKHHKHHKH"), None)?;
     Ok(Box::new(file))
 }
 
@@ -1139,7 +1145,7 @@ pub fn list_status_favouriters(client: &mut Client, id: &str) ->
     let file = File::<UserListFeedType, _>::new(
         client, FeedSource::new(FeedId::Favouriters(id.to_owned())),
         ColouredString::uniform(
-            &format!("Users who favourited post {id}"), 'H'))?;
+            &format!("Users who favourited post {id}"), 'H'), None)?;
     Ok(Box::new(file))
 }
 
@@ -1149,7 +1155,7 @@ pub fn list_status_boosters(client: &mut Client, id: &str) ->
     let file = File::<UserListFeedType, _>::new(
         client, FeedSource::new(FeedId::Boosters(id.to_owned())),
         ColouredString::uniform(
-            &format!("Users who boosted post {id}"), 'H'))?;
+            &format!("Users who boosted post {id}"), 'H'), None)?;
     Ok(Box::new(file))
 }
 
@@ -1162,7 +1168,7 @@ pub fn list_user_followers(client: &mut Client, id: &str) ->
     let file = File::<UserListFeedType, _>::new(
         client, FeedSource::new(FeedId::Followers(id.to_owned())),
         ColouredString::uniform(
-            &format!("Users who follow {name}"), 'H'))?;
+            &format!("Users who follow {name}"), 'H'), None)?;
     Ok(Box::new(file))
 }
 
@@ -1175,7 +1181,7 @@ pub fn list_user_followees(client: &mut Client, id: &str) ->
     let file = File::<UserListFeedType, _>::new(
         client, FeedSource::new(FeedId::Followees(id.to_owned())),
         ColouredString::uniform(
-            &format!("Users who {name} follows"), 'H'))?;
+            &format!("Users who {name} follows"), 'H'), None)?;
     Ok(Box::new(file))
 }
 
@@ -1185,7 +1191,7 @@ pub fn hashtag_timeline(client: &mut Client, tag: &str) ->
     let title = ColouredString::uniform(
         &format!("Posts mentioning hashtag #{tag}"), 'H');
     let file = File::<StatusFeedType, _>::new(
-        client, FeedSource::new(FeedId::Hashtag(tag.to_owned())), title)?;
+        client, FeedSource::new(FeedId::Hashtag(tag.to_owned())), title, None)?;
     Ok(Box::new(file))
 }
 
@@ -1211,7 +1217,7 @@ pub fn examine_user(client: &mut Client, account_id: &str) ->
         &format!("Information about user {username}"), 'H');
 
     let file = File::<ExamineUserFileType, _>::new(
-        client, StaticSource::singleton(ac.id), title)?;
+        client, StaticSource::singleton(ac.id), title, None)?;
     Ok(Box::new(file))
 }
 
@@ -1236,7 +1242,7 @@ pub fn view_single_post(client: &mut Client, status_id: &str) ->
         &format!("Information about post {}", st.id), 'H');
 
     let file = File::<DetailedStatusFileType, _>::new(
-        client, StaticSource::singleton(st.id), title)?;
+        client, StaticSource::singleton(st.id), title, None)?;
     Ok(Box::new(file))
 }
 
@@ -1272,6 +1278,6 @@ pub fn view_thread(client: &mut Client, start_id: &str, full: bool) ->
     let title = ColouredString::uniform(&title, 'H');
 
     let file = File::<StatusFeedType, _>::new(
-        client, StaticSource::vector(ids), title)?;
+        client, StaticSource::vector(ids), title, None)?;
     Ok(Box::new(file))
 }