From: Simon Tatham Date: Fri, 26 Jan 2024 08:48:04 +0000 (+0000) Subject: Turn FileType::get_from_client into an &self method. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=2f9fe150d516888873e3344a3150fb24256aa824;p=mastodonochrome.git Turn FileType::get_from_client into an &self method. This enables the FileType object itself to store information about where its data comes from, instead of _necessarily_ being constrained to get it from the client. Therefore, I've also renamed it, so that the method name doesn't imply that the data always lives in the client. This also means that every call to FileContents::update_items() must pass through the FileType from its owning File, but that's no trouble. --- diff --git a/src/file.rs b/src/file.rs index 5fd8785..915529e 100644 --- a/src/file.rs +++ b/src/file.rs @@ -173,7 +173,8 @@ trait FileType { const CAN_GET_POSTS: bool = false; const IS_EXAMINE_USER: bool = false; - fn get_from_client( + fn get_item( + &self, id: &str, client: &mut Client, ) -> Result; @@ -197,7 +198,8 @@ impl StatusFeedType { impl FileType for StatusFeedType { type Item = StatusDisplay; - fn get_from_client( + fn get_item( + &self, id: &str, client: &mut Client, ) -> Result { @@ -221,7 +223,8 @@ impl NotificationStatusFeedType { impl FileType for NotificationStatusFeedType { type Item = StatusDisplay; - fn get_from_client( + fn get_item( + &self, id: &str, client: &mut Client, ) -> Result { @@ -248,7 +251,8 @@ impl EgoNotificationFeedType { impl FileType for EgoNotificationFeedType { type Item = NotificationLog; - fn get_from_client( + fn get_item( + &self, id: &str, client: &mut Client, ) -> Result { @@ -265,7 +269,8 @@ struct UserListFeedType {} impl FileType for UserListFeedType { type Item = UserListEntry; - fn get_from_client( + fn get_item( + &self, id: &str, client: &mut Client, ) -> Result { @@ -283,7 +288,7 @@ struct FileContents { } impl FileContents { - fn update_items(&mut self, client: &mut Client) { + fn update_items(&mut self, file_desc: &Type, client: &mut Client) { // FIXME: if the feed has been extended rather than created, // we should be able to make less effort than this. But we // still need to regenerate any item derived from something we @@ -295,7 +300,8 @@ impl FileContents { self.items.clear(); for id in ids { - let item = Type::get_from_client(&id, client) + let item = file_desc + .get_item(&id, client) .expect("Any id stored in a Feed should also be cached"); self.items.push((id.to_owned(), item)); } @@ -463,7 +469,7 @@ impl File { items: Vec::new(), }; - contents.update_items(client); + contents.update_items(&file_desc, client); // Start with the initial position at the file top let mut initial_pos = FilePosition::item_top(contents.first_index()); @@ -763,7 +769,7 @@ impl File { } } - self.contents.update_items(client); + self.contents.update_items(&self.file_desc, client); self.clip_pos_within_item(); self.fix_overshoot_at_top(); // in case the extender vanished Ok(()) @@ -1014,7 +1020,8 @@ impl File { SelectionPurpose::Favourite => { match client.favourite_post(&id, !alt) { Ok(_) => { - self.contents.update_items(client); + self.contents + .update_items(&self.file_desc, client); LogicalAction::Nothing } Err(_) => LogicalAction::Beep, @@ -1023,7 +1030,8 @@ impl File { SelectionPurpose::Boost => { match client.boost_post(&id, !alt) { Ok(_) => { - self.contents.update_items(client); + self.contents + .update_items(&self.file_desc, client); LogicalAction::Nothing } Err(_) => LogicalAction::Beep, @@ -1062,7 +1070,8 @@ impl File { .copied(), ) { Ok(_) => { - self.contents.update_items(client); + self.contents + .update_items(&self.file_desc, client); LogicalAction::Nothing } Err(_) => LogicalAction::Beep, @@ -1720,7 +1729,7 @@ impl ActivityState client: &mut Client, ) { if self.contents.source.updated(feeds_updated) { - self.contents.update_items(client); + self.contents.update_items(&self.file_desc, client); self.ensure_enough_rendered(); // If someone's home feed was almost completely empty, @@ -1760,7 +1769,7 @@ impl ActivityState } fn show_new_content(&mut self, client: &mut Client) { - self.contents.update_items(client); + self.contents.update_items(&self.file_desc, client); if let Some(index) = self.latest_read_index { if self.contents.last_index() > index { self.pos = FilePosition::item_top(index + 1); @@ -2026,7 +2035,8 @@ impl FileType for ExamineUserFileType { const CAN_GET_POSTS: bool = true; const IS_EXAMINE_USER: bool = true; - fn get_from_client( + fn get_item( + &self, id: &str, client: &mut Client, ) -> Result { @@ -2063,7 +2073,8 @@ impl FileType for DetailedStatusFileType { type Item = DetailedStatusDisplay; const CAN_LIST: CanList = CanList::ForPost; - fn get_from_client( + fn get_item( + &self, id: &str, client: &mut Client, ) -> Result { @@ -2099,7 +2110,8 @@ struct InstanceRulesFileType; impl FileType for InstanceRulesFileType { type Item = InstanceRulesDisplay; - fn get_from_client( + fn get_item( + &self, _id: &str, client: &mut Client, ) -> Result {