.
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 2m56s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m43s
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
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 2m56s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m43s
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 commit is contained in:
@@ -701,7 +701,7 @@ async fn try_unwrap(
|
|||||||
|
|
||||||
// Try with the user's signer
|
// Try with the user's signer
|
||||||
let user_signer = client.signer().context("Signer not found")?;
|
let user_signer = client.signer().context("Signer not found")?;
|
||||||
let unwrapped = UnwrappedGift::from_gift_wrap(user_signer, gift_wrap).await?;
|
let unwrapped = try_unwrap_with(gift_wrap, user_signer).await?;
|
||||||
|
|
||||||
Ok(unwrapped)
|
Ok(unwrapped)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ use std::collections::HashMap;
|
|||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::Error;
|
||||||
use common::EventUtils;
|
use common::EventUtils;
|
||||||
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task};
|
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::{Person, PersonRegistry};
|
use person::{Person, PersonRegistry};
|
||||||
use settings::{RoomConfig, SignerKind};
|
use settings::{RoomConfig, SignerKind};
|
||||||
use state::{NostrRegistry, TIMEOUT};
|
use state::{NostrRegistry, BOOTSTRAP_RELAYS, TIMEOUT};
|
||||||
|
|
||||||
use crate::NewMessage;
|
use crate::NewMessage;
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ impl From<&UnsignedEvent> for Room {
|
|||||||
subject,
|
subject,
|
||||||
members,
|
members,
|
||||||
kind: RoomKind::default(),
|
kind: RoomKind::default(),
|
||||||
config: RoomConfig::default(),
|
config: RoomConfig::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,6 +232,12 @@ impl Room {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the backup config for the room
|
||||||
|
pub fn set_backup(&mut self, cx: &mut Context<Self>) {
|
||||||
|
self.config.toggle_backup();
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the config of the room
|
/// Returns the config of the room
|
||||||
pub fn config(&self) -> &RoomConfig {
|
pub fn config(&self) -> &RoomConfig {
|
||||||
&self.config
|
&self.config
|
||||||
@@ -319,85 +325,53 @@ impl Room {
|
|||||||
cx.emit(RoomEvent::Reload);
|
cx.emit(RoomEvent::Reload);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
|
||||||
/// Get gossip relays for each member
|
/// Get gossip relays for each member
|
||||||
pub fn connect(&self, cx: &App) -> HashMap<PublicKey, Task<Result<(bool, bool), Error>>> {
|
pub fn connect(&self, cx: &App) -> Task<Result<(), Error>> {
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
let signer = nostr.read(cx).signer();
|
let signer = nostr.read(cx).signer();
|
||||||
let public_key = signer.public_key().unwrap();
|
let sender = signer.public_key().unwrap();
|
||||||
|
|
||||||
let members = self.members();
|
// Get room's id
|
||||||
let mut tasks = HashMap::new();
|
let id = self.id;
|
||||||
|
|
||||||
for member in members.into_iter() {
|
// Get all members, excluding the sender
|
||||||
// Skip if member is the current user
|
let members: Vec<PublicKey> = self
|
||||||
if member == public_key {
|
.members
|
||||||
continue;
|
.iter()
|
||||||
}
|
.filter(|public_key| public_key != &&sender)
|
||||||
|
.copied()
|
||||||
|
.collect();
|
||||||
|
|
||||||
let client = nostr.read(cx).client();
|
cx.background_spawn(async move {
|
||||||
let ensure_write_relays = nostr.read(cx).ensure_write_relays(&member, cx);
|
let id = SubscriptionId::new(format!("room-{id}"));
|
||||||
|
let opts = SubscribeAutoCloseOptions::default()
|
||||||
|
.exit_policy(ReqExitPolicy::ExitOnEOSE)
|
||||||
|
.timeout(Some(Duration::from_secs(TIMEOUT)));
|
||||||
|
|
||||||
let task = cx.background_spawn(async move {
|
// Construct filters for each member
|
||||||
let mut has_inbox = false;
|
let filters: Vec<Filter> = members
|
||||||
let mut has_announcement = false;
|
.into_iter()
|
||||||
|
.map(|public_key| {
|
||||||
|
Filter::new()
|
||||||
|
.author(public_key)
|
||||||
|
.kind(Kind::RelayList)
|
||||||
|
.limit(1)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
// Get user's write relays
|
// Construct target for subscription
|
||||||
let urls = ensure_write_relays.await;
|
let target: HashMap<&str, Vec<Filter>> = BOOTSTRAP_RELAYS
|
||||||
|
.into_iter()
|
||||||
|
.map(|relay| (relay, filters.clone()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
// Return if no relays are available
|
// Subscribe to the target
|
||||||
if urls.is_empty() {
|
client.subscribe(target).close_on(opts).with_id(id).await?;
|
||||||
return Err(anyhow!(
|
|
||||||
"User has not set up any relays. You cannot send messages to them."
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct filters for inbox relays
|
Ok(())
|
||||||
let inbox = Filter::new()
|
})
|
||||||
.kind(Kind::InboxRelays)
|
|
||||||
.author(member)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
// Construct filters for announcement
|
|
||||||
let announcement = Filter::new()
|
|
||||||
.kind(Kind::Custom(10044))
|
|
||||||
.author(member)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
// Create subscription targets
|
|
||||||
let target: HashMap<RelayUrl, Vec<Filter>> = urls
|
|
||||||
.into_iter()
|
|
||||||
.map(|relay| (relay, vec![inbox.clone(), announcement.clone()]))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Stream events from user's write relays
|
|
||||||
let mut stream = client
|
|
||||||
.stream_events(target)
|
|
||||||
.timeout(Duration::from_secs(TIMEOUT))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
while let Some((_url, res)) = stream.next().await {
|
|
||||||
let event = res?;
|
|
||||||
|
|
||||||
match event.kind {
|
|
||||||
Kind::InboxRelays => has_inbox = true,
|
|
||||||
Kind::Custom(10044) => has_announcement = true,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Early exit if both flags are found
|
|
||||||
if has_inbox && has_announcement {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok((has_inbox, has_announcement))
|
|
||||||
});
|
|
||||||
|
|
||||||
tasks.insert(member, task);
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all messages belonging to the room
|
/// Get all messages belonging to the room
|
||||||
@@ -440,7 +414,7 @@ impl Room {
|
|||||||
// Get current user's public key
|
// Get current user's public key
|
||||||
let sender = nostr.read(cx).signer().public_key()?;
|
let sender = nostr.read(cx).signer().public_key()?;
|
||||||
|
|
||||||
// Get all members
|
// Get all members, excluding the sender
|
||||||
let members: Vec<Person> = self
|
let members: Vec<Person> = self
|
||||||
.members
|
.members
|
||||||
.iter()
|
.iter()
|
||||||
@@ -567,7 +541,9 @@ impl Room {
|
|||||||
reports.push(report);
|
reports.push(report);
|
||||||
sents += 1;
|
sents += 1;
|
||||||
}
|
}
|
||||||
Err(report) => reports.push(report),
|
Err(report) => {
|
||||||
|
reports.push(report);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ pub enum Command {
|
|||||||
Insert(&'static str),
|
Insert(&'static str),
|
||||||
ChangeSubject(&'static str),
|
ChangeSubject(&'static str),
|
||||||
ChangeSigner(SignerKind),
|
ChangeSigner(SignerKind),
|
||||||
|
ToggleBackup,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub use actions::*;
|
pub use actions::*;
|
||||||
use anyhow::{Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error};
|
||||||
@@ -134,7 +135,6 @@ impl ChatPanel {
|
|||||||
cx.defer_in(window, |this, window, cx| {
|
cx.defer_in(window, |this, window, cx| {
|
||||||
this.connect(window, cx);
|
this.connect(window, cx);
|
||||||
this.handle_notifications(cx);
|
this.handle_notifications(cx);
|
||||||
|
|
||||||
this.subscribe_room_events(window, cx);
|
this.subscribe_room_events(window, cx);
|
||||||
this.get_messages(window, cx);
|
this.get_messages(window, cx);
|
||||||
});
|
});
|
||||||
@@ -157,6 +157,49 @@ impl ChatPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get all necessary data for each member
|
||||||
|
fn connect(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let Ok((members, connect)) = self
|
||||||
|
.room
|
||||||
|
.read_with(cx, |this, cx| (this.members(), this.connect(cx)))
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run the connect task in background
|
||||||
|
self.tasks.push(connect);
|
||||||
|
|
||||||
|
// Spawn another task to verify after 2 seconds
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
cx.background_executor().timer(Duration::from_secs(2)).await;
|
||||||
|
|
||||||
|
// Verify the connection
|
||||||
|
this.update_in(cx, |this, _window, cx| {
|
||||||
|
let persons = PersonRegistry::global(cx);
|
||||||
|
|
||||||
|
for member in members.into_iter() {
|
||||||
|
let profile = persons.read(cx).get(&member, cx);
|
||||||
|
|
||||||
|
if profile.announcement().is_none() {
|
||||||
|
let content = format!("{} {}", profile.name(), NO_ANNOUNCEMENT);
|
||||||
|
let message = Message::warning(content);
|
||||||
|
|
||||||
|
this.insert_message(message, true, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if profile.messaging_relays().is_empty() {
|
||||||
|
let content = format!("{} {}", profile.name(), NO_INBOX);
|
||||||
|
let message = Message::warning(content);
|
||||||
|
|
||||||
|
this.insert_message(message, true, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle nostr notifications
|
/// Handle nostr notifications
|
||||||
fn handle_notifications(&mut self, cx: &mut Context<Self>) {
|
fn handle_notifications(&mut self, cx: &mut Context<Self>) {
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
@@ -227,46 +270,6 @@ impl ChatPanel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all necessary data for each member
|
|
||||||
fn connect(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
let Ok(tasks) = self.room.read_with(cx, |this, cx| this.connect(cx)) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
|
||||||
for (member, task) in tasks.into_iter() {
|
|
||||||
match task.await {
|
|
||||||
Ok((has_inbox, has_announcement)) => {
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
let persons = PersonRegistry::global(cx);
|
|
||||||
let profile = persons.read(cx).get(&member, cx);
|
|
||||||
|
|
||||||
if !has_inbox {
|
|
||||||
let content = format!("{} {}", profile.name(), NO_INBOX);
|
|
||||||
let message = Message::warning(content);
|
|
||||||
|
|
||||||
this.insert_message(message, true, cx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !has_announcement {
|
|
||||||
let content = format!("{} {}", profile.name(), NO_ANNOUNCEMENT);
|
|
||||||
let message = Message::warning(content);
|
|
||||||
|
|
||||||
this.insert_message(message, true, cx);
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
this.insert_message(Message::warning(e.to_string()), true, cx);
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Load all messages belonging to this room
|
/// Load all messages belonging to this room
|
||||||
fn get_messages(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
fn get_messages(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let Ok(get_messages) = self.room.read_with(cx, |this, cx| this.get_messages(cx)) else {
|
let Ok(get_messages) = self.room.read_with(cx, |this, cx| this.get_messages(cx)) else {
|
||||||
@@ -363,10 +366,12 @@ impl ChatPanel {
|
|||||||
// This can't fail, because we already ensured that the ID is set
|
// This can't fail, because we already ensured that the ID is set
|
||||||
let id = rumor.id.unwrap();
|
let id = rumor.id.unwrap();
|
||||||
|
|
||||||
|
// Upgrade room reference
|
||||||
let Some(room) = self.room.upgrade() else {
|
let Some(room) = self.room.upgrade() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get the send message task
|
||||||
let Some(task) = room.read(cx).send(rumor, cx) else {
|
let Some(task) = room.read(cx).send(rumor, cx) else {
|
||||||
window.push_notification("Failed to send message", cx);
|
window.push_notification("Failed to send message", cx);
|
||||||
return;
|
return;
|
||||||
@@ -612,6 +617,17 @@ impl ChatPanel {
|
|||||||
window.push_notification(Notification::error("Failed to change signer"), cx);
|
window.push_notification(Notification::error("Failed to change signer"), cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Command::ToggleBackup => {
|
||||||
|
if self
|
||||||
|
.room
|
||||||
|
.update(cx, |this, cx| {
|
||||||
|
this.set_backup(cx);
|
||||||
|
})
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
window.push_notification(Notification::error("Failed to toggle backup"), cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,7 +678,14 @@ impl ChatPanel {
|
|||||||
.text_color(cx.theme().warning_foreground)
|
.text_color(cx.theme().warning_foreground)
|
||||||
.child(Icon::new(IconName::Warning).small()),
|
.child(Icon::new(IconName::Warning).small()),
|
||||||
)
|
)
|
||||||
.child(content),
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.flex_initial()
|
||||||
|
.overflow_hidden()
|
||||||
|
.child(content),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
@@ -880,7 +903,7 @@ impl ChatPanel {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.id(SharedString::from(id.to_hex()))
|
.id(SharedString::from(id.to_hex()))
|
||||||
.gap_0p5()
|
.gap_0p5()
|
||||||
.text_color(cx.theme().danger_foreground)
|
.text_color(cx.theme().danger_active)
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.italic()
|
.italic()
|
||||||
.child(Icon::new(IconName::Info).xsmall())
|
.child(Icon::new(IconName::Info).xsmall())
|
||||||
@@ -935,13 +958,13 @@ impl ChatPanel {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.flex_wrap()
|
.flex_wrap()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.p_2()
|
.p_1()
|
||||||
.h_20()
|
.h_16()
|
||||||
.w_full()
|
.w_full()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius)
|
||||||
.bg(cx.theme().danger_background)
|
.bg(cx.theme().warning_background)
|
||||||
.text_color(cx.theme().danger_foreground)
|
.text_color(cx.theme().warning_foreground)
|
||||||
.child(div().flex_1().w_full().text_center().child(error)),
|
.child(div().flex_1().w_full().text_center().child(error)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -957,11 +980,10 @@ impl ChatPanel {
|
|||||||
items.push(
|
items.push(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_0p5()
|
.gap_0p5()
|
||||||
.py_1()
|
.p_1()
|
||||||
.px_2()
|
|
||||||
.w_full()
|
.w_full()
|
||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius)
|
||||||
.bg(cx.theme().elevated_surface_background)
|
.bg(cx.theme().danger_background)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
@@ -971,7 +993,7 @@ impl ChatPanel {
|
|||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_sm()
|
.text_xs()
|
||||||
.text_color(cx.theme().danger_foreground)
|
.text_color(cx.theme().danger_foreground)
|
||||||
.line_height(relative(1.25))
|
.line_height(relative(1.25))
|
||||||
.child(SharedString::from(msg.to_string())),
|
.child(SharedString::from(msg.to_string())),
|
||||||
@@ -988,8 +1010,7 @@ impl ChatPanel {
|
|||||||
items.push(
|
items.push(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_0p5()
|
.gap_0p5()
|
||||||
.py_1()
|
.p_1()
|
||||||
.px_2()
|
|
||||||
.w_full()
|
.w_full()
|
||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius)
|
||||||
.bg(cx.theme().elevated_surface_background)
|
.bg(cx.theme().elevated_surface_background)
|
||||||
@@ -1002,8 +1023,7 @@ impl ChatPanel {
|
|||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_sm()
|
.text_xs()
|
||||||
.text_color(cx.theme().secondary_foreground)
|
|
||||||
.line_height(relative(1.25))
|
.line_height(relative(1.25))
|
||||||
.child(SharedString::from("Successfully")),
|
.child(SharedString::from("Successfully")),
|
||||||
),
|
),
|
||||||
@@ -1196,15 +1216,17 @@ impl ChatPanel {
|
|||||||
items
|
items
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_encryption_menu(&self, _window: &mut Window, cx: &Context<Self>) -> impl IntoElement {
|
fn render_config_menu(&self, _window: &mut Window, cx: &Context<Self>) -> impl IntoElement {
|
||||||
let signer_kind = self
|
let (backup, signer_kind) = self
|
||||||
.room
|
.room
|
||||||
.read_with(cx, |this, _cx| this.config().signer_kind().clone())
|
.read_with(cx, |this, _cx| {
|
||||||
|
(this.config().backup(), this.config().signer_kind().clone())
|
||||||
|
})
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
Button::new("encryption")
|
Button::new("encryption")
|
||||||
.icon(IconName::UserKey)
|
.icon(IconName::Settings)
|
||||||
.ghost()
|
.ghost()
|
||||||
.large()
|
.large()
|
||||||
.dropdown_menu(move |this, _window, _cx| {
|
.dropdown_menu(move |this, _window, _cx| {
|
||||||
@@ -1212,24 +1234,28 @@ impl ChatPanel {
|
|||||||
let encryption = matches!(signer_kind, SignerKind::Encryption);
|
let encryption = matches!(signer_kind, SignerKind::Encryption);
|
||||||
let user = matches!(signer_kind, SignerKind::User);
|
let user = matches!(signer_kind, SignerKind::User);
|
||||||
|
|
||||||
this.menu_with_check_and_disabled(
|
this.label("Signer")
|
||||||
"Auto",
|
.menu_with_check_and_disabled(
|
||||||
auto,
|
"Auto",
|
||||||
Box::new(Command::ChangeSigner(SignerKind::Auto)),
|
auto,
|
||||||
auto,
|
Box::new(Command::ChangeSigner(SignerKind::Auto)),
|
||||||
)
|
auto,
|
||||||
.menu_with_check_and_disabled(
|
)
|
||||||
"Decoupled Encryption Key",
|
.menu_with_check_and_disabled(
|
||||||
encryption,
|
"Decoupled Encryption Key",
|
||||||
Box::new(Command::ChangeSigner(SignerKind::Encryption)),
|
encryption,
|
||||||
encryption,
|
Box::new(Command::ChangeSigner(SignerKind::Encryption)),
|
||||||
)
|
encryption,
|
||||||
.menu_with_check_and_disabled(
|
)
|
||||||
"User Identity",
|
.menu_with_check_and_disabled(
|
||||||
user,
|
"User Identity",
|
||||||
Box::new(Command::ChangeSigner(SignerKind::User)),
|
user,
|
||||||
user,
|
Box::new(Command::ChangeSigner(SignerKind::User)),
|
||||||
)
|
user,
|
||||||
|
)
|
||||||
|
.separator()
|
||||||
|
.label("Backup")
|
||||||
|
.menu_with_check("Backup messages", backup, Box::new(Command::ToggleBackup))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1327,15 +1353,15 @@ impl Render for ChatPanel {
|
|||||||
.child(
|
.child(
|
||||||
TextInput::new(&self.input)
|
TextInput::new(&self.input)
|
||||||
.appearance(false)
|
.appearance(false)
|
||||||
.flex_1()
|
.text_sm()
|
||||||
.text_sm(),
|
.flex_1(),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.pl_1()
|
.pl_1()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(self.render_emoji_menu(window, cx))
|
.child(self.render_emoji_menu(window, cx))
|
||||||
.child(self.render_encryption_menu(window, cx))
|
.child(self.render_config_menu(window, cx))
|
||||||
.child(
|
.child(
|
||||||
Button::new("send")
|
Button::new("send")
|
||||||
.icon(IconName::PaperPlaneFill)
|
.icon(IconName::PaperPlaneFill)
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ use common::RenderedTimestamp;
|
|||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, px, relative, rems, uniform_list, App, AppContext, Context, Div, Entity,
|
div, px, relative, rems, uniform_list, App, AppContext, Context, Div, Entity,
|
||||||
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Task, Window,
|
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Subscription,
|
||||||
|
Task, Window,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::{shorten_pubkey, Person, PersonRegistry};
|
use person::{shorten_pubkey, Person, PersonRegistry};
|
||||||
@@ -41,10 +42,20 @@ pub struct Screening {
|
|||||||
|
|
||||||
/// Async tasks
|
/// Async tasks
|
||||||
tasks: SmallVec<[Task<()>; 3]>,
|
tasks: SmallVec<[Task<()>; 3]>,
|
||||||
|
|
||||||
|
/// Subscriptions
|
||||||
|
_subscriptions: SmallVec<[Subscription; 1]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screening {
|
impl Screening {
|
||||||
pub fn new(public_key: PublicKey, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
pub fn new(public_key: PublicKey, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
|
subscriptions.push(cx.on_release_in(window, move |this, window, cx| {
|
||||||
|
this.tasks.clear();
|
||||||
|
window.close_all_modals(cx);
|
||||||
|
}));
|
||||||
|
|
||||||
cx.defer_in(window, move |this, _window, cx| {
|
cx.defer_in(window, move |this, _window, cx| {
|
||||||
this.check_contact(cx);
|
this.check_contact(cx);
|
||||||
this.check_wot(cx);
|
this.check_wot(cx);
|
||||||
@@ -59,6 +70,7 @@ impl Screening {
|
|||||||
last_active: None,
|
last_active: None,
|
||||||
mutual_contacts: vec![],
|
mutual_contacts: vec![],
|
||||||
tasks: smallvec![],
|
tasks: smallvec![],
|
||||||
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,10 +149,10 @@ impl Screening {
|
|||||||
let mut activity: Option<Timestamp> = None;
|
let mut activity: Option<Timestamp> = None;
|
||||||
|
|
||||||
// Construct target for subscription
|
// Construct target for subscription
|
||||||
let target = BOOTSTRAP_RELAYS
|
let target: HashMap<&str, Vec<Filter>> = BOOTSTRAP_RELAYS
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|relay| (relay, vec![filter.clone()]))
|
.map(|relay| (relay, vec![filter.clone()]))
|
||||||
.collect::<HashMap<_, _>>();
|
.collect();
|
||||||
|
|
||||||
if let Ok(mut stream) = client
|
if let Ok(mut stream) = client
|
||||||
.stream_events(target)
|
.stream_events(target)
|
||||||
@@ -279,11 +291,21 @@ impl Screening {
|
|||||||
|
|
||||||
impl Render for Screening {
|
impl Render for Screening {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
const CONTACT: &str = "This person is one of your contacts.";
|
||||||
|
const NOT_CONTACT: &str = "This person is not one of your contacts.";
|
||||||
|
const NO_ACTIVITY: &str = "This person hasn't had any activity.";
|
||||||
|
const RELAY_INFO: &str = "Only checked on public relays; may be inaccurate.";
|
||||||
|
const NO_MUTUAL: &str = "You don't have any mutual contacts.";
|
||||||
|
const NIP05_MATCH: &str = "The address matches the user's public key.";
|
||||||
|
const NIP05_NOT_MATCH: &str = "The address does not match the user's public key.";
|
||||||
|
const NO_NIP05: &str = "This person has not set up their friendly address";
|
||||||
|
|
||||||
let profile = self.profile(cx);
|
let profile = self.profile(cx);
|
||||||
let shorten_pubkey = shorten_pubkey(self.public_key, 8);
|
let shorten_pubkey = shorten_pubkey(self.public_key, 8);
|
||||||
|
|
||||||
let total_mutuals = self.mutual_contacts.len();
|
|
||||||
let last_active = self.last_active.map(|_| true);
|
let last_active = self.last_active.map(|_| true);
|
||||||
|
let mutuals = self.mutual_contacts.len();
|
||||||
|
let mutuals_str = format!("You have {} mutual contacts with this person.", mutuals);
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_4()
|
.gap_4()
|
||||||
@@ -336,6 +358,7 @@ impl Render for Screening {
|
|||||||
Button::new("report")
|
Button::new("report")
|
||||||
.tooltip("Report as a scam or impostor")
|
.tooltip("Report as a scam or impostor")
|
||||||
.icon(IconName::Boom)
|
.icon(IconName::Boom)
|
||||||
|
.small()
|
||||||
.danger()
|
.danger()
|
||||||
.rounded()
|
.rounded()
|
||||||
.on_click(cx.listener(move |this, _e, window, cx| {
|
.on_click(cx.listener(move |this, _e, window, cx| {
|
||||||
@@ -363,9 +386,9 @@ impl Render for Screening {
|
|||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child({
|
.child({
|
||||||
if self.followed {
|
if self.followed {
|
||||||
SharedString::from("This person is one of your contacts.")
|
SharedString::from(CONTACT)
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("This person is not one of your contacts.")
|
SharedString::from(NOT_CONTACT)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -390,7 +413,7 @@ impl Render for Screening {
|
|||||||
.xsmall()
|
.xsmall()
|
||||||
.ghost()
|
.ghost()
|
||||||
.rounded()
|
.rounded()
|
||||||
.tooltip("This may be inaccurate if the user only publishes to their private relays."),
|
.tooltip(RELAY_INFO),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -399,13 +422,13 @@ impl Render for Screening {
|
|||||||
.line_clamp(1)
|
.line_clamp(1)
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.map(|this| {
|
.map(|this| {
|
||||||
if let Some(date) = self.last_active {
|
if let Some(t) = self.last_active {
|
||||||
this.child(SharedString::from(format!(
|
this.child(SharedString::from(format!(
|
||||||
"Last active: {}.",
|
"Last active: {}.",
|
||||||
date.to_human_time()
|
t.to_human_time()
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
this.child(SharedString::from("This person hasn't had any activity."))
|
this.child(SharedString::from(NO_ACTIVITY))
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -423,7 +446,9 @@ impl Render for Screening {
|
|||||||
if let Some(addr) = self.address(cx) {
|
if let Some(addr) = self.address(cx) {
|
||||||
SharedString::from(format!("{} validation", addr))
|
SharedString::from(format!("{} validation", addr))
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("Friendly Address (NIP-05) validation")
|
SharedString::from(
|
||||||
|
"Friendly Address (NIP-05) validation",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
@@ -433,12 +458,12 @@ impl Render for Screening {
|
|||||||
.child({
|
.child({
|
||||||
if self.address(cx).is_some() {
|
if self.address(cx).is_some() {
|
||||||
if self.verified {
|
if self.verified {
|
||||||
SharedString::from("The address matches the user's public key.")
|
SharedString::from(NIP05_MATCH)
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("The address does not match the user's public key.")
|
SharedString::from(NIP05_NOT_MATCH)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("This person has not set up their friendly address")
|
SharedString::from(NO_NIP05)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -448,7 +473,7 @@ impl Render for Screening {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.items_start()
|
.items_start()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.child(status_badge(Some(total_mutuals > 0), cx))
|
.child(status_badge(Some(mutuals > 0), cx))
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
@@ -474,13 +499,10 @@ impl Render for Screening {
|
|||||||
.line_clamp(1)
|
.line_clamp(1)
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child({
|
.child({
|
||||||
if total_mutuals > 0 {
|
if mutuals > 0 {
|
||||||
SharedString::from(format!(
|
SharedString::from(mutuals_str)
|
||||||
"You have {} mutual contacts with this person.",
|
|
||||||
total_mutuals
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("You don't have any mutual contacts with this person.")
|
SharedString::from(NO_MUTUAL)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -57,14 +57,8 @@ impl DeviceRegistry {
|
|||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
// Observe the NIP-65 state
|
// Observe the NIP-65 state
|
||||||
cx.observe(&nostr, |this, state, cx| {
|
cx.observe(&nostr, |this, state, cx| {
|
||||||
match state.read(cx).relay_list_state() {
|
if state.read(cx).relay_list_state() == RelayState::Configured {
|
||||||
RelayState::Idle => {
|
this.get_announcement(cx);
|
||||||
this.reset(cx);
|
|
||||||
}
|
|
||||||
RelayState::Configured => {
|
|
||||||
this.get_announcement(cx);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -255,6 +249,10 @@ impl DeviceRegistry {
|
|||||||
let signer = nostr.read(cx).signer();
|
let signer = nostr.read(cx).signer();
|
||||||
let public_key = signer.public_key().unwrap();
|
let public_key = signer.public_key().unwrap();
|
||||||
|
|
||||||
|
// Reset state before fetching announcement
|
||||||
|
self.reset(cx);
|
||||||
|
|
||||||
|
// Get user's write relays
|
||||||
let write_relays = nostr.read(cx).write_relays(&public_key, cx);
|
let write_relays = nostr.read(cx).write_relays(&public_key, cx);
|
||||||
|
|
||||||
let task: Task<Result<Event, Error>> = cx.background_spawn(async move {
|
let task: Task<Result<Event, Error>> = cx.background_spawn(async move {
|
||||||
@@ -664,7 +662,8 @@ async fn get_keys(client: &Client) -> Result<Keys, Error> {
|
|||||||
|
|
||||||
let filter = Filter::new()
|
let filter = Filter::new()
|
||||||
.kind(Kind::ApplicationSpecificData)
|
.kind(Kind::ApplicationSpecificData)
|
||||||
.identifier(IDENTIFIER);
|
.identifier(IDENTIFIER)
|
||||||
|
.author(public_key);
|
||||||
|
|
||||||
if let Some(event) = client.database().query(filter).await?.first() {
|
if let Some(event) = client.database().query(filter).await?.first() {
|
||||||
let content = signer.nip44_decrypt(&public_key, &event.content).await?;
|
let content = signer.nip44_decrypt(&public_key, &event.content).await?;
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ impl PersonRegistry {
|
|||||||
match self.persons.get(&public_key) {
|
match self.persons.get(&public_key) {
|
||||||
Some(this) => {
|
Some(this) => {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
*this = person;
|
this.set_metadata(person.metadata());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -313,10 +313,10 @@ where
|
|||||||
.limit(limit);
|
.limit(limit);
|
||||||
|
|
||||||
// Construct target for subscription
|
// Construct target for subscription
|
||||||
let target = BOOTSTRAP_RELAYS
|
let target: HashMap<&str, Vec<Filter>> = BOOTSTRAP_RELAYS
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|relay| (relay, vec![filter.clone()]))
|
.map(|relay| (relay, vec![filter.clone()]))
|
||||||
.collect::<HashMap<_, _>>();
|
.collect();
|
||||||
|
|
||||||
client.subscribe(target).close_on(opts).await?;
|
client.subscribe(target).close_on(opts).await?;
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,11 @@ impl Person {
|
|||||||
self.metadata.clone()
|
self.metadata.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set profile metadata
|
||||||
|
pub fn set_metadata(&mut self, metadata: Metadata) {
|
||||||
|
self.metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get profile encryption keys announcement
|
/// Get profile encryption keys announcement
|
||||||
pub fn announcement(&self) -> Option<Announcement> {
|
pub fn announcement(&self) -> Option<Announcement> {
|
||||||
self.announcement.clone()
|
self.announcement.clone()
|
||||||
@@ -83,7 +88,6 @@ impl Person {
|
|||||||
/// Set profile encryption keys announcement
|
/// Set profile encryption keys announcement
|
||||||
pub fn set_announcement(&mut self, announcement: Announcement) {
|
pub fn set_announcement(&mut self, announcement: Announcement) {
|
||||||
self.announcement = Some(announcement);
|
self.announcement = Some(announcement);
|
||||||
log::info!("Updated announcement for: {}", self.public_key());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get profile messaging relays
|
/// Get profile messaging relays
|
||||||
@@ -102,7 +106,6 @@ impl Person {
|
|||||||
I: IntoIterator<Item = RelayUrl>,
|
I: IntoIterator<Item = RelayUrl>,
|
||||||
{
|
{
|
||||||
self.messaging_relays = relays.into_iter().collect();
|
self.messaging_relays = relays.into_iter().collect();
|
||||||
log::info!("Updated messaging relays for: {}", self.public_key());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get profile avatar
|
/// Get profile avatar
|
||||||
|
|||||||
@@ -94,21 +94,28 @@ pub struct RoomConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RoomConfig {
|
impl RoomConfig {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
backup: true,
|
||||||
|
signer_kind: SignerKind::Auto,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get backup config
|
/// Get backup config
|
||||||
pub fn backup(&self) -> bool {
|
pub fn backup(&self) -> bool {
|
||||||
self.backup
|
self.backup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set backup config
|
||||||
|
pub fn toggle_backup(&mut self) {
|
||||||
|
self.backup = !self.backup;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get signer kind config
|
/// Get signer kind config
|
||||||
pub fn signer_kind(&self) -> &SignerKind {
|
pub fn signer_kind(&self) -> &SignerKind {
|
||||||
&self.signer_kind
|
&self.signer_kind
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set backup config
|
|
||||||
pub fn set_backup(&mut self, backup: bool) {
|
|
||||||
self.backup = backup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set signer kind config
|
/// Set signer kind config
|
||||||
pub fn set_signer_kind(&mut self, kind: &SignerKind) {
|
pub fn set_signer_kind(&mut self, kind: &SignerKind) {
|
||||||
self.signer_kind = kind.to_owned();
|
self.signer_kind = kind.to_owned();
|
||||||
|
|||||||
@@ -168,14 +168,18 @@ impl NostrRegistry {
|
|||||||
// Channel for communication between nostr and gpui
|
// Channel for communication between nostr and gpui
|
||||||
let (tx, rx) = flume::bounded::<Event>(2048);
|
let (tx, rx) = flume::bounded::<Event>(2048);
|
||||||
|
|
||||||
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
self.tasks.push(cx.background_spawn(async move {
|
||||||
// Handle nostr notifications
|
// Handle nostr notifications
|
||||||
let mut notifications = client.notifications();
|
let mut notifications = client.notifications();
|
||||||
let mut processed_events = HashSet::new();
|
let mut processed_events = HashSet::new();
|
||||||
|
|
||||||
while let Some(notification) = notifications.next().await {
|
while let Some(notification) = notifications.next().await {
|
||||||
if let ClientNotification::Message {
|
if let ClientNotification::Message {
|
||||||
message: RelayMessage::Event { event, .. },
|
message:
|
||||||
|
RelayMessage::Event {
|
||||||
|
event,
|
||||||
|
subscription_id,
|
||||||
|
},
|
||||||
..
|
..
|
||||||
} = notification
|
} = notification
|
||||||
{
|
{
|
||||||
@@ -183,6 +187,9 @@ impl NostrRegistry {
|
|||||||
if processed_events.insert(event.id) {
|
if processed_events.insert(event.id) {
|
||||||
match event.kind {
|
match event.kind {
|
||||||
Kind::RelayList => {
|
Kind::RelayList => {
|
||||||
|
if subscription_id.as_str().contains("room-") {
|
||||||
|
get_events_for_room(&client, &event).await.ok();
|
||||||
|
}
|
||||||
tx.send_async(event.into_owned()).await?;
|
tx.send_async(event.into_owned()).await?;
|
||||||
}
|
}
|
||||||
Kind::InboxRelays => {
|
Kind::InboxRelays => {
|
||||||
@@ -195,10 +202,7 @@ impl NostrRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
}));
|
||||||
|
|
||||||
// Run task in the background
|
|
||||||
task.detach();
|
|
||||||
|
|
||||||
self.tasks.push(cx.spawn(async move |_this, cx| {
|
self.tasks.push(cx.spawn(async move |_this, cx| {
|
||||||
while let Ok(event) = rx.recv_async().await {
|
while let Ok(event) = rx.recv_async().await {
|
||||||
@@ -763,10 +767,10 @@ impl NostrRegistry {
|
|||||||
.event(output.id().to_owned());
|
.event(output.id().to_owned());
|
||||||
|
|
||||||
// Construct target for subscription
|
// Construct target for subscription
|
||||||
let target = WOT_RELAYS
|
let target: HashMap<&str, Vec<Filter>> = WOT_RELAYS
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|relay| (relay, vec![filter.clone()]))
|
.map(|relay| (relay, vec![filter.clone()]))
|
||||||
.collect::<HashMap<_, _>>();
|
.collect();
|
||||||
|
|
||||||
// Stream events from the wot relays
|
// Stream events from the wot relays
|
||||||
let mut stream = client
|
let mut stream = client
|
||||||
@@ -833,6 +837,52 @@ fn get_or_init_app_keys() -> Result<Keys, Error> {
|
|||||||
Ok(keys)
|
Ok(keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_events_for_room(client: &Client, nip65: &Event) -> Result<(), Error> {
|
||||||
|
// Subscription options
|
||||||
|
let opts = SubscribeAutoCloseOptions::default()
|
||||||
|
.timeout(Some(Duration::from_secs(TIMEOUT)))
|
||||||
|
.exit_policy(ReqExitPolicy::ExitOnEOSE);
|
||||||
|
|
||||||
|
// Extract write relays from event
|
||||||
|
let write_relays: Vec<&RelayUrl> = nip65::extract_relay_list(nip65)
|
||||||
|
.filter_map(|(url, metadata)| {
|
||||||
|
if metadata.is_none() || metadata == &Some(RelayMetadata::Write) {
|
||||||
|
Some(url)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Ensure relay connections
|
||||||
|
for url in write_relays.iter() {
|
||||||
|
client.add_relay(*url).and_connect().await.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct filter for inbox relays
|
||||||
|
let inbox = Filter::new()
|
||||||
|
.kind(Kind::InboxRelays)
|
||||||
|
.author(nip65.pubkey)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
// Construct filter for encryption announcement
|
||||||
|
let announcement = Filter::new()
|
||||||
|
.kind(Kind::Custom(10044))
|
||||||
|
.author(nip65.pubkey)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
// Construct target for subscription
|
||||||
|
let target: HashMap<&RelayUrl, Vec<Filter>> = write_relays
|
||||||
|
.into_iter()
|
||||||
|
.map(|relay| (relay, vec![inbox.clone(), announcement.clone()]))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Subscribe to inbox relays and encryption announcements
|
||||||
|
client.subscribe(target).close_on(opts).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn default_relay_list() -> Vec<(RelayUrl, Option<RelayMetadata>)> {
|
fn default_relay_list() -> Vec<(RelayUrl, Option<RelayMetadata>)> {
|
||||||
vec![
|
vec![
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -1026,7 +1026,7 @@ impl PopupMenu {
|
|||||||
} else if checked {
|
} else if checked {
|
||||||
Icon::new(IconName::Check)
|
Icon::new(IconName::Check)
|
||||||
} else {
|
} else {
|
||||||
return None;
|
Icon::empty()
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(icon.small())
|
Some(icon.small())
|
||||||
|
|||||||
Reference in New Issue
Block a user