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

@@ -139,6 +139,7 @@ fn render_note_contents(
let selectable = options.has_selectable_text();
let mut images: Vec<String> = 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")]

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 {
self.options_mut().set_textmode(enable);
self

View File

@@ -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