From 16530a3804ca866d845b1e5e004ed0394fef7cea Mon Sep 17 00:00:00 2001 From: reya Date: Fri, 28 Mar 2025 18:53:43 +0700 Subject: [PATCH] chore: only subscribe for metadata in specific relays --- crates/app/src/main.rs | 8 ++--- crates/app/src/views/sidebar/compose.rs | 43 ++++++++----------------- crates/global/src/constants.rs | 13 ++------ 3 files changed, 21 insertions(+), 43 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index bbe3b9a..ae50f50 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -61,9 +61,6 @@ fn main() { _ = client.add_relay(relay).await; } - _ = client.add_discovery_relay("wss://relaydiscovery.com").await; - _ = client.add_discovery_relay("wss://user.kindpag.es").await; - _ = client.connect().await }) .detach(); @@ -257,7 +254,10 @@ async fn handle_metadata(buffer: HashSet) { .limit(100) .kinds(vec![Kind::Metadata, Kind::UserStatus]); - if let Err(e) = client.subscribe(filter, Some(opts)).await { + if let Err(e) = client + .subscribe_to(BOOTSTRAP_RELAYS, filter, Some(opts)) + .await + { log::error!("Failed to sync metadata: {e}"); } } diff --git a/crates/app/src/views/sidebar/compose.rs b/crates/app/src/views/sidebar/compose.rs index 9dae4e2..741bb93 100644 --- a/crates/app/src/views/sidebar/compose.rs +++ b/crates/app/src/views/sidebar/compose.rs @@ -1,6 +1,6 @@ use chats::{room::Room, ChatRegistry}; use common::{profile::NostrProfile, utils::random_name}; -use global::{constants::DEVICE_ANNOUNCEMENT_KIND, get_client}; +use global::get_client; use gpui::{ div, img, impl_internal_actions, prelude::FluentBuilder, px, relative, uniform_list, App, AppContext, Context, Entity, FocusHandle, InteractiveElement, IntoElement, ParentElement, @@ -208,7 +208,6 @@ impl Compose { fn add(&mut self, window: &mut Window, cx: &mut Context) { let client = get_client(); - let window_handle = window.window_handle(); let content = self.user_input.read(cx).text().to_string(); // Show loading spinner @@ -243,29 +242,11 @@ impl Compose { }) }; - cx.spawn(async move |this, cx| { + cx.spawn_in(window, async move |this, cx| { match task.await { Ok(profile) => { - let public_key = profile.public_key; - - _ = cx - .background_spawn(async move { - let opts = SubscribeAutoCloseOptions::default() - .exit_policy(ReqExitPolicy::ExitOnEOSE); - - // Create a device announcement filter - let device = Filter::new() - .kind(Kind::Custom(DEVICE_ANNOUNCEMENT_KIND)) - .author(public_key) - .limit(1); - - // Only subscribe to the latest device announcement - client.subscribe(device, Some(opts)).await - }) - .await; - - _ = cx.update_window(window_handle, |_, window, cx| { - _ = this.update(cx, |this, cx| { + cx.update(|window, cx| { + this.update(cx, |this, cx| { let public_key = profile.public_key; this.contacts.update(cx, |this, cx| { @@ -286,16 +267,20 @@ impl Compose { this.set_text("", window, cx); cx.notify(); }); - }); - }); + }) + .ok(); + }) + .ok(); } Err(e) => { - _ = cx.update_window(window_handle, |_, _, cx| { - _ = this.update(cx, |this, cx| { + cx.update(|_, cx| { + this.update(cx, |this, cx| { this.set_loading(false, cx); this.set_error(Some(e.to_string().into()), cx); - }); - }); + }) + .ok(); + }) + .ok(); } } }) diff --git a/crates/global/src/constants.rs b/crates/global/src/constants.rs index d282803..5adcc14 100644 --- a/crates/global/src/constants.rs +++ b/crates/global/src/constants.rs @@ -1,25 +1,18 @@ pub const APP_NAME: &str = "Coop"; pub const APP_ID: &str = "su.reya.coop"; -pub const KEYRING_SERVICE: &str = "Coop Safe Storage"; -pub const CLIENT_KEYRING: &str = "Coop Client Keys"; -pub const MASTER_KEYRING: &str = "Coop Master Keys"; - -pub const DEVICE_ANNOUNCEMENT_KIND: u16 = 10044; -pub const DEVICE_REQUEST_KIND: u16 = 4454; -pub const DEVICE_RESPONSE_KIND: u16 = 4455; - /// Bootstrap relays -pub const BOOTSTRAP_RELAYS: [&str; 3] = [ +pub const BOOTSTRAP_RELAYS: [&str; 5] = [ "wss://relay.damus.io", "wss://relay.primal.net", "wss://purplepag.es", + "wss://user.kindpag.es", + "wss://relaydiscovery.com", ]; /// Subscriptions pub const NEW_MESSAGE_SUB_ID: &str = "listen_new_giftwraps"; pub const ALL_MESSAGES_SUB_ID: &str = "listen_all_giftwraps"; -pub const DEVICE_SUB_ID: &str = "listen_device_announcement"; /// Image Resizer Service pub const IMAGE_SERVICE: &str = "https://wsrv.nl";