note/options: remove redundant has function

there is a contains function generated by the bitflags macro

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-07-15 14:35:14 -07:00
parent fa545bc077
commit 23d02a9dd2
3 changed files with 16 additions and 20 deletions

View File

@@ -123,17 +123,17 @@ pub fn render_note_contents(
jobs: &mut JobsCache, jobs: &mut JobsCache,
) -> NoteResponse { ) -> NoteResponse {
let note_key = note.key().expect("todo: implement non-db notes"); 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 note_action: Option<NoteAction> = None;
let mut inline_note: Option<(&[u8; 32], &str)> = 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; let link_color = ui.visuals().hyperlink_color;
// The current length of the rendered blocks. Used in trucation logic // The current length of the rendered blocks. Used in trucation logic
let mut current_len: usize = 0; let mut current_len: usize = 0;
let truncate_len = 280; 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 // 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()); 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())); 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())); inline_note = Some((note.id(), block.as_str()));
} }
@@ -233,7 +233,7 @@ pub fn render_note_contents(
BlockType::Text => { BlockType::Text => {
// truncate logic // truncate logic
let mut truncate = false; 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) && (current_len + block.as_str().len() > truncate_len)
{ {
truncate = true; truncate = true;
@@ -251,7 +251,7 @@ pub fn render_note_contents(
block_str block_str
}; };
if options.has(NoteOptions::ScrambleText) { if options.contains(NoteOptions::ScrambleText) {
ui.add( ui.add(
egui::Label::new(rot13(block_str)) egui::Label::new(rot13(block_str))
.wrap() .wrap()
@@ -287,7 +287,7 @@ pub fn render_note_contents(
}); });
let mut media_action = None; 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); ui.add_space(2.0);
let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note"))); let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note")));

View File

@@ -252,7 +252,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>, profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
ui: &mut egui::Ui, ui: &mut egui::Ui,
) -> PfpResponse { ) -> PfpResponse {
if !self.options().has(NoteOptions::Wide) { if !self.options().contains(NoteOptions::Wide) {
ui.spacing_mut().item_spacing.x = 16.0; ui.spacing_mut().item_spacing.x = 16.0;
} else { } else {
ui.spacing_mut().item_spacing.x = 4.0; 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 { 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)) NoteResponse::new(self.textmode_ui(ui))
} else if self.framed { } else if self.framed {
egui::Frame::new() egui::Frame::new()
@@ -468,7 +468,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
note_action = contents.action.or(note_action); note_action = contents.action.or(note_action);
if self.options().has(NoteOptions::ActionBar) { if self.options().contains(NoteOptions::ActionBar) {
note_action = render_note_actionbar( note_action = render_note_actionbar(
ui, ui,
self.zapping_acc.as_ref().map(|c| Zapper { 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); note_action = contents.action.or(note_action);
if self.options().has(NoteOptions::ActionBar) { if self.options().contains(NoteOptions::ActionBar) {
note_action = render_note_actionbar( note_action = render_note_actionbar(
ui, ui,
self.zapping_acc.as_ref().map(|c| Zapper { 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); let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
// wide design // 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) self.wide_ui(ui, txn, note_key, &profile)
} else { } else {
self.standard_ui(ui, txn, note_key, &profile) 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 note_ui_resp = response.inner;
let mut note_action = note_ui_resp.action; let mut note_action = note_ui_resp.action;
if self.options().has(NoteOptions::OptionsButton) { if self.options().contains(NoteOptions::OptionsButton) {
let context_pos = { let context_pos = {
let size = NoteContextButton::max_width(); let size = NoteContextButton::max_width();
let top_right = response.response.rect.right_top(); let top_right = response.response.rect.right_top();

View File

@@ -35,10 +35,6 @@ impl Default for NoteOptions {
} }
impl NoteOptions { impl NoteOptions {
pub fn has(self, flag: NoteOptions) -> bool {
(self & flag) == flag
}
pub fn new(is_universe_timeline: bool) -> Self { pub fn new(is_universe_timeline: bool) -> Self {
let mut options = NoteOptions::default(); let mut options = NoteOptions::default();
options.set(NoteOptions::HideMedia, is_universe_timeline); options.set(NoteOptions::HideMedia, is_universe_timeline);
@@ -46,9 +42,9 @@ impl NoteOptions {
} }
pub fn pfp_size(&self) -> i8 { pub fn pfp_size(&self) -> i8 {
if self.has(NoteOptions::SmallPfp) { if self.contains(NoteOptions::SmallPfp) {
ProfilePic::small_size() ProfilePic::small_size()
} else if self.has(NoteOptions::MediumPfp) { } else if self.contains(NoteOptions::MediumPfp) {
ProfilePic::medium_size() ProfilePic::medium_size()
} else { } else {
ProfilePic::default_size() ProfilePic::default_size()