From 3debfa81d73009efda69da914eea03eec58c9dce Mon Sep 17 00:00:00 2001 From: reya Date: Fri, 27 Feb 2026 05:46:41 +0700 Subject: [PATCH] Revert "wip" This reverts commit e152154c3b187368d6af5342443d136136818399. --- crates/chat/src/room.rs | 19 +++--- crates/coop/src/panels/encryption_key.rs | 83 ++++++------------------ crates/coop/src/workspace.rs | 23 +------ crates/device/src/lib.rs | 38 ++++------- crates/person/src/lib.rs | 16 ++--- crates/state/src/constants.rs | 2 +- 6 files changed, 54 insertions(+), 127 deletions(-) diff --git a/crates/chat/src/room.rs b/crates/chat/src/room.rs index 55a1915..c54d5d8 100644 --- a/crates/chat/src/room.rs +++ b/crates/chat/src/room.rs @@ -350,23 +350,26 @@ impl Room { )); } - // Construct filters for inbox - let inbox = Filter::new() + // Construct filters for inbox and announcement + let inbox_filter = Filter::new() .kind(Kind::InboxRelays) .author(member) .limit(1); - - // Construct filters for announcement - let announcement = Filter::new() + let announcement_filter = Filter::new() .kind(Kind::Custom(10044)) .author(member) .limit(1); // Create subscription targets - let target: HashMap> = urls + let target = urls .into_iter() - .map(|relay| (relay, vec![inbox.clone(), announcement.clone()])) - .collect(); + .map(|relay| { + ( + relay, + vec![inbox_filter.clone(), announcement_filter.clone()], + ) + }) + .collect::>(); // Stream events from user's write relays let mut stream = client diff --git a/crates/coop/src/panels/encryption_key.rs b/crates/coop/src/panels/encryption_key.rs index 2b8dfd7..4584a63 100644 --- a/crates/coop/src/panels/encryption_key.rs +++ b/crates/coop/src/panels/encryption_key.rs @@ -36,9 +36,6 @@ pub struct EncryptionPanel { /// Whether the panel is loading loading: bool, - /// Whether the encryption is resetting - resetting: bool, - /// Tasks tasks: Vec>>, } @@ -50,7 +47,6 @@ impl EncryptionPanel { focus_handle: cx.focus_handle(), public_key, loading: false, - resetting: false, tasks: vec![], } } @@ -95,42 +91,6 @@ impl EncryptionPanel { })); } - fn set_resetting(&mut self, status: bool, cx: &mut Context) { - self.resetting = status; - cx.notify(); - } - - fn reset(&mut self, window: &mut Window, cx: &mut Context) { - let device = DeviceRegistry::global(cx); - let task = device.read(cx).create_encryption(cx); - - // Update the reset status - self.set_resetting(true, cx); - - self.tasks.push(cx.spawn_in(window, async move |this, cx| { - match task.await { - Ok(keys) => { - this.update_in(cx, |this, _window, cx| { - this.set_resetting(false, cx); - - device.update(cx, |this, cx| { - this.set_signer(keys, cx); - this.listen_request(cx); - }); - })?; - } - Err(e) => { - this.update_in(cx, |this, window, cx| { - this.set_resetting(false, cx); - window.push_notification(Notification::error(e.to_string()), cx); - })?; - } - } - - Ok(()) - })); - } - fn render_requests(&mut self, cx: &mut Context) -> Vec { const TITLE: &str = "You've requested for the Encryption Key from:"; @@ -309,27 +269,26 @@ impl Render for EncryptionPanel { )), ) }) - .child( - v_flex() - .gap_1() - .child( - Button::new("reset") - .icon(IconName::Reset) - .label("Reset") - .warning() - .small() - .font_semibold() - .on_click( - cx.listener(move |this, _ev, window, cx| this.reset(window, cx)), - ), - ) - .child( - div() - .italic() - .text_size(px(10.)) - .text_color(cx.theme().text_muted) - .child(SharedString::from(NOTICE)), - ), - ) + .when(state.set(), |this| { + this.child( + v_flex() + .gap_1() + .child( + Button::new("reset") + .icon(IconName::Reset) + .label("Reset") + .warning() + .small() + .font_semibold(), + ) + .child( + div() + .italic() + .text_size(px(10.)) + .text_color(cx.theme().text_muted) + .child(SharedString::from(NOTICE)), + ), + ) + }) } } diff --git a/crates/coop/src/workspace.rs b/crates/coop/src/workspace.rs index fb887a1..f6d6d5a 100644 --- a/crates/coop/src/workspace.rs +++ b/crates/coop/src/workspace.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use ::settings::AppSettings; use chat::{ChatEvent, ChatRegistry, InboxState}; -use device::DeviceRegistry; use gpui::prelude::FluentBuilder; use gpui::{ div, px, rems, Action, App, AppContext, Axis, Context, Entity, InteractiveElement, IntoElement, @@ -37,7 +36,6 @@ enum Command { RefreshRelayList, RefreshMessagingRelays, - RefreshEncryption, ShowRelayList, ShowMessaging, @@ -262,12 +260,6 @@ impl Workspace { ); }); } - Command::RefreshEncryption => { - let device = DeviceRegistry::global(cx); - device.update(cx, |this, cx| { - this.get_announcement(cx); - }); - } Command::RefreshRelayList => { let nostr = NostrRegistry::global(cx); nostr.update(cx, |this, cx| { @@ -448,19 +440,8 @@ impl Workspace { .tooltip("Decoupled encryption key") .small() .ghost() - .dropdown_menu(|this, _window, _cx| { - this.min_w(px(260.)) - .label("Encryption") - .menu_with_icon( - "Reload", - IconName::Refresh, - Box::new(Command::RefreshEncryption), - ) - .menu_with_icon( - "View encryption", - IconName::Settings, - Box::new(Command::ShowEncryption), - ) + .on_click(|_ev, window, cx| { + window.dispatch_action(Box::new(Command::ShowEncryption), cx); }), ) .child( diff --git a/crates/device/src/lib.rs b/crates/device/src/lib.rs index 876e1a8..6ea6d2f 100644 --- a/crates/device/src/lib.rs +++ b/crates/device/src/lib.rs @@ -157,7 +157,7 @@ impl DeviceRegistry { } /// Set the decoupled encryption key for the current user - pub fn set_signer(&mut self, new: S, cx: &mut Context) + fn set_signer(&mut self, new: S, cx: &mut Context) where S: NostrSigner + 'static, { @@ -248,7 +248,7 @@ impl DeviceRegistry { } /// Get device announcement for current user - pub fn get_announcement(&mut self, cx: &mut Context) { + fn get_announcement(&mut self, cx: &mut Context) { let nostr = NostrRegistry::global(cx); let client = nostr.read(cx).client(); @@ -309,7 +309,8 @@ impl DeviceRegistry { })); } - pub fn create_encryption(&self, cx: &App) -> Task> { + /// Create a new device signer and announce it + fn announce(&mut self, cx: &mut Context) { let nostr = NostrRegistry::global(cx); let client = nostr.read(cx).client(); @@ -324,7 +325,7 @@ impl DeviceRegistry { let secret = keys.secret_key().to_secret_hex(); let n = keys.public_key(); - cx.background_spawn(async move { + let task: Task> = cx.background_spawn(async move { let urls = write_relays.await; // Construct an announcement event @@ -341,26 +342,17 @@ impl DeviceRegistry { // Save device keys to the database set_keys(&client, &secret).await?; - Ok(keys) - }) - } - - /// Create a new device signer and announce it - fn announce(&mut self, cx: &mut Context) { - let task = self.create_encryption(cx); + Ok(()) + }); self.tasks.push(cx.spawn(async move |this, cx| { - match task.await { - Ok(keys) => { - this.update(cx, |this, cx| { - this.set_signer(keys, cx); - this.listen_request(cx); - })?; - } - Err(e) => { - log::error!("Failed to create encryption key: {}", e); - } + if task.await.is_ok() { + this.update(cx, |this, cx| { + this.set_signer(keys, cx); + this.listen_request(cx); + })?; } + Ok(()) })); } @@ -409,7 +401,7 @@ impl DeviceRegistry { } /// Listen for device key requests on user's write relays - pub fn listen_request(&mut self, cx: &mut Context) { + fn listen_request(&mut self, cx: &mut Context) { let nostr = NostrRegistry::global(cx); let client = nostr.read(cx).client(); @@ -679,8 +671,6 @@ async fn get_keys(client: &Client) -> Result { let secret = SecretKey::parse(&content)?; let keys = Keys::new(secret); - log::info!("Encryption keys retrieved successfully"); - Ok(keys) } else { Err(anyhow!("Key not found")) diff --git a/crates/person/src/lib.rs b/crates/person/src/lib.rs index 7b0699e..054c221 100644 --- a/crates/person/src/lib.rs +++ b/crates/person/src/lib.rs @@ -198,7 +198,7 @@ impl PersonRegistry { loop { match flume::Selector::new() .recv(rx, |result| result.ok()) - .wait_timeout(Duration::from_secs(TIMEOUT)) + .wait_timeout(Duration::from_secs(2)) { Ok(Some(public_key)) => { batch.insert(public_key); @@ -307,22 +307,16 @@ where .timeout(Some(Duration::from_secs(TIMEOUT))); // Construct the filter for metadata - let metadata = Filter::new() + let filter = Filter::new() .kind(Kind::Metadata) - .authors(authors.clone()) - .limit(limit); - - // Construct the filter for relay list - let gossip = Filter::new() - .kind(Kind::RelayList) .authors(authors) .limit(limit); // Construct target for subscription - let target: HashMap<&str, Vec> = BOOTSTRAP_RELAYS + let target = BOOTSTRAP_RELAYS .into_iter() - .map(|relay| (relay, vec![metadata.clone(), gossip.clone()])) - .collect(); + .map(|relay| (relay, vec![filter.clone()])) + .collect::>(); client.subscribe(target).close_on(opts).await?; diff --git a/crates/state/src/constants.rs b/crates/state/src/constants.rs index 3357b2d..cb34e2b 100644 --- a/crates/state/src/constants.rs +++ b/crates/state/src/constants.rs @@ -13,7 +13,7 @@ pub const APP_ID: &str = "su.reya.coop"; pub const KEYRING: &str = "Coop Safe Storage"; /// Default timeout for subscription -pub const TIMEOUT: u64 = 2; +pub const TIMEOUT: u64 = 3; /// Default delay for searching pub const FIND_DELAY: u64 = 600;