Move failed_avatars list so we can remove items from it when metadata is updated

This commit is contained in:
Mike Dilger 2023-01-02 23:51:15 +13:00
parent e64c85a5ea
commit f991e4e801
3 changed files with 15 additions and 7 deletions

View File

@ -7,9 +7,9 @@ use crate::people::People;
use crate::relationship::Relationship; use crate::relationship::Relationship;
use crate::settings::Settings; use crate::settings::Settings;
use crate::signer::Signer; use crate::signer::Signer;
use nostr_types::{Event, Id, IdHex, Unixtime, Url}; use nostr_types::{Event, Id, IdHex, PublicKeyHex, Unixtime, Url};
use rusqlite::Connection; use rusqlite::Connection;
use std::collections::HashMap; use std::collections::{HashMap, HashSet};
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use tokio::sync::{broadcast, mpsc, Mutex, RwLock}; use tokio::sync::{broadcast, mpsc, Mutex, RwLock};
use tracing::info; use tracing::info;
@ -76,6 +76,9 @@ pub struct Globals {
/// Fetcher /// Fetcher
pub fetcher: Fetcher, pub fetcher: Fetcher,
/// Failed Avatar Fetches
pub failed_avatars: RwLock<HashSet<PublicKeyHex>>,
} }
lazy_static! { lazy_static! {
@ -106,6 +109,7 @@ lazy_static! {
event_is_new: RwLock::new(Vec::new()), event_is_new: RwLock::new(Vec::new()),
feed: Mutex::new(Feed::new()), feed: Mutex::new(Feed::new()),
fetcher: Fetcher::new(), fetcher: Fetcher::new(),
failed_avatars: RwLock::new(HashSet::new()),
} }
}; };
} }

View File

@ -123,6 +123,9 @@ impl People {
}) })
.await??; .await??;
// Remove from failed avatars list so the UI will try to fetch the avatar again
GLOBALS.failed_avatars.write().await.remove(pubkeyhex);
Ok(()) Ok(())
} }

View File

@ -20,7 +20,7 @@ use egui::{
TextureOptions, Ui, TextureOptions, Ui,
}; };
use nostr_types::{Id, PublicKey, PublicKeyHex}; use nostr_types::{Id, PublicKey, PublicKeyHex};
use std::collections::{HashMap, HashSet}; use std::collections::HashMap;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use zeroize::Zeroize; use zeroize::Zeroize;
@ -89,7 +89,6 @@ struct GossipUi {
person_view_person: Option<DbPerson>, person_view_person: Option<DbPerson>,
person_view_name: Option<String>, person_view_name: Option<String>,
avatars: HashMap<PublicKeyHex, TextureHandle>, avatars: HashMap<PublicKeyHex, TextureHandle>,
failed_avatars: HashSet<PublicKeyHex>,
new_relay_url: String, new_relay_url: String,
} }
@ -165,7 +164,6 @@ impl GossipUi {
person_view_person: None, person_view_person: None,
person_view_name: None, person_view_name: None,
avatars: HashMap::new(), avatars: HashMap::new(),
failed_avatars: HashSet::new(),
new_relay_url: "".to_owned(), new_relay_url: "".to_owned(),
} }
} }
@ -287,7 +285,7 @@ impl GossipUi {
pubkeyhex: &PublicKeyHex, pubkeyhex: &PublicKeyHex,
) -> Option<TextureHandle> { ) -> Option<TextureHandle> {
// Do not keep retrying if failed // Do not keep retrying if failed
if self.failed_avatars.contains(pubkeyhex) { if GLOBALS.failed_avatars.blocking_read().contains(pubkeyhex) {
return None; return None;
} }
@ -297,7 +295,10 @@ impl GossipUi {
match GLOBALS.people.blocking_write().get_avatar(pubkeyhex) { match GLOBALS.people.blocking_write().get_avatar(pubkeyhex) {
Err(_) => { Err(_) => {
self.failed_avatars.insert(pubkeyhex.to_owned()); GLOBALS
.failed_avatars
.blocking_write()
.insert(pubkeyhex.to_owned());
None None
} }
Ok(Some(rgbaimage)) => { Ok(Some(rgbaimage)) => {