allow missing profiles in account switcher
Fixes: https://github.com/damus-io/notedeck/issues/119 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -64,8 +64,11 @@ impl<'a, 'cache> ProfilePreview<'a, 'cache> {
|
|||||||
|
|
||||||
fn body(self, ui: &mut egui::Ui) {
|
fn body(self, ui: &mut egui::Ui) {
|
||||||
crate::ui::padding(12.0, ui, |ui| {
|
crate::ui::padding(12.0, ui, |ui| {
|
||||||
ui.add(ProfilePic::new(self.cache, get_profile_url(self.profile)).size(80.0));
|
ui.add(ProfilePic::new(self.cache, get_profile_url(Some(self.profile))).size(80.0));
|
||||||
ui.add(display_name_widget(get_display_name(self.profile), false));
|
ui.add(display_name_widget(
|
||||||
|
get_display_name(Some(self.profile)),
|
||||||
|
false,
|
||||||
|
));
|
||||||
ui.add(about_section_widget(self.profile));
|
ui.add(about_section_widget(self.profile));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -85,12 +88,12 @@ impl<'a, 'cache> egui::Widget for ProfilePreview<'a, 'cache> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct SimpleProfilePreview<'a, 'cache> {
|
pub struct SimpleProfilePreview<'a, 'cache> {
|
||||||
profile: &'a ProfileRecord<'a>,
|
profile: Option<&'a ProfileRecord<'a>>,
|
||||||
cache: &'cache mut ImageCache,
|
cache: &'cache mut ImageCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'cache> SimpleProfilePreview<'a, 'cache> {
|
impl<'a, 'cache> SimpleProfilePreview<'a, 'cache> {
|
||||||
pub fn new(profile: &'a ProfileRecord<'a>, cache: &'cache mut ImageCache) -> Self {
|
pub fn new(profile: Option<&'a ProfileRecord<'a>>, cache: &'cache mut ImageCache) -> Self {
|
||||||
SimpleProfilePreview { profile, cache }
|
SimpleProfilePreview { profile, cache }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,16 +151,16 @@ mod previews {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_display_name<'a>(profile: &'a ProfileRecord<'a>) -> DisplayName<'a> {
|
pub fn get_display_name<'a>(profile: Option<&'a ProfileRecord<'a>>) -> DisplayName<'a> {
|
||||||
if let Some(name) = crate::profile::get_profile_name(profile) {
|
if let Some(name) = profile.and_then(|p| crate::profile::get_profile_name(p)) {
|
||||||
name
|
name
|
||||||
} else {
|
} else {
|
||||||
DisplayName::One("??")
|
DisplayName::One("??")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_profile_url<'a>(profile: &'a ProfileRecord<'a>) -> &'a str {
|
pub fn get_profile_url<'a>(profile: Option<&'a ProfileRecord<'a>>) -> &'a str {
|
||||||
if let Some(url) = profile.record().profile().and_then(|p| p.picture()) {
|
if let Some(url) = profile.and_then(|pr| pr.record().profile().and_then(|p| p.picture())) {
|
||||||
url
|
url
|
||||||
} else {
|
} else {
|
||||||
ProfilePic::no_pfp_url()
|
ProfilePic::no_pfp_url()
|
||||||
|
|||||||
@@ -40,14 +40,12 @@ pub fn set_profile_previews(
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let profile =
|
let profile = app
|
||||||
if let Ok(profile) = app.ndb.get_profile_by_pubkey(&txn, account.pubkey.bytes()) {
|
.ndb
|
||||||
profile
|
.get_profile_by_pubkey(&txn, account.pubkey.bytes())
|
||||||
} else {
|
.ok();
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let preview = SimpleProfilePreview::new(&profile, &mut app.img_cache);
|
let preview = SimpleProfilePreview::new(profile.as_ref(), &mut app.img_cache);
|
||||||
|
|
||||||
let is_selected = if let Some(selected) = app.account_manager.get_selected_account_index() {
|
let is_selected = if let Some(selected) = app.account_manager.get_selected_account_index() {
|
||||||
i == selected
|
i == selected
|
||||||
@@ -101,14 +99,12 @@ pub fn view_profile_previews(
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let profile =
|
let profile = app
|
||||||
if let Ok(profile) = app.ndb.get_profile_by_pubkey(&txn, account.pubkey.bytes()) {
|
.ndb
|
||||||
profile
|
.get_profile_by_pubkey(&txn, account.pubkey.bytes())
|
||||||
} else {
|
.ok();
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let preview = SimpleProfilePreview::new(&profile, &mut app.img_cache);
|
let preview = SimpleProfilePreview::new(profile.as_ref(), &mut app.img_cache);
|
||||||
|
|
||||||
let is_selected = if let Some(selected) = app.account_manager.get_selected_account_index() {
|
let is_selected = if let Some(selected) = app.account_manager.get_selected_account_index() {
|
||||||
i == selected
|
i == selected
|
||||||
@@ -132,7 +128,7 @@ pub fn show_with_nickname(
|
|||||||
) -> Result<egui::Response> {
|
) -> Result<egui::Response> {
|
||||||
let txn = Transaction::new(ndb)?;
|
let txn = Transaction::new(ndb)?;
|
||||||
let profile = ndb.get_profile_by_pubkey(&txn, key)?;
|
let profile = ndb.get_profile_by_pubkey(&txn, key)?;
|
||||||
Ok(ui_element(ui, &get_display_name(&profile)))
|
Ok(ui_element(ui, &get_display_name(Some(&profile))))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_with_selected_pfp(
|
pub fn show_with_selected_pfp(
|
||||||
@@ -147,14 +143,12 @@ pub fn show_with_selected_pfp(
|
|||||||
.ndb
|
.ndb
|
||||||
.get_profile_by_pubkey(&txn, selected_account.pubkey.bytes());
|
.get_profile_by_pubkey(&txn, selected_account.pubkey.bytes());
|
||||||
|
|
||||||
if let Ok(profile) = profile {
|
|
||||||
return Some(ui_element(
|
return Some(ui_element(
|
||||||
ui,
|
ui,
|
||||||
ProfilePic::new(&mut app.img_cache, get_profile_url(&profile)),
|
ProfilePic::new(&mut app.img_cache, get_profile_url(profile.ok().as_ref())),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -168,12 +162,10 @@ pub fn show_with_pfp(
|
|||||||
if let Ok(txn) = Transaction::new(&app.ndb) {
|
if let Ok(txn) = Transaction::new(&app.ndb) {
|
||||||
let profile = app.ndb.get_profile_by_pubkey(&txn, key);
|
let profile = app.ndb.get_profile_by_pubkey(&txn, key);
|
||||||
|
|
||||||
if let Ok(profile) = profile {
|
|
||||||
return Some(ui_element(
|
return Some(ui_element(
|
||||||
ui,
|
ui,
|
||||||
ProfilePic::new(&mut app.img_cache, get_profile_url(&profile)),
|
ProfilePic::new(&mut app.img_cache, get_profile_url(profile.ok().as_ref())),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user