From f991e4e8018b764882dfa96a2ed91a44521d6997 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Mon, 2 Jan 2023 23:51:15 +1300 Subject: [PATCH] Move failed_avatars list so we can remove items from it when metadata is updated --- src/globals.rs | 8 ++++++-- src/people.rs | 3 +++ src/ui/mod.rs | 11 ++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/globals.rs b/src/globals.rs index 9307a5c9..3f29b991 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -7,9 +7,9 @@ use crate::people::People; use crate::relationship::Relationship; use crate::settings::Settings; 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 std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::sync::atomic::AtomicBool; use tokio::sync::{broadcast, mpsc, Mutex, RwLock}; use tracing::info; @@ -76,6 +76,9 @@ pub struct Globals { /// Fetcher pub fetcher: Fetcher, + + /// Failed Avatar Fetches + pub failed_avatars: RwLock>, } lazy_static! { @@ -106,6 +109,7 @@ lazy_static! { event_is_new: RwLock::new(Vec::new()), feed: Mutex::new(Feed::new()), fetcher: Fetcher::new(), + failed_avatars: RwLock::new(HashSet::new()), } }; } diff --git a/src/people.rs b/src/people.rs index 4272e4b7..7f1f7021 100644 --- a/src/people.rs +++ b/src/people.rs @@ -123,6 +123,9 @@ impl People { }) .await??; + // Remove from failed avatars list so the UI will try to fetch the avatar again + GLOBALS.failed_avatars.write().await.remove(pubkeyhex); + Ok(()) } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index b895d355..415c6342 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -20,7 +20,7 @@ use egui::{ TextureOptions, Ui, }; use nostr_types::{Id, PublicKey, PublicKeyHex}; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use std::time::{Duration, Instant}; use zeroize::Zeroize; @@ -89,7 +89,6 @@ struct GossipUi { person_view_person: Option, person_view_name: Option, avatars: HashMap, - failed_avatars: HashSet, new_relay_url: String, } @@ -165,7 +164,6 @@ impl GossipUi { person_view_person: None, person_view_name: None, avatars: HashMap::new(), - failed_avatars: HashSet::new(), new_relay_url: "".to_owned(), } } @@ -287,7 +285,7 @@ impl GossipUi { pubkeyhex: &PublicKeyHex, ) -> Option { // Do not keep retrying if failed - if self.failed_avatars.contains(pubkeyhex) { + if GLOBALS.failed_avatars.blocking_read().contains(pubkeyhex) { return None; } @@ -297,7 +295,10 @@ impl GossipUi { match GLOBALS.people.blocking_write().get_avatar(pubkeyhex) { Err(_) => { - self.failed_avatars.insert(pubkeyhex.to_owned()); + GLOBALS + .failed_avatars + .blocking_write() + .insert(pubkeyhex.to_owned()); None } Ok(Some(rgbaimage)) => {