Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df82861101 | ||
|
|
fc99ef4dfe | ||
|
|
d0f7a1abd3 | ||
|
|
71140beb52 | ||
|
|
e177facef4 | ||
|
|
60bca49200 | ||
|
|
ede41c41c3 | ||
|
|
70e235dcc2 | ||
|
|
b11b0e0115 | ||
|
|
d8edac0bb9 | ||
|
|
d392602ed6 | ||
|
|
5a36354cc8 |
@@ -4,7 +4,7 @@ members = ["crates/*"]
|
|||||||
default-members = ["crates/coop"]
|
default-members = ["crates/coop"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ itertools = "0.13.0"
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
oneshot = "0.1.10"
|
oneshot = "0.1.10"
|
||||||
reqwest = { version = "0.12", features = ["multipart", "stream", "json"] }
|
reqwest = { version = "0.12", features = ["multipart", "stream", "json"] }
|
||||||
|
flume = { version = "0.11.1", default-features = false, features = ["async", "select"] }
|
||||||
rust-embed = "8.5.0"
|
rust-embed = "8.5.0"
|
||||||
rust-i18n = "3"
|
rust-i18n = "3"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
|
||||||
<path fill="currentColor" fill-rule="evenodd" d="M2 12C2 6.477 6.477 2 12 2s10 4.477 10 10-4.477 10-10 10S2 17.523 2 12Zm6.22-1.53 3.25-3.25a.75.75 0 0 1 1.06 0l3.25 3.25a.75.75 0 1 1-1.06 1.06l-1.97-1.97v6.69a.75.75 0 0 1-1.5 0V9.56l-1.97 1.97a.75.75 0 0 1-1.06-1.06Z" clip-rule="evenodd"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 397 B |
@@ -1,4 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
|
||||||
<path fill="currentColor" d="M4 4.75A2.75 2.75 0 0 1 6.75 2h10.5A2.75 2.75 0 0 1 20 4.75v7.917a3.9 3.9 0 0 0-4.091.909l-3.75 3.75a2.25 2.25 0 0 0-.659 1.59v2.334c0 .263.045.515.128.75H6.75A2.75 2.75 0 0 1 4 19.25V4.75Z"/>
|
|
||||||
<path fill="currentColor" fill-rule="evenodd" d="M19.303 15.697a.9.9 0 0 0-1.273 0l-3.53 3.53V20.5h1.273l3.53-3.53a.9.9 0 0 0 0-1.273Zm-2.333-1.06a2.4 2.4 0 1 1 3.394 3.393l-3.75 3.75a.75.75 0 0 1-.53.22H13.75a.75.75 0 0 1-.75-.75v-2.333a.75.75 0 0 1 .22-.53l3.75-3.75Z" clip-rule="evenodd"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 622 B |
@@ -1,3 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
|
||||||
<path stroke="currentColor" stroke-linejoin="round" stroke-width="1.5" d="m21.76 11.45-8.146-7.535a.75.75 0 0 0-1.26.55V8a.51.51 0 0 1-.504.504C3.765 8.632 1.604 11.92 1.604 20.25c1.47-2.94 2.22-4.679 10.245-4.748a.501.501 0 0 1 .505.498v3.535a.75.75 0 0 0 1.26.55l8.145-7.535a.75.75 0 0 0 0-1.1Z"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 405 B |
@@ -1,3 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
|
||||||
<path fill="currentColor" d="M3 11a8 8 0 1 1 14.162 5.102l3.368 3.368a.75.75 0 1 1-1.06 1.06l-3.368-3.368A8 8 0 0 1 3 11Z"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 230 B |
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||||
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 17v2m6-6v6m6-10v10m6-14v14"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 233 B |
@@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 256 256"><path d="M64.12,147.8a4,4,0,0,1-4,4.2H16a8,8,0,0,1-7.8-6.17,8.35,8.35,0,0,1,1.62-6.93A67.79,67.79,0,0,1,37,117.51a40,40,0,1,1,66.46-35.8,3.94,3.94,0,0,1-2.27,4.18A64.08,64.08,0,0,0,64,144C64,145.28,64,146.54,64.12,147.8Zm182-8.91A67.76,67.76,0,0,0,219,117.51a40,40,0,1,0-66.46-35.8,3.94,3.94,0,0,0,2.27,4.18A64.08,64.08,0,0,1,192,144c0,1.28,0,2.54-.12,3.8a4,4,0,0,0,4,4.2H240a8,8,0,0,0,7.8-6.17A8.33,8.33,0,0,0,246.17,138.89Zm-89,43.18a48,48,0,1,0-58.37,0A72.13,72.13,0,0,0,65.07,212,8,8,0,0,0,72,224H184a8,8,0,0,0,6.93-12A72.15,72.15,0,0,0,157.19,182.07Z"></path></svg>
|
|
||||||
|
Before Width: | Height: | Size: 676 B |
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||||
|
<path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M12 9.02v2.993M12 15h.01M10.277 3.99 3.275 15.998C2.499 17.328 3.458 19 4.998 19h14.004c1.54 0 2.5-1.671 1.723-3.002L13.723 3.99c-.77-1.32-2.677-1.32-3.447 0ZM12.25 15a.25.25 0 1 1-.5 0 .25.25 0 0 1 .5 0Z"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 384 B |
@@ -108,12 +108,9 @@ impl AutoUpdater {
|
|||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
if let Ok(Some(update)) = checking.await {
|
if let Ok(Some(update)) = checking.await {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
this.set_status(AutoUpdateStatus::checked(update), cx);
|
||||||
this.set_status(AutoUpdateStatus::checked(update), cx);
|
this.install_update(window, cx);
|
||||||
this.install_update(window, cx);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ product-name = "Coop"
|
|||||||
description = "Chat Freely, Stay Private on Nostr"
|
description = "Chat Freely, Stay Private on Nostr"
|
||||||
identifier = "su.reya.coop"
|
identifier = "su.reya.coop"
|
||||||
category = "SocialNetworking"
|
category = "SocialNetworking"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
out-dir = "../../dist"
|
out-dir = "../../dist"
|
||||||
before-packaging-command = "cargo build --release"
|
before-packaging-command = "cargo build --release"
|
||||||
resources = ["Cargo.toml", "src"]
|
resources = ["Cargo.toml", "src"]
|
||||||
@@ -59,6 +59,8 @@ smallvec.workspace = true
|
|||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
oneshot.workspace = true
|
oneshot.workspace = true
|
||||||
|
flume.workspace = true
|
||||||
webbrowser.workspace = true
|
webbrowser.workspace = true
|
||||||
|
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
|
tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
|
||||||
|
indexset = "0.12.3"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::sync::Mutex;
|
|||||||
use gpui::{actions, App};
|
use gpui::{actions, App};
|
||||||
|
|
||||||
actions!(coop, [DarkMode, Settings, Logout, Quit]);
|
actions!(coop, [DarkMode, Settings, Logout, Quit]);
|
||||||
|
actions!(sidebar, [Reload, RelayStatus]);
|
||||||
|
|
||||||
pub fn load_embedded_fonts(cx: &App) {
|
pub fn load_embedded_fonts(cx: &App) {
|
||||||
let asset_source = cx.asset_source();
|
let asset_source = cx.asset_source();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use assets::Assets;
|
use assets::Assets;
|
||||||
use global::constants::{APP_ID, APP_NAME};
|
use global::constants::{APP_ID, APP_NAME};
|
||||||
use global::{ingester, nostr_client, sent_ids, starting_time};
|
use global::{css, ingester, nostr_client};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
point, px, size, AppContext, Application, Bounds, KeyBinding, Menu, MenuItem, SharedString,
|
point, px, size, AppContext, Application, Bounds, KeyBinding, Menu, MenuItem, SharedString,
|
||||||
TitlebarOptions, WindowBackgroundAppearance, WindowBounds, WindowDecorations, WindowKind,
|
TitlebarOptions, WindowBackgroundAppearance, WindowBounds, WindowDecorations, WindowKind,
|
||||||
@@ -29,11 +29,8 @@ fn main() {
|
|||||||
// Initialize the ingester
|
// Initialize the ingester
|
||||||
let _ingester = ingester();
|
let _ingester = ingester();
|
||||||
|
|
||||||
// Initialize the starting time
|
// Initialize the coop simple storage
|
||||||
let _starting_time = starting_time();
|
let _css = css();
|
||||||
|
|
||||||
// Initialize the sent IDs storage
|
|
||||||
let _sent_ids = sent_ids();
|
|
||||||
|
|
||||||
// Initialize the Application
|
// Initialize the Application
|
||||||
let app = Application::new()
|
let app = Application::new()
|
||||||
@@ -82,6 +79,9 @@ fn main() {
|
|||||||
|
|
||||||
// Open a window with default options
|
// Open a window with default options
|
||||||
cx.open_window(opts, |window, cx| {
|
cx.open_window(opts, |window, cx| {
|
||||||
|
// Bring the app to the foreground
|
||||||
|
cx.activate(true);
|
||||||
|
|
||||||
// Automatically sync theme with system appearance
|
// Automatically sync theme with system appearance
|
||||||
window
|
window
|
||||||
.observe_window_appearance(|window, cx| {
|
.observe_window_appearance(|window, cx| {
|
||||||
@@ -91,7 +91,6 @@ fn main() {
|
|||||||
|
|
||||||
// Root Entity
|
// Root Entity
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
cx.activate(true);
|
|
||||||
// Initialize the tokio runtime
|
// Initialize the tokio runtime
|
||||||
gpui_tokio::init(cx);
|
gpui_tokio::init(cx);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use client_keys::ClientKeys;
|
|||||||
use common::display::ReadableProfile;
|
use common::display::ReadableProfile;
|
||||||
use common::handle_auth::CoopAuthUrlHandler;
|
use common::handle_auth::CoopAuthUrlHandler;
|
||||||
use global::constants::{ACCOUNT_IDENTIFIER, BUNKER_TIMEOUT};
|
use global::constants::{ACCOUNT_IDENTIFIER, BUNKER_TIMEOUT};
|
||||||
use global::{ingester, nostr_client, IngesterSignal};
|
use global::{ingester, nostr_client, Signal};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, relative, rems, svg, AnyElement, App, AppContext, Context, Entity, EventEmitter,
|
div, relative, rems, svg, AnyElement, App, AppContext, Context, Entity, EventEmitter,
|
||||||
@@ -15,6 +15,7 @@ use gpui::{
|
|||||||
use i18n::{shared_t, t};
|
use i18n::{shared_t, t};
|
||||||
use nostr_connect::prelude::*;
|
use nostr_connect::prelude::*;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
@@ -44,6 +45,7 @@ pub struct Account {
|
|||||||
// Panel
|
// Panel
|
||||||
name: SharedString,
|
name: SharedString,
|
||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
|
_tasks: SmallVec<[Task<()>; 1]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
@@ -59,6 +61,7 @@ impl Account {
|
|||||||
loading: false,
|
loading: false,
|
||||||
name: "Account".into(),
|
name: "Account".into(),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
|
_tasks: smallvec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,24 +92,25 @@ impl Account {
|
|||||||
// Handle auth url with the default browser
|
// Handle auth url with the default browser
|
||||||
signer.auth_url_handler(CoopAuthUrlHandler);
|
signer.auth_url_handler(CoopAuthUrlHandler);
|
||||||
|
|
||||||
// Handle connection
|
self._tasks.push(
|
||||||
cx.spawn_in(window, async move |_this, cx| {
|
// Handle connection
|
||||||
let client = nostr_client();
|
cx.spawn_in(window, async move |_this, cx| {
|
||||||
|
let client = nostr_client();
|
||||||
|
|
||||||
match signer.bunker_uri().await {
|
match signer.bunker_uri().await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Set the client's signer with the current nostr connect instance
|
// Set the client's signer with the current nostr connect instance
|
||||||
client.set_signer(signer).await;
|
client.set_signer(signer).await;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
cx.update(|window, cx| {
|
||||||
|
window.push_notification(e.to_string(), cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
}),
|
||||||
cx.update(|window, cx| {
|
);
|
||||||
window.push_notification(e.to_string(), cx);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_proxy(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn set_proxy(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
@@ -240,24 +244,26 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn logout(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
fn logout(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
cx.background_spawn(async move {
|
self._tasks.push(
|
||||||
let client = nostr_client();
|
// Reset the nostr client in the background
|
||||||
let ingester = ingester();
|
cx.background_spawn(async move {
|
||||||
|
let client = nostr_client();
|
||||||
|
let ingester = ingester();
|
||||||
|
|
||||||
let filter = Filter::new()
|
let filter = Filter::new()
|
||||||
.kind(Kind::ApplicationSpecificData)
|
.kind(Kind::ApplicationSpecificData)
|
||||||
.identifier(ACCOUNT_IDENTIFIER);
|
.identifier(ACCOUNT_IDENTIFIER);
|
||||||
|
|
||||||
// Delete account
|
// Delete account
|
||||||
client.database().delete(filter).await.ok();
|
client.database().delete(filter).await.ok();
|
||||||
|
|
||||||
// Unset the client's signer
|
// Unset the client's signer
|
||||||
client.unset_signer().await;
|
client.unset_signer().await;
|
||||||
|
|
||||||
// Notify the channel about the signer being unset
|
// Notify the channel about the signer being unset
|
||||||
ingester.send(IngesterSignal::SignerUnset).await;
|
ingester.send(Signal::SignerUnset).await;
|
||||||
})
|
}),
|
||||||
.detach();
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_loading(&mut self, status: bool, cx: &mut Context<Self>) {
|
fn set_loading(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
|
|
||||||
use anyhow::anyhow;
|
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::{nostr_client, sent_ids};
|
use global::{css, nostr_client};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, img, list, px, red, relative, rems, svg, white, Action, AnyElement, App, AppContext,
|
div, img, list, px, red, relative, rems, svg, white, Action, AnyElement, App, AppContext,
|
||||||
ClipboardItem, Context, Element, Entity, EventEmitter, Flatten, FocusHandle, Focusable,
|
ClipboardItem, Context, Element, Entity, EventEmitter, Flatten, FocusHandle, Focusable,
|
||||||
InteractiveElement, IntoElement, ListAlignment, ListState, MouseButton, ObjectFit,
|
InteractiveElement, IntoElement, ListAlignment, ListOffset, ListState, MouseButton, ObjectFit,
|
||||||
ParentElement, PathPromptOptions, Render, RetainAllImageCache, SharedString,
|
ParentElement, PathPromptOptions, Render, RetainAllImageCache, SharedString,
|
||||||
StatefulInteractiveElement, Styled, StyledImage, Subscription, Task, Window,
|
StatefulInteractiveElement, Styled, StyledImage, Subscription, Task, Window,
|
||||||
};
|
};
|
||||||
use gpui_tokio::Tokio;
|
use gpui_tokio::Tokio;
|
||||||
use i18n::{shared_t, t};
|
use i18n::{shared_t, t};
|
||||||
|
use indexset::{BTreeMap, BTreeSet};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use registry::message::{Message, RenderedMessage};
|
use registry::message::{Message, RenderedMessage};
|
||||||
@@ -51,14 +50,13 @@ pub struct Chat {
|
|||||||
// Chat Room
|
// Chat Room
|
||||||
room: Entity<Room>,
|
room: Entity<Room>,
|
||||||
list_state: ListState,
|
list_state: ListState,
|
||||||
messages: Vec<Message>,
|
messages: BTreeSet<Message>,
|
||||||
rendered_texts_by_id: HashMap<EventId, RenderedText>,
|
rendered_texts_by_id: BTreeMap<EventId, RenderedText>,
|
||||||
reports_by_id: HashMap<EventId, Vec<SendReport>>,
|
reports_by_id: BTreeMap<EventId, Vec<SendReport>>,
|
||||||
|
|
||||||
// New Message
|
// New Message
|
||||||
input: Entity<InputState>,
|
input: Entity<InputState>,
|
||||||
replies_to: Entity<Vec<EventId>>,
|
replies_to: Entity<Vec<EventId>>,
|
||||||
sending: bool,
|
|
||||||
|
|
||||||
// Media Attachment
|
// Media Attachment
|
||||||
attachments: Entity<Vec<Url>>,
|
attachments: Entity<Vec<Url>>,
|
||||||
@@ -75,7 +73,8 @@ pub struct Chat {
|
|||||||
|
|
||||||
impl Chat {
|
impl Chat {
|
||||||
pub fn new(room: Entity<Room>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
pub fn new(room: Entity<Room>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let list_state = ListState::new(1, ListAlignment::Bottom, px(1024.));
|
let attachments = cx.new(|_| vec![]);
|
||||||
|
let replies_to = cx.new(|_| vec![]);
|
||||||
let input = cx.new(|cx| {
|
let input = cx.new(|cx| {
|
||||||
InputState::new(window, cx)
|
InputState::new(window, cx)
|
||||||
.placeholder(t!("chat.placeholder"))
|
.placeholder(t!("chat.placeholder"))
|
||||||
@@ -87,8 +86,9 @@ impl Chat {
|
|||||||
.clean_on_escape()
|
.clean_on_escape()
|
||||||
});
|
});
|
||||||
|
|
||||||
let attachments = cx.new(|_| vec![]);
|
let messages = BTreeSet::from([Message::system()]);
|
||||||
let replies_to = cx.new(|_| vec![]);
|
let list_state = ListState::new(messages.len(), ListAlignment::Bottom, px(1024.));
|
||||||
|
|
||||||
let load_messages = room.read(cx).load_messages(cx);
|
let load_messages = room.read(cx).load_messages(cx);
|
||||||
|
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
@@ -139,7 +139,7 @@ impl Chat {
|
|||||||
match signal {
|
match signal {
|
||||||
RoomSignal::NewMessage((gift_wrap_id, event)) => {
|
RoomSignal::NewMessage((gift_wrap_id, event)) => {
|
||||||
if !this.is_sent_by_coop(gift_wrap_id) {
|
if !this.is_sent_by_coop(gift_wrap_id) {
|
||||||
this.insert_message(event, cx);
|
this.insert_message(event, false, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RoomSignal::Refresh => {
|
RoomSignal::Refresh => {
|
||||||
@@ -154,10 +154,9 @@ impl Chat {
|
|||||||
image_cache: RetainAllImageCache::new(cx),
|
image_cache: RetainAllImageCache::new(cx),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
uploading: false,
|
uploading: false,
|
||||||
sending: false,
|
rendered_texts_by_id: BTreeMap::new(),
|
||||||
messages: vec![Message::System],
|
reports_by_id: BTreeMap::new(),
|
||||||
rendered_texts_by_id: HashMap::new(),
|
messages,
|
||||||
reports_by_id: HashMap::new(),
|
|
||||||
room,
|
room,
|
||||||
list_state,
|
list_state,
|
||||||
input,
|
input,
|
||||||
@@ -169,26 +168,28 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Load all messages belonging to this room
|
/// Load all messages belonging to this room
|
||||||
fn load_messages(&self, window: &mut Window, cx: &mut Context<Self>) {
|
fn load_messages(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let load_messages = self.room.read(cx).load_messages(cx);
|
let load_messages = self.room.read(cx).load_messages(cx);
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
self._tasks.push(
|
||||||
match load_messages.await {
|
// Run the task in the background
|
||||||
Ok(events) => {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
this.update(cx, |this, cx| {
|
match load_messages.await {
|
||||||
this.insert_messages(events, cx);
|
Ok(events) => {
|
||||||
})
|
this.update(cx, |this, cx| {
|
||||||
.ok();
|
this.insert_messages(events, cx);
|
||||||
}
|
})
|
||||||
Err(e) => {
|
.ok();
|
||||||
cx.update(|window, cx| {
|
}
|
||||||
window.push_notification(e.to_string(), cx);
|
Err(e) => {
|
||||||
})
|
cx.update(|window, cx| {
|
||||||
.ok();
|
window.push_notification(e.to_string(), cx);
|
||||||
}
|
})
|
||||||
};
|
.ok();
|
||||||
})
|
}
|
||||||
.detach();
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -220,14 +221,7 @@ impl Chat {
|
|||||||
|
|
||||||
/// Check if the event is sent by Coop
|
/// Check if the event is sent by Coop
|
||||||
fn is_sent_by_coop(&self, gift_wrap_id: &EventId) -> bool {
|
fn is_sent_by_coop(&self, gift_wrap_id: &EventId) -> bool {
|
||||||
let sent_ids = sent_ids();
|
css().sent_ids.read_blocking().contains(gift_wrap_id)
|
||||||
sent_ids.read_blocking().contains(gift_wrap_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the sending state of the chat panel
|
|
||||||
fn set_sending(&mut self, sending: bool, cx: &mut Context<Self>) {
|
|
||||||
self.sending = sending;
|
|
||||||
cx.notify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a message to all members of the chat
|
/// Send a message to all members of the chat
|
||||||
@@ -235,24 +229,21 @@ impl Chat {
|
|||||||
// Get the message which includes all attachments
|
// Get the message which includes all attachments
|
||||||
let content = self.input_content(cx);
|
let content = self.input_content(cx);
|
||||||
|
|
||||||
// Get the backup setting
|
|
||||||
let backup = AppSettings::get_backup_messages(cx);
|
|
||||||
|
|
||||||
// Return if message is empty
|
// Return if message is empty
|
||||||
if content.trim().is_empty() {
|
if content.trim().is_empty() {
|
||||||
window.push_notification(t!("chat.empty_message_error"), cx);
|
window.push_notification(t!("chat.empty_message_error"), cx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark sending in progress
|
|
||||||
self.set_sending(true, cx);
|
|
||||||
|
|
||||||
// Temporary disable input
|
// Temporary disable input
|
||||||
self.input.update(cx, |this, cx| {
|
self.input.update(cx, |this, cx| {
|
||||||
this.set_loading(true, cx);
|
this.set_loading(true, cx);
|
||||||
this.set_disabled(true, cx);
|
this.set_disabled(true, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Get the backup setting
|
||||||
|
let backup = AppSettings::get_backup_messages(cx);
|
||||||
|
|
||||||
// Get replies_to if it's present
|
// Get replies_to if it's present
|
||||||
let replies = self.replies_to.read(cx).clone();
|
let replies = self.replies_to.read(cx).clone();
|
||||||
|
|
||||||
@@ -267,17 +258,19 @@ impl Chat {
|
|||||||
// Create a task for sending the message in the background
|
// Create a task for sending the message in the background
|
||||||
let send_message = room.send_in_background(&content, replies, backup, cx);
|
let send_message = room.send_in_background(&content, replies, backup, cx);
|
||||||
|
|
||||||
// Optimistically update message list
|
cx.defer_in(window, |this, window, cx| {
|
||||||
self.insert_message(temp_message, cx);
|
// Optimistically update message list
|
||||||
|
this.insert_message(temp_message, true, cx);
|
||||||
|
|
||||||
// Remove all replies
|
// Remove all replies
|
||||||
self.remove_all_replies(cx);
|
this.remove_all_replies(cx);
|
||||||
|
|
||||||
// Reset the input state
|
// Reset the input state
|
||||||
self.input.update(cx, |this, cx| {
|
this.input.update(cx, |this, cx| {
|
||||||
this.set_loading(false, cx);
|
this.set_loading(false, cx);
|
||||||
this.set_disabled(false, cx);
|
this.set_disabled(false, cx);
|
||||||
this.set_value("", window, cx);
|
this.set_value("", window, cx);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Continue sending the message in the background
|
// Continue sending the message in the background
|
||||||
@@ -285,15 +278,20 @@ impl Chat {
|
|||||||
match send_message.await {
|
match send_message.await {
|
||||||
Ok(reports) => {
|
Ok(reports) => {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
// Don't change the room kind if send failed
|
|
||||||
this.room.update(cx, |this, cx| {
|
this.room.update(cx, |this, cx| {
|
||||||
if this.kind != RoomKind::Ongoing {
|
if this.kind != RoomKind::Ongoing {
|
||||||
this.kind = RoomKind::Ongoing;
|
// Update the room kind to ongoing
|
||||||
cx.notify();
|
// But keep the room kind if send failed
|
||||||
|
if reports.iter().all(|r| !r.is_sent_success()) {
|
||||||
|
this.kind = RoomKind::Ongoing;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Insert the sent reports
|
||||||
this.reports_by_id.insert(temp_id, reports);
|
this.reports_by_id.insert(temp_id, reports);
|
||||||
this.sending = false;
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
@@ -341,62 +339,31 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convert and insert a nostr event into the chat panel
|
/// Convert and insert a nostr event into the chat panel
|
||||||
fn insert_message<E>(&mut self, event: E, cx: &mut Context<Self>)
|
fn insert_message<E>(&mut self, event: E, scroll: bool, cx: &mut Context<Self>)
|
||||||
where
|
where
|
||||||
E: Into<RenderedMessage>,
|
E: Into<RenderedMessage>,
|
||||||
{
|
{
|
||||||
let old_len = self.messages.len();
|
let old_len = self.messages.len();
|
||||||
let new_len = 1;
|
|
||||||
|
|
||||||
// Extend the messages list with the new events
|
// Extend the messages list with the new events
|
||||||
self.messages.push(Message::user(event));
|
if self.messages.insert(Message::user(event)) {
|
||||||
|
self.list_state.splice(old_len..old_len, 1);
|
||||||
|
|
||||||
// Update list state with the new messages
|
if scroll {
|
||||||
self.list_state.splice(old_len..old_len, new_len);
|
self.list_state.scroll_to(ListOffset {
|
||||||
|
item_ix: self.list_state.item_count(),
|
||||||
cx.notify();
|
offset_in_item: px(0.0),
|
||||||
|
});
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert and insert bulk nostr events into the chat panel
|
/// Convert and insert a vector of nostr events into the chat panel
|
||||||
fn insert_messages<E>(&mut self, events: E, cx: &mut Context<Self>)
|
fn insert_messages(&mut self, events: Vec<Event>, cx: &mut Context<Self>) {
|
||||||
where
|
for event in events.into_iter() {
|
||||||
E: IntoIterator,
|
self.insert_message(event, false, cx);
|
||||||
E::Item: Into<RenderedMessage>,
|
}
|
||||||
{
|
|
||||||
let old_events: HashSet<EventId> = self
|
|
||||||
.messages
|
|
||||||
.iter()
|
|
||||||
.filter_map(|msg| {
|
|
||||||
if let Message::User(rendered) = msg {
|
|
||||||
Some(rendered.id)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let events: Vec<Message> = events
|
|
||||||
.into_iter()
|
|
||||||
.map(|ev| ev.into())
|
|
||||||
.filter(|msg: &RenderedMessage| !old_events.contains(&msg.id))
|
|
||||||
.map(Message::User)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let old_len = self.messages.len();
|
|
||||||
let new_len = events.len();
|
|
||||||
|
|
||||||
// Extend the messages list with the new events
|
|
||||||
self.messages.extend(events);
|
|
||||||
self.messages.sort_by(|a, b| match (a, b) {
|
|
||||||
(Message::System, Message::System) => std::cmp::Ordering::Equal,
|
|
||||||
(Message::System, Message::User(_)) => std::cmp::Ordering::Less,
|
|
||||||
(Message::User(_), Message::System) => std::cmp::Ordering::Greater,
|
|
||||||
(Message::User(a_msg), Message::User(b_msg)) => a_msg.created_at.cmp(&b_msg.created_at),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Update list state with the new messages
|
|
||||||
self.list_state.splice(old_len..old_len, new_len);
|
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,12 +466,9 @@ impl Chat {
|
|||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
window.push_notification(e.to_string(), cx);
|
||||||
window.push_notification(e.to_string(), cx);
|
this.uploading(false, cx);
|
||||||
this.uploading(false, cx);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -561,15 +525,18 @@ impl Chat {
|
|||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_message_not_found(&self, cx: &Context<Self>) -> AnyElement {
|
fn render_message_not_found(&self, ix: usize, cx: &Context<Self>) -> AnyElement {
|
||||||
div()
|
div()
|
||||||
|
.id(ix)
|
||||||
.w_full()
|
.w_full()
|
||||||
.py_1()
|
.py_1()
|
||||||
.px_3()
|
.px_3()
|
||||||
.child(
|
.child(
|
||||||
div()
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.text_color(cx.theme().danger_foreground)
|
.text_color(cx.theme().danger_foreground)
|
||||||
|
.child(SharedString::from(ix.to_string()))
|
||||||
.child(shared_t!("chat.not_found")),
|
.child(shared_t!("chat.not_found")),
|
||||||
)
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
@@ -1173,7 +1140,7 @@ impl Render for Chat {
|
|||||||
list(
|
list(
|
||||||
self.list_state.clone(),
|
self.list_state.clone(),
|
||||||
cx.processor(move |this, ix: usize, window, cx| {
|
cx.processor(move |this, ix: usize, window, cx| {
|
||||||
if let Some(message) = this.messages.get(ix) {
|
if let Some(message) = this.messages.get_index(ix) {
|
||||||
match message {
|
match message {
|
||||||
Message::User(rendered) => {
|
Message::User(rendered) => {
|
||||||
let text = this
|
let text = this
|
||||||
@@ -1184,10 +1151,10 @@ impl Render for Chat {
|
|||||||
|
|
||||||
this.render_message(ix, rendered, text, cx)
|
this.render_message(ix, rendered, text, cx)
|
||||||
}
|
}
|
||||||
Message::System => this.render_announcement(ix, cx),
|
Message::System(_) => this.render_announcement(ix, cx),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.render_message_not_found(cx)
|
this.render_message_not_found(ix, cx)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -69,32 +69,29 @@ impl EditProfile {
|
|||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
if let Ok(Some(metadata)) = task.await {
|
if let Ok(Some(metadata)) = task.await {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this: &mut EditProfile, window, cx| {
|
||||||
this.update(cx, |this: &mut EditProfile, cx| {
|
this.avatar_input.update(cx, |this, cx| {
|
||||||
this.avatar_input.update(cx, |this, cx| {
|
if let Some(avatar) = metadata.picture.as_ref() {
|
||||||
if let Some(avatar) = metadata.picture.as_ref() {
|
this.set_value(avatar, window, cx);
|
||||||
this.set_value(avatar, window, cx);
|
}
|
||||||
}
|
});
|
||||||
});
|
this.bio_input.update(cx, |this, cx| {
|
||||||
this.bio_input.update(cx, |this, cx| {
|
if let Some(bio) = metadata.about.as_ref() {
|
||||||
if let Some(bio) = metadata.about.as_ref() {
|
this.set_value(bio, window, cx);
|
||||||
this.set_value(bio, window, cx);
|
}
|
||||||
}
|
});
|
||||||
});
|
this.name_input.update(cx, |this, cx| {
|
||||||
this.name_input.update(cx, |this, cx| {
|
if let Some(display_name) = metadata.display_name.as_ref() {
|
||||||
if let Some(display_name) = metadata.display_name.as_ref() {
|
this.set_value(display_name, window, cx);
|
||||||
this.set_value(display_name, window, cx);
|
}
|
||||||
}
|
});
|
||||||
});
|
this.website_input.update(cx, |this, cx| {
|
||||||
this.website_input.update(cx, |this, cx| {
|
if let Some(website) = metadata.website.as_ref() {
|
||||||
if let Some(website) = metadata.website.as_ref() {
|
this.set_value(website, window, cx);
|
||||||
this.set_value(website, window, cx);
|
}
|
||||||
}
|
});
|
||||||
});
|
this.profile = Some(metadata);
|
||||||
this.profile = Some(metadata);
|
cx.notify();
|
||||||
cx.notify();
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use common::nip96::nip96_upload;
|
use common::nip96::nip96_upload;
|
||||||
use global::constants::ACCOUNT_IDENTIFIER;
|
use global::constants::{ACCOUNT_IDENTIFIER, NIP17_RELAYS, NIP65_RELAYS};
|
||||||
use global::nostr_client;
|
use global::nostr_client;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, relative, rems, AnyElement, App, AppContext, AsyncWindowContext, Context, Entity,
|
div, relative, rems, AnyElement, App, AppContext, AsyncWindowContext, Context, Entity,
|
||||||
@@ -70,6 +70,7 @@ impl NewAccount {
|
|||||||
window.open_modal(cx, move |modal, _window, _cx| {
|
window.open_modal(cx, move |modal, _window, _cx| {
|
||||||
let weak_view = weak_view.clone();
|
let weak_view = weak_view.clone();
|
||||||
let current_view = current_view.clone();
|
let current_view = current_view.clone();
|
||||||
|
|
||||||
modal
|
modal
|
||||||
.alert()
|
.alert()
|
||||||
.title(shared_t!("new_account.backup_label"))
|
.title(shared_t!("new_account.backup_label"))
|
||||||
@@ -124,8 +125,44 @@ impl NewAccount {
|
|||||||
// Set the client's signer with the current keys
|
// Set the client's signer with the current keys
|
||||||
cx.background_spawn(async move {
|
cx.background_spawn(async move {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
|
|
||||||
|
// Set the client's signer with the current keys
|
||||||
client.set_signer(keys).await;
|
client.set_signer(keys).await;
|
||||||
client.set_metadata(&metadata).await.ok();
|
|
||||||
|
// Set metadata
|
||||||
|
if let Err(e) = client.set_metadata(&metadata).await {
|
||||||
|
log::error!("Failed to set metadata: {e}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set NIP-65 relays
|
||||||
|
let builder = EventBuilder::new(Kind::RelayList, "").tags(
|
||||||
|
NIP65_RELAYS.into_iter().filter_map(|url| {
|
||||||
|
if let Ok(url) = RelayUrl::parse(url) {
|
||||||
|
Some(Tag::relay_metadata(url, None))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Err(e) = client.send_event_builder(builder).await {
|
||||||
|
log::error!("Failed to send NIP-65 relay list event: {e}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set NIP-17 relays
|
||||||
|
let builder = EventBuilder::new(Kind::InboxRelays, "").tags(
|
||||||
|
NIP17_RELAYS.into_iter().filter_map(|url| {
|
||||||
|
if let Ok(url) = RelayUrl::parse(url) {
|
||||||
|
Some(Tag::relay(url))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Err(e) = client.send_event_builder(builder).await {
|
||||||
|
log::error!("Failed to send messaging relay list event: {e}");
|
||||||
|
};
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
@@ -194,14 +231,11 @@ impl NewAccount {
|
|||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
match Flatten::flatten(task.await.map_err(|e| e.into())) {
|
match Flatten::flatten(task.await.map_err(|e| e.into())) {
|
||||||
Ok(Ok(url)) => {
|
Ok(Ok(url)) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
this.uploading(false, cx);
|
||||||
this.uploading(false, cx);
|
this.avatar_input.update(cx, |this, cx| {
|
||||||
this.avatar_input.update(cx, |this, cx| {
|
this.set_value(url.to_string(), window, cx);
|
||||||
this.set_value(url.to_string(), window, cx);
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use gpui::prelude::FluentBuilder;
|
|||||||
use gpui::{
|
use gpui::{
|
||||||
div, img, px, relative, svg, AnyElement, App, AppContext, ClipboardItem, Context, Entity,
|
div, img, px, relative, svg, AnyElement, App, AppContext, ClipboardItem, Context, Entity,
|
||||||
EventEmitter, FocusHandle, Focusable, Image, InteractiveElement, IntoElement, ParentElement,
|
EventEmitter, FocusHandle, Focusable, Image, InteractiveElement, IntoElement, ParentElement,
|
||||||
Render, SharedString, StatefulInteractiveElement, Styled, Subscription, Window,
|
Render, SharedString, StatefulInteractiveElement, Styled, Subscription, Task, Window,
|
||||||
};
|
};
|
||||||
use i18n::{shared_t, t};
|
use i18n::{shared_t, t};
|
||||||
use nostr_connect::prelude::*;
|
use nostr_connect::prelude::*;
|
||||||
@@ -17,6 +17,7 @@ use smallvec::{smallvec, SmallVec};
|
|||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
use ui::dock_area::panel::{Panel, PanelEvent};
|
||||||
|
use ui::notification::Notification;
|
||||||
use ui::popup_menu::PopupMenu;
|
use ui::popup_menu::PopupMenu;
|
||||||
use ui::{divider, h_flex, v_flex, ContextModal, Icon, IconName, Sizable, StyledExt};
|
use ui::{divider, h_flex, v_flex, ContextModal, Icon, IconName, Sizable, StyledExt};
|
||||||
|
|
||||||
@@ -65,8 +66,8 @@ pub struct Onboarding {
|
|||||||
// Panel
|
// Panel
|
||||||
name: SharedString,
|
name: SharedString,
|
||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
#[allow(dead_code)]
|
_subscriptions: SmallVec<[Subscription; 2]>,
|
||||||
subscriptions: SmallVec<[Subscription; 2]>,
|
_tasks: SmallVec<[Task<()>; 1]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Onboarding {
|
impl Onboarding {
|
||||||
@@ -103,10 +104,11 @@ impl Onboarding {
|
|||||||
nostr_connect,
|
nostr_connect,
|
||||||
nostr_connect_uri,
|
nostr_connect_uri,
|
||||||
qr_code,
|
qr_code,
|
||||||
subscriptions,
|
|
||||||
connecting: false,
|
connecting: false,
|
||||||
name: "Onboarding".into(),
|
name: "Onboarding".into(),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
|
_subscriptions: subscriptions,
|
||||||
|
_tasks: smallvec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,32 +132,37 @@ impl Onboarding {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
self._tasks.push(
|
||||||
let client = nostr_client();
|
// Wait for Nostr Connect approval
|
||||||
let connect = this.read_with(cx, |this, cx| this.nostr_connect.read(cx).clone());
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
|
let client = nostr_client();
|
||||||
|
let connect = this.read_with(cx, |this, cx| this.nostr_connect.read(cx).clone());
|
||||||
|
|
||||||
if let Ok(Some(signer)) = connect {
|
if let Ok(Some(signer)) = connect {
|
||||||
match signer.bunker_uri().await {
|
match signer.bunker_uri().await {
|
||||||
Ok(uri) => {
|
Ok(uri) => {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.set_connecting(cx);
|
this.set_connecting(cx);
|
||||||
this.write_uri_to_disk(&uri, cx);
|
this.write_uri_to_disk(&uri, cx);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
// Set the client's signer with the current nostr connect instance
|
// Set the client's signer with the current nostr connect instance
|
||||||
client.set_signer(signer).await;
|
client.set_signer(signer).await;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |_, window, cx| {
|
||||||
window.push_notification(e.to_string(), cx);
|
window.push_notification(
|
||||||
})
|
Notification::error(e.to_string()).title("Nostr Connect"),
|
||||||
.ok();
|
cx,
|
||||||
}
|
);
|
||||||
};
|
})
|
||||||
}
|
.ok();
|
||||||
})
|
}
|
||||||
.detach();
|
};
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_proxy(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn set_proxy(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ impl Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn open_relays(&self, window: &mut Window, cx: &mut Context<Self>) {
|
fn open_relays(&self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let title = SharedString::new(t!("relays.modal_title"));
|
|
||||||
let view = setup_relay::init(Kind::InboxRelays, window, cx);
|
let view = setup_relay::init(Kind::InboxRelays, window, cx);
|
||||||
let weak_view = view.downgrade();
|
let weak_view = view.downgrade();
|
||||||
|
|
||||||
@@ -94,7 +93,7 @@ impl Preferences {
|
|||||||
let weak_view = weak_view.clone();
|
let weak_view = weak_view.clone();
|
||||||
|
|
||||||
this.confirm()
|
this.confirm()
|
||||||
.title(title.clone())
|
.title(shared_t!("relays.modal"))
|
||||||
.child(view.clone())
|
.child(view.clone())
|
||||||
.button_props(ModalButtonProps::default().ok_text(t!("common.update")))
|
.button_props(ModalButtonProps::default().ok_text(t!("common.update")))
|
||||||
.on_ok(move |_, window, cx| {
|
.on_ok(move |_, window, cx| {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
use common::display::{shorten_pubkey, ReadableProfile};
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use common::display::{shorten_pubkey, ReadableProfile, ReadableTimestamp};
|
||||||
use common::nip05::nip05_verify;
|
use common::nip05::nip05_verify;
|
||||||
|
use global::constants::BOOTSTRAP_RELAYS;
|
||||||
use global::nostr_client;
|
use global::nostr_client;
|
||||||
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, relative, rems, App, AppContext, Context, Div, Entity, IntoElement, ParentElement, Render,
|
div, px, relative, rems, uniform_list, App, AppContext, Context, Div, Entity,
|
||||||
SharedString, Styled, Task, Window,
|
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Task, Window,
|
||||||
};
|
};
|
||||||
use gpui_tokio::Tokio;
|
use gpui_tokio::Tokio;
|
||||||
use i18n::{shared_t, t};
|
use i18n::{shared_t, t};
|
||||||
@@ -14,6 +18,7 @@ use smallvec::{smallvec, SmallVec};
|
|||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::button::{Button, ButtonRounded, ButtonVariants};
|
use ui::button::{Button, ButtonRounded, ButtonVariants};
|
||||||
|
use ui::indicator::Indicator;
|
||||||
use ui::{h_flex, v_flex, ContextModal, Icon, IconName, Sizable, StyledExt};
|
use ui::{h_flex, v_flex, ContextModal, Icon, IconName, Sizable, StyledExt};
|
||||||
|
|
||||||
pub fn init(public_key: PublicKey, window: &mut Window, cx: &mut App) -> Entity<Screening> {
|
pub fn init(public_key: PublicKey, window: &mut Window, cx: &mut App) -> Entity<Screening> {
|
||||||
@@ -24,9 +29,10 @@ pub struct Screening {
|
|||||||
profile: Profile,
|
profile: Profile,
|
||||||
verified: bool,
|
verified: bool,
|
||||||
followed: bool,
|
followed: bool,
|
||||||
dm_relays: bool,
|
dm_relays: Option<bool>,
|
||||||
mutual_contacts: usize,
|
last_active: Option<Timestamp>,
|
||||||
_tasks: SmallVec<[Task<()>; 1]>,
|
mutual_contacts: Vec<Profile>,
|
||||||
|
_tasks: SmallVec<[Task<()>; 4]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screening {
|
impl Screening {
|
||||||
@@ -37,33 +43,65 @@ impl Screening {
|
|||||||
|
|
||||||
let mut tasks = smallvec![];
|
let mut tasks = smallvec![];
|
||||||
|
|
||||||
let check_trust_score: Task<(bool, usize, bool)> = cx.background_spawn(async move {
|
let contact_check: Task<(bool, Vec<Profile>)> = cx.background_spawn(async move {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
|
|
||||||
let follow = Filter::new()
|
// Check if user is in contact list
|
||||||
.kind(Kind::ContactList)
|
let contacts = client.database().contacts_public_keys(identity).await;
|
||||||
.author(identity)
|
let followed = contacts.unwrap_or_default().contains(&public_key);
|
||||||
.pubkey(public_key)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
let contacts = Filter::new()
|
// Check mutual contacts
|
||||||
.kind(Kind::ContactList)
|
let contact_list = Filter::new().kind(Kind::ContactList).pubkey(public_key);
|
||||||
.pubkey(public_key)
|
let mut mutual_contacts = vec![];
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
let relays = Filter::new()
|
if let Ok(events) = client.database().query(contact_list).await {
|
||||||
|
for event in events.into_iter().filter(|ev| ev.pubkey != identity) {
|
||||||
|
if let Ok(metadata) = client.database().metadata(event.pubkey).await {
|
||||||
|
let profile = Profile::new(event.pubkey, metadata.unwrap_or_default());
|
||||||
|
mutual_contacts.push(profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(followed, mutual_contacts)
|
||||||
|
});
|
||||||
|
|
||||||
|
let activity_check = cx.background_spawn(async move {
|
||||||
|
let client = nostr_client();
|
||||||
|
let filter = Filter::new().author(public_key).limit(1);
|
||||||
|
let mut activity: Option<Timestamp> = None;
|
||||||
|
|
||||||
|
if let Ok(mut stream) = client
|
||||||
|
.stream_events_from(BOOTSTRAP_RELAYS, filter, Duration::from_secs(2))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
while let Some(event) = stream.next().await {
|
||||||
|
activity = Some(event.created_at);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
activity
|
||||||
|
});
|
||||||
|
|
||||||
|
let relay_check = cx.background_spawn(async move {
|
||||||
|
let client = nostr_client();
|
||||||
|
let mut relay = false;
|
||||||
|
|
||||||
|
let filter = Filter::new()
|
||||||
.kind(Kind::InboxRelays)
|
.kind(Kind::InboxRelays)
|
||||||
.author(public_key)
|
.author(public_key)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
let is_follow = client.database().count(follow).await.unwrap_or(0) >= 1;
|
if let Ok(mut stream) = client.stream_events(filter, Duration::from_secs(2)).await {
|
||||||
let mutual_contacts = client.database().count(contacts).await.unwrap_or(0);
|
while stream.next().await.is_some() {
|
||||||
let dm_relays = client.database().count(relays).await.unwrap_or(0) >= 1;
|
relay = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(is_follow, mutual_contacts, dm_relays)
|
relay
|
||||||
});
|
});
|
||||||
|
|
||||||
let verify_nip05 = if let Some(address) = profile.metadata().nip05 {
|
let addr_check = if let Some(address) = profile.metadata().nip05 {
|
||||||
Some(Tokio::spawn(cx, async move {
|
Some(Tokio::spawn(cx, async move {
|
||||||
nip05_verify(public_key, &address).await.unwrap_or(false)
|
nip05_verify(public_key, &address).await.unwrap_or(false)
|
||||||
}))
|
}))
|
||||||
@@ -72,20 +110,49 @@ impl Screening {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tasks.push(
|
tasks.push(
|
||||||
// Load all necessary data
|
// Run the contact check in the background
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
let (followed, mutual_contacts, dm_relays) = check_trust_score.await;
|
let (followed, mutual_contacts) = contact_check.await;
|
||||||
|
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.followed = followed;
|
this.followed = followed;
|
||||||
this.mutual_contacts = mutual_contacts;
|
this.mutual_contacts = mutual_contacts;
|
||||||
this.dm_relays = dm_relays;
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
// Update the NIP05 verification status if user has NIP05 address
|
tasks.push(
|
||||||
if let Some(task) = verify_nip05 {
|
// Run the activity check in the background
|
||||||
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
|
let active = activity_check.await;
|
||||||
|
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.last_active = active;
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
tasks.push(
|
||||||
|
// Run the relay check in the background
|
||||||
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
|
let relay = relay_check.await;
|
||||||
|
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.dm_relays = Some(relay);
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
tasks.push(
|
||||||
|
// Run the NIP-05 verification in the background
|
||||||
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
|
if let Some(task) = addr_check {
|
||||||
if let Ok(verified) = task.await {
|
if let Ok(verified) = task.await {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.verified = verified;
|
this.verified = verified;
|
||||||
@@ -101,8 +168,9 @@ impl Screening {
|
|||||||
profile,
|
profile,
|
||||||
verified: false,
|
verified: false,
|
||||||
followed: false,
|
followed: false,
|
||||||
dm_relays: false,
|
dm_relays: None,
|
||||||
mutual_contacts: 0,
|
last_active: None,
|
||||||
|
mutual_contacts: vec![],
|
||||||
_tasks: tasks,
|
_tasks: tasks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,12 +209,55 @@ impl Screening {
|
|||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mutual_contacts(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let contacts = self.mutual_contacts.clone();
|
||||||
|
|
||||||
|
window.open_modal(cx, move |this, _window, _cx| {
|
||||||
|
let contacts = contacts.clone();
|
||||||
|
let total = contacts.len();
|
||||||
|
|
||||||
|
this.title(shared_t!("screening.mutual_label")).child(
|
||||||
|
v_flex().gap_1().pb_4().child(
|
||||||
|
uniform_list("contacts", total, move |range, _window, cx| {
|
||||||
|
let mut items = Vec::with_capacity(total);
|
||||||
|
|
||||||
|
for ix in range {
|
||||||
|
if let Some(contact) = contacts.get(ix) {
|
||||||
|
items.push(
|
||||||
|
h_flex()
|
||||||
|
.h_11()
|
||||||
|
.w_full()
|
||||||
|
.px_2()
|
||||||
|
.gap_1p5()
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.text_sm()
|
||||||
|
.hover(|this| {
|
||||||
|
this.bg(cx.theme().elevated_surface_background)
|
||||||
|
})
|
||||||
|
.child(
|
||||||
|
Avatar::new(contact.avatar_url(true)).size(rems(1.75)),
|
||||||
|
)
|
||||||
|
.child(contact.display_name()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
items
|
||||||
|
})
|
||||||
|
.h(px(300.)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for Screening {
|
impl Render for Screening {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let proxy = AppSettings::get_proxy_user_avatars(cx);
|
let proxy = AppSettings::get_proxy_user_avatars(cx);
|
||||||
let shorten_pubkey = shorten_pubkey(self.profile.public_key(), 8);
|
let shorten_pubkey = shorten_pubkey(self.profile.public_key(), 8);
|
||||||
|
let total_mutuals = self.mutual_contacts.len();
|
||||||
|
let last_active = self.last_active.map(|_| true);
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_4()
|
.gap_4()
|
||||||
@@ -168,12 +279,10 @@ impl Render for Screening {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.gap_3()
|
.gap_3()
|
||||||
.child(
|
.child(
|
||||||
div()
|
h_flex()
|
||||||
.p_1()
|
.p_1()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.h_7()
|
.h_7()
|
||||||
.flex()
|
|
||||||
.items_center()
|
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.rounded_full()
|
.rounded_full()
|
||||||
.bg(cx.theme().surface_background)
|
.bg(cx.theme().surface_background)
|
||||||
@@ -217,25 +326,70 @@ impl Render for Screening {
|
|||||||
.items_start()
|
.items_start()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.child(status_badge(self.followed, cx))
|
.child(status_badge(Some(self.followed), cx))
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.child(shared_t!("screening.contact_label"))
|
.child(shared_t!("screening.contact_label"))
|
||||||
.child(div().text_color(cx.theme().text_muted).child({
|
.child(
|
||||||
if self.followed {
|
div()
|
||||||
shared_t!("screening.contact")
|
.line_clamp(1)
|
||||||
} else {
|
.text_color(cx.theme().text_muted)
|
||||||
shared_t!("screening.not_contact")
|
.child({
|
||||||
}
|
if self.followed {
|
||||||
})),
|
shared_t!("screening.contact")
|
||||||
|
} else {
|
||||||
|
shared_t!("screening.not_contact")
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.items_start()
|
.items_start()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.child(status_badge(self.verified, cx))
|
.text_sm()
|
||||||
|
.child(status_badge(last_active, cx))
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_0p5()
|
||||||
|
.child(shared_t!("screening.active_label"))
|
||||||
|
.child(
|
||||||
|
Button::new("active")
|
||||||
|
.icon(IconName::Info)
|
||||||
|
.xsmall()
|
||||||
|
.ghost()
|
||||||
|
.rounded(ButtonRounded::Full)
|
||||||
|
.tooltip(t!("screening.active_tooltip")),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w_full()
|
||||||
|
.line_clamp(1)
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.map(|this| {
|
||||||
|
if let Some(date) = self.last_active {
|
||||||
|
this.child(shared_t!(
|
||||||
|
"screening.active_at",
|
||||||
|
d = date.to_human_time()
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
this.child(shared_t!("screening.no_active"))
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.items_start()
|
||||||
|
.gap_2()
|
||||||
|
.child(status_badge(Some(self.verified), cx))
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
@@ -246,35 +400,61 @@ impl Render for Screening {
|
|||||||
shared_t!("screening.nip05_label")
|
shared_t!("screening.nip05_label")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.child(div().text_color(cx.theme().text_muted).child({
|
.child(
|
||||||
if self.address(cx).is_some() {
|
div()
|
||||||
if self.verified {
|
.line_clamp(1)
|
||||||
shared_t!("screening.nip05_ok")
|
.text_color(cx.theme().text_muted)
|
||||||
} else {
|
.child({
|
||||||
shared_t!("screening.nip05_failed")
|
if self.address(cx).is_some() {
|
||||||
}
|
if self.verified {
|
||||||
} else {
|
shared_t!("screening.nip05_ok")
|
||||||
shared_t!("screening.nip05_empty")
|
} else {
|
||||||
}
|
shared_t!("screening.nip05_failed")
|
||||||
})),
|
}
|
||||||
|
} else {
|
||||||
|
shared_t!("screening.nip05_empty")
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.items_start()
|
.items_start()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.child(status_badge(self.mutual_contacts > 0, cx))
|
.child(status_badge(Some(total_mutuals > 0), cx))
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.child(shared_t!("screening.mutual_label"))
|
.child(
|
||||||
.child(div().text_color(cx.theme().text_muted).child({
|
h_flex()
|
||||||
if self.mutual_contacts > 0 {
|
.gap_0p5()
|
||||||
shared_t!("screening.mutual", u = self.mutual_contacts)
|
.child(shared_t!("screening.mutual_label"))
|
||||||
} else {
|
.child(
|
||||||
shared_t!("screening.no_mutual")
|
Button::new("mutuals")
|
||||||
}
|
.icon(IconName::Info)
|
||||||
})),
|
.xsmall()
|
||||||
|
.ghost()
|
||||||
|
.rounded(ButtonRounded::Full)
|
||||||
|
.on_click(cx.listener(
|
||||||
|
move |this, _, window, cx| {
|
||||||
|
this.mutual_contacts(window, cx);
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.line_clamp(1)
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child({
|
||||||
|
if total_mutuals > 0 {
|
||||||
|
shared_t!("screening.mutual", u = total_mutuals)
|
||||||
|
} else {
|
||||||
|
shared_t!("screening.no_mutual")
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -287,36 +467,47 @@ impl Render for Screening {
|
|||||||
.w_full()
|
.w_full()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.child({
|
.child({
|
||||||
if self.dm_relays {
|
if self.dm_relays == Some(true) {
|
||||||
shared_t!("screening.relay_found")
|
shared_t!("screening.relay_found")
|
||||||
} else {
|
} else {
|
||||||
shared_t!("screening.relay_empty")
|
shared_t!("screening.relay_empty")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.child(div().w_full().text_color(cx.theme().text_muted).child(
|
.child(
|
||||||
{
|
div()
|
||||||
if self.dm_relays {
|
.w_full()
|
||||||
shared_t!("screening.relay_found_desc")
|
.line_clamp(1)
|
||||||
} else {
|
.text_color(cx.theme().text_muted)
|
||||||
shared_t!("screening.relay_empty_desc")
|
.child({
|
||||||
}
|
if self.dm_relays == Some(true) {
|
||||||
},
|
shared_t!("screening.relay_found_desc")
|
||||||
)),
|
} else {
|
||||||
|
shared_t!("screening.relay_empty_desc")
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn status_badge(status: bool, cx: &App) -> Div {
|
fn status_badge(status: Option<bool>, cx: &App) -> Div {
|
||||||
div()
|
h_flex()
|
||||||
.pt_1()
|
.size_6()
|
||||||
|
.justify_center()
|
||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
.child(Icon::new(IconName::CheckCircleFill).small().text_color({
|
.map(|this| {
|
||||||
if status {
|
if let Some(status) = status {
|
||||||
cx.theme().icon_accent
|
this.child(Icon::new(IconName::CheckCircleFill).small().text_color({
|
||||||
|
if status {
|
||||||
|
cx.theme().icon_accent
|
||||||
|
} else {
|
||||||
|
cx.theme().icon_muted
|
||||||
|
}
|
||||||
|
}))
|
||||||
} else {
|
} else {
|
||||||
cx.theme().icon_muted
|
this.child(Indicator::new().small())
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{anyhow, Error};
|
||||||
use global::constants::NIP17_RELAYS;
|
use global::constants::NIP17_RELAYS;
|
||||||
use global::nostr_client;
|
use global::{css, nostr_client};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, px, uniform_list, App, AppContext, Context, Entity, InteractiveElement, IntoElement,
|
div, px, uniform_list, App, AppContext, Context, Entity, InteractiveElement, IntoElement,
|
||||||
@@ -10,7 +10,6 @@ use gpui::{
|
|||||||
TextAlign, UniformList, Window,
|
TextAlign, UniformList, Window,
|
||||||
};
|
};
|
||||||
use i18n::{shared_t, t};
|
use i18n::{shared_t, t};
|
||||||
use itertools::Itertools;
|
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use registry::Registry;
|
use registry::Registry;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
@@ -44,7 +43,7 @@ where
|
|||||||
|
|
||||||
modal
|
modal
|
||||||
.confirm()
|
.confirm()
|
||||||
.title(shared_t!("relays.modal_title"))
|
.title(shared_t!("relays.modal"))
|
||||||
.child(view.clone())
|
.child(view.clone())
|
||||||
.button_props(ModalButtonProps::default().ok_text(t!("common.update")))
|
.button_props(ModalButtonProps::default().ok_text(t!("common.update")))
|
||||||
.on_ok(move |_, window, cx| {
|
.on_ok(move |_, window, cx| {
|
||||||
@@ -82,7 +81,7 @@ impl SetupRelay {
|
|||||||
let filter = Filter::new().kind(kind).author(identity).limit(1);
|
let filter = Filter::new().kind(kind).author(identity).limit(1);
|
||||||
|
|
||||||
if let Some(event) = client.database().query(filter).await?.first() {
|
if let Some(event) = client.database().query(filter).await?.first() {
|
||||||
let relays = event
|
let relays: Vec<RelayUrl> = event
|
||||||
.tags
|
.tags
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|tag| tag.as_standardized())
|
.filter_map(|tag| tag.as_standardized())
|
||||||
@@ -95,7 +94,7 @@ impl SetupRelay {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect_vec();
|
.collect();
|
||||||
|
|
||||||
Ok(relays)
|
Ok(relays)
|
||||||
} else {
|
} else {
|
||||||
@@ -195,22 +194,41 @@ impl SetupRelay {
|
|||||||
|
|
||||||
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
|
let signer = client.signer().await?;
|
||||||
|
let public_key = signer.get_public_key().await?;
|
||||||
|
|
||||||
let tags: Vec<Tag> = relays
|
let tags: Vec<Tag> = relays
|
||||||
.iter()
|
.iter()
|
||||||
.map(|relay| Tag::relay(relay.clone()))
|
.map(|relay| Tag::relay(relay.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let builder = EventBuilder::new(Kind::InboxRelays, "").tags(tags);
|
let event = EventBuilder::new(Kind::InboxRelays, "")
|
||||||
|
.tags(tags)
|
||||||
|
.build(public_key)
|
||||||
|
.sign(&signer)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Set messaging relays
|
// Set messaging relays
|
||||||
client.send_event_builder(builder).await?;
|
client.send_event(&event).await?;
|
||||||
|
|
||||||
// Connect to messaging relays
|
// Connect to messaging relays
|
||||||
for relay in relays.into_iter() {
|
for relay in relays.iter() {
|
||||||
_ = client.add_relay(&relay).await;
|
_ = client.add_relay(relay).await;
|
||||||
_ = client.connect_relay(&relay).await;
|
_ = client.connect_relay(relay).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch gift wrap events
|
||||||
|
let sub_id = css().gift_wrap_sub_id.clone();
|
||||||
|
let filter = Filter::new().kind(Kind::GiftWrap).pubkey(public_key);
|
||||||
|
|
||||||
|
if client
|
||||||
|
.subscribe_with_id_to(relays.clone(), sub_id, filter, None)
|
||||||
|
.await
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
log::info!("Subscribed to messages in: {relays:?}");
|
||||||
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -223,11 +241,8 @@ impl SetupRelay {
|
|||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
this.set_error(e.to_string(), window, cx);
|
||||||
this.set_error(e.to_string(), window, cx);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -291,7 +306,7 @@ impl SetupRelay {
|
|||||||
.justify_center()
|
.justify_center()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.text_align(TextAlign::Center)
|
.text_align(TextAlign::Center)
|
||||||
.child(shared_t!("relays.add_some_relays"))
|
.child(shared_t!("relays.help_text"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +346,7 @@ impl Render for SetupRelay {
|
|||||||
.text_xs()
|
.text_xs()
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child(shared_t!("relays.recommended")),
|
.child(shared_t!("common.recommended")),
|
||||||
)
|
)
|
||||||
.child(h_flex().gap_1().children({
|
.child(h_flex().gap_1().children({
|
||||||
NIP17_RELAYS.iter().map(|&relay| {
|
NIP17_RELAYS.iter().map(|&relay| {
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ use registry::room::RoomKind;
|
|||||||
use registry::Registry;
|
use registry::Registry;
|
||||||
use settings::AppSettings;
|
use settings::AppSettings;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::actions::OpenProfile;
|
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::context_menu::ContextMenuExt;
|
|
||||||
use ui::modal::ModalButtonProps;
|
use ui::modal::ModalButtonProps;
|
||||||
|
use ui::skeleton::Skeleton;
|
||||||
use ui::{h_flex, ContextModal, StyledExt};
|
use ui::{h_flex, ContextModal, StyledExt};
|
||||||
|
|
||||||
use crate::views::screening;
|
use crate::views::screening;
|
||||||
@@ -108,7 +107,21 @@ impl RenderOnce for RoomListItem {
|
|||||||
self.handler,
|
self.handler,
|
||||||
)
|
)
|
||||||
else {
|
else {
|
||||||
return div().id(self.ix);
|
return h_flex()
|
||||||
|
.id(self.ix)
|
||||||
|
.h_9()
|
||||||
|
.w_full()
|
||||||
|
.px_1p5()
|
||||||
|
.gap_2()
|
||||||
|
.child(Skeleton::new().flex_shrink_0().size_6().rounded_full())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.flex()
|
||||||
|
.justify_between()
|
||||||
|
.child(Skeleton::new().w_32().h_2p5().rounded_sm())
|
||||||
|
.child(Skeleton::new().w_6().h_2p5().rounded_sm()),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
@@ -152,10 +165,6 @@ impl RenderOnce for RoomListItem {
|
|||||||
.child(created_at),
|
.child(created_at),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.context_menu(move |this, _window, _cx| {
|
|
||||||
// TODO: add share chat room
|
|
||||||
this.menu(t!("profile.view"), Box::new(OpenProfile(public_key)))
|
|
||||||
})
|
|
||||||
.hover(|this| this.bg(cx.theme().elevated_surface_background))
|
.hover(|this| this.bg(cx.theme().elevated_surface_background))
|
||||||
.on_click(move |event, window, cx| {
|
.on_click(move |event, window, cx| {
|
||||||
handler(event, window, cx);
|
handler(event, window, cx);
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ use anyhow::{anyhow, Error};
|
|||||||
use common::debounced_delay::DebouncedDelay;
|
use common::debounced_delay::DebouncedDelay;
|
||||||
use common::display::{ReadableTimestamp, TextUtils};
|
use common::display::{ReadableTimestamp, TextUtils};
|
||||||
use global::constants::{BOOTSTRAP_RELAYS, SEARCH_RELAYS};
|
use global::constants::{BOOTSTRAP_RELAYS, SEARCH_RELAYS};
|
||||||
use global::nostr_client;
|
use global::{css, nostr_client, UnwrappingStatus};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, uniform_list, AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle,
|
div, uniform_list, AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle,
|
||||||
Focusable, IntoElement, ParentElement, Render, RetainAllImageCache, SharedString, Styled,
|
Focusable, InteractiveElement, IntoElement, ParentElement, Render, RetainAllImageCache,
|
||||||
Subscription, Task, Window,
|
SharedString, Styled, Subscription, Task, Window,
|
||||||
};
|
};
|
||||||
use gpui_tokio::Tokio;
|
use gpui_tokio::Tokio;
|
||||||
use i18n::t;
|
use i18n::{shared_t, t};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use list_item::RoomListItem;
|
use list_item::RoomListItem;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
@@ -26,8 +26,10 @@ use theme::ActiveTheme;
|
|||||||
use ui::button::{Button, ButtonRounded, ButtonVariants};
|
use ui::button::{Button, ButtonRounded, ButtonVariants};
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
use ui::dock_area::panel::{Panel, PanelEvent};
|
||||||
use ui::input::{InputEvent, InputState, TextInput};
|
use ui::input::{InputEvent, InputState, TextInput};
|
||||||
use ui::popup_menu::PopupMenu;
|
use ui::popup_menu::{PopupMenu, PopupMenuExt};
|
||||||
use ui::{v_flex, ContextModal, IconName, Selectable, Sizable, StyledExt};
|
use ui::{h_flex, v_flex, ContextModal, Icon, IconName, Selectable, Sizable, StyledExt};
|
||||||
|
|
||||||
|
use crate::actions::{RelayStatus, Reload};
|
||||||
|
|
||||||
mod list_item;
|
mod list_item;
|
||||||
|
|
||||||
@@ -69,17 +71,16 @@ impl Sidebar {
|
|||||||
let global_result = cx.new(|_| None);
|
let global_result = cx.new(|_| None);
|
||||||
let cancel_handle = cx.new(|_| None);
|
let cancel_handle = cx.new(|_| None);
|
||||||
|
|
||||||
let find_input = cx.new(|cx| {
|
let find_input =
|
||||||
InputState::new(window, cx).placeholder(t!("sidebar.find_or_start_conversation"))
|
cx.new(|cx| InputState::new(window, cx).placeholder(t!("sidebar.search_label")));
|
||||||
});
|
|
||||||
|
|
||||||
let chats = Registry::global(cx);
|
let registry = Registry::global(cx);
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
subscriptions.push(cx.subscribe_in(
|
subscriptions.push(cx.subscribe_in(
|
||||||
&chats,
|
®istry,
|
||||||
window,
|
window,
|
||||||
move |this, _chats, event, _window, cx| {
|
move |this, _, event, _window, cx| {
|
||||||
if let RegistryEvent::NewRequest(kind) = event {
|
if let RegistryEvent::NewRequest(kind) = event {
|
||||||
this.indicator.update(cx, |this, cx| {
|
this.indicator.update(cx, |this, cx| {
|
||||||
*this = Some(kind.to_owned());
|
*this = Some(kind.to_owned());
|
||||||
@@ -192,11 +193,8 @@ impl Sidebar {
|
|||||||
|
|
||||||
fn debounced_search(&self, window: &mut Window, cx: &mut Context<Self>) -> Task<()> {
|
fn debounced_search(&self, window: &mut Window, cx: &mut Context<Self>) -> Task<()> {
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
this.search(window, cx);
|
||||||
this.search(window, cx);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
})
|
})
|
||||||
@@ -227,18 +225,15 @@ impl Sidebar {
|
|||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
match task.await {
|
match task.await {
|
||||||
Ok(Some(results)) => {
|
Ok(Some(results)) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
let msg = t!("sidebar.empty", query = query_cloned);
|
||||||
let msg = t!("sidebar.empty", query = query_cloned);
|
let rooms = results.into_iter().map(|r| cx.new(|_| r)).collect_vec();
|
||||||
let rooms = results.into_iter().map(|r| cx.new(|_| r)).collect_vec();
|
|
||||||
|
|
||||||
if rooms.is_empty() {
|
if rooms.is_empty() {
|
||||||
window.push_notification(msg, cx);
|
window.push_notification(msg, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.results(rooms, true, window, cx);
|
this.results(rooms, true, window, cx);
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -254,12 +249,10 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
// Async task failed
|
// Async task failed
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
window.push_notification(e.to_string(), cx);
|
||||||
window.push_notification(e.to_string(), cx);
|
this.set_finding(false, window, cx);
|
||||||
this.set_finding(false, window, cx);
|
this.set_cancel_handle(None, cx);
|
||||||
this.set_cancel_handle(None, cx);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -527,6 +520,88 @@ impl Sidebar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_reload(&mut self, _ev: &Reload, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
Registry::global(cx).update(cx, |this, cx| {
|
||||||
|
this.load_rooms(window, cx);
|
||||||
|
});
|
||||||
|
window.push_notification(t!("common.refreshed"), cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_manage(&mut self, _ev: &RelayStatus, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let task: Task<Result<Vec<Relay>, Error>> = cx.background_spawn(async move {
|
||||||
|
let client = nostr_client();
|
||||||
|
let css = css();
|
||||||
|
let subscription = client.subscription(&css.gift_wrap_sub_id).await;
|
||||||
|
let mut relays: Vec<Relay> = vec![];
|
||||||
|
|
||||||
|
for (url, _filter) in subscription.into_iter() {
|
||||||
|
relays.push(client.pool().relay(url).await?);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(relays)
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
|
if let Ok(relays) = task.await {
|
||||||
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
this.manage_relays(relays, window, cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn manage_relays(&mut self, relays: Vec<Relay>, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
window.open_modal(cx, move |this, _window, cx| {
|
||||||
|
this.show_close(true)
|
||||||
|
.overlay_closable(true)
|
||||||
|
.keyboard(true)
|
||||||
|
.title(shared_t!("manage_relays.modal"))
|
||||||
|
.child(v_flex().pb_4().gap_2().children({
|
||||||
|
let mut items = Vec::with_capacity(relays.len());
|
||||||
|
|
||||||
|
for relay in relays.clone().into_iter() {
|
||||||
|
let url = relay.url().to_string();
|
||||||
|
let time = relay.stats().connected_at().to_ago();
|
||||||
|
let connected = relay.is_connected();
|
||||||
|
|
||||||
|
items.push(
|
||||||
|
h_flex()
|
||||||
|
.h_8()
|
||||||
|
.px_2()
|
||||||
|
.justify_between()
|
||||||
|
.text_xs()
|
||||||
|
.bg(cx.theme().elevated_surface_background)
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.font_semibold()
|
||||||
|
.child(
|
||||||
|
Icon::new(IconName::Signal)
|
||||||
|
.small()
|
||||||
|
.text_color(cx.theme().danger_active)
|
||||||
|
.when(connected, |this| {
|
||||||
|
this.text_color(gpui::green().alpha(0.75))
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(url),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_right()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(shared_t!("manage_relays.time", t = time)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
items
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn list_items(
|
fn list_items(
|
||||||
&self,
|
&self,
|
||||||
rooms: &[Entity<Room>],
|
rooms: &[Entity<Room>],
|
||||||
@@ -609,7 +684,17 @@ impl Render for Sidebar {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get total rooms count
|
||||||
|
let mut total_rooms = rooms.len();
|
||||||
|
|
||||||
|
// Add 3 dummy rooms to display as skeletons
|
||||||
|
if registry.unwrapping_status.read(cx) != &UnwrappingStatus::Complete {
|
||||||
|
total_rooms += 3
|
||||||
|
}
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
|
.on_action(cx.listener(Self::on_reload))
|
||||||
|
.on_action(cx.listener(Self::on_manage))
|
||||||
.image_cache(self.image_cache.clone())
|
.image_cache(self.image_cache.clone())
|
||||||
.size_full()
|
.size_full()
|
||||||
.relative()
|
.relative()
|
||||||
@@ -632,7 +717,7 @@ impl Render for Sidebar {
|
|||||||
.suffix(
|
.suffix(
|
||||||
Button::new("find")
|
Button::new("find")
|
||||||
.icon(IconName::Search)
|
.icon(IconName::Search)
|
||||||
.tooltip(t!("sidebar.press_enter_to_search"))
|
.tooltip(t!("sidebar.search_tooltip"))
|
||||||
.transparent()
|
.transparent()
|
||||||
.small(),
|
.small(),
|
||||||
),
|
),
|
||||||
@@ -664,6 +749,7 @@ impl Render for Sidebar {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.small()
|
.small()
|
||||||
|
.cta()
|
||||||
.bold()
|
.bold()
|
||||||
.secondary()
|
.secondary()
|
||||||
.rounded(ButtonRounded::Full)
|
.rounded(ButtonRounded::Full)
|
||||||
@@ -684,6 +770,7 @@ impl Render for Sidebar {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.small()
|
.small()
|
||||||
|
.cta()
|
||||||
.bold()
|
.bold()
|
||||||
.secondary()
|
.secondary()
|
||||||
.rounded(ButtonRounded::Full)
|
.rounded(ButtonRounded::Full)
|
||||||
@@ -691,12 +778,37 @@ impl Render for Sidebar {
|
|||||||
.on_click(cx.listener(|this, _, _, cx| {
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
this.set_filter(RoomKind::default(), cx);
|
this.set_filter(RoomKind::default(), cx);
|
||||||
})),
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.justify_end()
|
||||||
|
.items_center()
|
||||||
|
.text_xs()
|
||||||
|
.child(
|
||||||
|
Button::new("option")
|
||||||
|
.icon(IconName::Ellipsis)
|
||||||
|
.xsmall()
|
||||||
|
.ghost()
|
||||||
|
.rounded(ButtonRounded::Full)
|
||||||
|
.popup_menu(move |this, _window, _cx| {
|
||||||
|
this.menu(
|
||||||
|
t!("sidebar.reload_menu"),
|
||||||
|
Box::new(Reload),
|
||||||
|
)
|
||||||
|
.menu(
|
||||||
|
t!("sidebar.status_menu"),
|
||||||
|
Box::new(RelayStatus),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
uniform_list(
|
uniform_list(
|
||||||
"rooms",
|
"rooms",
|
||||||
rooms.len(),
|
total_rooms,
|
||||||
cx.processor(move |this, range, _window, cx| {
|
cx.processor(move |this, range, _window, cx| {
|
||||||
this.list_items(&rooms, range, cx)
|
this.list_items(&rooms, range, cx)
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ edition.workspace = true
|
|||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nostr-connect.workspace = true
|
|
||||||
nostr-sdk.workspace = true
|
nostr-sdk.workspace = true
|
||||||
dirs.workspace = true
|
dirs.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
futures.workspace = true
|
flume.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ pub const NIP17_RELAYS: [&str; 2] = ["wss://nip17.com", "wss://auth.nostr1.com"]
|
|||||||
pub const NOSTR_CONNECT_RELAY: &str = "wss://relay.nsec.app";
|
pub const NOSTR_CONNECT_RELAY: &str = "wss://relay.nsec.app";
|
||||||
|
|
||||||
/// Default retry count for fetching NIP-17 relays
|
/// Default retry count for fetching NIP-17 relays
|
||||||
pub const TOTAL_RETRY: u64 = 2;
|
pub const RELAY_RETRY: u64 = 2;
|
||||||
|
|
||||||
|
/// Default retry count for sending messages
|
||||||
|
pub const SEND_RETRY: u64 = 5;
|
||||||
|
|
||||||
/// Default timeout (in seconds) for Nostr Connect
|
/// Default timeout (in seconds) for Nostr Connect
|
||||||
pub const NOSTR_CONNECT_TIMEOUT: u64 = 200;
|
pub const NOSTR_CONNECT_TIMEOUT: u64 = 200;
|
||||||
@@ -48,9 +51,6 @@ pub const METADATA_BATCH_LIMIT: usize = 100;
|
|||||||
/// Maximum timeout for grouping metadata requests. (milliseconds)
|
/// Maximum timeout for grouping metadata requests. (milliseconds)
|
||||||
pub const METADATA_BATCH_TIMEOUT: u64 = 300;
|
pub const METADATA_BATCH_TIMEOUT: u64 = 300;
|
||||||
|
|
||||||
/// Maximum timeout for waiting for finish (seconds)
|
|
||||||
pub const WAIT_FOR_FINISH: u64 = 60;
|
|
||||||
|
|
||||||
/// Default width of the sidebar.
|
/// Default width of the sidebar.
|
||||||
pub const DEFAULT_SIDEBAR_WIDTH: f32 = 240.;
|
pub const DEFAULT_SIDEBAR_WIDTH: f32 = 240.;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use nostr_connect::prelude::*;
|
use flume::{Receiver, Sender};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use paths::nostr_file;
|
use paths::nostr_file;
|
||||||
use smol::channel::{Receiver, Sender};
|
|
||||||
use smol::lock::RwLock;
|
use smol::lock::RwLock;
|
||||||
|
|
||||||
use crate::paths::support_dir;
|
use crate::paths::support_dir;
|
||||||
@@ -12,13 +13,13 @@ use crate::paths::support_dir;
|
|||||||
pub mod constants;
|
pub mod constants;
|
||||||
pub mod paths;
|
pub mod paths;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct AuthReq {
|
pub struct AuthRequest {
|
||||||
pub challenge: String,
|
pub challenge: String,
|
||||||
pub url: RelayUrl,
|
pub url: RelayUrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuthReq {
|
impl AuthRequest {
|
||||||
pub fn new(challenge: impl Into<String>, url: RelayUrl) -> Self {
|
pub fn new(challenge: impl Into<String>, url: RelayUrl) -> Self {
|
||||||
Self {
|
Self {
|
||||||
challenge: challenge.into(),
|
challenge: challenge.into(),
|
||||||
@@ -44,9 +45,17 @@ impl Notice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum UnwrappingStatus {
|
||||||
|
#[default]
|
||||||
|
Initialized,
|
||||||
|
Processing,
|
||||||
|
Complete,
|
||||||
|
}
|
||||||
|
|
||||||
/// Signals sent through the global event channel to notify UI
|
/// Signals sent through the global event channel to notify UI
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum IngesterSignal {
|
pub enum Signal {
|
||||||
/// A signal to notify UI that the client's signer has been set
|
/// A signal to notify UI that the client's signer has been set
|
||||||
SignerSet(PublicKey),
|
SignerSet(PublicKey),
|
||||||
|
|
||||||
@@ -54,7 +63,7 @@ pub enum IngesterSignal {
|
|||||||
SignerUnset,
|
SignerUnset,
|
||||||
|
|
||||||
/// A signal to notify UI that the relay requires authentication
|
/// A signal to notify UI that the relay requires authentication
|
||||||
Auth(AuthReq),
|
Auth(AuthRequest),
|
||||||
|
|
||||||
/// A signal to notify UI that the browser proxy service is down
|
/// A signal to notify UI that the browser proxy service is down
|
||||||
ProxyDown,
|
ProxyDown,
|
||||||
@@ -63,13 +72,10 @@ pub enum IngesterSignal {
|
|||||||
Metadata(Event),
|
Metadata(Event),
|
||||||
|
|
||||||
/// A signal to notify UI that a new gift wrap event has been received
|
/// A signal to notify UI that a new gift wrap event has been received
|
||||||
GiftWrap((EventId, Event)),
|
Message((EventId, Event)),
|
||||||
|
|
||||||
/// A signal to notify UI that all gift wrap events have been processed
|
/// A signal to notify UI that gift wrap process status has changed
|
||||||
Finish,
|
GiftWrapProcess(UnwrappingStatus),
|
||||||
|
|
||||||
/// A signal to notify UI that partial processing of gift wrap events has been completed
|
|
||||||
PartialFinish,
|
|
||||||
|
|
||||||
/// A signal to notify UI that no DM relay for current user was found
|
/// A signal to notify UI that no DM relay for current user was found
|
||||||
DmRelayNotFound,
|
DmRelayNotFound,
|
||||||
@@ -80,8 +86,8 @@ pub enum IngesterSignal {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Ingester {
|
pub struct Ingester {
|
||||||
rx: Receiver<IngesterSignal>,
|
rx: Receiver<Signal>,
|
||||||
tx: Sender<IngesterSignal>,
|
tx: Sender<Signal>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Ingester {
|
impl Default for Ingester {
|
||||||
@@ -92,29 +98,58 @@ impl Default for Ingester {
|
|||||||
|
|
||||||
impl Ingester {
|
impl Ingester {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let (tx, rx) = smol::channel::bounded::<IngesterSignal>(2048);
|
let (tx, rx) = flume::bounded::<Signal>(2048);
|
||||||
Self { rx, tx }
|
Self { rx, tx }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn signals(&self) -> &Receiver<IngesterSignal> {
|
pub fn signals(&self) -> &Receiver<Signal> {
|
||||||
&self.rx
|
&self.rx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send(&self, signal: IngesterSignal) {
|
pub async fn send(&self, signal: Signal) {
|
||||||
if let Err(e) = self.tx.send(signal).await {
|
if let Err(e) = self.tx.send_async(signal).await {
|
||||||
log::error!("Failed to send signal: {e}");
|
log::error!("Failed to send signal: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A simple storage to store all runtime states that using across the application.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct CoopSimpleStorage {
|
||||||
|
pub init_at: Timestamp,
|
||||||
|
pub gift_wrap_sub_id: SubscriptionId,
|
||||||
|
pub gift_wrap_processing: AtomicBool,
|
||||||
|
pub auto_close_opts: Option<SubscribeAutoCloseOptions>,
|
||||||
|
pub sent_ids: RwLock<HashSet<EventId>>,
|
||||||
|
pub resent_ids: RwLock<Vec<Output<EventId>>>,
|
||||||
|
pub resend_queue: RwLock<HashMap<EventId, RelayUrl>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CoopSimpleStorage {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CoopSimpleStorage {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
init_at: Timestamp::now(),
|
||||||
|
gift_wrap_sub_id: SubscriptionId::new("inbox"),
|
||||||
|
gift_wrap_processing: AtomicBool::new(false),
|
||||||
|
auto_close_opts: Some(
|
||||||
|
SubscribeAutoCloseOptions::default().exit_policy(ReqExitPolicy::ExitOnEOSE),
|
||||||
|
),
|
||||||
|
sent_ids: RwLock::new(HashSet::new()),
|
||||||
|
resent_ids: RwLock::new(Vec::new()),
|
||||||
|
resend_queue: RwLock::new(HashMap::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static NOSTR_CLIENT: OnceLock<Client> = OnceLock::new();
|
static NOSTR_CLIENT: OnceLock<Client> = OnceLock::new();
|
||||||
|
|
||||||
static INGESTER: OnceLock<Ingester> = OnceLock::new();
|
static INGESTER: OnceLock<Ingester> = OnceLock::new();
|
||||||
|
static COOP_SIMPLE_STORAGE: OnceLock<CoopSimpleStorage> = OnceLock::new();
|
||||||
static SENT_IDS: OnceLock<RwLock<Vec<EventId>>> = OnceLock::new();
|
|
||||||
|
|
||||||
static CURRENT_TIMESTAMP: OnceLock<Timestamp> = OnceLock::new();
|
|
||||||
|
|
||||||
static FIRST_RUN: OnceLock<bool> = OnceLock::new();
|
static FIRST_RUN: OnceLock<bool> = OnceLock::new();
|
||||||
|
|
||||||
pub fn nostr_client() -> &'static Client {
|
pub fn nostr_client() -> &'static Client {
|
||||||
@@ -132,7 +167,6 @@ pub fn nostr_client() -> &'static Client {
|
|||||||
.gossip(true)
|
.gossip(true)
|
||||||
.automatic_authentication(false)
|
.automatic_authentication(false)
|
||||||
.verify_subscriptions(false)
|
.verify_subscriptions(false)
|
||||||
// Sleep after idle for 30 seconds
|
|
||||||
.sleep_when_idle(SleepWhenIdle::Enabled {
|
.sleep_when_idle(SleepWhenIdle::Enabled {
|
||||||
timeout: Duration::from_secs(30),
|
timeout: Duration::from_secs(30),
|
||||||
});
|
});
|
||||||
@@ -145,12 +179,8 @@ pub fn ingester() -> &'static Ingester {
|
|||||||
INGESTER.get_or_init(Ingester::new)
|
INGESTER.get_or_init(Ingester::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn starting_time() -> &'static Timestamp {
|
pub fn css() -> &'static CoopSimpleStorage {
|
||||||
CURRENT_TIMESTAMP.get_or_init(Timestamp::now)
|
COOP_SIMPLE_STORAGE.get_or_init(CoopSimpleStorage::new)
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sent_ids() -> &'static RwLock<Vec<EventId>> {
|
|
||||||
SENT_IDS.get_or_init(|| RwLock::new(Vec::new()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn first_run() -> &'static bool {
|
pub fn first_run() -> &'static bool {
|
||||||
|
|||||||
@@ -19,4 +19,3 @@ smol.workspace = true
|
|||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
|
||||||
fuzzy-matcher = "0.3.7"
|
fuzzy-matcher = "0.3.7"
|
||||||
hashbrown = "0.15"
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::cmp::Reverse;
|
use std::cmp::Reverse;
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use common::event::EventUtils;
|
use common::event::EventUtils;
|
||||||
use fuzzy_matcher::skim::SkimMatcherV2;
|
use fuzzy_matcher::skim::SkimMatcherV2;
|
||||||
use fuzzy_matcher::FuzzyMatcher;
|
use fuzzy_matcher::FuzzyMatcher;
|
||||||
use global::nostr_client;
|
use global::{nostr_client, UnwrappingStatus};
|
||||||
use gpui::{App, AppContext, Context, Entity, EventEmitter, Global, Task, WeakEntity, Window};
|
use gpui::{App, AppContext, Context, Entity, EventEmitter, Global, Task, WeakEntity, Window};
|
||||||
use hashbrown::{HashMap, HashSet};
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use room::RoomKind;
|
use room::RoomKind;
|
||||||
@@ -41,10 +41,8 @@ pub struct Registry {
|
|||||||
/// Collection of all persons (user profiles)
|
/// Collection of all persons (user profiles)
|
||||||
pub persons: HashMap<PublicKey, Entity<Profile>>,
|
pub persons: HashMap<PublicKey, Entity<Profile>>,
|
||||||
|
|
||||||
/// Indicates if rooms are currently being loaded
|
/// Status of the unwrapping process
|
||||||
///
|
pub unwrapping_status: Entity<UnwrappingStatus>,
|
||||||
/// Always equal to `true` when the app starts
|
|
||||||
pub loading: bool,
|
|
||||||
|
|
||||||
/// Public Key of the current user
|
/// Public Key of the current user
|
||||||
pub identity: Option<PublicKey>,
|
pub identity: Option<PublicKey>,
|
||||||
@@ -73,6 +71,7 @@ impl Registry {
|
|||||||
|
|
||||||
/// Create a new Registry instance
|
/// Create a new Registry instance
|
||||||
pub(crate) fn new(cx: &mut Context<Self>) -> Self {
|
pub(crate) fn new(cx: &mut Context<Self>) -> Self {
|
||||||
|
let unwrapping_status = cx.new(|_| UnwrappingStatus::default());
|
||||||
let mut tasks = smallvec![];
|
let mut tasks = smallvec![];
|
||||||
|
|
||||||
let load_local_persons: Task<Result<Vec<Profile>, Error>> =
|
let load_local_persons: Task<Result<Vec<Profile>, Error>> =
|
||||||
@@ -104,10 +103,10 @@ impl Registry {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
unwrapping_status,
|
||||||
rooms: vec![],
|
rooms: vec![],
|
||||||
persons: HashMap::new(),
|
persons: HashMap::new(),
|
||||||
identity: None,
|
identity: None,
|
||||||
loading: true,
|
|
||||||
_tasks: tasks,
|
_tasks: tasks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,16 +243,24 @@ impl Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the loading status of the registry.
|
/// Set the loading status of the registry.
|
||||||
pub fn set_loading(&mut self, status: bool, cx: &mut Context<Self>) {
|
pub fn set_unwrapping_status(&mut self, status: UnwrappingStatus, cx: &mut Context<Self>) {
|
||||||
self.loading = status;
|
self.unwrapping_status.update(cx, |this, cx| {
|
||||||
cx.notify();
|
*this = status;
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reset the registry.
|
/// Reset the registry.
|
||||||
pub fn reset(&mut self, cx: &mut Context<Self>) {
|
pub fn reset(&mut self, cx: &mut Context<Self>) {
|
||||||
self.rooms = vec![];
|
// Reset the unwrapping status
|
||||||
self.loading = true;
|
self.set_unwrapping_status(UnwrappingStatus::default(), cx);
|
||||||
|
|
||||||
|
// Clear the current identity
|
||||||
self.identity = None;
|
self.identity = None;
|
||||||
|
|
||||||
|
// Clear all current rooms
|
||||||
|
self.rooms.clear();
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,12 +269,13 @@ impl Registry {
|
|||||||
log::info!("Starting to load chat rooms...");
|
log::info!("Starting to load chat rooms...");
|
||||||
|
|
||||||
// Get the contact bypass setting
|
// Get the contact bypass setting
|
||||||
let contact_bypass = AppSettings::get_contact_bypass(cx);
|
let bypass_setting = AppSettings::get_contact_bypass(cx);
|
||||||
|
|
||||||
let task: Task<Result<HashSet<Room>, Error>> = cx.background_spawn(async move {
|
let task: Task<Result<HashSet<Room>, Error>> = cx.background_spawn(async move {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
let signer = client.signer().await?;
|
let signer = client.signer().await?;
|
||||||
let public_key = signer.get_public_key().await?;
|
let public_key = signer.get_public_key().await?;
|
||||||
|
let contacts = client.database().contacts_public_keys(public_key).await?;
|
||||||
|
|
||||||
// Get messages sent by the user
|
// Get messages sent by the user
|
||||||
let send = Filter::new()
|
let send = Filter::new()
|
||||||
@@ -295,17 +303,17 @@ impl Registry {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all public keys from the event
|
// Get all public keys from the event's tags
|
||||||
let public_keys = event.all_pubkeys();
|
let mut public_keys = event.all_pubkeys();
|
||||||
|
public_keys.retain(|pk| pk != &public_key);
|
||||||
|
|
||||||
// Bypass screening flag
|
// Bypass screening flag
|
||||||
let mut bypass = false;
|
let mut bypassed = false;
|
||||||
|
|
||||||
// If user enabled bypass screening for contacts
|
// If the user has enabled bypass screening in settings,
|
||||||
// Check if room's members are in contact with current user
|
// check if any of the room's members are contacts of the current user
|
||||||
if contact_bypass {
|
if bypass_setting {
|
||||||
let contacts = client.database().contacts_public_keys(public_key).await?;
|
bypassed = public_keys.iter().any(|k| contacts.contains(k));
|
||||||
bypass = public_keys.iter().any(|k| contacts.contains(k));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the current user has sent at least one message to this room
|
// Check if the current user has sent at least one message to this room
|
||||||
@@ -320,7 +328,7 @@ impl Registry {
|
|||||||
// Create a new room
|
// Create a new room
|
||||||
let room = Room::new(&event).rearrange_by(public_key);
|
let room = Room::new(&event).rearrange_by(public_key);
|
||||||
|
|
||||||
if is_ongoing || bypass {
|
if is_ongoing || bypassed {
|
||||||
rooms.insert(room.kind(RoomKind::Ongoing));
|
rooms.insert(room.kind(RoomKind::Ongoing));
|
||||||
} else {
|
} else {
|
||||||
rooms.insert(room);
|
rooms.insert(room);
|
||||||
@@ -333,9 +341,11 @@ impl Registry {
|
|||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
match task.await {
|
match task.await {
|
||||||
Ok(rooms) => {
|
Ok(rooms) => {
|
||||||
this.update(cx, |this, cx| {
|
this.update_in(cx, move |_, window, cx| {
|
||||||
this.extend_rooms(rooms, cx);
|
cx.defer_in(window, move |this, _window, cx| {
|
||||||
this.sort(cx);
|
this.extend_rooms(rooms, cx);
|
||||||
|
this.sort(cx);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -348,23 +358,28 @@ impl Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn extend_rooms(&mut self, rooms: HashSet<Room>, cx: &mut Context<Self>) {
|
pub(crate) fn extend_rooms(&mut self, rooms: HashSet<Room>, cx: &mut Context<Self>) {
|
||||||
let mut room_map: HashMap<u64, usize> = HashMap::with_capacity(self.rooms.len());
|
let mut room_map: HashMap<u64, usize> = self
|
||||||
|
.rooms
|
||||||
for (index, room) in self.rooms.iter().enumerate() {
|
.iter()
|
||||||
room_map.insert(room.read(cx).id, index);
|
.enumerate()
|
||||||
}
|
.map(|(idx, room)| (room.read(cx).id, idx))
|
||||||
|
.collect();
|
||||||
|
|
||||||
for new_room in rooms.into_iter() {
|
for new_room in rooms.into_iter() {
|
||||||
// Check if we already have a room with this ID
|
// Check if we already have a room with this ID
|
||||||
if let Some(&index) = room_map.get(&new_room.id) {
|
if let Some(&index) = room_map.get(&new_room.id) {
|
||||||
self.rooms[index].update(cx, |this, cx| {
|
self.rooms[index].update(cx, |this, cx| {
|
||||||
*this = new_room;
|
if new_room.created_at > this.created_at {
|
||||||
cx.notify();
|
*this = new_room;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let new_index = self.rooms.len();
|
let new_room_id = new_room.id;
|
||||||
room_map.insert(new_room.id, new_index);
|
|
||||||
self.rooms.push(cx.new(|_| new_room));
|
self.rooms.push(cx.new(|_| new_room));
|
||||||
|
|
||||||
|
let new_index = self.rooms.len();
|
||||||
|
room_map.insert(new_room_id, new_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,12 +403,14 @@ impl Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Refresh messages for a room in the global registry
|
/// Refresh messages for a room in the global registry
|
||||||
pub fn refresh_rooms(&mut self, ids: Vec<u64>, cx: &mut Context<Self>) {
|
pub fn refresh_rooms(&mut self, ids: Option<Vec<u64>>, cx: &mut Context<Self>) {
|
||||||
for room in self.rooms.iter() {
|
if let Some(ids) = ids {
|
||||||
if ids.contains(&room.read(cx).id) {
|
for room in self.rooms.iter() {
|
||||||
room.update(cx, |this, cx| {
|
if ids.contains(&room.read(cx).id) {
|
||||||
this.emit_refresh(cx);
|
room.update(cx, |this, cx| {
|
||||||
});
|
this.emit_refresh(cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -417,9 +434,13 @@ impl Registry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(room) = self.rooms.iter().find(|room| room.read(cx).id == id) {
|
if let Some(room) = self.rooms.iter().find(|room| room.read(cx).id == id) {
|
||||||
|
let is_new_event = event.created_at > room.read(cx).created_at;
|
||||||
|
|
||||||
// Update room
|
// Update room
|
||||||
room.update(cx, |this, cx| {
|
room.update(cx, |this, cx| {
|
||||||
this.created_at(event.created_at, cx);
|
if is_new_event {
|
||||||
|
this.created_at(event.created_at, cx);
|
||||||
|
}
|
||||||
|
|
||||||
// Set this room is ongoing if the new message is from current user
|
// Set this room is ongoing if the new message is from current user
|
||||||
if author == identity {
|
if author == identity {
|
||||||
@@ -432,8 +453,12 @@ impl Registry {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Re-sort the rooms registry by their created at
|
// Resort all rooms in the registry by their created at (after updated)
|
||||||
self.sort(cx);
|
if is_new_event {
|
||||||
|
cx.defer_in(window, |this, _window, cx| {
|
||||||
|
this.sort(cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let room = Room::new(&event)
|
let room = Room::new(&event)
|
||||||
.kind(RoomKind::default())
|
.kind(RoomKind::default())
|
||||||
|
|||||||
@@ -2,16 +2,37 @@ use std::hash::Hash;
|
|||||||
|
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
User(RenderedMessage),
|
User(RenderedMessage),
|
||||||
System,
|
System(Timestamp),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
pub fn user(user: impl Into<RenderedMessage>) -> Self {
|
pub fn user(user: impl Into<RenderedMessage>) -> Self {
|
||||||
Self::User(user.into())
|
Self::User(user.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn system() -> Self {
|
||||||
|
Self::System(Timestamp::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for Message {
|
||||||
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
|
match (self, other) {
|
||||||
|
(Message::User(a), Message::User(b)) => a.cmp(b),
|
||||||
|
(Message::System(a), Message::System(b)) => a.cmp(b),
|
||||||
|
(Message::User(a), Message::System(b)) => a.created_at.cmp(b),
|
||||||
|
(Message::System(a), Message::User(b)) => a.cmp(&b.created_at),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for Message {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use common::display::ReadableProfile;
|
use common::display::ReadableProfile;
|
||||||
use common::event::EventUtils;
|
use common::event::EventUtils;
|
||||||
use global::nostr_client;
|
use global::constants::SEND_RETRY;
|
||||||
|
use global::{css, nostr_client};
|
||||||
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task};
|
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
@@ -472,7 +474,32 @@ impl Room {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
reports.push(SendReport::output(receiver, output));
|
if output
|
||||||
|
.failed
|
||||||
|
.iter()
|
||||||
|
.any(|(_, msg)| msg.starts_with("auth-required:"))
|
||||||
|
{
|
||||||
|
let id = output.id();
|
||||||
|
|
||||||
|
// Wait for authenticated and resent event successfully
|
||||||
|
for attempt in 0..=SEND_RETRY {
|
||||||
|
// Check if event was successfully resent
|
||||||
|
if let Some(output) =
|
||||||
|
css().resent_ids.read().await.iter().find(|o| o.id() == id)
|
||||||
|
{
|
||||||
|
reports.push(SendReport::output(receiver, output.to_owned()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if attempt == SEND_RETRY {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
smol::Timer::after(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reports.push(SendReport::output(receiver, output));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if let nostr_sdk::client::Error::PrivateMsgRelaysNotFound = e {
|
if let nostr_sdk::client::Error::PrivateMsgRelaysNotFound = e {
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ impl Global for GlobalAppSettings {}
|
|||||||
pub struct AppSettings {
|
pub struct AppSettings {
|
||||||
setting_values: Settings,
|
setting_values: Settings,
|
||||||
_subscriptions: SmallVec<[Subscription; 1]>,
|
_subscriptions: SmallVec<[Subscription; 1]>,
|
||||||
_tasks: SmallVec<[Task<()>; 1]>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppSettings {
|
impl AppSettings {
|
||||||
@@ -113,15 +112,23 @@ impl AppSettings {
|
|||||||
cx.set_global(GlobalAppSettings(state));
|
cx.set_global(GlobalAppSettings(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(cx: &mut Context<Self>) -> Self {
|
fn new(_cx: &mut Context<Self>) -> Self {
|
||||||
let setting_values = Settings::default();
|
Self {
|
||||||
let mut tasks = smallvec![];
|
setting_values: Settings::default(),
|
||||||
|
_subscriptions: smallvec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_settings(&self, cx: &mut Context<Self>) {
|
||||||
let task: Task<Result<Settings, anyhow::Error>> = cx.background_spawn(async move {
|
let task: Task<Result<Settings, anyhow::Error>> = cx.background_spawn(async move {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
|
let signer = client.signer().await?;
|
||||||
|
let public_key = signer.get_public_key().await?;
|
||||||
|
|
||||||
let filter = Filter::new()
|
let filter = Filter::new()
|
||||||
.kind(Kind::ApplicationSpecificData)
|
.kind(Kind::ApplicationSpecificData)
|
||||||
.identifier(SETTINGS_IDENTIFIER)
|
.identifier(SETTINGS_IDENTIFIER)
|
||||||
|
.author(public_key)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if let Some(event) = client.database().query(filter).await?.first_owned() {
|
if let Some(event) = client.database().query(filter).await?.first_owned() {
|
||||||
@@ -131,44 +138,37 @@ impl AppSettings {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tasks.push(
|
cx.spawn(async move |this, cx| {
|
||||||
// Load settings from database
|
if let Ok(settings) = task.await {
|
||||||
cx.spawn(async move |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
if let Ok(settings) = task.await {
|
this.setting_values = settings;
|
||||||
this.update(cx, |this, cx| {
|
cx.notify();
|
||||||
this.setting_values = settings;
|
})
|
||||||
cx.notify();
|
.ok();
|
||||||
})
|
}
|
||||||
.ok();
|
})
|
||||||
}
|
.detach();
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
setting_values,
|
|
||||||
_subscriptions: smallvec![],
|
|
||||||
_tasks: tasks,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_settings(&self, cx: &mut Context<Self>) {
|
pub fn set_settings(&self, cx: &mut Context<Self>) {
|
||||||
if let Ok(content) = serde_json::to_string(&self.setting_values) {
|
if let Ok(content) = serde_json::to_string(&self.setting_values) {
|
||||||
cx.background_spawn(async move {
|
let task: Task<Result<(), anyhow::Error>> = cx.background_spawn(async move {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
let builder = EventBuilder::new(Kind::ApplicationSpecificData, content)
|
let signer = client.signer().await?;
|
||||||
.tags(vec![Tag::identifier(SETTINGS_IDENTIFIER)])
|
let public_key = signer.get_public_key().await?;
|
||||||
.sign(&Keys::generate())
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if let Ok(event) = builder {
|
let event = EventBuilder::new(Kind::ApplicationSpecificData, content)
|
||||||
if let Err(e) = client.database().save_event(&event).await {
|
.tag(Tag::identifier(SETTINGS_IDENTIFIER))
|
||||||
log::error!("Failed to save user settings: {e}");
|
.build(public_key)
|
||||||
} else {
|
.sign(&Keys::generate())
|
||||||
log::info!("New settings have been saved successfully");
|
.await?;
|
||||||
}
|
|
||||||
}
|
client.database().save_event(&event).await?;
|
||||||
})
|
|
||||||
.detach();
|
Ok(())
|
||||||
|
});
|
||||||
|
|
||||||
|
task.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,12 +176,16 @@ impl AppSettings {
|
|||||||
!self.setting_values.authenticated_relays.is_empty() && self.setting_values.auto_auth
|
!self.setting_values.authenticated_relays.is_empty() && self.setting_values.auto_auth
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn auth_relays(&self) -> Vec<RelayUrl> {
|
pub fn is_authenticated(&self, url: &RelayUrl) -> bool {
|
||||||
self.setting_values.authenticated_relays.clone()
|
self.setting_values.authenticated_relays.contains(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_auth_relay(&mut self, relay_url: RelayUrl, cx: &mut Context<Self>) {
|
pub fn push_relay(&mut self, relay_url: &RelayUrl, cx: &mut Context<Self>) {
|
||||||
self.setting_values.authenticated_relays.push(relay_url);
|
if !self.is_authenticated(relay_url) {
|
||||||
cx.notify();
|
self.setting_values
|
||||||
|
.authenticated_relays
|
||||||
|
.push(relay_url.to_owned());
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, relative, AnyElement, App, ClickEvent, Div, ElementId, Hsla, InteractiveElement,
|
div, relative, AnyElement, App, ClickEvent, Div, ElementId, Hsla, InteractiveElement,
|
||||||
IntoElement, MouseButton, ParentElement, RenderOnce, SharedString,
|
IntoElement, MouseButton, ParentElement, RenderOnce, SharedString, Stateful,
|
||||||
StatefulInteractiveElement as _, Styled, Window,
|
StatefulInteractiveElement as _, StyleRefinement, Styled, Window,
|
||||||
};
|
};
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
|
|
||||||
@@ -121,8 +121,8 @@ type OnClick = Option<Box<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>>
|
|||||||
/// A Button element.
|
/// A Button element.
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Button {
|
pub struct Button {
|
||||||
pub base: Div,
|
base: Stateful<Div>,
|
||||||
id: ElementId,
|
style: StyleRefinement,
|
||||||
|
|
||||||
icon: Option<Icon>,
|
icon: Option<Icon>,
|
||||||
label: Option<SharedString>,
|
label: Option<SharedString>,
|
||||||
@@ -156,8 +156,8 @@ impl From<Button> for AnyElement {
|
|||||||
impl Button {
|
impl Button {
|
||||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
base: div().flex_shrink_0(),
|
base: div().id(id.into()).flex_shrink_0(),
|
||||||
id: id.into(),
|
style: StyleRefinement::default(),
|
||||||
icon: None,
|
icon: None,
|
||||||
label: None,
|
label: None,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
@@ -255,14 +255,14 @@ impl Disableable for Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Selectable for Button {
|
impl Selectable for Button {
|
||||||
fn element_id(&self) -> &ElementId {
|
|
||||||
&self.id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn selected(mut self, selected: bool) -> Self {
|
fn selected(mut self, selected: bool) -> Self {
|
||||||
self.selected = selected;
|
self.selected = selected;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_selected(&self) -> bool {
|
||||||
|
self.selected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sizable for Button {
|
impl Sizable for Button {
|
||||||
@@ -280,8 +280,8 @@ impl ButtonVariants for Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Styled for Button {
|
impl Styled for Button {
|
||||||
fn style(&mut self) -> &mut gpui::StyleRefinement {
|
fn style(&mut self) -> &mut StyleRefinement {
|
||||||
self.base.style()
|
&mut self.style
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,11 +308,11 @@ impl RenderOnce for Button {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.base
|
self.base
|
||||||
.id(self.id)
|
.flex_shrink_0()
|
||||||
.flex()
|
.flex()
|
||||||
.items_center()
|
.items_center()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.cursor_pointer()
|
.cursor_default()
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.map(|this| match self.rounded {
|
.map(|this| match self.rounded {
|
||||||
ButtonRounded::Normal => this.rounded(cx.theme().radius),
|
ButtonRounded::Normal => this.rounded(cx.theme().radius),
|
||||||
@@ -359,6 +359,8 @@ impl RenderOnce for Button {
|
|||||||
Size::XSmall => {
|
Size::XSmall => {
|
||||||
if self.icon.is_some() {
|
if self.icon.is_some() {
|
||||||
this.h_6().pl_2().pr_2p5()
|
this.h_6().pl_2().pr_2p5()
|
||||||
|
} else if self.cta {
|
||||||
|
this.h_6().px_4()
|
||||||
} else {
|
} else {
|
||||||
this.h_6().px_2()
|
this.h_6().px_2()
|
||||||
}
|
}
|
||||||
@@ -366,6 +368,8 @@ impl RenderOnce for Button {
|
|||||||
Size::Small => {
|
Size::Small => {
|
||||||
if self.icon.is_some() {
|
if self.icon.is_some() {
|
||||||
this.h_7().pl_2().pr_2p5()
|
this.h_7().pl_2().pr_2p5()
|
||||||
|
} else if self.cta {
|
||||||
|
this.h_7().px_4()
|
||||||
} else {
|
} else {
|
||||||
this.h_7().px_2()
|
this.h_7().px_2()
|
||||||
}
|
}
|
||||||
@@ -388,10 +392,6 @@ impl RenderOnce for Button {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.text_color(normal_style.fg)
|
.text_color(normal_style.fg)
|
||||||
.when(self.selected, |this| {
|
|
||||||
let selected_style = style.selected(window, cx);
|
|
||||||
this.bg(selected_style.bg).text_color(selected_style.fg)
|
|
||||||
})
|
|
||||||
.when(!self.disabled && !self.selected, |this| {
|
.when(!self.disabled && !self.selected, |this| {
|
||||||
this.bg(normal_style.bg)
|
this.bg(normal_style.bg)
|
||||||
.hover(|this| {
|
.hover(|this| {
|
||||||
@@ -403,6 +403,10 @@ impl RenderOnce for Button {
|
|||||||
this.bg(active_style.bg).text_color(active_style.fg)
|
this.bg(active_style.bg).text_color(active_style.fg)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.when(self.selected, |this| {
|
||||||
|
let selected_style = style.selected(window, cx);
|
||||||
|
this.bg(selected_style.bg).text_color(selected_style.fg)
|
||||||
|
})
|
||||||
.when(self.disabled, |this| {
|
.when(self.disabled, |this| {
|
||||||
let disabled_style = style.disabled(window, cx);
|
let disabled_style = style.disabled(window, cx);
|
||||||
this.cursor_not_allowed()
|
this.cursor_not_allowed()
|
||||||
@@ -410,6 +414,7 @@ impl RenderOnce for Button {
|
|||||||
.text_color(disabled_style.fg)
|
.text_color(disabled_style.fg)
|
||||||
.shadow_none()
|
.shadow_none()
|
||||||
})
|
})
|
||||||
|
.refine_style(&self.style)
|
||||||
.child({
|
.child({
|
||||||
h_flex()
|
h_flex()
|
||||||
.id("label")
|
.id("label")
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ impl Disableable for Checkbox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Selectable for Checkbox {
|
impl Selectable for Checkbox {
|
||||||
fn element_id(&self) -> &ElementId {
|
|
||||||
&self.id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn selected(self, selected: bool) -> Self {
|
fn selected(self, selected: bool) -> Self {
|
||||||
self.checked(selected)
|
self.checked(selected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_selected(&self) -> bool {
|
||||||
|
self.checked
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderOnce for Checkbox {
|
impl RenderOnce for Checkbox {
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ pub enum IconName {
|
|||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
ArrowUp,
|
ArrowUp,
|
||||||
ArrowUpCircle,
|
|
||||||
Bell,
|
|
||||||
CaretUp,
|
CaretUp,
|
||||||
CaretDown,
|
CaretDown,
|
||||||
CaretDownFill,
|
CaretDownFill,
|
||||||
@@ -28,7 +26,6 @@ pub enum IconName {
|
|||||||
CloseCircleFill,
|
CloseCircleFill,
|
||||||
Copy,
|
Copy,
|
||||||
Edit,
|
Edit,
|
||||||
EditFill,
|
|
||||||
Ellipsis,
|
Ellipsis,
|
||||||
Eye,
|
Eye,
|
||||||
EyeOff,
|
EyeOff,
|
||||||
@@ -52,9 +49,8 @@ pub enum IconName {
|
|||||||
Reply,
|
Reply,
|
||||||
Report,
|
Report,
|
||||||
Refresh,
|
Refresh,
|
||||||
Forward,
|
Signal,
|
||||||
Search,
|
Search,
|
||||||
SearchFill,
|
|
||||||
Settings,
|
Settings,
|
||||||
SortAscending,
|
SortAscending,
|
||||||
SortDescending,
|
SortDescending,
|
||||||
@@ -62,8 +58,8 @@ pub enum IconName {
|
|||||||
ThumbsDown,
|
ThumbsDown,
|
||||||
ThumbsUp,
|
ThumbsUp,
|
||||||
Upload,
|
Upload,
|
||||||
UsersThreeFill,
|
|
||||||
OpenUrl,
|
OpenUrl,
|
||||||
|
Warning,
|
||||||
WindowClose,
|
WindowClose,
|
||||||
WindowMaximize,
|
WindowMaximize,
|
||||||
WindowMinimize,
|
WindowMinimize,
|
||||||
@@ -78,8 +74,6 @@ impl IconName {
|
|||||||
Self::ArrowLeft => "icons/arrow-left.svg",
|
Self::ArrowLeft => "icons/arrow-left.svg",
|
||||||
Self::ArrowRight => "icons/arrow-right.svg",
|
Self::ArrowRight => "icons/arrow-right.svg",
|
||||||
Self::ArrowUp => "icons/arrow-up.svg",
|
Self::ArrowUp => "icons/arrow-up.svg",
|
||||||
Self::ArrowUpCircle => "icons/arrow-up-circle.svg",
|
|
||||||
Self::Bell => "icons/bell.svg",
|
|
||||||
Self::CaretRight => "icons/caret-right.svg",
|
Self::CaretRight => "icons/caret-right.svg",
|
||||||
Self::CaretUp => "icons/caret-up.svg",
|
Self::CaretUp => "icons/caret-up.svg",
|
||||||
Self::CaretDown => "icons/caret-down.svg",
|
Self::CaretDown => "icons/caret-down.svg",
|
||||||
@@ -92,7 +86,6 @@ impl IconName {
|
|||||||
Self::CloseCircleFill => "icons/close-circle-fill.svg",
|
Self::CloseCircleFill => "icons/close-circle-fill.svg",
|
||||||
Self::Copy => "icons/copy.svg",
|
Self::Copy => "icons/copy.svg",
|
||||||
Self::Edit => "icons/edit.svg",
|
Self::Edit => "icons/edit.svg",
|
||||||
Self::EditFill => "icons/edit-fill.svg",
|
|
||||||
Self::Ellipsis => "icons/ellipsis.svg",
|
Self::Ellipsis => "icons/ellipsis.svg",
|
||||||
Self::Eye => "icons/eye.svg",
|
Self::Eye => "icons/eye.svg",
|
||||||
Self::EmojiFill => "icons/emoji-fill.svg",
|
Self::EmojiFill => "icons/emoji-fill.svg",
|
||||||
@@ -116,9 +109,8 @@ impl IconName {
|
|||||||
Self::Reply => "icons/reply.svg",
|
Self::Reply => "icons/reply.svg",
|
||||||
Self::Report => "icons/report.svg",
|
Self::Report => "icons/report.svg",
|
||||||
Self::Refresh => "icons/refresh.svg",
|
Self::Refresh => "icons/refresh.svg",
|
||||||
Self::Forward => "icons/forward.svg",
|
Self::Signal => "icons/signal.svg",
|
||||||
Self::Search => "icons/search.svg",
|
Self::Search => "icons/search.svg",
|
||||||
Self::SearchFill => "icons/search-fill.svg",
|
|
||||||
Self::Settings => "icons/settings.svg",
|
Self::Settings => "icons/settings.svg",
|
||||||
Self::SortAscending => "icons/sort-ascending.svg",
|
Self::SortAscending => "icons/sort-ascending.svg",
|
||||||
Self::SortDescending => "icons/sort-descending.svg",
|
Self::SortDescending => "icons/sort-descending.svg",
|
||||||
@@ -126,8 +118,8 @@ impl IconName {
|
|||||||
Self::ThumbsDown => "icons/thumbs-down.svg",
|
Self::ThumbsDown => "icons/thumbs-down.svg",
|
||||||
Self::ThumbsUp => "icons/thumbs-up.svg",
|
Self::ThumbsUp => "icons/thumbs-up.svg",
|
||||||
Self::Upload => "icons/upload.svg",
|
Self::Upload => "icons/upload.svg",
|
||||||
Self::UsersThreeFill => "icons/users-three-fill.svg",
|
|
||||||
Self::OpenUrl => "icons/open-url.svg",
|
Self::OpenUrl => "icons/open-url.svg",
|
||||||
|
Self::Warning => "icons/warning.svg",
|
||||||
Self::WindowClose => "icons/window-close.svg",
|
Self::WindowClose => "icons/window-close.svg",
|
||||||
Self::WindowMaximize => "icons/window-maximize.svg",
|
Self::WindowMaximize => "icons/window-maximize.svg",
|
||||||
Self::WindowMinimize => "icons/window-minimize.svg",
|
Self::WindowMinimize => "icons/window-minimize.svg",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ impl Indicator {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
size: Size::Small,
|
size: Size::Small,
|
||||||
speed: Duration::from_secs_f64(0.8),
|
speed: Duration::from_secs(1),
|
||||||
icon: Icon::new(IconName::Loader),
|
icon: Icon::new(IconName::Loader),
|
||||||
color: None,
|
color: None,
|
||||||
}
|
}
|
||||||
@@ -52,17 +52,15 @@ impl Sizable for Indicator {
|
|||||||
|
|
||||||
impl RenderOnce for Indicator {
|
impl RenderOnce for Indicator {
|
||||||
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
||||||
div()
|
div().child(
|
||||||
.child(
|
self.icon
|
||||||
self.icon
|
.with_size(self.size)
|
||||||
.with_size(self.size)
|
.when_some(self.color, |this, color| this.text_color(color))
|
||||||
.when_some(self.color, |this, color| this.text_color(color))
|
.with_animation(
|
||||||
.with_animation(
|
"circle",
|
||||||
"circle",
|
Animation::new(self.speed).repeat().with_easing(ease_in_out),
|
||||||
Animation::new(self.speed).repeat().with_easing(ease_in_out),
|
|this, delta| this.transform(Transformation::rotate(percentage(delta))),
|
||||||
|this, delta| this.transform(Transformation::rotate(percentage(delta))),
|
),
|
||||||
),
|
)
|
||||||
)
|
|
||||||
.into_element()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ type Suffix = Option<Box<dyn Fn(&mut Window, &mut App) -> AnyElement + 'static>>
|
|||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct ListItem {
|
pub struct ListItem {
|
||||||
id: ElementId,
|
|
||||||
base: Stateful<Div>,
|
base: Stateful<Div>,
|
||||||
disabled: bool,
|
disabled: bool,
|
||||||
selected: bool,
|
selected: bool,
|
||||||
@@ -30,8 +29,8 @@ pub struct ListItem {
|
|||||||
impl ListItem {
|
impl ListItem {
|
||||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||||
let id: ElementId = id.into();
|
let id: ElementId = id.into();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id: id.clone(),
|
|
||||||
base: h_flex().id(id).gap_x_1().py_1().px_2().text_base(),
|
base: h_flex().id(id).gap_x_1().py_1().px_2().text_base(),
|
||||||
disabled: false,
|
disabled: false,
|
||||||
selected: false,
|
selected: false,
|
||||||
@@ -104,14 +103,14 @@ impl Disableable for ListItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Selectable for ListItem {
|
impl Selectable for ListItem {
|
||||||
fn element_id(&self) -> &ElementId {
|
|
||||||
&self.id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn selected(mut self, selected: bool) -> Self {
|
fn selected(mut self, selected: bool) -> Self {
|
||||||
self.selected = selected;
|
self.selected = selected;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_selected(&self) -> bool {
|
||||||
|
self.selected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Styled for ListItem {
|
impl Styled for ListItem {
|
||||||
|
|||||||
@@ -30,14 +30,10 @@ pub enum NotificationType {
|
|||||||
impl NotificationType {
|
impl NotificationType {
|
||||||
fn icon(&self, cx: &App) -> Icon {
|
fn icon(&self, cx: &App) -> Icon {
|
||||||
match self {
|
match self {
|
||||||
Self::Info => Icon::new(IconName::Info).text_color(cx.theme().element_active),
|
Self::Info => Icon::new(IconName::Info).text_color(cx.theme().element_foreground),
|
||||||
Self::Warning => Icon::new(IconName::Report).text_color(cx.theme().warning_foreground),
|
Self::Success => Icon::new(IconName::Info).text_color(cx.theme().secondary_foreground),
|
||||||
Self::Success => {
|
Self::Warning => Icon::new(IconName::Warning).text_color(cx.theme().warning_foreground),
|
||||||
Icon::new(IconName::CheckCircle).text_color(cx.theme().element_foreground)
|
Self::Error => Icon::new(IconName::Warning).text_color(cx.theme().danger_foreground),
|
||||||
}
|
|
||||||
Self::Error => {
|
|
||||||
Icon::new(IconName::CloseCircle).text_color(cx.theme().danger_foreground)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,7 +295,7 @@ impl Render for Notification {
|
|||||||
.border_1()
|
.border_1()
|
||||||
.border_color(cx.theme().border)
|
.border_color(cx.theme().border)
|
||||||
.bg(cx.theme().surface_background)
|
.bg(cx.theme().surface_background)
|
||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius * 1.6)
|
||||||
.shadow_md()
|
.shadow_md()
|
||||||
.p_2()
|
.p_2()
|
||||||
.gap_3()
|
.gap_3()
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ pub fn init(cx: &mut App) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PopupMenuExt: Styled + Selectable + IntoElement + 'static {
|
pub trait PopupMenuExt: Styled + Selectable + InteractiveElement + IntoElement + 'static {
|
||||||
/// Create a popup menu with the given items, anchored to the TopLeft corner
|
/// Create a popup menu with the given items, anchored to the TopLeft corner
|
||||||
fn popup_menu(
|
fn popup_menu(
|
||||||
self,
|
self,
|
||||||
@@ -60,9 +60,9 @@ pub trait PopupMenuExt: Styled + Selectable + IntoElement + 'static {
|
|||||||
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
||||||
) -> Popover<PopupMenu> {
|
) -> Popover<PopupMenu> {
|
||||||
let style = self.style().clone();
|
let style = self.style().clone();
|
||||||
let element_id = self.element_id();
|
let id = self.interactivity().element_id.clone();
|
||||||
|
|
||||||
Popover::new(SharedString::from(format!("popup-menu:{element_id:?}")))
|
Popover::new(SharedString::from(format!("popup-menu:{id:?}")))
|
||||||
.no_style()
|
.no_style()
|
||||||
.trigger(self)
|
.trigger(self)
|
||||||
.trigger_style(style)
|
.trigger_style(style)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ impl RenderOnce for Skeleton {
|
|||||||
.bg(color)
|
.bg(color)
|
||||||
.with_animation(
|
.with_animation(
|
||||||
"skeleton",
|
"skeleton",
|
||||||
Animation::new(Duration::from_secs(2))
|
Animation::new(Duration::from_secs(3))
|
||||||
.repeat()
|
.repeat()
|
||||||
.with_easing(bounce(ease_in_out)),
|
.with_easing(bounce(ease_in_out)),
|
||||||
move |this, delta| {
|
move |this, delta| {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{div, px, App, Axis, Div, Element, Pixels, Refineable, StyleRefinement, Styled};
|
||||||
div, px, App, Axis, Div, Element, ElementId, Pixels, Refineable, StyleRefinement, Styled,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
|
|
||||||
@@ -105,9 +103,16 @@ impl From<Pixels> for Size {
|
|||||||
|
|
||||||
/// A trait for defining element that can be selected.
|
/// A trait for defining element that can be selected.
|
||||||
pub trait Selectable: Sized {
|
pub trait Selectable: Sized {
|
||||||
fn element_id(&self) -> &ElementId;
|
|
||||||
/// Set the selected state of the element.
|
/// Set the selected state of the element.
|
||||||
fn selected(self, selected: bool) -> Self;
|
fn selected(self, selected: bool) -> Self;
|
||||||
|
|
||||||
|
/// Returns true if the element is selected.
|
||||||
|
fn is_selected(&self) -> bool;
|
||||||
|
|
||||||
|
/// Set is the element mouse right clicked, default do nothing.
|
||||||
|
fn secondary_selected(self, _: bool) -> Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for defining element that can be disabled.
|
/// A trait for defining element that can be disabled.
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ pub mod tab_bar;
|
|||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
id: ElementId,
|
|
||||||
base: Stateful<Div>,
|
base: Stateful<Div>,
|
||||||
label: AnyElement,
|
label: AnyElement,
|
||||||
prefix: Option<AnyElement>,
|
prefix: Option<AnyElement>,
|
||||||
@@ -25,7 +24,6 @@ impl Tab {
|
|||||||
let id: ElementId = id.into();
|
let id: ElementId = id.into();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id: id.clone(),
|
|
||||||
base: div().id(id),
|
base: div().id(id),
|
||||||
label: label.into_any_element(),
|
label: label.into_any_element(),
|
||||||
disabled: false,
|
disabled: false,
|
||||||
@@ -55,14 +53,14 @@ impl Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Selectable for Tab {
|
impl Selectable for Tab {
|
||||||
fn element_id(&self) -> &ElementId {
|
|
||||||
&self.id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn selected(mut self, selected: bool) -> Self {
|
fn selected(mut self, selected: bool) -> Self {
|
||||||
self.selected = selected;
|
self.selected = selected;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_selected(&self) -> bool {
|
||||||
|
self.selected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteractiveElement for Tab {
|
impl InteractiveElement for Tab {
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ common:
|
|||||||
en: "Ignore"
|
en: "Ignore"
|
||||||
relay:
|
relay:
|
||||||
en: "Relay"
|
en: "Relay"
|
||||||
|
relay_invalid:
|
||||||
|
en: "Relay URL is not valid."
|
||||||
|
recommended:
|
||||||
|
en: "Recommended:"
|
||||||
|
|
||||||
auto_update:
|
auto_update:
|
||||||
updating:
|
updating:
|
||||||
@@ -96,9 +100,9 @@ auth:
|
|||||||
label:
|
label:
|
||||||
en: "Authentication Required"
|
en: "Authentication Required"
|
||||||
message:
|
message:
|
||||||
en: "Approve the authentication request to allow Coop to continue getting your messages."
|
en: "Approve the authentication request to allow Coop to continue sending or receiving events."
|
||||||
requests:
|
requests:
|
||||||
en: "You have %{u} total pending authentication requests"
|
en: "You have %{u} pending authentication requests"
|
||||||
|
|
||||||
startup:
|
startup:
|
||||||
client_keys_warning:
|
client_keys_warning:
|
||||||
@@ -167,20 +171,22 @@ login:
|
|||||||
en: "Logging in..."
|
en: "Logging in..."
|
||||||
|
|
||||||
relays:
|
relays:
|
||||||
button_label:
|
button:
|
||||||
en: "Configure the Messaging Relays to receive messages"
|
en: "Configure the Messaging Relays to receive messages"
|
||||||
modal_title:
|
modal:
|
||||||
en: "Set Up Messaging Relays"
|
en: "Set Up Messaging Relays"
|
||||||
description:
|
description:
|
||||||
en: "In order to receive messages from others, you need to set up at least one Messaging Relay."
|
en: "In order to receive messages from others, you need to set up at least one Messaging Relay."
|
||||||
add_some_relays:
|
help_text:
|
||||||
en: "Please add some relays."
|
en: "Please add some relays."
|
||||||
invalid:
|
|
||||||
en: "Relay URL is not valid."
|
|
||||||
empty:
|
empty:
|
||||||
en: "You need to add at least 1 relay to receive messages."
|
en: "You need to add at least 1 relay to receive messages from others."
|
||||||
recommended:
|
|
||||||
en: "Recommended:"
|
manage_relays:
|
||||||
|
modal:
|
||||||
|
en: "Messaging Relay Status"
|
||||||
|
time:
|
||||||
|
en: "Last activity: %{t}"
|
||||||
|
|
||||||
subject:
|
subject:
|
||||||
title:
|
title:
|
||||||
@@ -213,6 +219,14 @@ screening:
|
|||||||
en: "This person is one of your contacts."
|
en: "This person is one of your contacts."
|
||||||
not_contact:
|
not_contact:
|
||||||
en: "This person is not one of your contacts."
|
en: "This person is not one of your contacts."
|
||||||
|
active_label:
|
||||||
|
en: "Activity on Public Relays"
|
||||||
|
active_tooltip:
|
||||||
|
en: "This may be inaccurate if the user only publishes to their private relays."
|
||||||
|
no_active:
|
||||||
|
en: "This person hasn't had any activity."
|
||||||
|
active_at:
|
||||||
|
en: "Last active: %{d}."
|
||||||
mutual_label:
|
mutual_label:
|
||||||
en: "Mutual contacts"
|
en: "Mutual contacts"
|
||||||
mutual:
|
mutual:
|
||||||
@@ -353,9 +367,13 @@ chat:
|
|||||||
en: "%{u} has not set up Messaging Relays, so they won't receive your message."
|
en: "%{u} has not set up Messaging Relays, so they won't receive your message."
|
||||||
|
|
||||||
sidebar:
|
sidebar:
|
||||||
find_or_start_conversation:
|
reload_menu:
|
||||||
|
en: "Reload"
|
||||||
|
status_menu:
|
||||||
|
en: "Relay Status"
|
||||||
|
search_label:
|
||||||
en: "Find or start a conversation"
|
en: "Find or start a conversation"
|
||||||
press_enter_to_search:
|
search_tooltip:
|
||||||
en: "Press Enter to search"
|
en: "Press Enter to search"
|
||||||
empty:
|
empty:
|
||||||
en: "There are no users matching query %{query}"
|
en: "There are no users matching query %{query}"
|
||||||
@@ -380,6 +398,6 @@ sidebar:
|
|||||||
|
|
||||||
loading:
|
loading:
|
||||||
label:
|
label:
|
||||||
en: "Downloading messages"
|
en: "Getting messages. This may take a while..."
|
||||||
tooltip:
|
tooltip:
|
||||||
en: "This may take a while. Please be patient."
|
en: "The progress runs in the background. It doesn't affect your experience."
|
||||||
|
|||||||