From 582db29209a1c23336a1325b8082cdd24614956f Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 21 Jan 2025 15:15:37 +0700 Subject: [PATCH] feat: add action to compose modal --- Cargo.lock | 227 +++++++++++------------- crates/app/src/states/chat/mod.rs | 11 ++ crates/app/src/states/chat/room.rs | 47 +++-- crates/app/src/utils.rs | 6 + crates/app/src/views/sidebar/compose.rs | 72 ++++++-- crates/app/src/views/sidebar/inbox.rs | 14 +- crates/app/src/views/sidebar/mod.rs | 60 +++++-- 7 files changed, 265 insertions(+), 172 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9b74b6..c2e8ddc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -481,7 +481,7 @@ version = "0.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "cexpr", "clang-sys", "itertools 0.13.0", @@ -568,9 +568,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1be3f42a67d6d345ecd59f675f3f012d6974981560836e938c22b424b85ce1be" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" dependencies = [ "serde", ] @@ -588,7 +588,7 @@ source = "git+https://github.com/kvark/blade?rev=091a8401033847bb9b6ace3fcf70448 dependencies = [ "ash", "ash-window", - "bitflags 2.7.0", + "bitflags 2.8.0", "bytemuck", "codespan-reporting", "glow", @@ -746,7 +746,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "log", "polling", "rustix", @@ -777,9 +777,9 @@ dependencies = [ [[package]] name = "cbindgen" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fce8dd7fcfcbf3a0a87d8f515194b49d6135acab73e18bd380d1d93bb1a15eb" +checksum = "eadd868a2ce9ca38de7eeafdcec9c7065ef89b42b32f0839278d55f35c54d1ff" dependencies = [ "heck 0.4.1", "indexmap", @@ -795,9 +795,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.9" +version = "1.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" +checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" dependencies = [ "jobserver", "libc", @@ -903,9 +903,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.26" +version = "4.5.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" +checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" dependencies = [ "clap_builder", "clap_derive", @@ -913,9 +913,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.26" +version = "4.5.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" +checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" dependencies = [ "anstream", "anstyle", @@ -963,7 +963,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f79398230a6e2c08f5c9760610eb6924b52aa9e7950a619602baba59dcbbdbb2" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block", "cocoa-foundation 0.2.0", "core-foundation 0.10.0", @@ -993,7 +993,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e14045fb83be07b5acf1c0884b2180461635b433455fa35d1cd6f17f1450679d" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block", "core-foundation 0.10.0", "core-graphics-types 0.2.0", @@ -1014,7 +1014,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "indexmap", "rustc-hash 2.1.0", @@ -1133,7 +1133,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "core-foundation 0.10.0", "core-graphics-types 0.2.0", "foreign-types", @@ -1157,7 +1157,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "core-foundation 0.10.0", "libc", ] @@ -1179,7 +1179,7 @@ name = "cosmic-text" version = "0.11.2" source = "git+https://github.com/pop-os/cosmic-text?rev=542b20c#542b20ca4376a3b5de5fa629db1a4ace44e18e0c" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "fontdb", "log", "rangemap", @@ -1277,9 +1277,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +checksum = "0e60eed09d8c01d3cee5b7d30acb059b76614c918fa0f992e0dd6eeb10daad6f" [[package]] name = "data-url" @@ -1303,7 +1303,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "proc-macro2", "quote", @@ -1458,9 +1458,9 @@ checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" [[package]] name = "enumflags2" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d232db7f5956f3f14313dc2f87985c58bd2c695ce124c8cdd984e08e15ac133d" +checksum = "ba2f4b465f5318854c6f8dd686ede6c0a9dc67d4b1ac241cf0eb51521a309147" dependencies = [ "enumflags2_derive", "serde", @@ -1468,9 +1468,9 @@ dependencies = [ [[package]] name = "enumflags2_derive" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" +checksum = "fc4caf64a58d7a6d65ab00639b046ff54399a39f5f2554728895ace4b297cd79" dependencies = [ "proc-macro2", "quote", @@ -1505,9 +1505,9 @@ dependencies = [ [[package]] name = "etagere" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e2f1e3be19fb10f549be8c1bf013e8675b4066c445e36eb76d2ebb2f54ee495" +checksum = "c732752b4ea11b36052d417d444d1474e948639fb02ff970efd7f18c180ca7f7" dependencies = [ "euclid", "svg_fmt", @@ -1648,7 +1648,7 @@ name = "font-kit" version = "0.14.1" source = "git+https://github.com/zed-industries/font-kit?rev=40391b7#40391b7c0041d8a8572af2afa3de32ae088f0120" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "byteorder", "core-foundation 0.9.4", "core-graphics 0.23.2", @@ -1971,7 +1971,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbcd2dba93594b227a1f57ee09b8b9da8892c34d55aa332e034a228d0fe6a171" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "gpu-alloc-types", ] @@ -1992,13 +1992,13 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98ff03b468aa837d70984d55f5d3f846f6ec31fe34bbb97c4f85219caeee1ca4" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", ] [[package]] name = "gpui" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "anyhow", "as-raw-xcb-connection", @@ -2083,7 +2083,7 @@ dependencies = [ [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "proc-macro2", "quote", @@ -2155,7 +2155,7 @@ version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d4f449bab7320c56003d37732a917e18798e2f1709d80263face2b4f9436ddb" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "byteorder", "heed-traits", "heed-types", @@ -2288,7 +2288,7 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "anyhow", "bytes", @@ -2574,9 +2574,9 @@ checksum = "d0263a3d970d5c054ed9312c0057b4f3bde9c0b33836d3637361d4a9e6e7a408" [[package]] name = "indexmap" -version = "2.7.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -2618,9 +2618,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.1" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "is-docker" @@ -2784,7 +2784,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "libc", ] @@ -2831,18 +2831,6 @@ dependencies = [ "libc", ] -[[package]] -name = "lnurl-pay" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "536e7c782167a2d48346ca0b2677fad19eaef20f19a4ab868e4d5b96ca879def" -dependencies = [ - "bech32", - "reqwest 0.12.12", - "serde", - "serde_json", -] - [[package]] name = "lock_api" version = "0.4.12" @@ -2855,9 +2843,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" dependencies = [ "serde", "value-bag", @@ -2910,7 +2898,7 @@ dependencies = [ [[package]] name = "media" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "anyhow", "bindgen", @@ -2951,7 +2939,7 @@ version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3572083504c43e14aec05447f8a3d57cce0f66d7a3c1b9058572eca4d70ab9" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block", "core-graphics-types 0.1.3", "foreign-types", @@ -3017,7 +3005,7 @@ checksum = "364f94bc34f61332abebe8cad6f6cd82a5b65cff22c828d05d0968911462ca4f" dependencies = [ "arrayvec", "bit-set", - "bitflags 2.7.0", + "bitflags 2.8.0", "cfg_aliases 0.1.1", "codespan-reporting", "hexf-parse", @@ -3063,7 +3051,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "cfg-if", "cfg_aliases 0.2.1", "libc", @@ -3089,10 +3077,9 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "nostr" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f" +source = "git+https://github.com/rust-nostr/nostr#d030b776f521fc2bb032f9490bab89e3bfbb5108" dependencies = [ "aes", - "async-trait", "base64", "bech32", "bip39", @@ -3118,9 +3105,8 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f" +source = "git+https://github.com/rust-nostr/nostr#d030b776f521fc2bb032f9490bab89e3bfbb5108" dependencies = [ - "async-trait", "flatbuffers", "nostr", "tokio", @@ -3129,7 +3115,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f" +source = "git+https://github.com/rust-nostr/nostr#d030b776f521fc2bb032f9490bab89e3bfbb5108" dependencies = [ "async-utility", "heed", @@ -3141,7 +3127,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f" +source = "git+https://github.com/rust-nostr/nostr#d030b776f521fc2bb032f9490bab89e3bfbb5108" dependencies = [ "async-utility", "async-wsocket", @@ -3157,28 +3143,17 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f" +source = "git+https://github.com/rust-nostr/nostr#d030b776f521fc2bb032f9490bab89e3bfbb5108" dependencies = [ "async-utility", - "lnurl-pay", "nostr", "nostr-database", "nostr-lmdb", "nostr-relay-pool", - "nostr-zapper", "tokio", "tracing", ] -[[package]] -name = "nostr-zapper" -version = "0.38.0" -source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f" -dependencies = [ - "async-trait", - "nostr", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3332,7 +3307,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block2", "libc", "objc2", @@ -3348,7 +3323,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block2", "objc2", "objc2-core-location", @@ -3372,7 +3347,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block2", "objc2", "objc2-foundation", @@ -3414,7 +3389,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block2", "libc", "objc2", @@ -3438,7 +3413,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block2", "objc2", "objc2-foundation", @@ -3450,7 +3425,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block2", "objc2", "objc2-foundation", @@ -3473,7 +3448,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block2", "objc2", "objc2-cloud-kit", @@ -3505,7 +3480,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "block2", "objc2", "objc2-core-location", @@ -4038,7 +4013,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83f35cf4ff1039c849a4d890c6aa4332df47f9def1e9398ef1e5959bc7f89992" dependencies = [ "anyhow", - "bitflags 2.7.0", + "bitflags 2.8.0", "clap", "lazy_static", "log", @@ -4158,7 +4133,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", ] [[package]] @@ -4175,7 +4150,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "derive_refineable", ] @@ -4304,7 +4279,7 @@ dependencies = [ [[package]] name = "reqwest_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "anyhow", "bytes", @@ -4429,7 +4404,7 @@ version = "0.38.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "errno", "libc", "linux-raw-sys", @@ -4503,7 +4478,7 @@ version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfb9cf8877777222e4a3bc7eb247e398b56baba500c38c1c46842431adc8b55c" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "bytemuck", "libm", "smallvec", @@ -4628,7 +4603,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "core-foundation 0.10.0", "core-foundation-sys", "libc", @@ -4654,7 +4629,7 @@ checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe" [[package]] name = "semantic_version" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "anyhow", "serde", @@ -4662,9 +4637,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" +checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" [[package]] name = "serde" @@ -4708,9 +4683,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" +checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" dependencies = [ "indexmap", "itoa", @@ -4909,7 +4884,7 @@ version = "0.3.0+sdk-1.3.268.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eda41003dc44290527a59b13432d4a0379379fa074b70174882adfbdfd917844" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", ] [[package]] @@ -4970,7 +4945,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "arrayvec", "log", @@ -4979,15 +4954,15 @@ dependencies = [ [[package]] name = "sval" -version = "2.13.2" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6dc0f9830c49db20e73273ffae9b5240f63c42e515af1da1fceefb69fceafd8" +checksum = "d4c2f18f53c889ec3dfe1c08b20fd51406d09b14bf18b366416718763ccff05a" [[package]] name = "sval_buffer" -version = "2.13.2" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "429922f7ad43c0ef8fd7309e14d750e38899e32eb7e8da656ea169dd28ee212f" +checksum = "4b8cb1bb48d0bed828b908e6b99e7ab8c7244994dc27948a2e31d42e8c4d77c1" dependencies = [ "sval", "sval_ref", @@ -4995,18 +4970,18 @@ dependencies = [ [[package]] name = "sval_dynamic" -version = "2.13.2" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f16ff5d839396c11a30019b659b0976348f3803db0626f736764c473b50ff4" +checksum = "ba574872d4ad653071a9db76c49656082db83a37cd5f559874273d36b4a02b9d" dependencies = [ "sval", ] [[package]] name = "sval_fmt" -version = "2.13.2" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c01c27a80b6151b0557f9ccbe89c11db571dc5f68113690c1e028d7e974bae94" +checksum = "944450b2dbbf8aae98537776b399b23d72b19243ee42522cfd110305f3c9ba5a" dependencies = [ "itoa", "ryu", @@ -5015,9 +4990,9 @@ dependencies = [ [[package]] name = "sval_json" -version = "2.13.2" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0deef63c70da622b2a8069d8600cf4b05396459e665862e7bdb290fd6cf3f155" +checksum = "411bbd543c413796ccfbaa44f6676e20032b6c69e4996cb6c3e6ef30c79b96d1" dependencies = [ "itoa", "ryu", @@ -5026,9 +5001,9 @@ dependencies = [ [[package]] name = "sval_nested" -version = "2.13.2" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a39ce5976ae1feb814c35d290cf7cf8cd4f045782fe1548d6bc32e21f6156e9f" +checksum = "f30582d2a90869b380f8260559138c1b68ac3e0765520959f22a1a1fdca31769" dependencies = [ "sval", "sval_buffer", @@ -5037,18 +5012,18 @@ dependencies = [ [[package]] name = "sval_ref" -version = "2.13.2" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7c6ee3751795a728bc9316a092023529ffea1783499afbc5c66f5fabebb1fa" +checksum = "762d3fbf3c0869064b7c93808c67ad2ed0292dde9b060ac282817941d4707dff" dependencies = [ "sval", ] [[package]] name = "sval_serde" -version = "2.13.2" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a5572d0321b68109a343634e3a5d576bf131b82180c6c442dee06349dfc652a" +checksum = "752d307438c6a6a3d095a2fecf6950cfb946d301a5bd6b57f047db4f6f8d97b9" dependencies = [ "serde", "sval", @@ -5063,9 +5038,9 @@ checksum = "ce5d813d71d82c4cbc1742135004e4a79fd870214c155443451c139c9470a0aa" [[package]] name = "svgtypes" -version = "0.15.2" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794de53cc48eaabeed0ab6a3404a65f40b3e38c067e4435883a65d2aa4ca000e" +checksum = "68c7541fff44b35860c1a7a47a7cadf3e4a304c457b58f9870d9706ece028afc" dependencies = [ "kurbo", "siphasher", @@ -5148,7 +5123,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "core-foundation 0.9.4", "system-configuration-sys", ] @@ -5792,7 +5767,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da" +source = "git+https://github.com/zed-industries/zed#aacd80ee4a65d490cefee4b6413ece78c5611945" dependencies = [ "anyhow", "async-fs", @@ -5817,9 +5792,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.11.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b913a3b5fe84142e269d63cc62b64319ccaf89b748fc31fe025177f767a756c4" +checksum = "744018581f9a3454a9e15beb8a33b017183f1e7c0cd170232a2d1453b23a51c4" dependencies = [ "getrandom", "serde", @@ -5839,9 +5814,9 @@ dependencies = [ [[package]] name = "valuable" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "value-bag" @@ -6046,7 +6021,7 @@ version = "0.31.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b66249d3fc69f76fd74c82cc319300faa554e9d865dab1f7cd66cc20db10b280" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "rustix", "wayland-backend", "wayland-scanner", @@ -6069,7 +6044,7 @@ version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "wayland-backend", "wayland-client", "wayland-scanner", @@ -6081,7 +6056,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", "wayland-backend", "wayland-client", "wayland-protocols", @@ -6520,7 +6495,7 @@ name = "xim-parser" version = "0.2.1" source = "git+https://github.com/XDeme1/xim-rs?rev=d50d461764c2213655cd9cf65a0ea94c70d3c4fd#d50d461764c2213655cd9cf65a0ea94c70d3c4fd" dependencies = [ - "bitflags 2.7.0", + "bitflags 2.8.0", ] [[package]] diff --git a/crates/app/src/states/chat/mod.rs b/crates/app/src/states/chat/mod.rs index 14fb2b8..d33c6f0 100644 --- a/crates/app/src/states/chat/mod.rs +++ b/crates/app/src/states/chat/mod.rs @@ -156,6 +156,17 @@ impl ChatRegistry { .map(|model| model.downgrade()) } + pub fn new_room(&mut self, room: Room, cx: &mut AppContext) { + let room = cx.new_model(|_| room); + + self.inbox.update(cx, |this, cx| { + if !this.rooms.iter().any(|r| r.read(cx) == room.read(cx)) { + this.rooms.insert(0, room); + cx.notify(); + } + }) + } + pub fn receive(&mut self, event: Event, cx: &mut AppContext) { let mut pubkeys: Vec<_> = event.tags.public_keys().copied().collect(); pubkeys.push(event.pubkey); diff --git a/crates/app/src/states/chat/room.rs b/crates/app/src/states/chat/room.rs index f2715e8..72769dd 100644 --- a/crates/app/src/states/chat/room.rs +++ b/crates/app/src/states/chat/room.rs @@ -1,10 +1,9 @@ use crate::{ constants::IMAGE_SERVICE, - utils::{room_hash, shorted_public_key}, + utils::{compare, random_name, room_hash, shorted_public_key}, }; use gpui::SharedString; use nostr_sdk::prelude::*; -use rnglib::{Language, RNG}; #[derive(Debug, Clone)] pub struct Member { @@ -67,6 +66,18 @@ pub struct Room { pub new_messages: Vec, // Hold all new messages } +impl PartialEq for Room { + fn eq(&self, other: &Self) -> bool { + let mut pubkeys: Vec = self.members.iter().map(|m| m.public_key()).collect(); + pubkeys.push(self.owner.public_key()); + + let mut pubkeys2: Vec = other.members.iter().map(|m| m.public_key()).collect(); + pubkeys2.push(other.owner.public_key()); + + compare(&pubkeys, &pubkeys2) + } +} + impl Room { pub fn new( id: u64, @@ -76,6 +87,11 @@ impl Room { last_seen: Timestamp, ) -> Self { let is_group = members.len() > 1; + let title = if title.is_none() { + Some(random_name(2).into()) + } else { + title + }; Self { id, @@ -103,10 +119,7 @@ impl Room { let title = if let Some(tag) = event.tags.find(TagKind::Title) { tag.content().map(|s| s.to_owned().into()) } else { - let rng = RNG::from(&Language::Roman); - let name = rng.generate_names(2, true).join("-").to_lowercase(); - - Some(name.into()) + None }; Self::new(id, owner, members, title, last_seen) @@ -136,11 +149,23 @@ impl Room { } pub fn name(&self) -> String { - self.members - .iter() - .map(|profile| profile.name()) - .collect::>() - .join(", ") + if self.members.len() <= 2 { + self.members + .iter() + .map(|profile| profile.name()) + .collect::>() + .join(", ") + } else { + let name = self + .members + .iter() + .take(2) + .map(|profile| profile.name()) + .collect::>() + .join(", "); + + format!("{}, +{}", name, self.members.len() - 2) + } } pub fn get_all_keys(&self) -> Vec { diff --git a/crates/app/src/utils.rs b/crates/app/src/utils.rs index 39f55b1..e2a0d86 100644 --- a/crates/app/src/utils.rs +++ b/crates/app/src/utils.rs @@ -1,6 +1,7 @@ use crate::{constants::NIP96_SERVER, get_client}; use chrono::{Datelike, Local, TimeZone}; use nostr_sdk::prelude::*; +use rnglib::{Language, RNG}; use std::{ collections::HashSet, hash::{DefaultHasher, Hash, Hasher}, @@ -26,6 +27,11 @@ pub fn room_hash(tags: &Tags) -> u64 { hasher.finish() } +pub fn random_name(length: usize) -> String { + let rng = RNG::from(&Language::Roman); + rng.generate_names(length, true).join("-").to_lowercase() +} + pub fn compare(a: &[T], b: &[T]) -> bool where T: Eq + Hash, diff --git a/crates/app/src/views/sidebar/compose.rs b/crates/app/src/views/sidebar/compose.rs index 914f935..e241740 100644 --- a/crates/app/src/views/sidebar/compose.rs +++ b/crates/app/src/views/sidebar/compose.rs @@ -1,8 +1,15 @@ -use crate::{get_client, states::chat::room::Member}; +use crate::{ + get_client, + states::{ + app::AppRegistry, + chat::room::{Member, Room}, + }, + utils::{random_name, room_hash}, +}; use gpui::{ div, img, impl_internal_actions, px, uniform_list, Context, FocusHandle, InteractiveElement, - IntoElement, Model, ParentElement, Render, StatefulInteractiveElement, Styled, View, - ViewContext, VisualContext, WindowContext, + IntoElement, Model, ParentElement, Render, SharedString, StatefulInteractiveElement, Styled, + View, ViewContext, VisualContext, WindowContext, }; use nostr_sdk::prelude::*; use serde::Deserialize; @@ -44,17 +51,19 @@ impl Compose { }); let title_input = cx.new_view(|cx| { - TextInput::new(cx) - .appearance(false) - .text_size(Size::XSmall) - .placeholder("Family...") + let name = random_name(2); + let mut input = TextInput::new(cx).appearance(false).text_size(Size::XSmall); + + input.set_placeholder("Family... . (Optional)"); + input.set_text(name, cx); + input }); let message_input = cx.new_view(|cx| { TextInput::new(cx) .appearance(false) .text_size(Size::XSmall) - .placeholder("Hello...") + .placeholder("Hello... (Optional)") }); cx.subscribe(&user_input, move |this, _, input_event, cx| { @@ -110,8 +119,51 @@ impl Compose { } } - pub fn selected<'a>(&self, cx: &'a WindowContext) -> Vec<&'a PublicKey> { - self.selected.read(cx).iter().collect() + pub fn room(&self, cx: &WindowContext) -> Option { + let weak_user = cx.global::().current_user(); + + if let Some(user) = weak_user.upgrade() { + let public_key = user.read(cx).unwrap(); + + // Convert selected pubkeys into nostr tags + let tags: Vec = self + .selected + .read(cx) + .iter() + .map(|pk| Tag::public_key(*pk)) + .collect(); + let tags = Tags::new(tags); + + // Convert selected pubkeys into members + let members: Vec = self + .selected + .read(cx) + .clone() + .into_iter() + .map(|pk| Member::new(pk, Metadata::new())) + .collect(); + + // Get room's id + let id = room_hash(&tags); + + // Get room's owner (current user) + let owner = Member::new(public_key, Metadata::new()); + + // Get room's title + let title = self.title_input.read(cx).text().to_string().into(); + + Some(Room::new(id, owner, members, Some(title), Timestamp::now())) + } else { + None + } + } + + pub fn label(&self, cx: &WindowContext) -> SharedString { + if self.selected.read(cx).len() > 1 { + "Create Group DM".into() + } else { + "Create DM".into() + } } fn add(&mut self, cx: &mut ViewContext) { diff --git a/crates/app/src/views/sidebar/inbox.rs b/crates/app/src/views/sidebar/inbox.rs index 1ea0dd3..e5c75c6 100644 --- a/crates/app/src/views/sidebar/inbox.rs +++ b/crates/app/src/views/sidebar/inbox.rs @@ -22,7 +22,7 @@ pub struct Inbox { impl Inbox { pub fn new(_cx: &mut ViewContext<'_, Self>) -> Self { Self { - label: "Direct Messages".into(), + label: "Inbox".into(), is_collapsed: false, } } @@ -138,11 +138,6 @@ impl Render for Inbox { .rounded(px(cx.theme().radius)) .text_xs() .font_semibold() - .hover(|this| this.bg(cx.theme().base.step(cx, ColorScaleStep::THREE))) - .on_click(cx.listener(move |view, _event, cx| { - view.is_collapsed = !view.is_collapsed; - cx.notify(); - })) .child( Icon::new(IconName::ChevronDown) .size_6() @@ -150,7 +145,12 @@ impl Render for Inbox { this.rotate(percentage(270. / 360.)) }), ) - .child(self.label.clone()), + .child(self.label.clone()) + .hover(|this| this.bg(cx.theme().base.step(cx, ColorScaleStep::THREE))) + .on_click(cx.listener(move |view, _event, cx| { + view.is_collapsed = !view.is_collapsed; + cx.notify(); + })), ) .when(!self.is_collapsed, |this| this.child(self.render_item(cx))) } diff --git a/crates/app/src/views/sidebar/mod.rs b/crates/app/src/views/sidebar/mod.rs index 8f27cc9..c783afb 100644 --- a/crates/app/src/views/sidebar/mod.rs +++ b/crates/app/src/views/sidebar/mod.rs @@ -1,9 +1,9 @@ -use crate::views::sidebar::inbox::Inbox; +use crate::{states::chat::ChatRegistry, views::sidebar::inbox::Inbox}; use compose::Compose; use gpui::{ - div, px, AnyElement, AppContext, Entity, EntityId, EventEmitter, FocusHandle, FocusableView, - IntoElement, ParentElement, Render, SharedString, Styled, View, ViewContext, VisualContext, - WindowContext, + div, px, AnyElement, AppContext, BorrowAppContext, Entity, EntityId, EventEmitter, FocusHandle, + FocusableView, InteractiveElement, IntoElement, ParentElement, Render, SharedString, + StatefulInteractiveElement, Styled, View, ViewContext, VisualContext, WindowContext, }; use ui::{ button::{Button, ButtonRounded, ButtonVariants}, @@ -53,12 +53,7 @@ impl Sidebar { let compose = cx.new_view(Compose::new); cx.open_modal(move |modal, cx| { - let selected = compose.model.read(cx).selected(cx); - let label = if selected.len() > 1 { - "Create Group DM" - } else { - "Create DM" - }; + let label = compose.read(cx).label(cx); modal .title("Direct Messages") @@ -75,7 +70,16 @@ impl Sidebar { .primary() .bold() .rounded(ButtonRounded::Large) - .w_full(), + .w_full() + .on_click(cx.listener_for(&compose, |this, _, cx| { + if let Some(room) = this.room(cx) { + cx.update_global::(|this, cx| { + this.new_room(room, cx); + }); + + cx.close_modal(); + } + })), ), ) }) @@ -127,13 +131,33 @@ impl Render for Sidebar { .py_3() .gap_3() .child( - v_flex().px_2().gap_0p5().child( - Button::new("compose") - .small() - .ghost() - .not_centered() - .icon(Icon::new(IconName::ComposeFill)) - .label("Compose") + v_flex().px_2().gap_1().child( + div() + .id("new") + .flex() + .items_center() + .gap_2() + .px_1() + .h_7() + .text_xs() + .font_semibold() + .rounded(px(cx.theme().radius)) + .child( + div() + .size_6() + .flex() + .items_center() + .justify_center() + .rounded_full() + .bg(cx.theme().accent.step(cx, ColorScaleStep::NINE)) + .child( + Icon::new(IconName::ComposeFill) + .small() + .text_color(cx.theme().base.darken(cx)), + ), + ) + .child("New Message") + .hover(|this| this.bg(cx.theme().base.step(cx, ColorScaleStep::THREE))) .on_click(cx.listener(|this, _, cx| this.show_compose(cx))), ), )