78
Cargo.lock
generated
78
Cargo.lock
generated
@@ -87,9 +87,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.99"
|
version = "1.0.100"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
|
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arbitrary"
|
name = "arbitrary"
|
||||||
@@ -912,9 +912,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.37"
|
version = "1.2.38"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "65193589c6404eb80b450d618eaf9a2cafaaafd57ecce47370519ef674a7bd44"
|
checksum = "80f41ae168f955c12fb8960b057d70d0ca153fb83182b57d86380443527be7e9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"find-msvc-tools",
|
"find-msvc-tools",
|
||||||
"jobserver",
|
"jobserver",
|
||||||
@@ -1131,7 +1131,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "collections"
|
name = "collections"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"rustc-hash 2.1.1",
|
"rustc-hash 2.1.1",
|
||||||
@@ -1572,7 +1572,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#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -1739,9 +1739,9 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embed-resource"
|
name = "embed-resource"
|
||||||
version = "3.0.5"
|
version = "3.0.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4c6d81016d6c977deefb2ef8d8290da019e27cc26167e102185da528e6c0ab38"
|
checksum = "55a075fc573c64510038d7ee9abc7990635863992f83ebc52c8b433b8411a02e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -1976,9 +1976,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "find-msvc-tools"
|
name = "find-msvc-tools"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
|
checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flatbuffers"
|
name = "flatbuffers"
|
||||||
@@ -2499,7 +2499,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "gpui"
|
name = "gpui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"as-raw-xcb-connection",
|
"as-raw-xcb-connection",
|
||||||
@@ -2571,6 +2571,7 @@ dependencies = [
|
|||||||
"thiserror 2.0.16",
|
"thiserror 2.0.16",
|
||||||
"usvg",
|
"usvg",
|
||||||
"util",
|
"util",
|
||||||
|
"util_macros",
|
||||||
"uuid",
|
"uuid",
|
||||||
"waker-fn",
|
"waker-fn",
|
||||||
"wayland-backend",
|
"wayland-backend",
|
||||||
@@ -2592,7 +2593,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#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.5.0",
|
"heck 0.5.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -2604,7 +2605,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#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"gpui",
|
"gpui",
|
||||||
@@ -2824,7 +2825,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#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -2844,7 +2845,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#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustls",
|
"rustls",
|
||||||
"rustls-platform-verifier",
|
"rustls-platform-verifier",
|
||||||
@@ -3636,7 +3637,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "media"
|
name = "media"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bindgen 0.71.1",
|
"bindgen 0.71.1",
|
||||||
@@ -4751,9 +4752,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pxfm"
|
name = "pxfm"
|
||||||
version = "0.1.23"
|
version = "0.1.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f55f4fedc84ed39cb7a489322318976425e42a147e2be79d8f878e2884f94e84"
|
checksum = "83f9b339b02259ada5c0f4a389b7fb472f933aa17ce176fd2ad98f28bb401fde"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
@@ -5076,7 +5077,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "refineable"
|
name = "refineable"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_refineable",
|
"derive_refineable",
|
||||||
"workspace-hack",
|
"workspace-hack",
|
||||||
@@ -5230,7 +5231,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#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -5442,9 +5443,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls"
|
name = "rustls"
|
||||||
version = "0.23.31"
|
version = "0.23.32"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0ebcbd2f03de0fc1122ad9bb24b127a5a6cd51d72604a3f3c50ac459762b6cc"
|
checksum = "cd3c25631629d034ce7cd9940adc9d45762d46de2b0f57193c4443b92c6d4d40"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-lc-rs",
|
"aws-lc-rs",
|
||||||
"log",
|
"log",
|
||||||
@@ -5765,7 +5766,7 @@ checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "semantic_version"
|
name = "semantic_version"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -5780,9 +5781,9 @@ checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.225"
|
version = "1.0.226"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fd6c24dee235d0da097043389623fb913daddf92c76e9f5a1db88607a0bcbd1d"
|
checksum = "0dca6411025b24b60bfa7ec1fe1f8e710ac09782dca409ee8237ba74b51295fd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
@@ -5790,18 +5791,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_core"
|
name = "serde_core"
|
||||||
version = "1.0.225"
|
version = "1.0.226"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "659356f9a0cb1e529b24c01e43ad2bdf520ec4ceaf83047b83ddcc2251f96383"
|
checksum = "ba2ba63999edb9dac981fb34b3e5c0d111a69b0924e253ed29d83f7c99e966a4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.225"
|
version = "1.0.226"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ea936adf78b1f766949a4977b91d2f5595825bd6ec079aa9543ad2685fc4516"
|
checksum = "8db53ae22f34573731bafa1db20f04027b2d25e02d8205921b569171699cdb33"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -6217,7 +6218,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#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"log",
|
"log",
|
||||||
@@ -6592,11 +6593,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.3.43"
|
version = "0.3.44"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031"
|
checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"deranged",
|
"deranged",
|
||||||
|
"itoa",
|
||||||
"num-conv",
|
"num-conv",
|
||||||
"powerfmt",
|
"powerfmt",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -7259,7 +7261,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "util"
|
name = "util"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#e5e308ba78c3de679b822e50a07b3432a1624ce1"
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-fs",
|
"async-fs",
|
||||||
@@ -7291,6 +7293,16 @@ dependencies = [
|
|||||||
"workspace-hack",
|
"workspace-hack",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "util_macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/zed-industries/zed#839c216620af116459e2ba15e82f3df8c3597349"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.106",
|
||||||
|
"workspace-hack",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.18.1"
|
version = "1.18.1"
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
|
||||||
use common::display::{ReadableProfile, ReadableTimestamp};
|
use common::display::{ReadableProfile, ReadableTimestamp};
|
||||||
use common::nip96::nip96_upload;
|
use common::nip96::nip96_upload;
|
||||||
use global::{app_state, nostr_client};
|
use global::{app_state, nostr_client};
|
||||||
@@ -31,6 +30,7 @@ use ui::dock_area::panel::{Panel, PanelEvent};
|
|||||||
use ui::emoji_picker::EmojiPicker;
|
use ui::emoji_picker::EmojiPicker;
|
||||||
use ui::input::{InputEvent, InputState, TextInput};
|
use ui::input::{InputEvent, InputState, TextInput};
|
||||||
use ui::modal::ModalButtonProps;
|
use ui::modal::ModalButtonProps;
|
||||||
|
use ui::notification::Notification;
|
||||||
use ui::popup_menu::{PopupMenu, PopupMenuExt};
|
use ui::popup_menu::{PopupMenu, PopupMenuExt};
|
||||||
use ui::text::RenderedText;
|
use ui::text::RenderedText;
|
||||||
use ui::{
|
use ui::{
|
||||||
@@ -215,7 +215,6 @@ impl Chat {
|
|||||||
id: room.read(cx).id.to_string().into(),
|
id: room.read(cx).id.to_string().into(),
|
||||||
image_cache: RetainAllImageCache::new(cx),
|
image_cache: RetainAllImageCache::new(cx),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
uploading: false,
|
|
||||||
rendered_texts_by_id: BTreeMap::new(),
|
rendered_texts_by_id: BTreeMap::new(),
|
||||||
reports_by_id: BTreeMap::new(),
|
reports_by_id: BTreeMap::new(),
|
||||||
relays,
|
relays,
|
||||||
@@ -225,6 +224,7 @@ impl Chat {
|
|||||||
input,
|
input,
|
||||||
replies_to,
|
replies_to,
|
||||||
attachments,
|
attachments,
|
||||||
|
uploading: false,
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
_tasks: tasks,
|
_tasks: tasks,
|
||||||
}
|
}
|
||||||
@@ -282,15 +282,17 @@ impl Chat {
|
|||||||
let attachments = self.attachments.read(cx);
|
let attachments = self.attachments.read(cx);
|
||||||
|
|
||||||
if !attachments.is_empty() {
|
if !attachments.is_empty() {
|
||||||
content = format!(
|
let urls = attachments
|
||||||
"{}\n{}",
|
|
||||||
content,
|
|
||||||
attachments
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|url| url.to_string())
|
.map(|url| url.to_string())
|
||||||
.collect_vec()
|
.collect_vec()
|
||||||
.join("\n")
|
.join("\n");
|
||||||
)
|
|
||||||
|
if content.is_empty() {
|
||||||
|
content = urls;
|
||||||
|
} else {
|
||||||
|
content = format!("{content}\n{urls}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content
|
content
|
||||||
@@ -342,6 +344,9 @@ impl Chat {
|
|||||||
// Remove all replies
|
// Remove all replies
|
||||||
this.remove_all_replies(cx);
|
this.remove_all_replies(cx);
|
||||||
|
|
||||||
|
// remove all attachments
|
||||||
|
this.remove_all_attachments(cx);
|
||||||
|
|
||||||
// Reset the input state
|
// Reset the input state
|
||||||
this.input.update(cx, |this, cx| {
|
this.input.update(cx, |this, cx| {
|
||||||
this.set_loading(false, cx);
|
this.set_loading(false, cx);
|
||||||
@@ -533,73 +538,74 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn upload(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn upload(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if self.uploading {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Block the upload button to until current task is resolved
|
|
||||||
self.uploading(true, cx);
|
|
||||||
|
|
||||||
// Get the user's configured NIP96 server
|
// Get the user's configured NIP96 server
|
||||||
let nip96_server = AppSettings::get_media_server(cx);
|
let nip96_server = AppSettings::get_media_server(cx);
|
||||||
|
|
||||||
// Open native file dialog
|
let path = cx.prompt_for_paths(PathPromptOptions {
|
||||||
let paths = cx.prompt_for_paths(PathPromptOptions {
|
|
||||||
files: true,
|
files: true,
|
||||||
directories: false,
|
directories: false,
|
||||||
multiple: false,
|
multiple: false,
|
||||||
prompt: None,
|
prompt: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
let task = Tokio::spawn(cx, async move {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
match Flatten::flatten(paths.await.map_err(|e| e.into())) {
|
let mut paths = path.await.ok()?.ok()??;
|
||||||
Ok(Some(mut paths)) => {
|
let path = paths.pop()?;
|
||||||
if let Some(path) = paths.pop() {
|
|
||||||
let file = fs::read(path).await?;
|
|
||||||
let url = nip96_upload(nostr_client(), &nip96_server, file).await?;
|
|
||||||
|
|
||||||
Ok(url)
|
let upload = Tokio::spawn(cx, async move {
|
||||||
} else {
|
let client = nostr_client();
|
||||||
Err(anyhow!("Path not found"))
|
let file = fs::read(path).await.ok()?;
|
||||||
}
|
let url = nip96_upload(client, &nip96_server, file).await.ok()?;
|
||||||
}
|
|
||||||
Ok(None) => Err(anyhow!("User cancelled")),
|
Some(url)
|
||||||
Err(e) => Err(anyhow!("File dialog error: {e}")),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
if let Ok(task) = upload {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.set_uploading(true, cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
match Flatten::flatten(task.await.map_err(|e| e.into())) {
|
match Flatten::flatten(task.await.map_err(|e| e.into())) {
|
||||||
Ok(Ok(url)) => {
|
Ok(Some(url)) => {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.add_attachment(url, cx);
|
this.add_attachment(url, cx);
|
||||||
|
this.set_uploading(false, cx);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
Ok(Err(e)) => {
|
Ok(None) => {
|
||||||
log::warn!("User cancelled: {e}");
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
window.push_notification("Failed to upload file", cx);
|
||||||
this.uploading(false, cx);
|
this.set_uploading(false, cx);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
this.update_in(cx, |this, window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
window.push_notification(e.to_string(), cx);
|
window.push_notification(Notification::error(e.to_string()), cx);
|
||||||
this.uploading(false, cx);
|
this.set_uploading(false, cx);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(())
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_uploading(&mut self, uploading: bool, cx: &mut Context<Self>) {
|
||||||
|
self.uploading = uploading;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
fn add_attachment(&mut self, url: Url, cx: &mut Context<Self>) {
|
fn add_attachment(&mut self, url: Url, cx: &mut Context<Self>) {
|
||||||
self.attachments.update(cx, |this, cx| {
|
self.attachments.update(cx, |this, cx| {
|
||||||
this.push(url);
|
this.push(url);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
self.uploading(false, cx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_attachment(&mut self, url: &Url, _window: &mut Window, cx: &mut Context<Self>) {
|
fn remove_attachment(&mut self, url: &Url, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
@@ -611,9 +617,11 @@ impl Chat {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uploading(&mut self, status: bool, cx: &mut Context<Self>) {
|
fn remove_all_attachments(&mut self, cx: &mut Context<Self>) {
|
||||||
self.uploading = status;
|
self.attachments.update(cx, |this, cx| {
|
||||||
|
this.clear();
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_announcement(&mut self, ix: usize, cx: &mut Context<Self>) -> AnyElement {
|
fn render_announcement(&mut self, ix: usize, cx: &mut Context<Self>) -> AnyElement {
|
||||||
@@ -1418,10 +1426,10 @@ impl Render for Chat {
|
|||||||
.child(
|
.child(
|
||||||
Button::new("upload")
|
Button::new("upload")
|
||||||
.icon(IconName::Upload)
|
.icon(IconName::Upload)
|
||||||
|
.loading(self.uploading)
|
||||||
|
.disabled(self.uploading)
|
||||||
.ghost()
|
.ghost()
|
||||||
.large()
|
.large()
|
||||||
.disabled(self.uploading)
|
|
||||||
.loading(self.uploading)
|
|
||||||
.on_click(cx.listener(
|
.on_click(cx.listener(
|
||||||
move |this, _, window, cx| {
|
move |this, _, window, cx| {
|
||||||
this.upload(window, cx);
|
this.upload(window, cx);
|
||||||
|
|||||||
Reference in New Issue
Block a user