hide media on universe view

Also fixes textmode

Fixes: https://github.com/damus-io/notedeck/issues/443
This commit is contained in:
William Casarin
2024-11-17 16:44:52 -08:00
parent 33b2fa263e
commit a678e647a4
7 changed files with 86 additions and 23 deletions

View File

@@ -7,12 +7,12 @@ use crate::{
notes_holder::NotesHolderStorage, notes_holder::NotesHolderStorage,
profile::Profile, profile::Profile,
thread::Thread, thread::Thread,
timeline::TimelineId, timeline::{TimelineId, TimelineKind},
ui::{ ui::{
self, self,
note::{ note::{
post::{PostAction, PostResponse}, post::{PostAction, PostResponse},
QuoteRepostView, NoteOptions, QuoteRepostView,
}, },
profile::ProfileView, profile::ProfileView,
}, },
@@ -57,9 +57,28 @@ pub fn render_timeline_route(
) -> Option<AfterRouteExecution> { ) -> Option<AfterRouteExecution> {
match route { match route {
TimelineRoute::Timeline(timeline_id) => { TimelineRoute::Timeline(timeline_id) => {
let timeline_response = let note_options = {
ui::TimelineView::new(timeline_id, columns, ndb, note_cache, img_cache, textmode) let is_universe = if let Some(timeline) = columns.find_timeline(timeline_id) {
.ui(ui); 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 { if let Some(bar_action) = timeline_response.bar_action {
let txn = Transaction::new(ndb).expect("txn"); let txn = Transaction::new(ndb).expect("txn");
let mut cur_column = columns.columns_mut(); let mut cur_column = columns.columns_mut();
@@ -168,8 +187,16 @@ pub fn render_profile_route(
col: usize, col: usize,
ui: &mut egui::Ui, ui: &mut egui::Ui,
) -> Option<AfterRouteExecution> { ) -> Option<AfterRouteExecution> {
let timeline_response = let timeline_response = ProfileView::new(
ProfileView::new(pubkey, col, profiles, ndb, note_cache, img_cache).ui(ui); pubkey,
col,
profiles,
ndb,
note_cache,
img_cache,
NoteOptions::default(),
)
.ui(ui);
if let Some(bar_action) = timeline_response.bar_action { if let Some(bar_action) = timeline_response.bar_action {
let txn = nostrdb::Transaction::new(ndb).expect("txn"); let txn = nostrdb::Transaction::new(ndb).expect("txn");
let mut cur_column = columns.columns_mut(); let mut cur_column = columns.columns_mut();

View File

@@ -139,6 +139,7 @@ fn render_note_contents(
let selectable = options.has_selectable_text(); let selectable = options.has_selectable_text();
let mut images: Vec<String> = vec![]; let mut images: Vec<String> = vec![];
let mut inline_note: Option<(&[u8; 32], &str)> = None; let mut inline_note: Option<(&[u8; 32], &str)> = None;
let hide_media = options.has_hide_media();
let response = ui.horizontal_wrapped(|ui| { let response = ui.horizontal_wrapped(|ui| {
let blocks = if let Ok(blocks) = ndb.get_blocks_by_key(txn, note_key) { let blocks = if let Ok(blocks) = ndb.get_blocks_by_key(txn, note_key) {
@@ -183,7 +184,7 @@ fn render_note_contents(
BlockType::Url => { BlockType::Url => {
let lower_url = block.as_str().to_lowercase(); 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()); images.push(block.as_str().to_string());
} else { } else {
#[cfg(feature = "profiling")] #[cfg(feature = "profiling")]

View File

@@ -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 { pub fn textmode(mut self, enable: bool) -> Self {
self.options_mut().set_textmode(enable); self.options_mut().set_textmode(enable);
self self

View File

@@ -14,6 +14,13 @@ bitflags! {
const selectable_text = 0b0000000000100000; const selectable_text = 0b0000000000100000;
const textmode = 0b0000000001000000; const textmode = 0b0000000001000000;
const options_button = 0b0000000010000000; 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_actionbar, actionbar);
create_setter!(set_wide, wide); create_setter!(set_wide, wide);
create_setter!(set_options_button, options_button); 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] #[inline]
pub fn has_actionbar(self) -> bool { pub fn has_actionbar(self) -> bool {
(self & NoteOptions::actionbar) == NoteOptions::actionbar (self & NoteOptions::actionbar) == NoteOptions::actionbar
} }
#[inline]
pub fn has_hide_media(self) -> bool {
(self & NoteOptions::hide_media) == NoteOptions::hide_media
}
#[inline] #[inline]
pub fn has_selectable_text(self) -> bool { pub fn has_selectable_text(self) -> bool {
(self & NoteOptions::selectable_text) == NoteOptions::selectable_text (self & NoteOptions::selectable_text) == NoteOptions::selectable_text

View File

@@ -1,6 +1,7 @@
pub mod picture; pub mod picture;
pub mod preview; pub mod preview;
use crate::ui::note::NoteOptions;
use egui::{ScrollArea, Widget}; use egui::{ScrollArea, Widget};
use enostr::Pubkey; use enostr::Pubkey;
use nostrdb::{Ndb, Transaction}; use nostrdb::{Ndb, Transaction};
@@ -18,6 +19,7 @@ pub struct ProfileView<'a> {
pubkey: &'a Pubkey, pubkey: &'a Pubkey,
col_id: usize, col_id: usize,
profiles: &'a mut NotesHolderStorage<Profile>, profiles: &'a mut NotesHolderStorage<Profile>,
note_options: NoteOptions,
ndb: &'a Ndb, ndb: &'a Ndb,
note_cache: &'a mut NoteCache, note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache, img_cache: &'a mut ImageCache,
@@ -31,6 +33,7 @@ impl<'a> ProfileView<'a> {
ndb: &'a Ndb, ndb: &'a Ndb,
note_cache: &'a mut NoteCache, note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache, img_cache: &'a mut ImageCache,
note_options: NoteOptions,
) -> Self { ) -> Self {
ProfileView { ProfileView {
pubkey, pubkey,
@@ -39,6 +42,7 @@ impl<'a> ProfileView<'a> {
ndb, ndb,
note_cache, note_cache,
img_cache, img_cache,
note_options,
} }
} }
@@ -59,10 +63,12 @@ impl<'a> ProfileView<'a> {
profile.timeline.selected_view = tabs_ui(ui); profile.timeline.selected_view = tabs_ui(ui);
let reversed = false;
TimelineTabView::new( TimelineTabView::new(
profile.timeline.current_view(), profile.timeline.current_view(),
false, reversed,
false, self.note_options,
&txn, &txn,
self.ndb, self.ndb,
self.note_cache, self.note_cache,

View File

@@ -4,6 +4,7 @@ use crate::{
notecache::NoteCache, notecache::NoteCache,
notes_holder::{NotesHolder, NotesHolderStorage}, notes_holder::{NotesHolder, NotesHolderStorage},
thread::Thread, thread::Thread,
ui::note::NoteOptions,
}; };
use nostrdb::{Ndb, NoteKey, Transaction}; use nostrdb::{Ndb, NoteKey, Transaction};
use tracing::error; use tracing::error;
@@ -102,10 +103,15 @@ impl<'a> ThreadView<'a> {
error!("Thread::poll_notes_into_view: {e}"); 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( TimelineTabView::new(
thread.view(), thread.view(),
true, true,
self.textmode, note_options,
&txn, &txn,
self.ndb, self.ndb,
self.note_cache, self.note_cache,

View File

@@ -2,6 +2,7 @@ use crate::actionbar::{BarAction, NoteActionResponse};
use crate::timeline::TimelineTab; use crate::timeline::TimelineTab;
use crate::{ use crate::{
column::Columns, imgcache::ImageCache, notecache::NoteCache, timeline::TimelineId, ui, column::Columns, imgcache::ImageCache, notecache::NoteCache, timeline::TimelineId, ui,
ui::note::NoteOptions,
}; };
use egui::containers::scroll_area::ScrollBarVisibility; use egui::containers::scroll_area::ScrollBarVisibility;
use egui::{Direction, Layout}; use egui::{Direction, Layout};
@@ -15,7 +16,7 @@ pub struct TimelineView<'a> {
ndb: &'a Ndb, ndb: &'a Ndb,
note_cache: &'a mut NoteCache, note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache, img_cache: &'a mut ImageCache,
textmode: bool, note_options: NoteOptions,
reverse: bool, reverse: bool,
} }
@@ -26,7 +27,7 @@ impl<'a> TimelineView<'a> {
ndb: &'a Ndb, ndb: &'a Ndb,
note_cache: &'a mut NoteCache, note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache, img_cache: &'a mut ImageCache,
textmode: bool, note_options: NoteOptions,
) -> TimelineView<'a> { ) -> TimelineView<'a> {
let reverse = false; let reverse = false;
TimelineView { TimelineView {
@@ -36,7 +37,7 @@ impl<'a> TimelineView<'a> {
note_cache, note_cache,
img_cache, img_cache,
reverse, reverse,
textmode, note_options,
} }
} }
@@ -49,7 +50,7 @@ impl<'a> TimelineView<'a> {
self.note_cache, self.note_cache,
self.img_cache, self.img_cache,
self.reverse, self.reverse,
self.textmode, self.note_options,
) )
} }
@@ -68,7 +69,7 @@ fn timeline_ui(
note_cache: &mut NoteCache, note_cache: &mut NoteCache,
img_cache: &mut ImageCache, img_cache: &mut ImageCache,
reversed: bool, reversed: bool,
textmode: bool, note_options: NoteOptions,
) -> NoteActionResponse { ) -> NoteActionResponse {
//padding(4.0, ui, |ui| ui.heading("Notifications")); //padding(4.0, ui, |ui| ui.heading("Notifications"));
/* /*
@@ -114,7 +115,7 @@ fn timeline_ui(
TimelineTabView::new( TimelineTabView::new(
timeline.current_view(), timeline.current_view(),
reversed, reversed,
textmode, note_options,
&txn, &txn,
ndb, ndb,
note_cache, note_cache,
@@ -212,7 +213,7 @@ fn shrink_range_to_width(range: egui::Rangef, width: f32) -> egui::Rangef {
pub struct TimelineTabView<'a> { pub struct TimelineTabView<'a> {
tab: &'a TimelineTab, tab: &'a TimelineTab,
reversed: bool, reversed: bool,
textmode: bool, note_options: NoteOptions,
txn: &'a Transaction, txn: &'a Transaction,
ndb: &'a Ndb, ndb: &'a Ndb,
note_cache: &'a mut NoteCache, note_cache: &'a mut NoteCache,
@@ -223,7 +224,7 @@ impl<'a> TimelineTabView<'a> {
pub fn new( pub fn new(
tab: &'a TimelineTab, tab: &'a TimelineTab,
reversed: bool, reversed: bool,
textmode: bool, note_options: NoteOptions,
txn: &'a Transaction, txn: &'a Transaction,
ndb: &'a Ndb, ndb: &'a Ndb,
note_cache: &'a mut NoteCache, note_cache: &'a mut NoteCache,
@@ -233,7 +234,7 @@ impl<'a> TimelineTabView<'a> {
tab, tab,
reversed, reversed,
txn, txn,
textmode, note_options,
ndb, ndb,
note_cache, note_cache,
img_cache, img_cache,
@@ -270,9 +271,7 @@ impl<'a> TimelineTabView<'a> {
ui::padding(8.0, ui, |ui| { ui::padding(8.0, ui, |ui| {
let resp = ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, &note) let resp = ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, &note)
.note_previews(!self.textmode) .note_options(self.note_options)
.selectable_text(false)
.options_button(true)
.show(ui); .show(ui);
bar_action = bar_action.or(resp.action.bar_action); bar_action = bar_action.or(resp.action.bar_action);