feat(settings): allow sorting thread replies newest first

This commit is contained in:
Fernando López Guevara
2025-07-29 21:30:35 -03:00
parent 40764d7368
commit f2153f53dc
7 changed files with 154 additions and 97 deletions

View File

@@ -5,6 +5,7 @@ mod token_handler;
mod zoom;
pub use app_size::AppSizeHandler;
pub use settings_handler::Settings;
pub use settings_handler::SettingsHandler;
pub use theme_handler::ThemeHandler;
pub use token_handler::TokenHandler;

View File

@@ -29,6 +29,7 @@ pub struct Settings {
pub locale: String,
pub zoom_factor: f32,
pub show_source_client: String,
pub show_replies_newest_first: bool,
}
impl Default for Settings {
@@ -38,10 +39,12 @@ impl Default for Settings {
theme: DEFAULT_THEME,
locale: DEFAULT_LOCALE.to_string(),
zoom_factor: DEFAULT_ZOOM_FACTOR,
show_source_client: "Hide".to_string(),
show_source_client: DEFAULT_SHOW_SOURCE_CLIENT.to_string(),
show_replies_newest_first: false,
}
}
}
pub struct SettingsHandler {
directory: Directory,
current_settings: Option<Settings>,
@@ -129,7 +132,7 @@ impl SettingsHandler {
};
}
fn get_settings_mut(&mut self) -> &mut Settings {
pub fn get_settings_mut(&mut self) -> &mut Settings {
if self.current_settings.is_none() {
self.current_settings = Some(Settings::default());
}
@@ -162,6 +165,11 @@ impl SettingsHandler {
self.save();
}
pub fn set_show_replies_newest_first(&mut self, value: bool) {
self.get_settings_mut().show_replies_newest_first = value;
self.save();
}
pub fn update_batch<F>(&mut self, update_fn: F)
where
F: FnOnce(&mut Settings),
@@ -204,6 +212,13 @@ impl SettingsHandler {
.unwrap_or(DEFAULT_SHOW_SOURCE_CLIENT.to_string())
}
pub fn show_replies_newest_first(&self) -> bool {
self.current_settings
.as_ref()
.map(|s| s.show_replies_newest_first)
.unwrap_or(false)
}
pub fn is_loaded(&self) -> bool {
self.current_settings.is_some()
}