Skip to content

Commit

Permalink
hide media on universe view
Browse files Browse the repository at this point in the history
Also fixes textmode

Fixes: #443
  • Loading branch information
jb55 committed Nov 18, 2024
1 parent 33b2fa2 commit a678e64
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 23 deletions.
41 changes: 34 additions & 7 deletions src/timeline/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -57,9 +57,28 @@ pub fn render_timeline_route(
) -> Option<AfterRouteExecution> {
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();
Expand Down Expand Up @@ -168,8 +187,16 @@ pub fn render_profile_route(
col: usize,
ui: &mut egui::Ui,
) -> Option<AfterRouteExecution> {
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();
Expand Down
3 changes: 2 additions & 1 deletion src/ui/note/contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")]
Expand Down
5 changes: 5 additions & 0 deletions src/ui/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/ui/note/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/ui/profile/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -18,6 +19,7 @@ pub struct ProfileView<'a> {
pubkey: &'a Pubkey,
col_id: usize,
profiles: &'a mut NotesHolderStorage<Profile>,
note_options: NoteOptions,
ndb: &'a Ndb,
note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache,
Expand All @@ -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,
Expand All @@ -39,6 +42,7 @@ impl<'a> ProfileView<'a> {
ndb,
note_cache,
img_cache,
note_options,
}
}

Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/ui/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 11 additions & 12 deletions src/ui/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
}

Expand All @@ -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 {
Expand All @@ -36,7 +37,7 @@ impl<'a> TimelineView<'a> {
note_cache,
img_cache,
reverse,
textmode,
note_options,
}
}

Expand All @@ -49,7 +50,7 @@ impl<'a> TimelineView<'a> {
self.note_cache,
self.img_cache,
self.reverse,
self.textmode,
self.note_options,
)
}

Expand All @@ -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"));
/*
Expand Down Expand Up @@ -114,7 +115,7 @@ fn timeline_ui(
TimelineTabView::new(
timeline.current_view(),
reversed,
textmode,
note_options,
&txn,
ndb,
note_cache,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -233,7 +234,7 @@ impl<'a> TimelineTabView<'a> {
tab,
reversed,
txn,
textmode,
note_options,
ndb,
note_cache,
img_cache,
Expand Down Expand Up @@ -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, &note)
.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);
Expand Down

0 comments on commit a678e64

Please sign in to comment.