Revert "wip"
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m50s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m50s
Rust / build (macos-latest, stable) (push) Has been cancelled
Rust / build (windows-latest, stable) (push) Has been cancelled
Rust / build (macos-latest, stable) (pull_request) Has been cancelled
Rust / build (windows-latest, stable) (pull_request) Has been cancelled

This reverts commit e152154c3b.
This commit is contained in:
2026-02-27 05:46:41 +07:00
parent 4ba2049756
commit 3debfa81d7
6 changed files with 54 additions and 127 deletions

View File

@@ -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<RelayUrl, Vec<Filter>> = 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::<HashMap<_, _>>();
// Stream events from user's write relays
let mut stream = client

View File

@@ -36,9 +36,6 @@ pub struct EncryptionPanel {
/// Whether the panel is loading
loading: bool,
/// Whether the encryption is resetting
resetting: bool,
/// Tasks
tasks: Vec<Task<Result<(), Error>>>,
}
@@ -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>) {
self.resetting = status;
cx.notify();
}
fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {
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<Self>) -> Vec<impl IntoElement> {
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)),
),
)
})
}
}

View File

@@ -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(

View File

@@ -157,7 +157,7 @@ impl DeviceRegistry {
}
/// Set the decoupled encryption key for the current user
pub fn set_signer<S>(&mut self, new: S, cx: &mut Context<Self>)
fn set_signer<S>(&mut self, new: S, cx: &mut Context<Self>)
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<Self>) {
fn get_announcement(&mut self, cx: &mut Context<Self>) {
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<Result<Keys, Error>> {
/// Create a new device signer and announce it
fn announce(&mut self, cx: &mut Context<Self>) {
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<Result<(), Error>> = 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<Self>) {
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<Self>) {
fn listen_request(&mut self, cx: &mut Context<Self>) {
let nostr = NostrRegistry::global(cx);
let client = nostr.read(cx).client();
@@ -679,8 +671,6 @@ async fn get_keys(client: &Client) -> Result<Keys, Error> {
let secret = SecretKey::parse(&content)?;
let keys = Keys::new(secret);
log::info!("Encryption keys retrieved successfully");
Ok(keys)
} else {
Err(anyhow!("Key not found"))

View File

@@ -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<Filter>> = BOOTSTRAP_RELAYS
let target = BOOTSTRAP_RELAYS
.into_iter()
.map(|relay| (relay, vec![metadata.clone(), gossip.clone()]))
.collect();
.map(|relay| (relay, vec![filter.clone()]))
.collect::<HashMap<_, _>>();
client.subscribe(target).close_on(opts).await?;

View File

@@ -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;