Store bookmarks in GLOBALS and populate in init()

This commit is contained in:
Mike Dilger 2024-07-03 09:05:41 +12:00
parent 0e3b06e24f
commit b424579cc5
2 changed files with 17 additions and 0 deletions

View File

@ -1,3 +1,4 @@
use crate::bookmarks::BookmarkList;
use crate::comms::{RelayJob, ToMinionMessage, ToOverlordMessage};
use crate::feed::Feed;
use crate::fetcher::Fetcher;
@ -153,6 +154,9 @@ pub struct Globals {
/// Loading more - how many relays are still loading a chunk of events.
pub loading_more: AtomicUsize,
/// Bookmarks
pub bookmarks: PRwLock<BookmarkList>,
}
lazy_static! {
@ -221,6 +225,7 @@ lazy_static! {
advertise_jobs_remaining: AtomicUsize::new(0),
pending: Pending::new(),
loading_more: AtomicUsize::new(0),
bookmarks: PRwLock::new(BookmarkList::empty()),
}
};
}

View File

@ -157,6 +157,7 @@ extern crate lazy_static;
/// when connecting to relays
pub static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
use nostr_types::EventKind;
use std::ops::DerefMut;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -220,6 +221,17 @@ pub fn init() -> Result<(), Error> {
}
}
// Populate global bookmarks
if let Some(pubkey) = GLOBALS.identity.public_key() {
if let Some(event) =
GLOBALS
.storage
.get_replaceable_event(EventKind::BookmarkList, pubkey, "")?
{
*GLOBALS.bookmarks.write() = BookmarkList::from_event(&event)?;
}
}
Ok(())
}