From c7683a14d12733e8a561f5586cd15a7e252402eb Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 4 Jan 2024 12:54:34 +0000 Subject: [PATCH] Store an actual FileType in File. That way it can remember what feed the file is about, so as to save the file position later. --- src/file.rs | 60 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/file.rs b/src/file.rs index 599775e..ea66e26 100644 --- a/src/file.rs +++ b/src/file.rs @@ -254,11 +254,12 @@ struct File { ui_mode: UIMode, selection: Option<(isize, usize)>, select_aux: Option, // distinguishes fave from unfave, etc + file_desc: Type, } impl File { fn new(client: &mut Client, source: Source, desc: ColouredString, - initial_pos: Option) -> + file_desc: Type, initial_pos: Option) -> Result { source.init(client)?; @@ -296,6 +297,7 @@ impl File { ui_mode: UIMode::Normal, selection: None, select_aux: None, + file_desc, }; Ok(ff) } @@ -1092,70 +1094,72 @@ impl pub fn home_timeline(client: &mut Client) -> Result, ClientError> { - let file = File::::new( + let file = File::new( client, FeedSource::new(FeedId::Home), ColouredString::general( "Home timeline ", - "HHHHHHHHHHHHHHHHHKH"), None)?; + "HHHHHHHHHHHHHHHHHKH"), StatusFeedType{}, None)?; Ok(Box::new(file)) } pub fn local_timeline(client: &mut Client) -> Result, ClientError> { - let file = File::::new( + let file = File::new( client, FeedSource::new(FeedId::Local), ColouredString::general( "Local public timeline ", - "HHHHHHHHHHHHHHHHHHHHHHHHHKH"), None)?; + "HHHHHHHHHHHHHHHHHHHHHHHHHKH"), StatusFeedType{}, None)?; Ok(Box::new(file)) } pub fn public_timeline(client: &mut Client) -> Result, ClientError> { - let file = File::::new( + let file = File::new( client, FeedSource::new(FeedId::Public), ColouredString::general( "Public timeline

", - "HHHHHHHHHHHHHHHHHHHKH"), None)?; + "HHHHHHHHHHHHHHHHHHHKH"), StatusFeedType{}, None)?; Ok(Box::new(file)) } pub fn mentions(client: &mut Client) -> Result, ClientError> { - let file = File::::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, ClientError> { - let file = File::::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, ClientError> { - let file = File::::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, ClientError> { - let file = File::::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::::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::::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::::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::::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::::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::::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)) } -- 2.30.2