This commit is contained in:
2026-07-27 16:07:25 +07:00
parent 2ff83079b8
commit da7167013f
3 changed files with 57 additions and 108 deletions

71
Cargo.lock generated
View File

@@ -470,8 +470,7 @@ dependencies = [
[[package]]
name = "async-wsocket"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c69f24cf7a798027c6b0801de5bfd05d01fe343e87a8329f7c8b46a6d3bc4a79"
source = "git+https://github.com/shadowylab/async-wsocket?rev=16818f3100544bde3fe8338cd80306f3d320426b#16818f3100544bde3fe8338cd80306f3d320426b"
dependencies = [
"futures",
"futures-util",
@@ -1229,7 +1228,7 @@ dependencies = [
[[package]]
name = "collections"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"gpui_util",
"indexmap",
@@ -1711,7 +1710,7 @@ dependencies = [
[[package]]
name = "derive_refineable"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"proc-macro2",
"quote",
@@ -2607,7 +2606,7 @@ dependencies = [
[[package]]
name = "gpui"
version = "0.2.2"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"accesskit",
"anyhow",
@@ -2689,7 +2688,7 @@ dependencies = [
[[package]]
name = "gpui_linux"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"accesskit",
"accesskit_unix",
@@ -2741,7 +2740,7 @@ dependencies = [
[[package]]
name = "gpui_macos"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"accesskit",
"accesskit_macos",
@@ -2790,7 +2789,7 @@ dependencies = [
[[package]]
name = "gpui_macros"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"heck 0.5.0",
"proc-macro2",
@@ -2801,7 +2800,7 @@ dependencies = [
[[package]]
name = "gpui_platform"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"console_error_panic_hook",
"gpui",
@@ -2814,7 +2813,7 @@ dependencies = [
[[package]]
name = "gpui_shared_string"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"schemars",
"serde",
@@ -2824,7 +2823,7 @@ dependencies = [
[[package]]
name = "gpui_tokio"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"anyhow",
"gpui",
@@ -2835,7 +2834,7 @@ dependencies = [
[[package]]
name = "gpui_util"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"anyhow",
"log",
@@ -2845,7 +2844,7 @@ dependencies = [
[[package]]
name = "gpui_web"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"anyhow",
"console_error_panic_hook",
@@ -2869,7 +2868,7 @@ dependencies = [
[[package]]
name = "gpui_wgpu"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"anyhow",
"bytemuck",
@@ -2899,7 +2898,7 @@ dependencies = [
[[package]]
name = "gpui_windows"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"accesskit",
"accesskit_windows",
@@ -3189,7 +3188,7 @@ dependencies = [
[[package]]
name = "http_client"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"anyhow",
"async-compression",
@@ -3209,7 +3208,7 @@ dependencies = [
[[package]]
name = "http_client_tls"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"rustls",
"rustls-platform-verifier",
@@ -4004,7 +4003,7 @@ dependencies = [
[[package]]
name = "media"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"anyhow",
"bindgen",
@@ -4198,7 +4197,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"
[[package]]
name = "nostr"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"aes",
"base64",
@@ -4223,7 +4222,7 @@ dependencies = [
[[package]]
name = "nostr-blossom"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"base64",
"nostr",
@@ -4235,7 +4234,7 @@ dependencies = [
[[package]]
name = "nostr-connect"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"async-utility",
"futures-core",
@@ -4249,7 +4248,7 @@ dependencies = [
[[package]]
name = "nostr-database"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"btreecap",
"flatbuffers",
@@ -4260,7 +4259,7 @@ dependencies = [
[[package]]
name = "nostr-gossip"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"nostr",
"opaquerr",
@@ -4269,7 +4268,7 @@ dependencies = [
[[package]]
name = "nostr-gossip-memory"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"indexmap",
"lru",
@@ -4281,7 +4280,7 @@ dependencies = [
[[package]]
name = "nostr-lmdb"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"async-utility",
"flume 0.12.0",
@@ -4295,7 +4294,7 @@ dependencies = [
[[package]]
name = "nostr-memory"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"btreecap",
"nostr",
@@ -4306,7 +4305,7 @@ dependencies = [
[[package]]
name = "nostr-sdk"
version = "0.45.0-alpha.6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#edf9ab4b523af6c969b1f0ca36cbc9486cc21ac6"
source = "git+https://github.com/rust-nostr/nostr?branch=send-bound#0d9e68e19f6afb6c93492ed28c0e3c572d34aee1"
dependencies = [
"async-utility",
"async-wsocket",
@@ -4907,7 +4906,7 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "perf"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"collections",
"serde",
@@ -5718,7 +5717,7 @@ dependencies = [
[[package]]
name = "refineable"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"derive_refineable",
]
@@ -5800,7 +5799,7 @@ dependencies = [
[[package]]
name = "reqwest_client"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"anyhow",
"bytes",
@@ -6115,7 +6114,7 @@ dependencies = [
[[package]]
name = "scheduler"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"async-task",
"backtrace",
@@ -6739,7 +6738,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sum_tree"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"heapless 0.9.3",
"log",
@@ -7733,7 +7732,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "util_macros"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"perf",
"quote",
@@ -9466,7 +9465,7 @@ dependencies = [
[[package]]
name = "zlog"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"anyhow",
"chrono",
@@ -9483,7 +9482,7 @@ checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
[[package]]
name = "ztracing"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
dependencies = [
"tracing",
"tracing-subscriber",
@@ -9494,7 +9493,7 @@ dependencies = [
[[package]]
name = "ztracing_macro"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#50da8c40dcd596a91fe252537d8e4249f2fd3a50"
source = "git+https://github.com/zed-industries/zed#5a020093f5bfb59f3bb683ff28686f97b6d7b9c8"
[[package]]
name = "zune-core"

View File

@@ -1,11 +1,10 @@
use std::cmp::Reverse;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::hash::{DefaultHasher, Hash, Hasher};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, LazyLock, RwLock};
use std::time::Duration;
use anyhow::{Context as AnyhowContext, Error, anyhow};
use anyhow::{Error, anyhow};
use common::EventExt;
use fuzzy_matcher::FuzzyMatcher;
use fuzzy_matcher::skim::SkimMatcherV2;
@@ -301,7 +300,7 @@ impl ChatRegistry {
Signal::Eose => {
this.update(cx, |this, cx| {
this.tracking.store(false, Ordering::Release);
this.sort(cx);
this.get_rooms(cx);
})?;
}
Signal::Error(failed) => {
@@ -642,37 +641,21 @@ impl ChatRegistry {
let client = nostr.read(cx).client();
cx.background_spawn(async move {
// Get contacts
let contacts = client
.database()
.contacts_public_keys(public_key)
.await
.unwrap_or_default();
// Construct authored filter
let authored_filter = Filter::new()
// Query all cached rumor events (works with both old and new cache formats)
let filter = Filter::new()
.kind(Kind::ApplicationSpecificData)
.custom_tag(SingleLetterTag::lowercase(Alphabet::A), public_key);
.custom_tag(SingleLetterTag::lowercase(Alphabet::K), "14");
let events = client.database().query(filter).await?;
// Get all authored events
let authored = client.database().query(authored_filter).await?;
// Construct addressed filter
let addressed_filter = Filter::new()
.kind(Kind::ApplicationSpecificData)
.custom_tag(SingleLetterTag::lowercase(Alphabet::P), public_key);
// Get all addressed events
let addressed = client.database().query(addressed_filter).await?;
// Merge authored and addressed events
let events = authored.merge(addressed);
// Collect results
let mut rooms: HashSet<Room> = HashSet::new();
let mut grouped: HashMap<u64, Vec<UnsignedEvent>> = HashMap::new();
// Process each event and group by room hash
for raw in events.into_iter() {
if let Ok(rumor) = UnsignedEvent::from_json(&raw.content)
&& rumor.tags.public_keys().peekable().peek().is_some()
@@ -767,6 +750,11 @@ async fn extract_rumor(
let unwrapped = try_unwrap_with(signer, gift_wrap).await?;
let mut rumor = unwrapped.rumor;
// Verify rumor author matches the seal sender (as per mobile implementation)
if rumor.pubkey != unwrapped.sender {
return Err(anyhow!("Rumor author does not match seal sender"));
}
// Generate event id for the rumor if it doesn't have one
rumor.ensure_id();
@@ -807,39 +795,20 @@ async fn try_unwrap_with(
/// Stores an unwrapped event in local database with reference to original
async fn set_rumor(client: &Client, id: EventId, rumor: &UnsignedEvent) -> Result<(), Error> {
let rumor_id = rumor.id.context("Rumor is missing an event id")?;
let author = rumor.pubkey;
let conversation = conversation_id(rumor);
let room_id = rumor.uniq_id().to_string();
let mut tags = rumor.tags.clone().to_vec();
let tags = vec![
Tag::identifier(id),
Tag::public_key(rumor.pubkey),
Tag::custom("r", [room_id]),
Tag::custom("k", ["14"]),
];
// Add a unique identifier
tags.push(Tag::identifier(id));
// Add a reference to the rumor's author
tags.push(Tag::custom("a", [author]));
// Add a conversation id
tags.push(Tag::custom("c", [conversation.to_string()]));
// Add a reference to the rumor's id
tags.push(Tag::event(rumor_id));
// Add references to the rumor's participants
for receiver in rumor.tags.public_keys() {
tags.push(Tag::custom("P", [receiver]));
}
// Convert rumor to json
let content = rumor.as_json();
// Construct the event
let event = EventBuilder::new(Kind::ApplicationSpecificData, content)
let event = EventBuilder::new(Kind::ApplicationSpecificData, rumor.as_json())
.tags(tags)
.finalize_async(&*LOCAL_KEYS)
.await?;
// Save the event to the database
client.database().save_event(&event).await?;
Ok(())
@@ -847,10 +816,7 @@ async fn set_rumor(client: &Client, id: EventId, rumor: &UnsignedEvent) -> Resul
/// Retrieves a previously unwrapped event from local database
async fn get_rumor(client: &Client, gift_wrap: EventId) -> Result<UnsignedEvent, Error> {
let filter = Filter::new()
.kind(Kind::ApplicationSpecificData)
.identifier(gift_wrap)
.limit(1);
let filter = Filter::new().identifier(gift_wrap).limit(1);
if let Some(event) = client.database().query(filter).await?.first_owned() {
UnsignedEvent::from_json(event.content).map_err(|e| anyhow!(e))
@@ -858,15 +824,3 @@ async fn get_rumor(client: &Client, gift_wrap: EventId) -> Result<UnsignedEvent,
Err(anyhow!("Event is not cached yet."))
}
}
/// Get the conversation ID for a given rumor (message).
fn conversation_id(rumor: &UnsignedEvent) -> u64 {
let mut hasher = DefaultHasher::new();
let mut pubkeys: Vec<PublicKey> = rumor.tags.public_keys().collect();
pubkeys.push(rumor.pubkey);
pubkeys.sort();
pubkeys.dedup();
pubkeys.hash(&mut hasher);
hasher.finish()
}

View File

@@ -398,12 +398,12 @@ impl Room {
pub fn get_messages(&self, cx: &App) -> Task<Result<Vec<UnsignedEvent>, Error>> {
let nostr = NostrRegistry::global(cx);
let client = nostr.read(cx).client();
let conversation_id = self.id.to_string();
let room_id = self.id.to_string();
cx.background_spawn(async move {
let filter = Filter::new()
.kind(Kind::ApplicationSpecificData)
.custom_tag(SingleLetterTag::lowercase(Alphabet::C), conversation_id);
.custom_tag(SingleLetterTag::lowercase(Alphabet::R), room_id);
let messages = client
.database()
@@ -411,10 +411,6 @@ impl Room {
.await?
.into_iter()
.filter_map(|event| UnsignedEvent::from_json(&event.content).ok())
.filter(|event| {
// Only process private direct messages and file messages
event.kind == Kind::PrivateDirectMessage || event.kind == Kind::Custom(15)
})
.sorted_by_key(|message| message.created_at)
.collect();