chore: only subscribe for metadata in specific relays
This commit is contained in:
@@ -61,9 +61,6 @@ fn main() {
|
|||||||
_ = client.add_relay(relay).await;
|
_ = client.add_relay(relay).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = client.add_discovery_relay("wss://relaydiscovery.com").await;
|
|
||||||
_ = client.add_discovery_relay("wss://user.kindpag.es").await;
|
|
||||||
|
|
||||||
_ = client.connect().await
|
_ = client.connect().await
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
@@ -257,7 +254,10 @@ async fn handle_metadata(buffer: HashSet<PublicKey>) {
|
|||||||
.limit(100)
|
.limit(100)
|
||||||
.kinds(vec![Kind::Metadata, Kind::UserStatus]);
|
.kinds(vec![Kind::Metadata, Kind::UserStatus]);
|
||||||
|
|
||||||
if let Err(e) = client.subscribe(filter, Some(opts)).await {
|
if let Err(e) = client
|
||||||
|
.subscribe_to(BOOTSTRAP_RELAYS, filter, Some(opts))
|
||||||
|
.await
|
||||||
|
{
|
||||||
log::error!("Failed to sync metadata: {e}");
|
log::error!("Failed to sync metadata: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use chats::{room::Room, ChatRegistry};
|
use chats::{room::Room, ChatRegistry};
|
||||||
use common::{profile::NostrProfile, utils::random_name};
|
use common::{profile::NostrProfile, utils::random_name};
|
||||||
use global::{constants::DEVICE_ANNOUNCEMENT_KIND, get_client};
|
use global::get_client;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, img, impl_internal_actions, prelude::FluentBuilder, px, relative, uniform_list, App,
|
div, img, impl_internal_actions, prelude::FluentBuilder, px, relative, uniform_list, App,
|
||||||
AppContext, Context, Entity, FocusHandle, InteractiveElement, IntoElement, ParentElement,
|
AppContext, Context, Entity, FocusHandle, InteractiveElement, IntoElement, ParentElement,
|
||||||
@@ -208,7 +208,6 @@ impl Compose {
|
|||||||
|
|
||||||
fn add(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn add(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let client = get_client();
|
let client = get_client();
|
||||||
let window_handle = window.window_handle();
|
|
||||||
let content = self.user_input.read(cx).text().to_string();
|
let content = self.user_input.read(cx).text().to_string();
|
||||||
|
|
||||||
// Show loading spinner
|
// Show loading spinner
|
||||||
@@ -243,29 +242,11 @@ impl Compose {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
cx.spawn(async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
match task.await {
|
match task.await {
|
||||||
Ok(profile) => {
|
Ok(profile) => {
|
||||||
let public_key = profile.public_key;
|
cx.update(|window, cx| {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
_ = cx
|
|
||||||
.background_spawn(async move {
|
|
||||||
let opts = SubscribeAutoCloseOptions::default()
|
|
||||||
.exit_policy(ReqExitPolicy::ExitOnEOSE);
|
|
||||||
|
|
||||||
// Create a device announcement filter
|
|
||||||
let device = Filter::new()
|
|
||||||
.kind(Kind::Custom(DEVICE_ANNOUNCEMENT_KIND))
|
|
||||||
.author(public_key)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
// Only subscribe to the latest device announcement
|
|
||||||
client.subscribe(device, Some(opts)).await
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
|
|
||||||
_ = cx.update_window(window_handle, |_, window, cx| {
|
|
||||||
_ = this.update(cx, |this, cx| {
|
|
||||||
let public_key = profile.public_key;
|
let public_key = profile.public_key;
|
||||||
|
|
||||||
this.contacts.update(cx, |this, cx| {
|
this.contacts.update(cx, |this, cx| {
|
||||||
@@ -286,16 +267,20 @@ impl Compose {
|
|||||||
this.set_text("", window, cx);
|
this.set_text("", window, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
});
|
.ok();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
_ = cx.update_window(window_handle, |_, _, cx| {
|
cx.update(|_, cx| {
|
||||||
_ = this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.set_loading(false, cx);
|
this.set_loading(false, cx);
|
||||||
this.set_error(Some(e.to_string().into()), cx);
|
this.set_error(Some(e.to_string().into()), cx);
|
||||||
});
|
})
|
||||||
});
|
.ok();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,25 +1,18 @@
|
|||||||
pub const APP_NAME: &str = "Coop";
|
pub const APP_NAME: &str = "Coop";
|
||||||
pub const APP_ID: &str = "su.reya.coop";
|
pub const APP_ID: &str = "su.reya.coop";
|
||||||
|
|
||||||
pub const KEYRING_SERVICE: &str = "Coop Safe Storage";
|
|
||||||
pub const CLIENT_KEYRING: &str = "Coop Client Keys";
|
|
||||||
pub const MASTER_KEYRING: &str = "Coop Master Keys";
|
|
||||||
|
|
||||||
pub const DEVICE_ANNOUNCEMENT_KIND: u16 = 10044;
|
|
||||||
pub const DEVICE_REQUEST_KIND: u16 = 4454;
|
|
||||||
pub const DEVICE_RESPONSE_KIND: u16 = 4455;
|
|
||||||
|
|
||||||
/// Bootstrap relays
|
/// Bootstrap relays
|
||||||
pub const BOOTSTRAP_RELAYS: [&str; 3] = [
|
pub const BOOTSTRAP_RELAYS: [&str; 5] = [
|
||||||
"wss://relay.damus.io",
|
"wss://relay.damus.io",
|
||||||
"wss://relay.primal.net",
|
"wss://relay.primal.net",
|
||||||
"wss://purplepag.es",
|
"wss://purplepag.es",
|
||||||
|
"wss://user.kindpag.es",
|
||||||
|
"wss://relaydiscovery.com",
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Subscriptions
|
/// Subscriptions
|
||||||
pub const NEW_MESSAGE_SUB_ID: &str = "listen_new_giftwraps";
|
pub const NEW_MESSAGE_SUB_ID: &str = "listen_new_giftwraps";
|
||||||
pub const ALL_MESSAGES_SUB_ID: &str = "listen_all_giftwraps";
|
pub const ALL_MESSAGES_SUB_ID: &str = "listen_all_giftwraps";
|
||||||
pub const DEVICE_SUB_ID: &str = "listen_device_announcement";
|
|
||||||
|
|
||||||
/// Image Resizer Service
|
/// Image Resizer Service
|
||||||
pub const IMAGE_SERVICE: &str = "https://wsrv.nl";
|
pub const IMAGE_SERVICE: &str = "https://wsrv.nl";
|
||||||
|
|||||||
Reference in New Issue
Block a user