mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 08:21:47 +00:00
Store bookmarks in GLOBALS and populate in init()
This commit is contained in:
parent
0e3b06e24f
commit
b424579cc5
@ -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()),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user