From 82f18fc4782fb482dde2b4fe5d0a03f7d3f3803e Mon Sep 17 00:00:00 2001 From: reya Date: Thu, 30 Jan 2025 08:03:39 +0700 Subject: [PATCH] chore: adapt latest changes from GPUI and nostr-sdk --- Cargo.lock | 191 +++++++++++++++++------- crates/app/src/main.rs | 155 ++++++++++--------- crates/app/src/views/chat/mod.rs | 6 +- crates/app/src/views/sidebar/compose.rs | 2 +- crates/app/src/views/sidebar/mod.rs | 2 +- crates/registry/src/app.rs | 4 +- crates/registry/src/chat.rs | 2 +- crates/ui/src/dock_area/dock.rs | 8 +- crates/ui/src/dock_area/mod.rs | 12 +- crates/ui/src/dock_area/stack_panel.rs | 4 +- crates/ui/src/dock_area/tab_panel.rs | 16 +- crates/ui/src/dropdown.rs | 4 +- crates/ui/src/input/element.rs | 12 +- crates/ui/src/input/input.rs | 4 +- crates/ui/src/list/list.rs | 4 +- crates/ui/src/modal.rs | 2 +- crates/ui/src/popup_menu.rs | 5 +- crates/ui/src/resizable/panel.rs | 16 +- crates/ui/src/root.rs | 13 +- 19 files changed, 276 insertions(+), 186 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39e77f8..34c4c0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -584,7 +584,7 @@ checksum = "6099cdc01846bc367c4e7dd630dc5966dccf36b652fae7a74e17b640411a91b2" [[package]] name = "blade-graphics" version = "0.6.0" -source = "git+https://github.com/kvark/blade?rev=091a8401033847bb9b6ace3fcf70448d069621c5#091a8401033847bb9b6ace3fcf70448d069621c5" +source = "git+https://github.com/kvark/blade?rev=b16f5c7bd873c7126f48c82c39e7ae64602ae74f#b16f5c7bd873c7126f48c82c39e7ae64602ae74f" dependencies = [ "ash", "ash-window", @@ -616,7 +616,7 @@ dependencies = [ [[package]] name = "blade-macros" version = "0.3.0" -source = "git+https://github.com/kvark/blade?rev=091a8401033847bb9b6ace3fcf70448d069621c5#091a8401033847bb9b6ace3fcf70448d069621c5" +source = "git+https://github.com/kvark/blade?rev=b16f5c7bd873c7126f48c82c39e7ae64602ae74f#b16f5c7bd873c7126f48c82c39e7ae64602ae74f" dependencies = [ "proc-macro2", "quote", @@ -626,7 +626,7 @@ dependencies = [ [[package]] name = "blade-util" version = "0.2.0" -source = "git+https://github.com/kvark/blade?rev=091a8401033847bb9b6ace3fcf70448d069621c5#091a8401033847bb9b6ace3fcf70448d069621c5" +source = "git+https://github.com/kvark/blade?rev=b16f5c7bd873c7126f48c82c39e7ae64602ae74f#b16f5c7bd873c7126f48c82c39e7ae64602ae74f" dependencies = [ "blade-graphics", "bytemuck", @@ -698,9 +698,9 @@ checksum = "c360505aed52b7ec96a3636c3f039d99103c37d1d9b4f7a8c743d3ea9ffcd03b" [[package]] name = "bumpalo" -version = "3.16.0" +version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" [[package]] name = "bytemuck" @@ -1014,7 +1014,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "indexmap", "rustc-hash 2.1.0", @@ -1068,7 +1068,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" dependencies = [ - "getrandom", + "getrandom 0.2.15", "once_cell", "tiny-keccak", ] @@ -1318,7 +1318,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "proc-macro2", "quote", @@ -1640,6 +1640,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce81f49ae8a0482e4c55ea62ebbd7e5a686af544c00b9d090bba3ff9be97b3d" +[[package]] +name = "float_next_after" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8" + [[package]] name = "flume" version = "0.11.1" @@ -1917,10 +1923,22 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.13.3+wasi-0.2.2", + "windows-targets 0.52.6", +] + [[package]] name = "gif" version = "0.13.1" @@ -2013,7 +2031,7 @@ dependencies = [ [[package]] name = "gpui" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "anyhow", "as-raw-xcb-connection", @@ -2050,8 +2068,10 @@ dependencies = [ "itertools 0.14.0", "linkme", "log", + "lyon", "media", "metal", + "naga", "num_cpus", "objc", "oo7", @@ -2098,7 +2118,7 @@ dependencies = [ [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "proc-macro2", "quote", @@ -2303,7 +2323,7 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "anyhow", "bytes", @@ -2318,15 +2338,15 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.5" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" +checksum = "f2d708df4e7140240a16cd6ab0ab65c972d7433ab77819ea693fde9c43811e2a" [[package]] name = "hyper" -version = "1.5.2" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256fb8d4bd6413123cc9d91832d78325c48ff41677595be797d90f42969beae0" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" dependencies = [ "bytes", "futures-channel", @@ -2769,9 +2789,9 @@ checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libfuzzer-sys" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b9569d2f74e257076d8c6bfa73fb505b46b851e51ddaecc825944aa3bed17fa" +checksum = "cf78f52d400cf2d84a3a973a78a592b4adc535739e0a5597a0da6f0c357adc75" dependencies = [ "arbitrary", "cc", @@ -2875,6 +2895,58 @@ dependencies = [ "imgref", ] +[[package]] +name = "lyon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e7f9cda98b5430809e63ca5197b06c7d191bf7e26dfc467d5a3f0290e2a74f" +dependencies = [ + "lyon_algorithms", + "lyon_tessellation", +] + +[[package]] +name = "lyon_algorithms" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f13c9be19d257c7d37e70608ed858e8eab4b2afcea2e3c9a622e892acbf43c08" +dependencies = [ + "lyon_path", + "num-traits", +] + +[[package]] +name = "lyon_geom" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8af69edc087272df438b3ee436c4bb6d7c04aa8af665cfd398feae627dbd8570" +dependencies = [ + "arrayvec", + "euclid", + "num-traits", +] + +[[package]] +name = "lyon_path" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e0b8aec2f58586f6eef237985b9a9b7cb3a3aff4417c575075cf95bf925252e" +dependencies = [ + "lyon_geom", + "num-traits", +] + +[[package]] +name = "lyon_tessellation" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579d42360a4b09846eff2feef28f538696c7d6c7439bfa65874ff3cbe0951b2c" +dependencies = [ + "float_next_after", + "lyon_path", + "num-traits", +] + [[package]] name = "mac" version = "0.1.1" @@ -2913,7 +2985,7 @@ dependencies = [ [[package]] name = "media" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "anyhow", "bindgen", @@ -3008,7 +3080,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.52.0", ] @@ -3039,7 +3111,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" dependencies = [ - "getrandom", + "getrandom 0.2.15", ] [[package]] @@ -3091,7 +3163,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "nostr" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#d8dcb0697b1ebce28cce6f89747dc6ba73a45b56" +source = "git+https://github.com/rust-nostr/nostr#3c248e5fbb42f608110c33d4c8d470e479e361f3" dependencies = [ "aes", "base64", @@ -3101,7 +3173,7 @@ dependencies = [ "cbc", "chacha20", "chacha20poly1305", - "getrandom", + "getrandom 0.2.15", "instant", "js-sys", "reqwest 0.12.12", @@ -3119,7 +3191,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#d8dcb0697b1ebce28cce6f89747dc6ba73a45b56" +source = "git+https://github.com/rust-nostr/nostr#3c248e5fbb42f608110c33d4c8d470e479e361f3" dependencies = [ "flatbuffers", "nostr", @@ -3129,7 +3201,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#d8dcb0697b1ebce28cce6f89747dc6ba73a45b56" +source = "git+https://github.com/rust-nostr/nostr#3c248e5fbb42f608110c33d4c8d470e479e361f3" dependencies = [ "async-utility", "heed", @@ -3140,7 +3212,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#d8dcb0697b1ebce28cce6f89747dc6ba73a45b56" +source = "git+https://github.com/rust-nostr/nostr#3c248e5fbb42f608110c33d4c8d470e479e361f3" dependencies = [ "async-utility", "async-wsocket", @@ -3156,7 +3228,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#d8dcb0697b1ebce28cce6f89747dc6ba73a45b56" +source = "git+https://github.com/rust-nostr/nostr#3c248e5fbb42f608110c33d4c8d470e479e361f3" dependencies = [ "async-utility", "nostr", @@ -3277,6 +3349,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -3953,7 +4026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" dependencies = [ "bytes", - "getrandom", + "getrandom 0.2.15", "rand", "ring", "rustc-hash 2.1.0", @@ -4016,7 +4089,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.15", ] [[package]] @@ -4155,7 +4228,7 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ - "getrandom", + "getrandom 0.2.15", "libredox", "thiserror 1.0.69", ] @@ -4163,7 +4236,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "derive_refineable", ] @@ -4304,7 +4377,7 @@ dependencies = [ [[package]] name = "reqwest_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "anyhow", "bytes", @@ -4348,7 +4421,7 @@ checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", "cfg-if", - "getrandom", + "getrandom 0.2.15", "libc", "spin", "untrusted", @@ -4473,9 +4546,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37" +checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" dependencies = [ "web-time", ] @@ -4516,9 +4589,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" [[package]] name = "salsa20" @@ -4654,7 +4727,7 @@ checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe" [[package]] name = "semantic_version" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "anyhow", "serde", @@ -4708,9 +4781,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.137" +version = "1.0.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" +checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" dependencies = [ "indexmap", "itoa", @@ -4979,7 +5052,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "arrayvec", "log", @@ -5212,13 +5285,13 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tempfile" -version = "3.15.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704" +checksum = "38c246215d7d24f48ae091a2902398798e05d978b24315d6efbc00ede9a8bb91" dependencies = [ "cfg-if", "fastrand 2.3.0", - "getrandom", + "getrandom 0.3.1", "once_cell", "rustix", "windows-sys 0.59.0", @@ -5675,9 +5748,9 @@ checksum = "1df77b101bcc4ea3d78dafc5ad7e4f58ceffe0b2b16bf446aeb50b6cb4157656" [[package]] name = "unicode-ident" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243" +checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" [[package]] name = "unicode-linebreak" @@ -5801,7 +5874,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#a6b1514246c2efeefde5ed0f1fb18aac5c7cc8b2" +source = "git+https://github.com/zed-industries/zed#19383036d5ec1ac7821ad21b3ff1fae95a5f004e" dependencies = [ "anyhow", "async-fs", @@ -5830,7 +5903,7 @@ version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b" dependencies = [ - "getrandom", + "getrandom 0.2.15", "serde", "sha1_smol", ] @@ -5951,6 +6024,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.13.3+wasi-0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2" +dependencies = [ + "wit-bindgen-rt", +] + [[package]] name = "wasm-bindgen" version = "0.2.100" @@ -6420,9 +6502,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.24" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" +checksum = "ad699df48212c6cc6eb4435f35500ac6fd3b9913324f938aea302022ce19d310" dependencies = [ "memchr", ] @@ -6446,6 +6528,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "wit-bindgen-rt" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" +dependencies = [ + "bitflags 2.8.0", +] + [[package]] name = "write16" version = "1.0.0" diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index b552214..b8b61db 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -61,7 +61,81 @@ async fn main() { // Handle notifications from relays // Send notify back to GPUI - tokio::spawn(async move { handle_notifications(client, signal_tx, mta_tx).await }); + tokio::spawn(async move { + let mut notifications = client.notifications(); + let sig = Signature::from_str(FAKE_SIG).unwrap(); + let new_message = SubscriptionId::new(NEW_MESSAGE_SUB_ID); + let all_messages = SubscriptionId::new(ALL_MESSAGES_SUB_ID); + + while let Ok(notification) = notifications.recv().await { + if let RelayPoolNotification::Message { message, .. } = notification { + if let RelayMessage::Event { + event, + subscription_id, + } = message + { + match event.kind { + Kind::GiftWrap => { + match client.unwrap_gift_wrap(&event).await { + Ok(UnwrappedGift { mut rumor, sender }) => { + // Request metadata + if let Err(e) = mta_tx.send(sender).await { + warn!("Send error: {}", e) + }; + + // Compute event id if not exist + rumor.ensure_id(); + + if let Some(id) = rumor.id { + let ev = Event::new( + id, + rumor.pubkey, + rumor.created_at, + rumor.kind, + rumor.tags, + rumor.content, + sig, + ); + + // Save rumor to database to further query + if let Err(e) = client.database().save_event(&ev).await { + warn!("Save error: {}", e); + } + + // Send event back to channel + if subscription_id == new_message { + if let Err(e) = signal_tx.send(Signal::Event(ev)).await + { + warn!("Send error: {}", e) + } + } + } + } + Err(e) => warn!("Unwrap error: {}", e), + } + } + Kind::ContactList => { + let public_keys: Vec = + event.tags.public_keys().copied().collect(); + + for public_key in public_keys.into_iter() { + if let Err(e) = mta_tx.send(public_key).await { + warn!("Send error: {}", e) + }; + } + } + _ => {} + } + } else if let RelayMessage::EndOfStoredEvents(subscription_id) = message { + if subscription_id == all_messages { + if let Err(e) = signal_tx.send(Signal::Eose).await { + warn!("Send error: {}", e) + }; + } + } + } + } + }); // Handle metadata request // Merge all requests into single subscription @@ -187,85 +261,6 @@ async fn main() { }); } -async fn handle_notifications( - client: &Client, - signal_tx: mpsc::Sender, - mta_tx: mpsc::Sender, -) { - let mut notifications = client.notifications(); - let sig = Signature::from_str(FAKE_SIG).unwrap(); - let new_message = SubscriptionId::new(NEW_MESSAGE_SUB_ID); - let all_messages = SubscriptionId::new(ALL_MESSAGES_SUB_ID); - - while let Ok(notification) = notifications.recv().await { - if let RelayPoolNotification::Message { message, .. } = notification { - if let RelayMessage::Event { - event, - subscription_id, - } = message - { - match event.kind { - Kind::GiftWrap => { - match client.unwrap_gift_wrap(&event).await { - Ok(UnwrappedGift { mut rumor, sender }) => { - // Request metadata - if let Err(e) = mta_tx.send(sender).await { - warn!("Send error: {}", e) - }; - - // Compute event id if not exist - rumor.ensure_id(); - - if let Some(id) = rumor.id { - let ev = Event::new( - id, - rumor.pubkey, - rumor.created_at, - rumor.kind, - rumor.tags, - rumor.content, - sig, - ); - - // Save rumor to database to further query - if let Err(e) = client.database().save_event(&ev).await { - warn!("Save error: {}", e); - } - - // Send event back to channel - if subscription_id == new_message { - if let Err(e) = signal_tx.send(Signal::Event(ev)).await { - warn!("Send error: {}", e) - } - } - } - } - Err(e) => warn!("Unwrap error: {}", e), - } - } - Kind::ContactList => { - let public_keys: Vec = - event.tags.public_keys().copied().collect(); - - for public_key in public_keys.into_iter() { - if let Err(e) = mta_tx.send(public_key).await { - warn!("Send error: {}", e) - }; - } - } - _ => {} - } - } else if let RelayMessage::EndOfStoredEvents(subscription_id) = message { - if subscription_id == all_messages { - if let Err(e) = signal_tx.send(Signal::Eose).await { - warn!("Send error: {}", e) - }; - } - } - } - } -} - async fn handle_metadata(client: &'static Client, mut mta_rx: mpsc::Receiver) { let queue: Arc>> = Arc::new(Mutex::new(HashSet::new())); let queue_clone = Arc::clone(&queue); diff --git a/crates/app/src/views/chat/mod.rs b/crates/app/src/views/chat/mod.rs index 53d3c0d..38d1f7a 100644 --- a/crates/app/src/views/chat/mod.rs +++ b/crates/app/src/views/chat/mod.rs @@ -169,9 +169,11 @@ impl ChatPanel { .pubkey(author); // Get all DM events in database - let query = client.database().query(vec![recv, send]).await?; + let recv_events = client.database().query(recv).await?; + let send_events = client.database().query(send).await?; + let events = recv_events.merge(send_events); - Ok(query) + Ok(events) } }) .await; diff --git a/crates/app/src/views/sidebar/compose.rs b/crates/app/src/views/sidebar/compose.rs index 63299a2..d99bb47 100644 --- a/crates/app/src/views/sidebar/compose.rs +++ b/crates/app/src/views/sidebar/compose.rs @@ -312,7 +312,7 @@ impl Render for Compose { if let Some(contacts) = self.contacts.read(cx).clone() { this.child( uniform_list( - cx.model().clone(), + cx.entity().clone(), "contacts", contacts.len(), move |this, range, window, cx| { diff --git a/crates/app/src/views/sidebar/mod.rs b/crates/app/src/views/sidebar/mod.rs index cd40a3a..2b76e0c 100644 --- a/crates/app/src/views/sidebar/mod.rs +++ b/crates/app/src/views/sidebar/mod.rs @@ -42,7 +42,7 @@ impl Sidebar { closeable: true, zoomable: true, focus_handle: cx.focus_handle(), - view_id: cx.model().entity_id(), + view_id: cx.entity().entity_id(), inbox, } } diff --git a/crates/registry/src/app.rs b/crates/registry/src/app.rs index f327703..596443d 100644 --- a/crates/registry/src/app.rs +++ b/crates/registry/src/app.rs @@ -60,12 +60,12 @@ impl AppRegistry { // Subscribe for all messages _ = client - .subscribe_with_id(all_messages_sub_id, vec![all_messages], Some(opts)) + .subscribe_with_id(all_messages_sub_id, all_messages, Some(opts)) .await; // Subscribe for new message _ = client - .subscribe_with_id(new_message_sub_id, vec![new_message], None) + .subscribe_with_id(new_message_sub_id, new_message, None) .await; }) .detach(); diff --git a/crates/registry/src/chat.rs b/crates/registry/src/chat.rs index d37431c..f54856d 100644 --- a/crates/registry/src/chat.rs +++ b/crates/registry/src/chat.rs @@ -35,7 +35,7 @@ impl Inbox { .author(public_key); // Get all DM events from database - let events = client.database().query(vec![filter]).await?; + let events = client.database().query(filter).await?; // Filter result // - Get unique rooms only diff --git a/crates/ui/src/dock_area/dock.rs b/crates/ui/src/dock_area/dock.rs index b0c5339..8044755 100644 --- a/crates/ui/src/dock_area/dock.rs +++ b/crates/ui/src/dock_area/dock.rs @@ -268,7 +268,7 @@ impl Dock { ) -> impl IntoElement { let axis = self.placement.axis(); let neg_offset = -HANDLE_PADDING; - let view = cx.model().clone(); + let view = cx.entity().clone(); div() .id("resize-handle") @@ -336,7 +336,7 @@ impl Dock { // Get the size of the left dock if it's open and not the current dock if let Some(left_dock) = &dock_area.left_dock { - if left_dock.entity_id() != cx.model().entity_id() { + if left_dock.entity_id() != cx.entity().entity_id() { let left_dock_read = left_dock.read(cx); if left_dock_read.is_open() { left_dock_size = left_dock_read.size; @@ -346,7 +346,7 @@ impl Dock { // Get the size of the right dock if it's open and not the current dock if let Some(right_dock) = &dock_area.right_dock { - if right_dock.entity_id() != cx.model().entity_id() { + if right_dock.entity_id() != cx.entity().entity_id() { let right_dock_read = right_dock.read(cx); if right_dock_read.is_open() { right_dock_size = right_dock_read.size; @@ -409,7 +409,7 @@ impl Render for Dock { }) .child(self.render_resize_handle(window, cx)) .child(DockElement { - view: cx.model().clone(), + view: cx.entity().clone(), }) } } diff --git a/crates/ui/src/dock_area/mod.rs b/crates/ui/src/dock_area/mod.rs index 96eb7d8..1fed464 100644 --- a/crates/ui/src/dock_area/mod.rs +++ b/crates/ui/src/dock_area/mod.rs @@ -355,7 +355,7 @@ impl DockArea { cx: &mut Context, ) { self.subscribe_item(&panel, window, cx); - let weak_self = cx.model().downgrade(); + let weak_self = cx.entity().downgrade(); self.left_dock = Some(cx.new(|cx| { let mut dock = Dock::left(weak_self.clone(), window, cx); if let Some(size) = size { @@ -377,7 +377,7 @@ impl DockArea { cx: &mut Context, ) { self.subscribe_item(&panel, window, cx); - let weak_self = cx.model().downgrade(); + let weak_self = cx.entity().downgrade(); self.bottom_dock = Some(cx.new(|cx| { let mut dock = Dock::bottom(weak_self.clone(), window, cx); if let Some(size) = size { @@ -399,7 +399,7 @@ impl DockArea { cx: &mut Context, ) { self.subscribe_item(&panel, window, cx); - let weak_self = cx.model().downgrade(); + let weak_self = cx.entity().downgrade(); self.right_dock = Some(cx.new(|cx| { let mut dock = Dock::right(weak_self.clone(), window, cx); if let Some(size) = size { @@ -534,7 +534,7 @@ impl DockArea { window: &mut Window, cx: &mut Context, ) { - let weak_self = cx.model().downgrade(); + let weak_self = cx.entity().downgrade(); match placement { DockPlacement::Left => { if let Some(dock) = self.left_dock.as_ref() { @@ -577,7 +577,7 @@ impl DockArea { } DockPlacement::Center => { self.items - .add_panel(panel, &cx.model().downgrade(), window, cx); + .add_panel(panel, &cx.entity().downgrade(), window, cx); } } } @@ -717,7 +717,7 @@ impl EventEmitter for DockArea {} impl Render for DockArea { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { - let view = cx.model().clone(); + let view = cx.entity().clone(); div() .id("dock-area") diff --git a/crates/ui/src/dock_area/stack_panel.rs b/crates/ui/src/dock_area/stack_panel.rs index 2b331ca..784b2c7 100644 --- a/crates/ui/src/dock_area/stack_panel.rs +++ b/crates/ui/src/dock_area/stack_panel.rs @@ -191,7 +191,7 @@ impl StackPanel { return; } - let view = cx.model().clone(); + let view = cx.entity().clone(); window.defer(cx, { let panel = panel.clone(); @@ -289,7 +289,7 @@ impl StackPanel { return; } - let view = cx.model().clone(); + let view = cx.entity().clone(); if let Some(parent) = self.parent.as_ref() { _ = parent.update(cx, |parent, cx| { parent.remove_panel(Arc::new(view.clone()), window, cx); diff --git a/crates/ui/src/dock_area/tab_panel.rs b/crates/ui/src/dock_area/tab_panel.rs index f90b79b..214bbd0 100644 --- a/crates/ui/src/dock_area/tab_panel.rs +++ b/crates/ui/src/dock_area/tab_panel.rs @@ -284,7 +284,7 @@ impl TabPanel { return; } - let tab_view = cx.model().clone(); + let tab_view = cx.entity().clone(); if let Some(stack_panel) = self.stack_panel.as_ref() { _ = stack_panel.update(cx, |view, cx| { @@ -353,7 +353,7 @@ impl TabPanel { cx: &mut Context, ) -> impl IntoElement { let is_zoomed = self.is_zoomed && state.zoomable; - let view = cx.model().clone(); + let view = cx.entity().clone(); let build_popup_menu = move |this, cx: &App| view.read(cx).popup_menu(this, cx); // TODO: Do not show MenuButton if there is no menu items @@ -413,7 +413,7 @@ impl TabPanel { return None; } - let view_entity_id = cx.model().entity_id(); + let view_entity_id = cx.entity().entity_id(); let toggle_button_panels = dock_area.toggle_button_panels; // Check if current TabPanel's entity_id matches the one stored in DockArea for this placement @@ -486,7 +486,7 @@ impl TabPanel { window: &mut Window, cx: &mut Context, ) -> impl IntoElement { - let view = cx.model().clone(); + let view = cx.entity().clone(); let Some(dock_area) = self.dock_area.upgrade() else { return div().into_any_element(); @@ -800,7 +800,7 @@ impl TabPanel { cx: &mut Context, ) { let panel = drag.panel.clone(); - let is_same_tab = drag.tab_panel == cx.model(); + let is_same_tab = drag.tab_panel == cx.entity(); // If target is same tab, and it is only one panel, do nothing. if is_same_tab && ix.is_none() { @@ -863,7 +863,7 @@ impl TabPanel { let ix = stack_panel .read(cx) - .index_of_panel(Arc::new(cx.model().clone())) + .index_of_panel(Arc::new(cx.entity().clone())) .unwrap_or_default(); if parent_axis.is_vertical() && placement.is_vertical() { @@ -892,10 +892,10 @@ impl TabPanel { }); } else { // 1. Create new StackPanel with new axis - // 2. Move cx.model() from parent StackPanel to the new StackPanel + // 2. Move cx.entity() from parent StackPanel to the new StackPanel // 3. Add the new TabPanel to the new StackPanel at the correct index // 4. Add new StackPanel to the parent StackPanel at the correct index - let tab_panel = cx.model().clone(); + let tab_panel = cx.entity().clone(); // Try to use the old stack panel, not just create a new one, to avoid too many nested stack panels let new_stack_panel = if stack_panel.read(cx).panels_len() <= 1 { diff --git a/crates/ui/src/dropdown.rs b/crates/ui/src/dropdown.rs index 26226c1..e748f9e 100644 --- a/crates/ui/src/dropdown.rs +++ b/crates/ui/src/dropdown.rs @@ -328,7 +328,7 @@ where let focus_handle = cx.focus_handle(); let delegate = DropdownListDelegate { delegate, - dropdown: cx.model().downgrade(), + dropdown: cx.entity().downgrade(), selected_index, }; @@ -589,7 +589,7 @@ where { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { let is_focused = self.focus_handle.is_focused(window); - let view = cx.model().clone(); + let view = cx.entity().clone(); let bounds = self.bounds; let allow_open = !(self.open || self.disabled); let outline_visible = self.open || is_focused && !self.disabled; diff --git a/crates/ui/src/input/element.rs b/crates/ui/src/input/element.rs index 3ced038..04482a1 100644 --- a/crates/ui/src/input/element.rs +++ b/crates/ui/src/input/element.rs @@ -271,12 +271,14 @@ impl TextElement { // print_points_as_svg_path(&line_corners, &points); - let first_p = *points.first().unwrap(); - let mut path = gpui::Path::new(bounds.origin + first_p); + let first_p = *points.get(0).unwrap(); + let mut builder = gpui::PathBuilder::fill(); + builder.move_to(bounds.origin + first_p); for p in points.iter().skip(1) { - path.line_to(bounds.origin + *p); + builder.line_to(bounds.origin + *p); } - Some(path) + + builder.build().ok() } } @@ -423,7 +425,7 @@ impl Element for TextElement { let lines = window .text_system() - .shape_text(display_text, font_size, &runs, wrap_width) + .shape_text(display_text, font_size, &runs, wrap_width, None) .unwrap(); // `position_for_index` for example diff --git a/crates/ui/src/input/input.rs b/crates/ui/src/input/input.rs index df282c0..2afa552 100644 --- a/crates/ui/src/input/input.rs +++ b/crates/ui/src/input/input.rs @@ -1492,14 +1492,14 @@ impl Render for TextInput { .id("TextElement") .flex_grow() .overflow_x_hidden() - .child(TextElement::new(cx.model().clone())), + .child(TextElement::new(cx.entity().clone())), ) .when(self.loading, |this| { this.child(Indicator::new().color(cx.theme().base.step(cx, ColorScaleStep::ELEVEN))) }) .children(suffix) .when(self.is_multi_line(), |this| { - let entity_id = cx.model().entity_id(); + let entity_id = cx.entity().entity_id(); if self.last_layout.is_some() { let scroll_size = self.scroll_size; diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index 1dcdbd6..5e3987c 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -234,7 +234,7 @@ where } Some(Scrollbar::uniform_scroll( - cx.model().entity_id(), + cx.entity().entity_id(), self.scrollbar_state.clone(), self.vertical_scroll_handle.clone(), )) @@ -431,7 +431,7 @@ where D: ListDelegate, { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { - let view = cx.model().clone(); + let view = cx.entity().clone(); let vertical_scroll_handle = self.vertical_scroll_handle.clone(); let items_count = self.delegate.items_count(cx); let sizing_behavior = if self.max_height.is_some() { diff --git a/crates/ui/src/modal.rs b/crates/ui/src/modal.rs index 5e2b0df..e48d499 100644 --- a/crates/ui/src/modal.rs +++ b/crates/ui/src/modal.rs @@ -39,7 +39,7 @@ pub struct Modal { } impl Modal { - pub fn new(window: &mut Window, cx: &mut App) -> Self { + pub fn new(_window: &mut Window, cx: &mut App) -> Self { let base = v_flex() .bg(cx.theme().background) .border_1() diff --git a/crates/ui/src/popup_menu.rs b/crates/ui/src/popup_menu.rs index bf2c56d..f312b05 100644 --- a/crates/ui/src/popup_menu.rs +++ b/crates/ui/src/popup_menu.rs @@ -328,7 +328,8 @@ impl PopupMenu { f: impl Fn(PopupMenu, &mut Window, &mut Context) -> PopupMenu + 'static, ) -> Self { let submenu = PopupMenu::build(window, cx, f); - let parent_menu = cx.model().downgrade(); + let parent_menu = cx.entity().downgrade(); + submenu.update(cx, |view, _| { view.parent_menu = Some(parent_menu); }); @@ -506,7 +507,7 @@ impl Focusable for PopupMenu { impl Render for PopupMenu { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { - let view = cx.model().clone(); + let view = cx.entity().clone(); let has_icon = self.menu_items.iter().any(|item| item.has_icon()); let items_count = self.menu_items.len(); let max_width = self.max_width; diff --git a/crates/ui/src/resizable/panel.rs b/crates/ui/src/resizable/panel.rs index 5ed0b75..dbd6674 100644 --- a/crates/ui/src/resizable/panel.rs +++ b/crates/ui/src/resizable/panel.rs @@ -108,7 +108,7 @@ impl ResizablePanelGroup { ) { let mut panel = panel; panel.axis = self.axis; - panel.group = Some(cx.model().downgrade()); + panel.group = Some(cx.entity().downgrade()); self.sizes.push(panel.initial_size.unwrap_or_default()); self.panels.push(cx.new(|_| panel)); } @@ -122,7 +122,7 @@ impl ResizablePanelGroup { ) { let mut panel = panel; panel.axis = self.axis; - panel.group = Some(cx.model().downgrade()); + panel.group = Some(cx.entity().downgrade()); self.sizes .insert(ix, panel.initial_size.unwrap_or_default()); @@ -148,7 +148,7 @@ impl ResizablePanelGroup { panel.initial_size = old_panel_initial_size; panel.size_ratio = old_panel_size_ratio; panel.axis = self.axis; - panel.group = Some(cx.model().downgrade()); + panel.group = Some(cx.entity().downgrade()); self.sizes[ix] = panel.initial_size.unwrap_or_default(); self.panels[ix] = cx.new(|_| panel); cx.notify() @@ -172,7 +172,7 @@ impl ResizablePanelGroup { _window: &mut Window, cx: &mut Context, ) -> impl IntoElement { - let view = cx.model().clone(); + let view = cx.entity().clone(); resize_handle(("resizable-handle", ix), self.axis).on_drag( DragPanel((cx.entity_id(), ix, self.axis)), move |drag_panel, _, _window, cx| { @@ -273,7 +273,7 @@ impl EventEmitter for ResizablePanelGroup {} impl Render for ResizablePanelGroup { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { - let view = cx.model().clone(); + let view = cx.entity().clone(); let container = if self.axis.is_horizontal() { h_flex() } else { @@ -301,7 +301,7 @@ impl Render for ResizablePanelGroup { .size_full() }) .child(ResizePanelGroupElement { - view: cx.model().clone(), + view: cx.entity().clone(), axis: self.axis, }) } @@ -370,7 +370,7 @@ impl ResizablePanel { self.bounds = bounds; self.size = Some(new_size); - let panel_view = cx.model().clone(); + let panel_view = cx.entity().clone(); if let Some(group) = self.group.as_ref() { _ = group.update(cx, |view, _| { if let Some(ix) = view @@ -390,7 +390,7 @@ impl FluentBuilder for ResizablePanel {} impl Render for ResizablePanel { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { - let view = cx.model().clone(); + let view = cx.entity().clone(); let total_size = self .group .as_ref() diff --git a/crates/ui/src/root.rs b/crates/ui/src/root.rs index 2f5b8f2..f386bd1 100644 --- a/crates/ui/src/root.rs +++ b/crates/ui/src/root.rs @@ -5,8 +5,8 @@ use crate::{ window_border, }; use gpui::{ - div, AnyView, App, AppContext, Context, DefiniteLength, Entity, FocusHandle, - InteractiveElement, IntoElement, ParentElement as _, Render, Styled, Window, + div, AnyView, App, AppContext, Context, Entity, FocusHandle, InteractiveElement, IntoElement, + ParentElement as _, Render, Styled, Window, }; use std::rc::Rc; @@ -195,14 +195,14 @@ impl Root { where F: FnOnce(&mut Self, &mut Window, &mut Context) + 'static, { - if let Some(Some(root)) = window.root_model::() { + if let Some(Some(root)) = window.root::() { root.update(cx, |root, cx| f(root, window, cx)); } } pub fn read<'a>(window: &'a mut Window, cx: &'a mut App) -> &'a Self { window - .root_model::() + .root::() .expect("The window root view should be of type `ui::Root`.") .unwrap() .read(cx) @@ -219,15 +219,14 @@ impl Root { window: &mut Window, cx: &mut App, ) -> Option { - let root = window.root_model::()??; + let root = window.root::()??; Some(div().child(root.read(cx).notification.clone())) } /// Render the Modal layer. pub fn render_modal_layer(window: &mut Window, cx: &mut App) -> Option { - let root = window.root_model::()??; - + let root = window.root::()??; let active_modals = root.read(cx).active_modals.clone(); let mut has_overlay = false;