feat: add contact list panel #10
@@ -118,6 +118,7 @@ impl ChatRegistry {
|
|||||||
this.reset(cx);
|
this.reset(cx);
|
||||||
}
|
}
|
||||||
RelayState::Configured => {
|
RelayState::Configured => {
|
||||||
|
this.get_contact_list(cx);
|
||||||
this.ensure_messaging_relays(cx);
|
this.ensure_messaging_relays(cx);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -257,6 +258,43 @@ impl ChatRegistry {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get contact list from relays
|
||||||
|
pub fn get_contact_list(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
|
let signer = nostr.read(cx).signer();
|
||||||
|
let public_key = signer.public_key().unwrap();
|
||||||
|
let write_relays = nostr.read(cx).write_relays(&public_key, cx);
|
||||||
|
|
||||||
|
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||||
|
let id = SubscriptionId::new("contact-list");
|
||||||
|
let opts = SubscribeAutoCloseOptions::default()
|
||||||
|
.exit_policy(ReqExitPolicy::ExitOnEOSE)
|
||||||
|
.timeout(Some(Duration::from_secs(TIMEOUT)));
|
||||||
|
|
||||||
|
// Get user's write relays
|
||||||
|
let urls = write_relays.await;
|
||||||
|
|
||||||
|
// Construct filter for inbox relays
|
||||||
|
let filter = Filter::new()
|
||||||
|
.kind(Kind::ContactList)
|
||||||
|
.author(public_key)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
// Construct target for subscription
|
||||||
|
let target: HashMap<&RelayUrl, Filter> =
|
||||||
|
urls.iter().map(|relay| (relay, filter.clone())).collect();
|
||||||
|
|
||||||
|
// Subscribe
|
||||||
|
client.subscribe(target).close_on(opts).with_id(id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tasks.push(task);
|
||||||
|
}
|
||||||
|
|
||||||
/// Ensure messaging relays are set up for the current user.
|
/// Ensure messaging relays are set up for the current user.
|
||||||
pub fn ensure_messaging_relays(&mut self, cx: &mut Context<Self>) {
|
pub fn ensure_messaging_relays(&mut self, cx: &mut Context<Self>) {
|
||||||
let task = self.verify_relays(cx);
|
let task = self.verify_relays(cx);
|
||||||
|
|||||||
@@ -183,20 +183,16 @@ impl NostrRegistry {
|
|||||||
..
|
..
|
||||||
} = notification
|
} = notification
|
||||||
{
|
{
|
||||||
// Skip if the event has already been processed
|
if !processed_events.insert(event.id) {
|
||||||
if processed_events.insert(event.id) {
|
// Skip if the event has already been processed
|
||||||
match event.kind {
|
continue;
|
||||||
Kind::RelayList => {
|
}
|
||||||
if subscription_id.as_str().contains("room-") {
|
|
||||||
get_events_for_room(&client, &event).await.ok();
|
if let Kind::RelayList = event.kind {
|
||||||
}
|
if subscription_id.as_str().contains("room-") {
|
||||||
tx.send_async(event.into_owned()).await?;
|
get_events_for_room(&client, &event).await.ok();
|
||||||
}
|
|
||||||
Kind::InboxRelays => {
|
|
||||||
tx.send_async(event.into_owned()).await?;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
tx.send_async(event.into_owned()).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user