notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 23d02a9dd215c4d87bba3d529ac2f3c4a8ee70a0
parent fa545bc07774a6eab272db065d95481c783b6257
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 15 Jul 2025 14:35:14 -0700

note/options: remove redundant has function

there is a contains function generated by the bitflags macro

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mcrates/notedeck_ui/src/note/contents.rs | 16++++++++--------
Mcrates/notedeck_ui/src/note/mod.rs | 12++++++------
Mcrates/notedeck_ui/src/note/options.rs | 8++------
3 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/crates/notedeck_ui/src/note/contents.rs b/crates/notedeck_ui/src/note/contents.rs @@ -123,17 +123,17 @@ pub fn render_note_contents( jobs: &mut JobsCache, ) -> NoteResponse { let note_key = note.key().expect("todo: implement non-db notes"); - let selectable = options.has(NoteOptions::SelectableText); + let selectable = options.contains(NoteOptions::SelectableText); let mut note_action: Option<NoteAction> = None; let mut inline_note: Option<(&[u8; 32], &str)> = None; - let hide_media = options.has(NoteOptions::HideMedia); + let hide_media = options.contains(NoteOptions::HideMedia); let link_color = ui.visuals().hyperlink_color; // The current length of the rendered blocks. Used in trucation logic let mut current_len: usize = 0; let truncate_len = 280; - if !options.has(NoteOptions::IsPreview) { + if !options.contains(NoteOptions::IsPreview) { // need this for the rect to take the full width of the column let _ = ui.allocate_at_least(egui::vec2(ui.available_width(), 0.0), egui::Sense::click()); } @@ -183,11 +183,11 @@ pub fn render_note_contents( } } - Mention::Note(note) if options.has(NoteOptions::HasNotePreviews) => { + Mention::Note(note) if options.contains(NoteOptions::HasNotePreviews) => { inline_note = Some((note.id(), block.as_str())); } - Mention::Event(note) if options.has(NoteOptions::HasNotePreviews) => { + Mention::Event(note) if options.contains(NoteOptions::HasNotePreviews) => { inline_note = Some((note.id(), block.as_str())); } @@ -233,7 +233,7 @@ pub fn render_note_contents( BlockType::Text => { // truncate logic let mut truncate = false; - let block_str = if options.has(NoteOptions::Truncate) + let block_str = if options.contains(NoteOptions::Truncate) && (current_len + block.as_str().len() > truncate_len) { truncate = true; @@ -251,7 +251,7 @@ pub fn render_note_contents( block_str }; - if options.has(NoteOptions::ScrambleText) { + if options.contains(NoteOptions::ScrambleText) { ui.add( egui::Label::new(rot13(block_str)) .wrap() @@ -287,7 +287,7 @@ pub fn render_note_contents( }); let mut media_action = None; - if !supported_medias.is_empty() && !options.has(NoteOptions::Textmode) { + if !supported_medias.is_empty() && !options.contains(NoteOptions::Textmode) { ui.add_space(2.0); let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note"))); diff --git a/crates/notedeck_ui/src/note/mod.rs b/crates/notedeck_ui/src/note/mod.rs @@ -252,7 +252,7 @@ impl<'a, 'd> NoteView<'a, 'd> { profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>, ui: &mut egui::Ui, ) -> PfpResponse { - if !self.options().has(NoteOptions::Wide) { + if !self.options().contains(NoteOptions::Wide) { ui.spacing_mut().item_spacing.x = 16.0; } else { ui.spacing_mut().item_spacing.x = 4.0; @@ -337,7 +337,7 @@ impl<'a, 'd> NoteView<'a, 'd> { } pub fn show(&mut self, ui: &mut egui::Ui) -> NoteResponse { - if self.options().has(NoteOptions::Textmode) { + if self.options().contains(NoteOptions::Textmode) { NoteResponse::new(self.textmode_ui(ui)) } else if self.framed { egui::Frame::new() @@ -468,7 +468,7 @@ impl<'a, 'd> NoteView<'a, 'd> { note_action = contents.action.or(note_action); - if self.options().has(NoteOptions::ActionBar) { + if self.options().contains(NoteOptions::ActionBar) { note_action = render_note_actionbar( ui, self.zapping_acc.as_ref().map(|c| Zapper { @@ -549,7 +549,7 @@ impl<'a, 'd> NoteView<'a, 'd> { note_action = contents.action.or(note_action); - if self.options().has(NoteOptions::ActionBar) { + if self.options().contains(NoteOptions::ActionBar) { note_action = render_note_actionbar( ui, self.zapping_acc.as_ref().map(|c| Zapper { @@ -587,7 +587,7 @@ impl<'a, 'd> NoteView<'a, 'd> { let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id); // wide design - let response = if self.options().has(NoteOptions::Wide) { + let response = if self.options().contains(NoteOptions::Wide) { self.wide_ui(ui, txn, note_key, &profile) } else { self.standard_ui(ui, txn, note_key, &profile) @@ -596,7 +596,7 @@ impl<'a, 'd> NoteView<'a, 'd> { let note_ui_resp = response.inner; let mut note_action = note_ui_resp.action; - if self.options().has(NoteOptions::OptionsButton) { + if self.options().contains(NoteOptions::OptionsButton) { let context_pos = { let size = NoteContextButton::max_width(); let top_right = response.response.rect.right_top(); diff --git a/crates/notedeck_ui/src/note/options.rs b/crates/notedeck_ui/src/note/options.rs @@ -35,10 +35,6 @@ impl Default for NoteOptions { } impl NoteOptions { - pub fn has(self, flag: NoteOptions) -> bool { - (self & flag) == flag - } - pub fn new(is_universe_timeline: bool) -> Self { let mut options = NoteOptions::default(); options.set(NoteOptions::HideMedia, is_universe_timeline); @@ -46,9 +42,9 @@ impl NoteOptions { } pub fn pfp_size(&self) -> i8 { - if self.has(NoteOptions::SmallPfp) { + if self.contains(NoteOptions::SmallPfp) { ProfilePic::small_size() - } else if self.has(NoteOptions::MediumPfp) { + } else if self.contains(NoteOptions::MediumPfp) { ProfilePic::medium_size() } else { ProfilePic::default_size()