commit 1920df7d0a5cdc100efd68a13669ba260372b9e1
parent c52a49f251a8d93396077c4fb895cc26bdf60006
Author: William Casarin <jb55@jb55.com>
Date: Thu, 5 Feb 2026 00:49:18 -0800
contacts_list: simplify ContactsListView with generic iterator
Replace ContactsCollection/ContactsIter enums with a generic
IntoIterator parameter. Callers can now pass any iterator of
&Pubkey directly instead of wrapping in enum variants.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat:
3 files changed, 13 insertions(+), 43 deletions(-)
diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs
@@ -41,9 +41,7 @@ use notedeck::{
get_current_default_msats, nav::DragResponse, tr, ui::is_narrow, Accounts, AppContext,
NoteAction, NoteCache, NoteContext, RelayAction,
};
-use notedeck_ui::{
- contacts_list::ContactsCollection, ContactsListAction, ContactsListView, NoteOptions,
-};
+use notedeck_ui::{ContactsListAction, ContactsListView, NoteOptions};
use tracing::error;
/// The result of processing a nav response
@@ -1011,7 +1009,7 @@ fn render_nav_body(
};
ContactsListView::new(
- ContactsCollection::Vec(&contacts),
+ &contacts,
note_context.jobs,
note_context.ndb,
note_context.img_cache,
diff --git a/crates/notedeck_messages/src/ui/create_convo.rs b/crates/notedeck_messages/src/ui/create_convo.rs
@@ -3,8 +3,7 @@ use enostr::Pubkey;
use nostrdb::{Ndb, Transaction};
use notedeck::{tr, ContactState, Images, Localization, MediaJobSender, NotedeckTextStyle};
use notedeck_ui::{
- contacts_list::ContactsCollection, profile_row, search_input_box, search_profiles,
- ContactsListView, ProfileSearchResult,
+ profile_row, search_input_box, search_profiles, ContactsListView, ProfileSearchResult,
};
use crate::cache::CreateConvoState;
@@ -69,7 +68,7 @@ impl<'a> CreateConvoUi<'a> {
if let ContactState::Received { contacts, .. } = self.contacts {
let resp = ContactsListView::new(
- ContactsCollection::Set(contacts),
+ contacts,
self.jobs,
self.ndb,
self.img_cache,
diff --git a/crates/notedeck_ui/src/contacts_list.rs b/crates/notedeck_ui/src/contacts_list.rs
@@ -150,8 +150,8 @@ pub fn profile_row(
.clicked()
}
-pub struct ContactsListView<'a, 'txn> {
- contacts: ContactsCollection<'a>,
+pub struct ContactsListView<'a, 'txn, I> {
+ contacts: I,
jobs: &'a MediaJobSender,
ndb: &'a Ndb,
img_cache: &'a mut Images,
@@ -164,39 +164,12 @@ pub enum ContactsListAction {
Select(Pubkey),
}
-pub enum ContactsCollection<'a> {
- Vec(&'a Vec<Pubkey>),
- Set(&'a HashSet<Pubkey>),
-}
-
-pub enum ContactsIter<'a> {
- Vec(std::slice::Iter<'a, Pubkey>),
- Set(std::collections::hash_set::Iter<'a, Pubkey>),
-}
-
-impl<'a> ContactsCollection<'a> {
- pub fn iter(&'a self) -> ContactsIter<'a> {
- match self {
- ContactsCollection::Vec(v) => ContactsIter::Vec(v.iter()),
- ContactsCollection::Set(s) => ContactsIter::Set(s.iter()),
- }
- }
-}
-
-impl<'a> Iterator for ContactsIter<'a> {
- type Item = &'a Pubkey;
-
- fn next(&mut self) -> Option<Self::Item> {
- match self {
- ContactsIter::Vec(iter) => iter.next().as_ref().copied(),
- ContactsIter::Set(iter) => iter.next().as_ref().copied(),
- }
- }
-}
-
-impl<'a, 'txn> ContactsListView<'a, 'txn> {
+impl<'a, 'txn, I> ContactsListView<'a, 'txn, I>
+where
+ I: IntoIterator<Item = &'a Pubkey>,
+{
pub fn new(
- contacts: ContactsCollection<'a>,
+ contacts: I,
jobs: &'a MediaJobSender,
ndb: &'a Ndb,
img_cache: &'a mut Images,
@@ -213,11 +186,11 @@ impl<'a, 'txn> ContactsListView<'a, 'txn> {
}
}
- pub fn ui(&mut self, ui: &mut egui::Ui) -> DragResponse<ContactsListAction> {
+ pub fn ui(self, ui: &mut egui::Ui) -> DragResponse<ContactsListAction> {
let mut action = None;
egui::ScrollArea::vertical().show(ui, |ui| {
- for contact_pubkey in self.contacts.iter() {
+ for contact_pubkey in self.contacts {
let profile = self
.ndb
.get_profile_by_pubkey(self.txn, contact_pubkey.bytes())