commit 7f37f1e9d30fcc9add463f88eba992505d6f4dad
parent d17b5e07038ea76684d6cf8c20d9f5523b8b80ee
Author: William Casarin <jb55@jb55.com>
Date: Wed, 12 Jun 2024 11:02:03 -0700
perf: don't clone bytes via a more specialized function
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/ui/profile/profile_preview_controller.rs b/src/ui/profile/profile_preview_controller.rs
@@ -135,6 +135,30 @@ pub fn show_with_nickname(
Ok(ui_element(ui, &get_display_name(&profile)))
}
+pub fn show_with_selected_pfp(
+ app: &mut Damus,
+ ui: &mut egui::Ui,
+ ui_element: fn(ui: &mut egui::Ui, pfp: ProfilePic) -> egui::Response,
+) -> Option<egui::Response> {
+ let selected_account = app.account_manager.get_selected_account();
+ if let Some(selected_account) = selected_account {
+ if let Ok(txn) = Transaction::new(&app.ndb) {
+ let profile = app
+ .ndb
+ .get_profile_by_pubkey(&txn, selected_account.pubkey.bytes());
+
+ if let Ok(profile) = profile {
+ return Some(ui_element(
+ ui,
+ ProfilePic::new(&mut app.img_cache, get_profile_url(&profile)),
+ ));
+ }
+ }
+ }
+
+ None
+}
+
pub fn show_with_pfp(
app: &mut Damus,
ui: &mut egui::Ui,
diff --git a/src/ui/side_panel.rs b/src/ui/side_panel.rs
@@ -71,18 +71,7 @@ impl<'a> DesktopSidePanel<'a> {
}
fn pfp_button(&mut self, ui: &mut egui::Ui) -> egui::Response {
- let selected_account = self.app.account_manager.get_selected_account();
- if let Some(selected_account) = selected_account {
- if let Some(response) = profile_preview_controller::show_with_pfp(
- self.app,
- ui,
- &selected_account.pubkey.bytes().clone(),
- show_pfp(),
- ) {
- return response;
- }
- }
-
+ profile_preview_controller::show_with_selected_pfp(self.app, ui, show_pfp());
add_button_to_ui(ui, no_account_pfp())
}
}