chore: minor fixes
This commit is contained in:
@@ -44,11 +44,11 @@ pub fn default_nip65_relays() -> &'static Vec<(RelayUrl, Option<RelayMetadata>)>
|
|||||||
Some(RelayMetadata::Read),
|
Some(RelayMetadata::Read),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
RelayUrl::parse("wss://nostr.oxtr.dev").unwrap(),
|
RelayUrl::parse("wss://nos.lol").unwrap(),
|
||||||
Some(RelayMetadata::Write),
|
Some(RelayMetadata::Write),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
RelayUrl::parse("wss://nostr.fmt.wiz.biz").unwrap(),
|
RelayUrl::parse("wss://relay.snort.social").unwrap(),
|
||||||
Some(RelayMetadata::Write),
|
Some(RelayMetadata::Write),
|
||||||
),
|
),
|
||||||
(RelayUrl::parse("wss://relay.primal.net").unwrap(), None),
|
(RelayUrl::parse("wss://relay.primal.net").unwrap(), None),
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ impl Encryption {
|
|||||||
/// Get the announcement from the database
|
/// Get the announcement from the database
|
||||||
fn get_announcement(&mut self, cx: &mut Context<Self>) {
|
fn get_announcement(&mut self, cx: &mut Context<Self>) {
|
||||||
let task = self._get_announcement(cx);
|
let task = self._get_announcement(cx);
|
||||||
let delay = Duration::from_secs(10);
|
let delay = Duration::from_secs(5);
|
||||||
|
|
||||||
self._tasks.push(
|
self._tasks.push(
|
||||||
// Run task in the background
|
// Run task in the background
|
||||||
@@ -413,7 +413,7 @@ impl Encryption {
|
|||||||
let signer = client.signer().await?;
|
let signer = client.signer().await?;
|
||||||
let signer_pubkey = signer.get_public_key().await?;
|
let signer_pubkey = signer.get_public_key().await?;
|
||||||
let gossip = gossip.read().await;
|
let gossip = gossip.read().await;
|
||||||
let write_relays = gossip.inbox_relays(&signer_pubkey);
|
let write_relays = gossip.outbox_relays(&signer_pubkey);
|
||||||
|
|
||||||
// Ensure connections to the write relays
|
// Ensure connections to the write relays
|
||||||
gossip.ensure_connections(&client, &write_relays).await;
|
gossip.ensure_connections(&client, &write_relays).await;
|
||||||
@@ -479,7 +479,7 @@ impl Encryption {
|
|||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let gossip = gossip.read().await;
|
let gossip = gossip.read().await;
|
||||||
let write_relays = gossip.inbox_relays(&public_key);
|
let write_relays = gossip.outbox_relays(&public_key);
|
||||||
|
|
||||||
// Ensure connections to the write relays
|
// Ensure connections to the write relays
|
||||||
gossip.ensure_connections(&client, &write_relays).await;
|
gossip.ensure_connections(&client, &write_relays).await;
|
||||||
@@ -532,7 +532,7 @@ impl Encryption {
|
|||||||
let signer = client.signer().await?;
|
let signer = client.signer().await?;
|
||||||
let public_key = signer.get_public_key().await?;
|
let public_key = signer.get_public_key().await?;
|
||||||
let gossip = gossip.read().await;
|
let gossip = gossip.read().await;
|
||||||
let write_relays = gossip.inbox_relays(&public_key);
|
let write_relays = gossip.outbox_relays(&public_key);
|
||||||
|
|
||||||
// Ensure connections to the write relays
|
// Ensure connections to the write relays
|
||||||
gossip.ensure_connections(&client, &write_relays).await;
|
gossip.ensure_connections(&client, &write_relays).await;
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ impl EncryptionPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ask_for_approval(&mut self, req: Announcement, window: &mut Window, cx: &mut Context<Self>) {
|
fn ask_for_approval(&mut self, req: Announcement, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let client_name = SharedString::from(req.client().to_string());
|
let client_name = req.client_name();
|
||||||
let target = req.public_key();
|
let target = req.public_key();
|
||||||
let id = SharedString::from(req.id().to_hex());
|
let id = SharedString::from(req.id().to_hex());
|
||||||
let loading = Rc::new(Cell::new(false));
|
let loading = Rc::new(Cell::new(false));
|
||||||
@@ -302,7 +302,7 @@ impl Render for EncryptionPanel {
|
|||||||
.text_sm()
|
.text_sm()
|
||||||
.when_some(announcement.as_ref(), |this, announcement| {
|
.when_some(announcement.as_ref(), |this, announcement| {
|
||||||
let pubkey = shorten_pubkey(announcement.public_key(), 16);
|
let pubkey = shorten_pubkey(announcement.public_key(), 16);
|
||||||
let name = announcement.client();
|
let client_name = announcement.client_name();
|
||||||
|
|
||||||
this.child(
|
this.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
@@ -341,7 +341,7 @@ impl Render for EncryptionPanel {
|
|||||||
.justify_center()
|
.justify_center()
|
||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius)
|
||||||
.bg(cx.theme().elevated_surface_background)
|
.bg(cx.theme().elevated_surface_background)
|
||||||
.child(name),
|
.child(client_name.clone()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ impl NostrRegistry {
|
|||||||
let urls: Vec<RelayUrl> = Self::extract_write_relays(&event);
|
let urls: Vec<RelayUrl> = Self::extract_write_relays(&event);
|
||||||
let author = event.pubkey;
|
let author = event.pubkey;
|
||||||
|
|
||||||
|
log::info!("Write relays: {urls:?}");
|
||||||
|
|
||||||
// Fetch user's encryption announcement event
|
// Fetch user's encryption announcement event
|
||||||
Self::get(client, &urls, author, Kind::Custom(10044)).await;
|
Self::get(client, &urls, author, Kind::Custom(10044)).await;
|
||||||
// Fetch user's messaging relays event
|
// Fetch user's messaging relays event
|
||||||
@@ -305,7 +307,20 @@ impl NostrRegistry {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_write_relays(event: &Event) -> Vec<RelayUrl> {
|
pub fn extract_read_relays(event: &Event) -> Vec<RelayUrl> {
|
||||||
|
nip65::extract_relay_list(event)
|
||||||
|
.filter_map(|(url, metadata)| {
|
||||||
|
if metadata.is_none() || metadata == &Some(RelayMetadata::Read) {
|
||||||
|
Some(url.to_owned())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.take(3)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extract_write_relays(event: &Event) -> Vec<RelayUrl> {
|
||||||
nip65::extract_relay_list(event)
|
nip65::extract_relay_list(event)
|
||||||
.filter_map(|(url, metadata)| {
|
.filter_map(|(url, metadata)| {
|
||||||
if metadata.is_none() || metadata == &Some(RelayMetadata::Write) {
|
if metadata.is_none() || metadata == &Some(RelayMetadata::Write) {
|
||||||
@@ -332,8 +347,7 @@ impl NostrRegistry {
|
|||||||
.tags
|
.tags
|
||||||
.find(TagKind::Client)
|
.find(TagKind::Client)
|
||||||
.and_then(|tag| tag.content())
|
.and_then(|tag| tag.content())
|
||||||
.map(|c| c.to_string())
|
.map(|c| c.to_string());
|
||||||
.context("Cannot parse client name from the event's tags")?;
|
|
||||||
|
|
||||||
Ok(Announcement::new(event.id, client_name, public_key))
|
Ok(Announcement::new(event.id, client_name, public_key))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ use crate::NostrRegistry;
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Announcement {
|
pub struct Announcement {
|
||||||
id: EventId,
|
id: EventId,
|
||||||
client: String,
|
|
||||||
public_key: PublicKey,
|
public_key: PublicKey,
|
||||||
|
client_name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Announcement {
|
impl Announcement {
|
||||||
pub fn new(id: EventId, client_name: String, public_key: PublicKey) -> Self {
|
pub fn new(id: EventId, client_name: Option<String>, public_key: PublicKey) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
client: client_name,
|
client_name,
|
||||||
public_key,
|
public_key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,8 +29,11 @@ impl Announcement {
|
|||||||
self.public_key
|
self.public_key
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn client(&self) -> SharedString {
|
pub fn client_name(&self) -> SharedString {
|
||||||
SharedString::from(self.client.clone())
|
self.client_name
|
||||||
|
.as_ref()
|
||||||
|
.map(SharedString::from)
|
||||||
|
.unwrap_or(SharedString::from("Unknown"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user