feat: add support for launch arguments #40

Merged
reya merged 2 commits from feat/launch-arg into master 2026-08-02 07:10:47 +00:00
3 changed files with 21 additions and 48 deletions
Showing only changes of commit 677a42df2a - Show all commits

13
Cargo.lock generated
View File

@@ -3989,15 +3989,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "matchers"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
dependencies = [
"regex-automata",
]
[[package]] [[package]]
name = "maybe-rayon" name = "maybe-rayon"
version = "0.1.1" version = "0.1.1"
@@ -7478,14 +7469,10 @@ version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319"
dependencies = [ dependencies = [
"matchers",
"nu-ansi-term", "nu-ansi-term",
"once_cell",
"regex-automata",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local", "thread_local",
"tracing",
"tracing-core", "tracing-core",
"tracing-log", "tracing-log",
] ]

View File

@@ -42,7 +42,7 @@ schemars = "1"
smallvec = "1.14.0" smallvec = "1.14.0"
smol = "2" smol = "2"
webbrowser = "1.0.4" webbrowser = "1.0.4"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
errno = { version = "0.3.14", default-features = false } errno = { version = "0.3.14", default-features = false }
instant = "0.1" instant = "0.1"

View File

@@ -627,13 +627,7 @@ impl ChatRegistry {
/// Load all rooms from the database. /// Load all rooms from the database.
pub fn get_rooms(&mut self, cx: &mut Context<Self>) { pub fn get_rooms(&mut self, cx: &mut Context<Self>) {
let nostr = NostrRegistry::global(cx); let task = self.get_rooms_task(cx);
let Some(public_key) = nostr.read(cx).current_user() else {
return;
};
let task = self.get_rooms_from_database(public_key, cx);
self.tasks.push(cx.spawn(async move |this, cx| { self.tasks.push(cx.spawn(async move |this, cx| {
match task.await { match task.await {
@@ -655,61 +649,53 @@ impl ChatRegistry {
} }
/// Create a task to load rooms from the database /// Create a task to load rooms from the database
fn get_rooms_from_database( fn get_rooms_task(&self, cx: &App) -> Task<Result<HashSet<Room>, Error>> {
&self,
public_key: PublicKey,
cx: &App,
) -> Task<Result<HashSet<Room>, Error>> {
let nostr = NostrRegistry::global(cx); let nostr = NostrRegistry::global(cx);
let client = nostr.read(cx).client(); let client = nostr.read(cx).client();
let signer = nostr.read(cx).signer();
cx.background_spawn(async move { cx.background_spawn(async move {
let public_key = signer.get_public_key_async().await?;
let contacts = client let contacts = client
.database() .database()
.contacts_public_keys(public_key) .contacts_public_keys(public_key)
.await .await
.unwrap_or_default(); .unwrap_or_default();
// Query all cached rumor events (works with both old and new cache formats)
let filter = Filter::new() let filter = Filter::new()
.kind(Kind::ApplicationSpecificData) .kind(Kind::ApplicationSpecificData)
.custom_tag(SingleLetterTag::lowercase(Alphabet::K), "14"); .custom_tag(SingleLetterTag::lowercase(Alphabet::K), "14");
let events = client.database().query(filter).await?;
let mut rooms: HashSet<Room> = HashSet::new(); let events = client.database().query(filter).await?;
let mut grouped: HashMap<u64, Vec<UnsignedEvent>> = HashMap::new(); let mut grouped: HashMap<u64, Vec<UnsignedEvent>> = HashMap::new();
for raw in events.into_iter() { for raw in events.into_iter() {
if let Ok(rumor) = UnsignedEvent::from_json(&raw.content) if let Ok(rumor) = UnsignedEvent::from_json(&raw.content)
&& rumor.tags.public_keys().peekable().peek().is_some() && rumor.tags.public_keys().next().is_some()
{ {
if rumor.pubkey != public_key
&& !rumor.tags.public_keys().any(|k| k == public_key)
{
continue;
}
grouped.entry(rumor.uniq_id()).or_default().push(rumor); grouped.entry(rumor.uniq_id()).or_default().push(rumor);
} }
} }
for (_id, mut messages) in grouped.into_iter() { let mut rooms = HashSet::with_capacity(grouped.len());
messages.sort_by_key(|m| Reverse(m.created_at));
// Always use the latest message for (_id, messages) in grouped.into_iter() {
let Some(latest) = messages.first() else { let latest = messages.iter().max_by_key(|m| m.created_at).unwrap();
continue; let room = Room::from(latest).organize(&public_key);
};
// Construct the room from the latest message.
//
// Call `.organize` to ensure the current user is at the end of the list.
let mut room = Room::from(latest).organize(&public_key);
// Check if the user has responded to the room
let user_sent = messages.iter().any(|m| m.pubkey == public_key); let user_sent = messages.iter().any(|m| m.pubkey == public_key);
// Check if public keys are from the user's contacts
let is_contact = room.members.iter().any(|k| contacts.contains(k)); let is_contact = room.members.iter().any(|k| contacts.contains(k));
// Set the room's kind based on status let room = if user_sent || is_contact {
if user_sent || is_contact { room.kind(RoomKind::Ongoing)
room = room.kind(RoomKind::Ongoing); } else {
} room
};
rooms.insert(room); rooms.insert(room);
} }