chore: simplify codebase

This commit is contained in:
2025-10-17 08:51:34 +07:00
parent 1742031901
commit 32a0401907
12 changed files with 489 additions and 735 deletions

View File

@@ -225,7 +225,7 @@ impl ChatSpace {
app_state.signal.send(SignalKind::SignerSet(pk)).await;
// Get user's gossip relays
app_state.gossip.write().await.get_nip65(pk).await.ok();
app_state.get_nip65(pk).await.ok();
// Exit the current loop
break;
@@ -877,9 +877,7 @@ impl ChatSpace {
.spawn(cx, async move |cx| {
let app_state = app_state();
let relays = default_nip65_relays();
let mut gossip = app_state.gossip.write().await;
let result = gossip.set_nip65(relays).await;
let result = app_state.set_nip65(relays).await;
cx.update(|window, cx| {
match result {
@@ -981,9 +979,7 @@ impl ChatSpace {
.spawn(cx, async move |cx| {
let app_state = app_state();
let relays = default_nip17_relays();
let mut gossip = app_state.gossip.write().await;
let result = gossip.set_nip17(relays).await;
let result = app_state.set_nip17(relays).await;
cx.update(|window, cx| {
match result {

View File

@@ -2,7 +2,7 @@ use std::str::FromStr;
use std::time::Duration;
use anyhow::Error;
use app_state::{app_state, nostr_client};
use app_state::nostr_client;
use common::nip96::nip96_upload;
use gpui::prelude::FluentBuilder;
use gpui::{
@@ -188,9 +188,6 @@ impl EditProfile {
}
cx.background_spawn(async move {
let app_state = app_state();
let gossip = app_state.gossip.read().await;
let client = nostr_client();
let signer = client.signer().await?;
@@ -198,7 +195,7 @@ impl EditProfile {
let event = EventBuilder::metadata(&new_metadata).sign(&signer).await?;
// Send event to user's write relayss
gossip.send_event_to_write_relays(&event).await?;
client.send_event(&event).await?;
// Return the updated profile
let metadata = Metadata::from_json(&event.content).unwrap_or_default();

View File

@@ -1,6 +1,6 @@
use anyhow::{anyhow, Error};
use app_state::constants::{ACCOUNT_IDENTIFIER, BOOTSTRAP_RELAYS};
use app_state::{app_state, default_nip17_relays, default_nip65_relays, nostr_client};
use app_state::{default_nip17_relays, default_nip65_relays, nostr_client};
use common::nip96::nip96_upload;
use gpui::{
div, relative, rems, AnyElement, App, AppContext, AsyncWindowContext, Context, Entity,
@@ -125,8 +125,6 @@ impl NewAccount {
// Set the client's signer with the current keys
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
let client = nostr_client();
let app_state = app_state();
let gossip = app_state.gossip.read().await;
// Set the client's signer with the current keys
client.set_signer(keys).await;
@@ -156,13 +154,13 @@ impl NewAccount {
.await?;
// Set NIP-17 relays
gossip.send_event_to_write_relays(&event).await?;
client.send_event(&event).await?;
// Construct a metadata event
let event = EventBuilder::metadata(&metadata).sign(&signer).await?;
// Set metadata
gossip.send_event_to_write_relays(&event).await?;
client.send_event(&event).await?;
Ok(())
});

View File

@@ -152,13 +152,11 @@ impl SetupRelay {
let relays = self.relays.clone();
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
let app_state = app_state();
let client = nostr_client();
let signer = client.signer().await?;
let public_key = signer.get_public_key().await?;
let app_state = app_state();
let gossip = app_state.gossip.read().await;
let tags: Vec<Tag> = relays
.iter()
.map(|relay| Tag::relay(relay.clone()))
@@ -170,7 +168,7 @@ impl SetupRelay {
.await?;
// Set messaging relays
gossip.send_event_to_write_relays(&event).await?;
client.send_event(&event).await?;
// Connect to messaging relays
for relay in relays.iter() {