commit 1ce777c306283632581c4a5fac3e23d0c876cc7c
parent 3e92f868c7b7272d38efea7270ccbd82e8144cb5
Author: kernelkind <kernelkind@gmail.com>
Date: Thu, 11 Dec 2025 13:08:38 -0600
feat(ContactsListView): add ability to use HashSet as well
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
2 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs
@@ -41,7 +41,9 @@ use notedeck::{
get_current_default_msats, nav::DragResponse, tr, ui::is_narrow, Accounts, AppContext,
NoteAction, NoteCache, NoteContext, RelayAction,
};
-use notedeck_ui::{ContactsListAction, ContactsListView, NoteOptions};
+use notedeck_ui::{
+ contacts_list::ContactsCollection, ContactsListAction, ContactsListView, NoteOptions,
+};
use tracing::error;
/// The result of processing a nav response
@@ -999,7 +1001,7 @@ fn render_nav_body(
(txn, contacts)
};
- ContactsListView::new(pubkey, contacts, &mut note_context, &txn)
+ ContactsListView::new(ContactsCollection::Vec(&contacts), &mut note_context, &txn)
.ui(ui)
.map_output(|action| match action {
ContactsListAction::OpenProfile(pk) => {
diff --git a/crates/notedeck_ui/src/contacts_list.rs b/crates/notedeck_ui/src/contacts_list.rs
@@ -1,3 +1,5 @@
+use std::collections::HashSet;
+
use crate::ProfilePic;
use egui::{RichText, Sense};
use enostr::Pubkey;
@@ -5,7 +7,7 @@ use nostrdb::Transaction;
use notedeck::{name::get_display_name, profile::get_profile_url, DragResponse, NoteContext};
pub struct ContactsListView<'a, 'd, 'txn> {
- contacts: Vec<Pubkey>,
+ contacts: ContactsCollection<'a>,
note_context: &'a mut NoteContext<'d>,
txn: &'txn Transaction,
}
@@ -15,10 +17,39 @@ pub enum ContactsListAction {
OpenProfile(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, 'd, 'txn> ContactsListView<'a, 'd, 'txn> {
pub fn new(
- _pubkey: &'a Pubkey,
- contacts: Vec<Pubkey>,
+ contacts: ContactsCollection<'a>,
note_context: &'a mut NoteContext<'d>,
txn: &'txn Transaction,
) -> Self {
@@ -35,7 +66,7 @@ impl<'a, 'd, 'txn> ContactsListView<'a, 'd, 'txn> {
egui::ScrollArea::vertical().show(ui, |ui| {
let clip_rect = ui.clip_rect();
- for contact_pubkey in &self.contacts {
+ for contact_pubkey in self.contacts.iter() {
let (rect, resp) =
ui.allocate_exact_size(egui::vec2(ui.available_width(), 56.0), Sense::click());