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

View File

@@ -1,11 +1,10 @@
use std::cmp::Reverse; use std::cmp::Reverse;
use std::collections::{BTreeSet, HashMap, HashSet}; use std::collections::{BTreeSet, HashMap, HashSet};
use std::hash::{DefaultHasher, Hash, Hasher};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, LazyLock, RwLock}; use std::sync::{Arc, LazyLock, RwLock};
use std::time::Duration; use std::time::Duration;
use anyhow::{Context as AnyhowContext, Error, anyhow}; use anyhow::{Error, anyhow};
use common::EventExt; use common::EventExt;
use fuzzy_matcher::FuzzyMatcher; use fuzzy_matcher::FuzzyMatcher;
use fuzzy_matcher::skim::SkimMatcherV2; use fuzzy_matcher::skim::SkimMatcherV2;
@@ -301,7 +300,7 @@ impl ChatRegistry {
Signal::Eose => { Signal::Eose => {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.tracking.store(false, Ordering::Release); this.tracking.store(false, Ordering::Release);
this.sort(cx); this.get_rooms(cx);
})?; })?;
} }
Signal::Error(failed) => { Signal::Error(failed) => {
@@ -642,37 +641,21 @@ impl ChatRegistry {
let client = nostr.read(cx).client(); let client = nostr.read(cx).client();
cx.background_spawn(async move { cx.background_spawn(async move {
// Get contacts
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();
// Construct authored filter // Query all cached rumor events (works with both old and new cache formats)
let authored_filter = Filter::new() let filter = Filter::new()
.kind(Kind::ApplicationSpecificData) .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 rooms: HashSet<Room> = HashSet::new();
let mut grouped: HashMap<u64, Vec<UnsignedEvent>> = HashMap::new(); let mut grouped: HashMap<u64, Vec<UnsignedEvent>> = HashMap::new();
// Process each event and group by room hash
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().peekable().peek().is_some()
@@ -767,6 +750,11 @@ async fn extract_rumor(
let unwrapped = try_unwrap_with(signer, gift_wrap).await?; let unwrapped = try_unwrap_with(signer, gift_wrap).await?;
let mut rumor = unwrapped.rumor; 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 // Generate event id for the rumor if it doesn't have one
rumor.ensure_id(); rumor.ensure_id();
@@ -807,39 +795,20 @@ async fn try_unwrap_with(
/// Stores an unwrapped event in local database with reference to original /// Stores an unwrapped event in local database with reference to original
async fn set_rumor(client: &Client, id: EventId, rumor: &UnsignedEvent) -> Result<(), Error> { 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 room_id = rumor.uniq_id().to_string();
let author = rumor.pubkey;
let conversation = conversation_id(rumor);
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 let event = EventBuilder::new(Kind::ApplicationSpecificData, rumor.as_json())
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)
.tags(tags) .tags(tags)
.finalize_async(&*LOCAL_KEYS) .finalize_async(&*LOCAL_KEYS)
.await?; .await?;
// Save the event to the database
client.database().save_event(&event).await?; client.database().save_event(&event).await?;
Ok(()) Ok(())
@@ -847,10 +816,7 @@ async fn set_rumor(client: &Client, id: EventId, rumor: &UnsignedEvent) -> Resul
/// Retrieves a previously unwrapped event from local database /// Retrieves a previously unwrapped event from local database
async fn get_rumor(client: &Client, gift_wrap: EventId) -> Result<UnsignedEvent, Error> { async fn get_rumor(client: &Client, gift_wrap: EventId) -> Result<UnsignedEvent, Error> {
let filter = Filter::new() let filter = Filter::new().identifier(gift_wrap).limit(1);
.kind(Kind::ApplicationSpecificData)
.identifier(gift_wrap)
.limit(1);
if let Some(event) = client.database().query(filter).await?.first_owned() { if let Some(event) = client.database().query(filter).await?.first_owned() {
UnsignedEvent::from_json(event.content).map_err(|e| anyhow!(e)) 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.")) 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>> { pub fn get_messages(&self, cx: &App) -> Task<Result<Vec<UnsignedEvent>, Error>> {
let nostr = NostrRegistry::global(cx); let nostr = NostrRegistry::global(cx);
let client = nostr.read(cx).client(); 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 { cx.background_spawn(async move {
let filter = Filter::new() let filter = Filter::new()
.kind(Kind::ApplicationSpecificData) .kind(Kind::ApplicationSpecificData)
.custom_tag(SingleLetterTag::lowercase(Alphabet::C), conversation_id); .custom_tag(SingleLetterTag::lowercase(Alphabet::R), room_id);
let messages = client let messages = client
.database() .database()
@@ -411,10 +411,6 @@ impl Room {
.await? .await?
.into_iter() .into_iter()
.filter_map(|event| UnsignedEvent::from_json(&event.content).ok()) .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) .sorted_by_key(|message| message.created_at)
.collect(); .collect();