From a678e647a479d556fe8809d09a4abb8c85e3f0cc Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sun, 17 Nov 2024 16:44:52 -0800 Subject: [PATCH] hide media on universe view Also fixes textmode Fixes: https://github.com/damus-io/notedeck/issues/443 --- src/timeline/route.rs | 41 ++++++++++++++++++++++++++++++++++------- src/ui/note/contents.rs | 3 ++- src/ui/note/mod.rs | 5 +++++ src/ui/note/options.rs | 19 +++++++++++++++++++ src/ui/profile/mod.rs | 10 ++++++++-- src/ui/thread.rs | 8 +++++++- src/ui/timeline.rs | 23 +++++++++++------------ 7 files changed, 86 insertions(+), 23 deletions(-) diff --git a/src/timeline/route.rs b/src/timeline/route.rs index 059989f0..1769f87f 100644 --- a/src/timeline/route.rs +++ b/src/timeline/route.rs @@ -7,12 +7,12 @@ use crate::{ notes_holder::NotesHolderStorage, profile::Profile, thread::Thread, - timeline::TimelineId, + timeline::{TimelineId, TimelineKind}, ui::{ self, note::{ post::{PostAction, PostResponse}, - QuoteRepostView, + NoteOptions, QuoteRepostView, }, profile::ProfileView, }, @@ -57,9 +57,28 @@ pub fn render_timeline_route( ) -> Option { match route { TimelineRoute::Timeline(timeline_id) => { - let timeline_response = - ui::TimelineView::new(timeline_id, columns, ndb, note_cache, img_cache, textmode) - .ui(ui); + let note_options = { + let is_universe = if let Some(timeline) = columns.find_timeline(timeline_id) { + timeline.kind == TimelineKind::Universe + } else { + false + }; + + let mut options = NoteOptions::new(is_universe); + options.set_textmode(textmode); + options + }; + + let timeline_response = ui::TimelineView::new( + timeline_id, + columns, + ndb, + note_cache, + img_cache, + note_options, + ) + .ui(ui); + if let Some(bar_action) = timeline_response.bar_action { let txn = Transaction::new(ndb).expect("txn"); let mut cur_column = columns.columns_mut(); @@ -168,8 +187,16 @@ pub fn render_profile_route( col: usize, ui: &mut egui::Ui, ) -> Option { - let timeline_response = - ProfileView::new(pubkey, col, profiles, ndb, note_cache, img_cache).ui(ui); + let timeline_response = ProfileView::new( + pubkey, + col, + profiles, + ndb, + note_cache, + img_cache, + NoteOptions::default(), + ) + .ui(ui); if let Some(bar_action) = timeline_response.bar_action { let txn = nostrdb::Transaction::new(ndb).expect("txn"); let mut cur_column = columns.columns_mut(); diff --git a/src/ui/note/contents.rs b/src/ui/note/contents.rs index 1a7bf915..7916797a 100644 --- a/src/ui/note/contents.rs +++ b/src/ui/note/contents.rs @@ -139,6 +139,7 @@ fn render_note_contents( let selectable = options.has_selectable_text(); let mut images: Vec = vec![]; let mut inline_note: Option<(&[u8; 32], &str)> = None; + let hide_media = options.has_hide_media(); let response = ui.horizontal_wrapped(|ui| { let blocks = if let Ok(blocks) = ndb.get_blocks_by_key(txn, note_key) { @@ -183,7 +184,7 @@ fn render_note_contents( BlockType::Url => { let lower_url = block.as_str().to_lowercase(); - if lower_url.ends_with("png") || lower_url.ends_with("jpg") { + if !hide_media && (lower_url.ends_with("png") || lower_url.ends_with("jpg")) { images.push(block.as_str().to_string()); } else { #[cfg(feature = "profiling")] diff --git a/src/ui/note/mod.rs b/src/ui/note/mod.rs index b328f5cf..a8d0b209 100644 --- a/src/ui/note/mod.rs +++ b/src/ui/note/mod.rs @@ -204,6 +204,11 @@ impl<'a> NoteView<'a> { } } + pub fn note_options(mut self, options: NoteOptions) -> Self { + *self.options_mut() = options; + self + } + pub fn textmode(mut self, enable: bool) -> Self { self.options_mut().set_textmode(enable); self diff --git a/src/ui/note/options.rs b/src/ui/note/options.rs index 12cf04fe..1090d154 100644 --- a/src/ui/note/options.rs +++ b/src/ui/note/options.rs @@ -14,6 +14,13 @@ bitflags! { const selectable_text = 0b0000000000100000; const textmode = 0b0000000001000000; const options_button = 0b0000000010000000; + const hide_media = 0b0000000100000000; + } +} + +impl Default for NoteOptions { + fn default() -> NoteOptions { + NoteOptions::options_button | NoteOptions::note_previews | NoteOptions::actionbar } } @@ -39,12 +46,24 @@ impl NoteOptions { create_setter!(set_actionbar, actionbar); create_setter!(set_wide, wide); create_setter!(set_options_button, options_button); + create_setter!(set_hide_media, hide_media); + + pub fn new(is_universe_timeline: bool) -> Self { + let mut options = NoteOptions::default(); + options.set_hide_media(is_universe_timeline); + options + } #[inline] pub fn has_actionbar(self) -> bool { (self & NoteOptions::actionbar) == NoteOptions::actionbar } + #[inline] + pub fn has_hide_media(self) -> bool { + (self & NoteOptions::hide_media) == NoteOptions::hide_media + } + #[inline] pub fn has_selectable_text(self) -> bool { (self & NoteOptions::selectable_text) == NoteOptions::selectable_text diff --git a/src/ui/profile/mod.rs b/src/ui/profile/mod.rs index f9de10cb..cc03de3f 100644 --- a/src/ui/profile/mod.rs +++ b/src/ui/profile/mod.rs @@ -1,6 +1,7 @@ pub mod picture; pub mod preview; +use crate::ui::note::NoteOptions; use egui::{ScrollArea, Widget}; use enostr::Pubkey; use nostrdb::{Ndb, Transaction}; @@ -18,6 +19,7 @@ pub struct ProfileView<'a> { pubkey: &'a Pubkey, col_id: usize, profiles: &'a mut NotesHolderStorage, + note_options: NoteOptions, ndb: &'a Ndb, note_cache: &'a mut NoteCache, img_cache: &'a mut ImageCache, @@ -31,6 +33,7 @@ impl<'a> ProfileView<'a> { ndb: &'a Ndb, note_cache: &'a mut NoteCache, img_cache: &'a mut ImageCache, + note_options: NoteOptions, ) -> Self { ProfileView { pubkey, @@ -39,6 +42,7 @@ impl<'a> ProfileView<'a> { ndb, note_cache, img_cache, + note_options, } } @@ -59,10 +63,12 @@ impl<'a> ProfileView<'a> { profile.timeline.selected_view = tabs_ui(ui); + let reversed = false; + TimelineTabView::new( profile.timeline.current_view(), - false, - false, + reversed, + self.note_options, &txn, self.ndb, self.note_cache, diff --git a/src/ui/thread.rs b/src/ui/thread.rs index 6cf6b48e..689dd554 100644 --- a/src/ui/thread.rs +++ b/src/ui/thread.rs @@ -4,6 +4,7 @@ use crate::{ notecache::NoteCache, notes_holder::{NotesHolder, NotesHolderStorage}, thread::Thread, + ui::note::NoteOptions, }; use nostrdb::{Ndb, NoteKey, Transaction}; use tracing::error; @@ -102,10 +103,15 @@ impl<'a> ThreadView<'a> { error!("Thread::poll_notes_into_view: {e}"); } + // This is threadview. We are not the universe view... + let is_universe = false; + let mut note_options = NoteOptions::new(is_universe); + note_options.set_textmode(self.textmode); + TimelineTabView::new( thread.view(), true, - self.textmode, + note_options, &txn, self.ndb, self.note_cache, diff --git a/src/ui/timeline.rs b/src/ui/timeline.rs index 1c2d33c1..b0f7fb12 100644 --- a/src/ui/timeline.rs +++ b/src/ui/timeline.rs @@ -2,6 +2,7 @@ use crate::actionbar::{BarAction, NoteActionResponse}; use crate::timeline::TimelineTab; use crate::{ column::Columns, imgcache::ImageCache, notecache::NoteCache, timeline::TimelineId, ui, + ui::note::NoteOptions, }; use egui::containers::scroll_area::ScrollBarVisibility; use egui::{Direction, Layout}; @@ -15,7 +16,7 @@ pub struct TimelineView<'a> { ndb: &'a Ndb, note_cache: &'a mut NoteCache, img_cache: &'a mut ImageCache, - textmode: bool, + note_options: NoteOptions, reverse: bool, } @@ -26,7 +27,7 @@ impl<'a> TimelineView<'a> { ndb: &'a Ndb, note_cache: &'a mut NoteCache, img_cache: &'a mut ImageCache, - textmode: bool, + note_options: NoteOptions, ) -> TimelineView<'a> { let reverse = false; TimelineView { @@ -36,7 +37,7 @@ impl<'a> TimelineView<'a> { note_cache, img_cache, reverse, - textmode, + note_options, } } @@ -49,7 +50,7 @@ impl<'a> TimelineView<'a> { self.note_cache, self.img_cache, self.reverse, - self.textmode, + self.note_options, ) } @@ -68,7 +69,7 @@ fn timeline_ui( note_cache: &mut NoteCache, img_cache: &mut ImageCache, reversed: bool, - textmode: bool, + note_options: NoteOptions, ) -> NoteActionResponse { //padding(4.0, ui, |ui| ui.heading("Notifications")); /* @@ -114,7 +115,7 @@ fn timeline_ui( TimelineTabView::new( timeline.current_view(), reversed, - textmode, + note_options, &txn, ndb, note_cache, @@ -212,7 +213,7 @@ fn shrink_range_to_width(range: egui::Rangef, width: f32) -> egui::Rangef { pub struct TimelineTabView<'a> { tab: &'a TimelineTab, reversed: bool, - textmode: bool, + note_options: NoteOptions, txn: &'a Transaction, ndb: &'a Ndb, note_cache: &'a mut NoteCache, @@ -223,7 +224,7 @@ impl<'a> TimelineTabView<'a> { pub fn new( tab: &'a TimelineTab, reversed: bool, - textmode: bool, + note_options: NoteOptions, txn: &'a Transaction, ndb: &'a Ndb, note_cache: &'a mut NoteCache, @@ -233,7 +234,7 @@ impl<'a> TimelineTabView<'a> { tab, reversed, txn, - textmode, + note_options, ndb, note_cache, img_cache, @@ -270,9 +271,7 @@ impl<'a> TimelineTabView<'a> { ui::padding(8.0, ui, |ui| { let resp = ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e) - .note_previews(!self.textmode) - .selectable_text(false) - .options_button(true) + .note_options(self.note_options) .show(ui); bar_action = bar_action.or(resp.action.bar_action);