diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs index a6543f97..b768bfcc 100644 --- a/src-tauri/src/commands/mod.rs +++ b/src-tauri/src/commands/mod.rs @@ -2,5 +2,4 @@ pub mod account; pub mod event; pub mod metadata; pub mod relay; -pub mod sync; pub mod window; diff --git a/src-tauri/src/commands/sync.rs b/src-tauri/src/commands/sync.rs deleted file mode 100644 index 5accb93a..00000000 --- a/src-tauri/src/commands/sync.rs +++ /dev/null @@ -1,116 +0,0 @@ -use nostr_sdk::prelude::*; -use std::fs::{self, File}; -use tauri::{ipc::Channel, Manager, State}; - -use crate::Nostr; - -#[tauri::command] -#[specta::specta] -pub fn is_account_sync(id: String, app_handle: tauri::AppHandle) -> Result { - let config_dir = app_handle - .path() - .app_config_dir() - .map_err(|e| e.to_string())?; - let exist = fs::metadata(config_dir.join(id)).is_ok(); - - Ok(exist) -} - -#[tauri::command] -#[specta::specta] -pub async fn sync_account( - id: String, - state: State<'_, Nostr>, - reader: Channel, - app_handle: tauri::AppHandle, -) -> Result<(), String> { - let client = &state.client; - let public_key = PublicKey::from_bech32(&id).map_err(|e| e.to_string())?; - - let filter = Filter::new().author(public_key).kinds(vec![ - Kind::Metadata, - Kind::ContactList, - Kind::Interests, - Kind::InterestSet, - Kind::FollowSet, - Kind::RelayList, - Kind::MuteList, - Kind::EventDeletion, - Kind::Bookmarks, - Kind::BookmarkSet, - Kind::TextNote, - Kind::Repost, - Kind::Custom(30315), - ]); - - let (tx, mut rx) = SyncProgress::channel(); - let opts = SyncOptions::default().progress(tx); - - tauri::async_runtime::spawn(async move { - while (rx.changed().await).is_ok() { - let SyncProgress { total, current } = *rx.borrow_and_update(); - - if total > 0 { - reader - .send((current as f64 / total as f64) * 100.0) - .unwrap() - } - } - }); - - if let Ok(output) = client.sync(filter, &opts).await { - println!("Success: {:?}", output.success); - println!("Failed: {:?}", output.failed); - - let event_pubkeys = client - .database() - .query(vec![Filter::new().kinds(vec![ - Kind::ContactList, - Kind::FollowSet, - Kind::MuteList, - Kind::Repost, - Kind::TextNote, - ])]) - .await - .map_err(|e| e.to_string())?; - - if !event_pubkeys.is_empty() { - let pubkeys: Vec = event_pubkeys - .iter() - .flat_map(|ev| ev.tags.public_keys().copied()) - .collect(); - - let filter = Filter::new() - .authors(pubkeys) - .kinds(vec![ - Kind::Metadata, - Kind::TextNote, - Kind::Repost, - Kind::EventDeletion, - Kind::Interests, - Kind::InterestSet, - Kind::FollowSet, - Kind::RelayList, - Kind::MuteList, - Kind::EventDeletion, - Kind::Bookmarks, - Kind::BookmarkSet, - Kind::Custom(30315), - ]) - .limit(10000); - - if let Ok(output) = client.sync(filter, &opts).await { - println!("Success: {:?}", output.success); - println!("Failed: {:?}", output.failed); - } - }; - } - - let config_dir = app_handle - .path() - .app_config_dir() - .map_err(|e| e.to_string())?; - let _ = File::create(config_dir.join(id)); - - Ok(()) -} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4462d8b2..840b177a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -11,16 +11,9 @@ use nostr_sdk::prelude::{Profile as DatabaseProfile, *}; use serde::{Deserialize, Serialize}; use specta::Type; use specta_typescript::Typescript; -use std::{ - collections::HashSet, - fs, - io::{self, BufRead}, - str::FromStr, - time::Duration, -}; +use std::{collections::HashSet, fs, str::FromStr, time::Duration}; use tauri::{ menu::{Menu, MenuItem}, - path::BaseDirectory, Emitter, EventTarget, Listener, Manager, WebviewWindowBuilder, }; use tauri_plugin_decorum::WebviewWindowExt; @@ -70,6 +63,14 @@ pub const DEFAULT_DIFFICULTY: u8 = 0; pub const FETCH_LIMIT: usize = 50; pub const QUEUE_DELAY: u64 = 150; pub const NOTIFICATION_SUB_ID: &str = "lume_notification"; +// Will be removed when almost relays support negentropy +pub const BOOTSTRAP_RELAYS: [&str; 5] = [ + "wss://relay.damus.io", + "wss://relay.primal.net", + "wss://nostr.fmt.wiz.biz", + "wss://directory.yabu.me", + "wss://purplepag.es", +]; fn main() { tracing_subscriber::fmt::init(); @@ -241,7 +242,7 @@ fn main() { .opts(opts) .build(); - // Get bootstrap relays + /* Get bootstrap relays if let Ok(path) = handle .path() .resolve("resources/relays.txt", BaseDirectory::Resource) @@ -268,6 +269,11 @@ fn main() { } } } + */ + + for relay in BOOTSTRAP_RELAYS { + let _ = client.add_relay(relay).await; + } let _ = client.add_discovery_relay("wss://user.kindpag.es/").await; @@ -378,7 +384,8 @@ fn main() { // Sync notification // - if let Ok(output) = client.sync(filter, &opts).await { + if let Ok(output) = client.sync_with(BOOTSTRAP_RELAYS, filter, &opts).await + { println!("Received: {}", output.received.len()) } @@ -418,7 +425,9 @@ fn main() { // Sync metadata // - if let Ok(output) = client.sync(filter, &opts).await { + if let Ok(output) = + client.sync_with(BOOTSTRAP_RELAYS, filter, &opts).await + { println!("Received: {}", output.received.len()) } @@ -431,7 +440,9 @@ fn main() { // Sync text note // - if let Ok(output) = client.sync(filter, &opts).await { + if let Ok(output) = + client.sync_with(BOOTSTRAP_RELAYS, filter, &opts).await + { println!("Received: {}", output.received.len()) } }