chiark / gitweb /
Store an actual FileType in File.
authorSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 12:54:34 +0000 (12:54 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 13:15:54 +0000 (13:15 +0000)
That way it can remember what feed the file is about, so as to save
the file position later.

src/file.rs

index 599775e9d9ad6b03c062dafb1e7f0af191a20a8f..ea66e26de8038e079f731bb8285d2786be69e67f 100644 (file)
@@ -254,11 +254,12 @@ struct File<Type: FileType, Source: FileDataSource> {
     ui_mode: UIMode,
     selection: Option<(isize, usize)>,
     select_aux: Option<bool>, // distinguishes fave from unfave, etc
+    file_desc: Type,
 }
 
 impl<Type: FileType, Source: FileDataSource> File<Type, Source> {
     fn new(client: &mut Client, source: Source, desc: ColouredString,
-           initial_pos: Option<FilePosition>) ->
+           file_desc: Type, initial_pos: Option<FilePosition>) ->
         Result<Self, ClientError>
     {
         source.init(client)?;
@@ -296,6 +297,7 @@ impl<Type: FileType, Source: FileDataSource> File<Type, Source> {
             ui_mode: UIMode::Normal,
             selection: None,
             select_aux: None,
+            file_desc,
         };
         Ok(ff)
     }
@@ -1092,70 +1094,72 @@ impl<Type: FileType, Source: FileDataSource>
 pub fn home_timeline(client: &mut Client) ->
     Result<Box<dyn ActivityState>, ClientError>
 {
-    let file = File::<StatusFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Home), ColouredString::general(
             "Home timeline   <H>",
-            "HHHHHHHHHHHHHHHHHKH"), None)?;
+            "HHHHHHHHHHHHHHHHHKH"), StatusFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
 pub fn local_timeline(client: &mut Client) ->
     Result<Box<dyn ActivityState>, ClientError>
 {
-    let file = File::<StatusFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Local), ColouredString::general(
             "Local public timeline   <L>",
-            "HHHHHHHHHHHHHHHHHHHHHHHHHKH"), None)?;
+            "HHHHHHHHHHHHHHHHHHHHHHHHHKH"), StatusFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
 pub fn public_timeline(client: &mut Client) ->
     Result<Box<dyn ActivityState>, ClientError>
 {
-    let file = File::<StatusFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Public), ColouredString::general(
             "Public timeline   <P>",
-            "HHHHHHHHHHHHHHHHHHHKH"), None)?;
+            "HHHHHHHHHHHHHHHHHHHKH"), StatusFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
 pub fn mentions(client: &mut Client) ->
     Result<Box<dyn ActivityState>, ClientError>
 {
-    let file = File::<NotificationStatusFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Mentions), ColouredString::general(
             "Mentions   [ESC][R]",
-            "HHHHHHHHHHHHKKKHHKH"), None)?;
+            "HHHHHHHHHHHHKKKHHKH"), NotificationStatusFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
 pub fn ego_log(client: &mut Client) ->
     Result<Box<dyn ActivityState>, ClientError>
 {
-    let file = File::<EgoNotificationFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Ego), ColouredString::general(
             "Ego Log   [ESC][L][L][E]",
-            "HHHHHHHHHHHKKKHHKHHKHHKH"), None)?;
+            "HHHHHHHHHHHKKKHHKHHKHHKH"), EgoNotificationFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
 pub fn list_status_favouriters(client: &mut Client, id: &str) ->
     Result<Box<dyn ActivityState>, ClientError>
 {
-    let file = File::<UserListFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Favouriters(id.to_owned())),
         ColouredString::uniform(
-            &format!("Users who favourited post {id}"), 'H'), None)?;
+            &format!("Users who favourited post {id}"), 'H'),
+        UserListFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
 pub fn list_status_boosters(client: &mut Client, id: &str) ->
     Result<Box<dyn ActivityState>, ClientError>
 {
-    let file = File::<UserListFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Boosters(id.to_owned())),
         ColouredString::uniform(
-            &format!("Users who boosted post {id}"), 'H'), None)?;
+            &format!("Users who boosted post {id}"), 'H'),
+        UserListFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
@@ -1165,10 +1169,11 @@ pub fn list_user_followers(client: &mut Client, id: &str) ->
     let ac = client.account_by_id(&id)?;
     let name = client.fq(&ac.acct);
 
-    let file = File::<UserListFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Followers(id.to_owned())),
         ColouredString::uniform(
-            &format!("Users who follow {name}"), 'H'), None)?;
+            &format!("Users who follow {name}"), 'H'),
+        UserListFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
@@ -1178,10 +1183,11 @@ pub fn list_user_followees(client: &mut Client, id: &str) ->
     let ac = client.account_by_id(&id)?;
     let name = client.fq(&ac.acct);
 
-    let file = File::<UserListFeedType, _>::new(
+    let file = File::new(
         client, FeedSource::new(FeedId::Followees(id.to_owned())),
         ColouredString::uniform(
-            &format!("Users who {name} follows"), 'H'), None)?;
+            &format!("Users who {name} follows"), 'H'),
+        UserListFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
@@ -1190,8 +1196,9 @@ 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, None)?;
+    let file = File::new(
+        client, FeedSource::new(FeedId::Hashtag(tag.to_owned())), title,
+        StatusFeedType{}, None)?;
     Ok(Box::new(file))
 }
 
@@ -1216,8 +1223,8 @@ pub fn examine_user(client: &mut Client, account_id: &str) ->
     let title = ColouredString::uniform(
         &format!("Information about user {username}"), 'H');
 
-    let file = File::<ExamineUserFileType, _>::new(
-        client, StaticSource::singleton(ac.id), title,
+    let file = File::new(
+        client, StaticSource::singleton(ac.id), title, ExamineUserFileType{},
         Some(FilePosition::item_top(isize::MIN)))?;
     Ok(Box::new(file))
 }
@@ -1242,8 +1249,9 @@ pub fn view_single_post(client: &mut Client, status_id: &str) ->
     let title = ColouredString::uniform(
         &format!("Information about post {}", st.id), 'H');
 
-    let file = File::<DetailedStatusFileType, _>::new(
+    let file = File::new(
         client, StaticSource::singleton(st.id), title,
+        DetailedStatusFileType{},
         Some(FilePosition::item_top(isize::MIN)))?;
     Ok(Box::new(file))
 }
@@ -1283,8 +1291,8 @@ pub fn view_thread(client: &mut Client, start_id: &str, full: bool) ->
     let index = ids.iter().position(|x| x == start_id)
         .map_or(isize::MIN, |u| u as isize);
 
-    let file = File::<StatusFeedType, _>::new(
-        client, StaticSource::vector(ids), title,
+    let file = File::new(
+        client, StaticSource::vector(ids), title, StatusFeedType{},
         Some(FilePosition::item_top(index as isize)))?;
     Ok(Box::new(file))
 }