wip: command bar
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m47s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m58s
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m47s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m58s
This commit is contained in:
@@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{anyhow, Context as AnyhowContext, Error};
|
||||
use common::{EventUtils, BOOTSTRAP_RELAYS};
|
||||
use common::EventUtils;
|
||||
use device::DeviceRegistry;
|
||||
use flume::Sender;
|
||||
use fuzzy_matcher::skim::SkimMatcherV2;
|
||||
@@ -16,7 +16,7 @@ use gpui::{
|
||||
};
|
||||
use nostr_sdk::prelude::*;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use state::{tracker, NostrAddress, NostrRegistry, RelayState, DEVICE_GIFTWRAP, USER_GIFTWRAP};
|
||||
use state::{tracker, NostrRegistry, RelayState, DEVICE_GIFTWRAP, USER_GIFTWRAP};
|
||||
|
||||
mod message;
|
||||
mod room;
|
||||
@@ -365,56 +365,8 @@ impl ChatRegistry {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Find for rooms that match the query.
|
||||
pub fn find(&self, query: &str, cx: &App) -> Task<Result<Vec<Entity<Room>>, Error>> {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let client = nostr.read(cx).client();
|
||||
let http_client = cx.http_client();
|
||||
let query = query.to_string();
|
||||
|
||||
if let Ok(addr) = Nip05Address::parse(&query) {
|
||||
let task: Task<Result<PublicKey, Error>> = cx.background_spawn(async move {
|
||||
let profile = addr.profile(&http_client).await?;
|
||||
let public_key = profile.public_key;
|
||||
|
||||
let opts = SubscribeAutoCloseOptions::default()
|
||||
.exit_policy(ReqExitPolicy::ExitOnEOSE)
|
||||
.timeout(Some(Duration::from_secs(3)));
|
||||
|
||||
// Construct the filter for the metadata event
|
||||
let filter = Filter::new()
|
||||
.kind(Kind::Metadata)
|
||||
.author(public_key)
|
||||
.limit(1);
|
||||
|
||||
// Subscribe to bootstrap relays
|
||||
client
|
||||
.subscribe_to(BOOTSTRAP_RELAYS, vec![filter], Some(opts))
|
||||
.await?;
|
||||
|
||||
Ok(public_key)
|
||||
});
|
||||
|
||||
cx.spawn(async move |cx| {
|
||||
let public_key = task.await?;
|
||||
let results = cx.read_global::<GlobalChatRegistry, _>(|this, cx| {
|
||||
this.0
|
||||
.read_with(cx, |this, cx| this.find_rooms(&public_key.to_hex(), cx))
|
||||
});
|
||||
Ok(results)
|
||||
})
|
||||
} else {
|
||||
cx.spawn(async move |cx| {
|
||||
let results = cx.read_global::<GlobalChatRegistry, _>(|this, cx| {
|
||||
this.0.read_with(cx, |this, cx| this.find_rooms(&query, cx))
|
||||
});
|
||||
Ok(results)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal find function for finding rooms based on a query.
|
||||
fn find_rooms(&self, query: &str, cx: &App) -> Vec<Entity<Room>> {
|
||||
/// Finding rooms based on a query.
|
||||
pub fn find(&self, query: &str, cx: &App) -> Vec<Entity<Room>> {
|
||||
let matcher = SkimMatcherV2::default();
|
||||
|
||||
if let Ok(public_key) = PublicKey::parse(query) {
|
||||
@@ -436,27 +388,6 @@ impl ChatRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a chat room based on NIP-05 address.
|
||||
pub fn address_to_room(&self, addr: Nip05Address, cx: &App) -> Task<Result<Room, Error>> {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let client = nostr.read(cx).client();
|
||||
let http_client = cx.http_client();
|
||||
|
||||
cx.background_spawn(async move {
|
||||
let signer = client.signer().await?;
|
||||
let public_key = signer.get_public_key().await?;
|
||||
|
||||
// Get the profile belonging to the address
|
||||
let profile = addr.profile(&http_client).await?;
|
||||
|
||||
// Construct the room
|
||||
let receivers = vec![profile.public_key];
|
||||
let room = Room::new(None, public_key, receivers);
|
||||
|
||||
Ok(room)
|
||||
})
|
||||
}
|
||||
|
||||
/// Reset the registry.
|
||||
pub fn reset(&mut self, cx: &mut Context<Self>) {
|
||||
self.rooms.clear();
|
||||
|
||||
@@ -167,22 +167,11 @@ impl From<&UnsignedEvent> for Room {
|
||||
|
||||
impl Room {
|
||||
/// Constructs a new room with the given receiver and tags.
|
||||
pub fn new(subject: Option<String>, author: PublicKey, receivers: Vec<PublicKey>) -> Self {
|
||||
// Convert receiver's public keys into tags
|
||||
let mut tags: Tags = Tags::from_list(
|
||||
receivers
|
||||
.iter()
|
||||
.map(|pubkey| Tag::public_key(pubkey.to_owned()))
|
||||
.collect(),
|
||||
);
|
||||
|
||||
// Add subject if it is present
|
||||
if let Some(subject) = subject {
|
||||
tags.push(Tag::from_standardized_without_cell(TagStandard::Subject(
|
||||
subject,
|
||||
)));
|
||||
}
|
||||
|
||||
pub fn new<T>(author: PublicKey, receivers: T) -> Self
|
||||
where
|
||||
T: IntoIterator<Item = PublicKey>,
|
||||
{
|
||||
let tags = Tags::from_list(receivers.into_iter().map(Tag::public_key).collect());
|
||||
let mut event = EventBuilder::new(Kind::PrivateDirectMessage, "")
|
||||
.tags(tags)
|
||||
.build(author);
|
||||
|
||||
Reference in New Issue
Block a user