Skip to content

Commit

Permalink
Separate settings for DM feed order and top/bottom posting
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Jan 20, 2025
1 parent ecb8d30 commit e2f2980
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 15 deletions.
10 changes: 7 additions & 3 deletions gossip-bin/src/ui/feed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ fn render_a_feed(
fn render_dm_feed(app: &mut GossipUi, ui: &mut Ui, channel: DmChannel) {
let feed = app.displayed_feed.clone();
let scroll_area_id = channel.name();
let feed_newest_at_bottom = GLOBALS.db().read_setting_feed_newest_at_bottom();
let feed_newest_at_bottom = GLOBALS.db().read_setting_dm_feed_newest_at_bottom();
let iterator: Box<dyn Iterator<Item = &Id>> = if feed_newest_at_bottom {
Box::new(feed.iter().rev())
} else {
Expand Down Expand Up @@ -637,7 +637,8 @@ fn recompute_btn(app: &mut GossipUi, ui: &mut Ui) {
}

let update_immediately = {
let mut update_immediately: bool = matches!(GLOBALS.feed.get_feed_kind(), FeedKind::DmChat(_));
let mut update_immediately: bool =
matches!(GLOBALS.feed.get_feed_kind(), FeedKind::DmChat(_));
if let Some(pubkey) = GLOBALS.identity.public_key() {
update_immediately |= GLOBALS.feed.get_feed_kind() == FeedKind::Person(pubkey);
}
Expand All @@ -646,7 +647,10 @@ fn recompute_btn(app: &mut GossipUi, ui: &mut Ui) {

let feed_hash = GLOBALS.feed.get_feed_hash();
if feed_hash != app.displayed_feed_hash {
if app.displayed_feed.is_empty() || update_immediately || ui.link("Show New Updates").clicked() {
if app.displayed_feed.is_empty()
|| update_immediately
|| ui.link("Show New Updates").clicked()
{
app.displayed_feed = GLOBALS.feed.get_feed_events();
app.displayed_feed_hash = feed_hash;
}
Expand Down
5 changes: 2 additions & 3 deletions gossip-bin/src/ui/feed/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ fn dm_posting_area(
let response = widgets::options_menu_button(ui, &app.theme, &app.assets);
let menu =
widgets::MoreMenu::bubble(ui.next_auto_id(), vec2(190.0, 40.0), vec2(190.0, 40.0))
.place_above(!read_setting!(posting_area_at_top));
.place_above(!read_setting!(dm_posting_area_at_top));

let mut items: Vec<MoreMenuItem> = Vec::new();
if app.dm_draft_data.include_subject {
Expand Down Expand Up @@ -766,8 +766,7 @@ fn real_posting_area(app: &mut GossipUi, ctx: &Context, ui: &mut Ui) {
let mut tags: Vec<Tag> = Vec::new();
if app.draft_data.include_content_warning {
tags.push(
ParsedTag::ContentWarning(Some(app.draft_data.content_warning.clone()))
.into_tag(),
ParsedTag::ContentWarning(Some(app.draft_data.content_warning.clone())).into_tag(),
);
}
if let Some(delegatee_tag) = GLOBALS.delegation.get_delegatee_tag() {
Expand Down
8 changes: 7 additions & 1 deletion gossip-bin/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,13 @@ impl eframe::App for GossipUi {
self.side_panel(ctx);

let (show_top_post_area, show_bottom_post_area) = if self.show_post_area_fn() {
if read_setting!(posting_area_at_top) {
let posting_area_at_top = if matches!(self.page, Page::Feed(FeedKind::DmChat(_))) {
read_setting!(dm_posting_area_at_top)
} else {
read_setting!(posting_area_at_top)
};

if posting_area_at_top {
(true, false)
} else {
(false, true)
Expand Down
23 changes: 19 additions & 4 deletions gossip-bin/src/ui/settings/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,34 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
);
reset_button!(app, ui, highlight_unread_events);
});

ui.horizontal(|ui| {
ui.checkbox(
&mut app.unsaved_settings.feed_newest_at_bottom,
"Order feed with newest at bottom (else top)",
);
reset_button!(app, ui, feed_newest_at_bottom);
});
ui.horizontal(|ui| {
ui.checkbox(
&mut app.unsaved_settings.posting_area_at_top,
"Show posting area at the top instead of the bottom",
"Show posting area at the top (else bottom)",
);
reset_button!(app, ui, posting_area_at_top);
});
ui.horizontal(|ui| {
ui.checkbox(
&mut app.unsaved_settings.feed_newest_at_bottom,
"Order feed with newest at bottom (instead of top)",
&mut app.unsaved_settings.dm_feed_newest_at_bottom,
"Order DM feed with newest at bottom (else top)",
);
reset_button!(app, ui, feed_newest_at_bottom);
reset_button!(app, ui, dm_feed_newest_at_bottom);
});
ui.horizontal(|ui| {
ui.checkbox(
&mut app.unsaved_settings.dm_posting_area_at_top,
"Show DM posting area at the top (else bottom)",
);
reset_button!(app, ui, dm_posting_area_at_top);
});

ui.add_space(20.0);
Expand Down
8 changes: 8 additions & 0 deletions gossip-bin/src/unsaved_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ pub struct UnsavedSettings {
pub highlight_unread_events: bool,
pub feed_newest_at_bottom: bool,
pub posting_area_at_top: bool,
pub dm_feed_newest_at_bottom: bool,
pub dm_posting_area_at_top: bool,
pub status_bar: bool,
pub image_resize_algorithm: String,
pub inertial_scrolling: bool,
Expand Down Expand Up @@ -189,6 +191,8 @@ impl Default for UnsavedSettings {
highlight_unread_events: default_setting!(highlight_unread_events),
feed_newest_at_bottom: default_setting!(feed_newest_at_bottom),
posting_area_at_top: default_setting!(posting_area_at_top),
dm_feed_newest_at_bottom: default_setting!(dm_feed_newest_at_bottom),
dm_posting_area_at_top: default_setting!(dm_posting_area_at_top),
status_bar: default_setting!(status_bar),
image_resize_algorithm: default_setting!(image_resize_algorithm),
inertial_scrolling: default_setting!(inertial_scrolling),
Expand Down Expand Up @@ -281,6 +285,8 @@ impl UnsavedSettings {
highlight_unread_events: load_setting!(highlight_unread_events),
feed_newest_at_bottom: load_setting!(feed_newest_at_bottom),
posting_area_at_top: load_setting!(posting_area_at_top),
dm_feed_newest_at_bottom: load_setting!(dm_feed_newest_at_bottom),
dm_posting_area_at_top: load_setting!(dm_posting_area_at_top),
status_bar: load_setting!(status_bar),
image_resize_algorithm: load_setting!(image_resize_algorithm),
inertial_scrolling: load_setting!(inertial_scrolling),
Expand Down Expand Up @@ -367,6 +373,8 @@ impl UnsavedSettings {
save_setting!(highlight_unread_events, self, txn);
save_setting!(feed_newest_at_bottom, self, txn);
save_setting!(posting_area_at_top, self, txn);
save_setting!(dm_feed_newest_at_bottom, self, txn);
save_setting!(dm_posting_area_at_top, self, txn);
save_setting!(status_bar, self, txn);
save_setting!(image_resize_algorithm, self, txn);
save_setting!(inertial_scrolling, self, txn);
Expand Down
19 changes: 15 additions & 4 deletions gossip-lib/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,22 @@ impl Storage {
bool,
true
);

def_setting!(feed_newest_at_bottom, b"feed_newest_at_bottom", bool, false);
def_setting!(posting_area_at_top, b"posting_area_at_top", bool, true);
def_setting!(
dm_feed_newest_at_bottom,
b"dm_feed_newest_at_bottom",
bool,
true
);
def_setting!(
dm_posting_area_at_top,
b"dm_posting_area_at_top",
bool,
false
);

def_setting!(status_bar, b"status_bar", bool, false);
def_setting!(
image_resize_algorithm,
Expand Down Expand Up @@ -2404,10 +2418,7 @@ impl Storage {
})
.collect();

sortable.sort_by(|a, b| {
b.0.cmp(&a.0)
.then(b.1.id.cmp(&a.1.id))
});
sortable.sort_by(|a, b| b.0.cmp(&a.0).then(b.1.id.cmp(&a.1.id)));

Ok(sortable.iter().map(|(_, e)| e.id).collect())
}
Expand Down

0 comments on commit e2f2980

Please sign in to comment.