wip: refactor
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1094,6 +1094,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"coop-ui",
|
"coop-ui",
|
||||||
"dirs 5.0.1",
|
"dirs 5.0.1",
|
||||||
|
"flume",
|
||||||
"gpui",
|
"gpui",
|
||||||
"itertools 0.13.0",
|
"itertools 0.13.0",
|
||||||
"keyring",
|
"keyring",
|
||||||
|
|||||||
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
3
assets/icons/arrow-up-circle.svg
Normal file
3
assets/icons/arrow-up-circle.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 397 B |
3
assets/icons/circle-x.svg
Normal file
3
assets/icons/circle-x.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||||
|
<path fill="#000" 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 12Zm7.53-3.53a.75.75 0 0 0-1.06 1.06L10.94 12l-2.47 2.47a.75.75 0 1 0 1.06 1.06L12 13.06l2.47 2.47a.75.75 0 1 0 1.06-1.06L13.06 12l2.47-2.47a.75.75 0 0 0-1.06-1.06L12 10.94 9.53 8.47Z" clip-rule="evenodd"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 421 B |
3
assets/icons/moon.svg
Normal file
3
assets/icons/moon.svg
Normal file
@@ -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="1.5" d="M21.248 11.811a6.5 6.5 0 0 1-9.06-9.06 9.25 9.25 0 1 0 9.06 9.06Z"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 271 B |
3
assets/icons/plus.svg
Normal file
3
assets/icons/plus.svg
Normal file
@@ -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="1.5" d="M12 3.75V12m0 0v8.25M12 12H3.75M12 12h8.25"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 248 B |
3
assets/icons/sun.svg
Normal file
3
assets/icons/sun.svg
Normal file
@@ -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="1.5" d="M11.998 3.29V1.769M5.84 18.158l-1.077 1.078m7.235 2.997v-1.524m7.235-15.944-1.077 1.077M20.707 12h1.523m-4.074 6.159 1.077 1.077M1.766 12h1.523m1.474-7.235L5.84 5.842m9.87 2.446a5.25 5.25 0 1 1-7.424 7.424 5.25 5.25 0 0 1 7.424-7.424Z"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 440 B |
3
assets/icons/upload.svg
Normal file
3
assets/icons/upload.svg
Normal file
@@ -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="1.5" d="M12 19.25V13m0 0 2.5 2.5M12 13l-2.5 2.5m-2.125 3.75H4.75a2 2 0 0 1-2-2V5.75a2 2 0 0 1 2-2h4.18a2 2 0 0 1 1.664.89l1.11 1.665a1 1 0 0 0 .831.445h6.715a2 2 0 0 1 2 2v8.5a2 2 0 0 1-2 2h-2.625"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 394 B |
@@ -28,3 +28,4 @@ rust-embed.workspace = true
|
|||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
|
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
|
tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
|
||||||
|
flume = "0.11.1"
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ use std::{
|
|||||||
sync::{Arc, OnceLock},
|
sync::{Arc, OnceLock},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{sync::mpsc, time::sleep};
|
||||||
sync::{broadcast, mpsc},
|
|
||||||
time::sleep,
|
|
||||||
};
|
|
||||||
|
|
||||||
use constants::{ALL_MESSAGES_SUB_ID, APP_NAME, FAKE_SIG, METADATA_DELAY, NEW_MESSAGE_SUB_ID};
|
use constants::{ALL_MESSAGES_SUB_ID, APP_NAME, FAKE_SIG, METADATA_DELAY, NEW_MESSAGE_SUB_ID};
|
||||||
use states::{account::AccountRegistry, chat::ChatRegistry, signal::SignalRegistry};
|
use states::{
|
||||||
|
account::AccountRegistry,
|
||||||
|
chat::ChatRegistry,
|
||||||
|
metadata::{MetadataRegistry, Signal},
|
||||||
|
};
|
||||||
use views::app::AppView;
|
use views::app::AppView;
|
||||||
|
|
||||||
pub mod asset;
|
pub mod asset;
|
||||||
@@ -74,23 +75,24 @@ async fn main() {
|
|||||||
// Connect to all relays
|
// Connect to all relays
|
||||||
_ = client.connect().await;
|
_ = client.connect().await;
|
||||||
|
|
||||||
// Channel for metadata signal
|
// Channel for EOSE
|
||||||
let (signal_tx, mut signal_rx) = mpsc::channel::<PublicKey>(1000); // TODO: adjust?
|
// When receive EOSE from relay(s) -> Load all rooms and push it into UI.
|
||||||
|
let (eose_tx, mut eose_rx) = mpsc::channel::<SubscriptionId>(200);
|
||||||
|
|
||||||
// Channel for new chat
|
// Channel for new message
|
||||||
let (new_chat_tx, mut new_chat_rx) = mpsc::channel::<Event>(1000); // TODO: adjust?
|
// Push new message to chat panel or create new chat room if not exist.
|
||||||
|
let (message_tx, message_rx) = flume::unbounded::<Event>();
|
||||||
|
let message_rx_clone = message_rx.clone();
|
||||||
|
|
||||||
// Channel for all chats
|
// Channel for signal
|
||||||
// When receive EOSE from relay(s). Reload UI
|
// Merge all metadata requests into single one.
|
||||||
let (all_chats_tx, mut all_chats_rx) = mpsc::channel::<i32>(1);
|
// Notify to reload element if receive new metadata.
|
||||||
|
let (signal_tx, mut signal_rx) = mpsc::channel::<Signal>(5000);
|
||||||
// Channel for metadata request queue
|
let signal_tx_clone = signal_tx.clone();
|
||||||
let (queue_tx, mut queue_rx) = broadcast::channel::<PublicKey>(100);
|
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let sig = Signature::from_str(FAKE_SIG).unwrap();
|
let sig = Signature::from_str(FAKE_SIG).unwrap();
|
||||||
let all_messages_sub_id = SubscriptionId::new(ALL_MESSAGES_SUB_ID);
|
let new_message = SubscriptionId::new(NEW_MESSAGE_SUB_ID);
|
||||||
let new_message_sub_id = SubscriptionId::new(NEW_MESSAGE_SUB_ID);
|
|
||||||
|
|
||||||
while let Ok(notification) = notifications.recv().await {
|
while let Ok(notification) = notifications.recv().await {
|
||||||
#[allow(clippy::collapsible_match)]
|
#[allow(clippy::collapsible_match)]
|
||||||
@@ -121,32 +123,55 @@ async fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Save rumor to database to further query
|
// Save rumor to database to further query
|
||||||
_ = client.database().save_event(&ev).await;
|
if let Err(e) = client.database().save_event(&ev).await {
|
||||||
|
println!("Save error: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
// Send event back to channel
|
// Send event back to channel
|
||||||
if subscription_id == new_message_sub_id {
|
if subscription_id == new_message {
|
||||||
if let Err(e) = new_chat_tx.send(ev).await {
|
if let Err(e) = message_tx.send_async(ev).await {
|
||||||
println!("Error: {}", e)
|
println!("Error: {}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if event.kind == Kind::Metadata {
|
} else if event.kind == Kind::Metadata {
|
||||||
_ = signal_tx.send(event.pubkey).await;
|
if let Err(e) = signal_tx.send(Signal::DONE(event.pubkey)).await {
|
||||||
|
println!("Error: {}", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if let RelayMessage::EndOfStoredEvents(subscription_id) = message {
|
} else if let RelayMessage::EndOfStoredEvents(subscription_id) = message {
|
||||||
if all_messages_sub_id == subscription_id {
|
if let Err(e) = eose_tx.send(subscription_id).await {
|
||||||
_ = all_chats_tx.send(1).await;
|
println!("Error: {}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tokio::spawn(async move {
|
App::new()
|
||||||
|
.with_assets(Assets)
|
||||||
|
.with_http_client(Arc::new(reqwest_client::ReqwestClient::new()))
|
||||||
|
.run(move |cx| {
|
||||||
|
// Account state
|
||||||
|
AccountRegistry::set_global(cx);
|
||||||
|
// Metadata state
|
||||||
|
MetadataRegistry::set_global(cx, signal_tx_clone);
|
||||||
|
// Chat state
|
||||||
|
ChatRegistry::set_global(cx, message_rx);
|
||||||
|
|
||||||
|
// Initialize components
|
||||||
|
coop_ui::init(cx);
|
||||||
|
|
||||||
|
// Set quit action
|
||||||
|
cx.on_action(quit);
|
||||||
|
|
||||||
|
cx.spawn(|async_cx| async move {
|
||||||
let mut queue: HashSet<PublicKey> = HashSet::new();
|
let mut queue: HashSet<PublicKey> = HashSet::new();
|
||||||
|
|
||||||
while let Ok(public_key) = queue_rx.recv().await {
|
while let Some(signal) = signal_rx.recv().await {
|
||||||
|
match signal {
|
||||||
|
Signal::REQ(public_key) => {
|
||||||
queue.insert(public_key);
|
queue.insert(public_key);
|
||||||
|
|
||||||
// Wait for METADATA_DELAY
|
// Wait for METADATA_DELAY
|
||||||
@@ -161,47 +186,36 @@ async fn main() {
|
|||||||
.kind(Kind::Metadata)
|
.kind(Kind::Metadata)
|
||||||
.limit(total);
|
.limit(total);
|
||||||
|
|
||||||
let opts = SubscribeAutoCloseOptions::default()
|
let opts = SubscribeAutoCloseOptions::default().filter(
|
||||||
.filter(FilterOptions::WaitDurationAfterEOSE(Duration::from_secs(2)));
|
FilterOptions::WaitDurationAfterEOSE(Duration::from_secs(2)),
|
||||||
|
);
|
||||||
|
|
||||||
// Clear queue
|
|
||||||
queue.clear();
|
queue.clear();
|
||||||
|
|
||||||
if let Err(e) = client.subscribe(vec![filter], Some(opts)).await {
|
async_cx
|
||||||
|
.background_executor()
|
||||||
|
.spawn(async move {
|
||||||
|
if let Err(e) =
|
||||||
|
client.subscribe(vec![filter], Some(opts)).await
|
||||||
|
{
|
||||||
println!("Error: {}", e);
|
println!("Error: {}", e);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Signal::DONE(public_key) => {
|
||||||
|
_ = async_cx.update_global::<MetadataRegistry, _>(|state, _| {
|
||||||
|
state.seen(public_key);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
App::new()
|
}
|
||||||
.with_assets(Assets)
|
|
||||||
.with_http_client(Arc::new(reqwest_client::ReqwestClient::new()))
|
|
||||||
.run(move |cx| {
|
|
||||||
// Account state
|
|
||||||
AccountRegistry::set_global(cx);
|
|
||||||
// Chat state
|
|
||||||
ChatRegistry::set_global(cx);
|
|
||||||
// Hold all metadata requests and merged it
|
|
||||||
SignalRegistry::set_global(cx, Arc::new(queue_tx));
|
|
||||||
|
|
||||||
// Initialize components
|
|
||||||
coop_ui::init(cx);
|
|
||||||
|
|
||||||
// Set quit action
|
|
||||||
cx.on_action(quit);
|
|
||||||
|
|
||||||
cx.spawn(|async_cx| async move {
|
|
||||||
while let Some(public_key) = signal_rx.recv().await {
|
|
||||||
_ = async_cx.update_global::<SignalRegistry, _>(|state, _cx| {
|
|
||||||
state.push(public_key);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
cx.spawn(|async_cx| async move {
|
cx.spawn(|async_cx| async move {
|
||||||
while let Some(event) = new_chat_rx.recv().await {
|
while let Ok(event) = message_rx_clone.recv_async().await {
|
||||||
_ = async_cx.update_global::<ChatRegistry, _>(|state, cx| {
|
_ = async_cx.update_global::<ChatRegistry, _>(|state, cx| {
|
||||||
state.push(event, cx);
|
state.push(event, cx);
|
||||||
});
|
});
|
||||||
@@ -210,11 +224,15 @@ async fn main() {
|
|||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
cx.spawn(|async_cx| async move {
|
cx.spawn(|async_cx| async move {
|
||||||
while let Some(_n) = all_chats_rx.recv().await {
|
let all_messages = SubscriptionId::new(ALL_MESSAGES_SUB_ID);
|
||||||
|
|
||||||
|
while let Some(subscription_id) = eose_rx.recv().await {
|
||||||
|
if subscription_id == all_messages {
|
||||||
_ = async_cx.update_global::<ChatRegistry, _>(|state, cx| {
|
_ = async_cx.update_global::<ChatRegistry, _>(|state, cx| {
|
||||||
state.load(cx);
|
state.load(cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ impl AccountRegistry {
|
|||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get(&self) -> Option<PublicKey> {
|
||||||
|
self.public_key
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_user(&mut self, public_key: Option<PublicKey>) {
|
pub fn set_user(&mut self, public_key: Option<PublicKey>) {
|
||||||
self.public_key = public_key
|
self.public_key = public_key
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,32 @@
|
|||||||
|
use flume::Receiver;
|
||||||
use gpui::*;
|
use gpui::*;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use std::cmp::Reverse;
|
|
||||||
|
|
||||||
use crate::get_client;
|
use crate::get_client;
|
||||||
|
|
||||||
pub struct ChatRegistry {
|
pub struct ChatRegistry {
|
||||||
events: Model<Option<Vec<Event>>>,
|
chats: Model<Option<Vec<Event>>>,
|
||||||
|
is_initialized: bool,
|
||||||
|
// Use for receive new message
|
||||||
|
pub(crate) receiver: Receiver<Event>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Global for ChatRegistry {}
|
impl Global for ChatRegistry {}
|
||||||
|
|
||||||
impl ChatRegistry {
|
impl ChatRegistry {
|
||||||
pub fn set_global(cx: &mut AppContext) {
|
pub fn set_global(cx: &mut AppContext, receiver: Receiver<Event>) {
|
||||||
let events = cx.new_model(|_| None);
|
let chats = cx.new_model(|_| None);
|
||||||
|
|
||||||
cx.set_global(Self::new(events));
|
cx.set_global(Self::new(chats, receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(&self, cx: &mut AppContext) {
|
pub fn load(&mut self, cx: &mut AppContext) {
|
||||||
let mut async_cx = cx.to_async();
|
let mut async_cx = cx.to_async();
|
||||||
let async_events = self.events.clone();
|
let async_chats = self.chats.clone();
|
||||||
|
|
||||||
|
if !self.is_initialized {
|
||||||
|
self.is_initialized = true;
|
||||||
|
|
||||||
cx.foreground_executor()
|
cx.foreground_executor()
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
@@ -38,9 +44,8 @@ impl ChatRegistry {
|
|||||||
if let Ok(events) = client.database().query(vec![filter]).await {
|
if let Ok(events) = client.database().query(vec![filter]).await {
|
||||||
events
|
events
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|ev| ev.pubkey != public_key) // Filter messages from current user
|
.filter(|ev| ev.pubkey != public_key) // Filter all messages from current user
|
||||||
.unique_by(|ev| ev.pubkey) // Get unique list
|
.unique_by(|ev| ev.pubkey) // Get unique list
|
||||||
.sorted_by_key(|ev| Reverse(ev.created_at)) // Sort by created at
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
@@ -48,28 +53,40 @@ impl ChatRegistry {
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
async_cx.update_model(&async_events, |a, b| {
|
async_cx.update_model(&async_chats, |a, b| {
|
||||||
*a = Some(events);
|
*a = Some(events);
|
||||||
b.notify();
|
b.notify();
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn push(&self, event: Event, cx: &mut AppContext) {
|
pub fn push(&self, event: Event, cx: &mut AppContext) {
|
||||||
cx.update_model(&self.events, |a, b| {
|
cx.update_model(&self.chats, |a, b| {
|
||||||
if let Some(events) = a {
|
if let Some(chats) = a {
|
||||||
events.push(event);
|
if let Some(index) = chats.iter().position(|c| c.pubkey == event.pubkey) {
|
||||||
|
chats.swap_remove(index);
|
||||||
|
chats.push(event);
|
||||||
|
|
||||||
b.notify();
|
b.notify();
|
||||||
|
} else {
|
||||||
|
chats.push(event);
|
||||||
|
b.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, cx: &WindowContext) -> Option<Vec<Event>> {
|
pub fn get(&self, cx: &WindowContext) -> Option<Vec<Event>> {
|
||||||
self.events.read(cx).clone()
|
self.chats.read(cx).clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(events: Model<Option<Vec<Event>>>) -> Self {
|
fn new(chats: Model<Option<Vec<Event>>>, receiver: Receiver<Event>) -> Self {
|
||||||
Self { events }
|
Self {
|
||||||
|
chats,
|
||||||
|
receiver,
|
||||||
|
is_initialized: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
crates/app/src/states/metadata.rs
Normal file
41
crates/app/src/states/metadata.rs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
use gpui::*;
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum Signal {
|
||||||
|
/// Send
|
||||||
|
DONE(PublicKey),
|
||||||
|
/// Receive
|
||||||
|
REQ(PublicKey),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MetadataRegistry {
|
||||||
|
seens: Vec<PublicKey>,
|
||||||
|
pub reqs: Sender<Signal>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Global for MetadataRegistry {}
|
||||||
|
|
||||||
|
impl MetadataRegistry {
|
||||||
|
pub fn set_global(cx: &mut AppContext, reqs: Sender<Signal>) {
|
||||||
|
cx.set_global(Self::new(reqs));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn contains(&self, public_key: PublicKey) -> bool {
|
||||||
|
self.seens.contains(&public_key)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn seen(&mut self, public_key: PublicKey) {
|
||||||
|
if !self.seens.contains(&public_key) {
|
||||||
|
self.seens.push(public_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new(reqs: Sender<Signal>) -> Self {
|
||||||
|
Self {
|
||||||
|
seens: Vec::new(),
|
||||||
|
reqs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
pub mod account;
|
pub mod account;
|
||||||
pub mod chat;
|
pub mod chat;
|
||||||
pub mod signal;
|
pub mod metadata;
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
use gpui::*;
|
|
||||||
use nostr_sdk::prelude::*;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::sync::broadcast::Sender;
|
|
||||||
|
|
||||||
pub struct SignalRegistry {
|
|
||||||
public_keys: Vec<PublicKey>,
|
|
||||||
pub queue: Arc<Sender<PublicKey>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Global for SignalRegistry {}
|
|
||||||
|
|
||||||
impl SignalRegistry {
|
|
||||||
pub fn set_global(cx: &mut AppContext, queue: Arc<Sender<PublicKey>>) {
|
|
||||||
cx.set_global(Self::new(queue));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn contains(&self, public_key: PublicKey) -> bool {
|
|
||||||
self.public_keys.contains(&public_key)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn push(&mut self, public_key: PublicKey) {
|
|
||||||
self.public_keys.push(public_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_to_queue(&mut self, public_key: PublicKey) {
|
|
||||||
if let Err(e) = self.queue.send(public_key) {
|
|
||||||
println!("Dropped: {}", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new(queue: Arc<Sender<PublicKey>>) -> Self {
|
|
||||||
Self {
|
|
||||||
public_keys: Vec::new(),
|
|
||||||
queue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,7 @@ pub fn ago(time: u64) -> String {
|
|||||||
"now".to_owned()
|
"now".to_owned()
|
||||||
} else if diff < 24 {
|
} else if diff < 24 {
|
||||||
let duration = now.signed_duration_since(input_time);
|
let duration = now.signed_duration_since(input_time);
|
||||||
format!("{} ago", duration.num_hours())
|
format!("{} hours ago", duration.num_hours())
|
||||||
} else {
|
} else {
|
||||||
input_time.format("%b %d").to_string()
|
input_time.format("%b %d").to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use coop_ui::{
|
use coop_ui::{
|
||||||
|
button::{Button, ButtonVariants},
|
||||||
dock::{DockArea, DockItem, DockPlacement},
|
dock::{DockArea, DockItem, DockPlacement},
|
||||||
theme::{ActiveTheme, Theme},
|
theme::{ActiveTheme, Theme, ThemeMode},
|
||||||
Root, TitleBar,
|
IconName, Root, Sizable, TitleBar,
|
||||||
};
|
};
|
||||||
use gpui::*;
|
use gpui::*;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
use prelude::FluentBuilder;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -62,6 +64,18 @@ impl AppView {
|
|||||||
AppView { onboarding, dock }
|
AppView { onboarding, dock }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn change_theme_mode(&mut self, _: &ClickEvent, cx: &mut ViewContext<Self>) {
|
||||||
|
let mode = match cx.theme().mode.is_dark() {
|
||||||
|
true => ThemeMode::Light,
|
||||||
|
false => ThemeMode::Dark,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Change theme
|
||||||
|
Theme::change(mode, cx);
|
||||||
|
// Rerender
|
||||||
|
cx.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
fn init_layout(dock_area: WeakView<DockArea>, cx: &mut WindowContext) {
|
fn init_layout(dock_area: WeakView<DockArea>, cx: &mut WindowContext) {
|
||||||
let left = DockItem::panel(Arc::new(LeftDock::new(cx)));
|
let left = DockItem::panel(Arc::new(LeftDock::new(cx)));
|
||||||
let center = Self::init_dock_items(&dock_area, cx);
|
let center = Self::init_dock_items(&dock_area, cx);
|
||||||
@@ -119,7 +133,33 @@ impl Render for AppView {
|
|||||||
.size_full()
|
.size_full()
|
||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.flex_col()
|
||||||
.child(TitleBar::new())
|
.child(
|
||||||
|
TitleBar::new()
|
||||||
|
// Left side
|
||||||
|
.child(div())
|
||||||
|
// Right side
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_end()
|
||||||
|
.px_2()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
Button::new("theme-mode")
|
||||||
|
.map(|this| {
|
||||||
|
if cx.theme().mode.is_dark() {
|
||||||
|
this.icon(IconName::Sun)
|
||||||
|
} else {
|
||||||
|
this.icon(IconName::Moon)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.small()
|
||||||
|
.ghost()
|
||||||
|
.on_click(cx.listener(Self::change_theme_mode)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
.child(self.dock.clone())
|
.child(self.dock.clone())
|
||||||
} else {
|
} else {
|
||||||
content = content.size_full().child(self.onboarding.clone())
|
content = content.size_full().child(self.onboarding.clone())
|
||||||
|
|||||||
91
crates/app/src/views/dock/chat/form.rs
Normal file
91
crates/app/src/views/dock/chat/form.rs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
use coop_ui::{
|
||||||
|
button::{Button, ButtonVariants},
|
||||||
|
input::{InputEvent, TextInput},
|
||||||
|
theme::ActiveTheme,
|
||||||
|
Icon, IconName,
|
||||||
|
};
|
||||||
|
use gpui::*;
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
|
use crate::get_client;
|
||||||
|
|
||||||
|
pub struct Form {
|
||||||
|
to: PublicKey,
|
||||||
|
input: View<TextInput>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Form {
|
||||||
|
pub fn new(to: PublicKey, cx: &mut ViewContext<'_, Self>) -> Self {
|
||||||
|
let input = cx.new_view(|cx| {
|
||||||
|
TextInput::new(cx)
|
||||||
|
.appearance(false)
|
||||||
|
.text_size(coop_ui::Size::Small)
|
||||||
|
.placeholder("Message...")
|
||||||
|
.cleanable()
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.subscribe(&input, move |form, text_input, input_event, cx| {
|
||||||
|
if let InputEvent::PressEnter = input_event {
|
||||||
|
let content = text_input.read(cx).text().to_string();
|
||||||
|
// TODO: clean up content
|
||||||
|
|
||||||
|
form.send_message(content, cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
Self { to, input }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_message(&mut self, content: String, cx: &mut ViewContext<Self>) {
|
||||||
|
let send_to = self.to;
|
||||||
|
let content_clone = content.clone();
|
||||||
|
|
||||||
|
cx.foreground_executor()
|
||||||
|
.spawn(async move {
|
||||||
|
let client = get_client();
|
||||||
|
let signer = client.signer().await.unwrap();
|
||||||
|
let public_key = signer.get_public_key().await.unwrap();
|
||||||
|
|
||||||
|
match client.send_private_msg(send_to, content, vec![]).await {
|
||||||
|
Ok(_) => {
|
||||||
|
// Send a copy to yourself
|
||||||
|
if let Err(_e) = client
|
||||||
|
.send_private_msg(public_key, content_clone, vec![])
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => todo!(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for Form {
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.h_12()
|
||||||
|
.flex_shrink_0()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.px_2()
|
||||||
|
.child(
|
||||||
|
Button::new("upload")
|
||||||
|
.icon(Icon::new(IconName::Upload))
|
||||||
|
.ghost(),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.flex()
|
||||||
|
.bg(cx.theme().muted)
|
||||||
|
.rounded(px(cx.theme().radius))
|
||||||
|
.px_2()
|
||||||
|
.child(self.input.clone()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,26 @@
|
|||||||
use gpui::*;
|
use gpui::*;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
use crate::get_client;
|
use crate::{get_client, states::chat::ChatRegistry};
|
||||||
|
|
||||||
pub struct Messages {
|
pub struct MessageList {
|
||||||
|
member: PublicKey,
|
||||||
messages: Model<Option<Events>>,
|
messages: Model<Option<Events>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Messages {
|
impl MessageList {
|
||||||
pub fn new(from: PublicKey, cx: &mut ViewContext<'_, Self>) -> Self {
|
pub fn new(from: PublicKey, cx: &mut ViewContext<'_, Self>) -> Self {
|
||||||
let messages = cx.new_model(|_| None);
|
let messages = cx.new_model(|_| None);
|
||||||
let async_messages = messages.clone();
|
|
||||||
|
Self {
|
||||||
|
member: from,
|
||||||
|
messages,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(&self, cx: &mut ViewContext<Self>) {
|
||||||
|
let messages = self.messages.clone();
|
||||||
|
let member = self.member;
|
||||||
|
|
||||||
let mut async_cx = cx.to_async();
|
let mut async_cx = cx.to_async();
|
||||||
|
|
||||||
@@ -20,40 +30,45 @@ impl Messages {
|
|||||||
let signer = client.signer().await.unwrap();
|
let signer = client.signer().await.unwrap();
|
||||||
let public_key = signer.get_public_key().await.unwrap();
|
let public_key = signer.get_public_key().await.unwrap();
|
||||||
|
|
||||||
let recv_filter = Filter::new()
|
let recv = Filter::new()
|
||||||
.kind(Kind::PrivateDirectMessage)
|
.kind(Kind::PrivateDirectMessage)
|
||||||
.author(from)
|
.author(member)
|
||||||
.pubkey(public_key);
|
.pubkey(public_key);
|
||||||
|
|
||||||
let sender_filter = Filter::new()
|
let send = Filter::new()
|
||||||
.kind(Kind::PrivateDirectMessage)
|
.kind(Kind::PrivateDirectMessage)
|
||||||
.author(public_key)
|
.author(public_key)
|
||||||
.pubkey(from);
|
.pubkey(member);
|
||||||
|
|
||||||
let events = async_cx
|
let events = async_cx
|
||||||
.background_executor()
|
.background_executor()
|
||||||
.spawn(async move {
|
.spawn(async move { client.database().query(vec![recv, send]).await })
|
||||||
client
|
|
||||||
.database()
|
|
||||||
.query(vec![recv_filter, sender_filter])
|
|
||||||
.await
|
|
||||||
})
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Ok(events) = events {
|
if let Ok(events) = events {
|
||||||
_ = async_cx.update_model(&async_messages, |a, b| {
|
_ = async_cx.update_model(&messages, |a, b| {
|
||||||
*a = Some(events);
|
*a = Some(events);
|
||||||
b.notify();
|
b.notify();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
Self { messages }
|
pub fn subscribe(&self, cx: &mut ViewContext<Self>) {
|
||||||
|
let receiver = cx.global::<ChatRegistry>().receiver.clone();
|
||||||
|
|
||||||
|
cx.foreground_executor()
|
||||||
|
.spawn(async move {
|
||||||
|
while let Ok(event) = receiver.recv_async().await {
|
||||||
|
println!("New message: {}", event.as_json())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for Messages {
|
impl Render for MessageList {
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||||
let mut content = div().size_full().flex().flex_col().justify_end();
|
let mut content = div().size_full().flex().flex_col().justify_end();
|
||||||
|
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
use coop_ui::{
|
use coop_ui::{
|
||||||
button::Button,
|
button::Button,
|
||||||
button_group::ButtonGroup,
|
|
||||||
dock::{DockItemState, Panel, PanelEvent, TitleStyle},
|
dock::{DockItemState, Panel, PanelEvent, TitleStyle},
|
||||||
input::TextInput,
|
|
||||||
popup_menu::PopupMenu,
|
popup_menu::PopupMenu,
|
||||||
Sizable,
|
|
||||||
};
|
};
|
||||||
|
use form::Form;
|
||||||
use gpui::*;
|
use gpui::*;
|
||||||
use messages::Messages;
|
use list::MessageList;
|
||||||
use nostr_sdk::*;
|
use nostr_sdk::*;
|
||||||
|
|
||||||
pub mod messages;
|
pub mod form;
|
||||||
|
pub mod list;
|
||||||
|
|
||||||
pub struct ChatPanel {
|
pub struct ChatPanel {
|
||||||
// Panel
|
// Panel
|
||||||
@@ -19,17 +18,21 @@ pub struct ChatPanel {
|
|||||||
zoomable: bool,
|
zoomable: bool,
|
||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
// Chat Room
|
// Chat Room
|
||||||
messages: View<Messages>,
|
list: View<MessageList>,
|
||||||
input: View<TextInput>,
|
form: View<Form>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatPanel {
|
impl ChatPanel {
|
||||||
pub fn new(from: PublicKey, cx: &mut WindowContext) -> View<Self> {
|
pub fn new(from: PublicKey, cx: &mut WindowContext) -> View<Self> {
|
||||||
let input = cx.new_view(TextInput::new);
|
let form = cx.new_view(|cx| Form::new(from, cx));
|
||||||
let messages = cx.new_view(|cx| Messages::new(from, cx));
|
let list = cx.new_view(|cx| {
|
||||||
|
let list = MessageList::new(from, cx);
|
||||||
|
// Load messages from database
|
||||||
|
list.init(cx);
|
||||||
|
// Subscribe for new message
|
||||||
|
list.subscribe(cx);
|
||||||
|
|
||||||
input.update(cx, |input, _cx| {
|
list
|
||||||
input.set_placeholder("Message");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.new_view(|cx| Self {
|
cx.new_view(|cx| Self {
|
||||||
@@ -37,8 +40,8 @@ impl ChatPanel {
|
|||||||
closeable: true,
|
closeable: true,
|
||||||
zoomable: true,
|
zoomable: true,
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
messages,
|
list,
|
||||||
input,
|
form,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,22 +94,7 @@ impl Render for ChatPanel {
|
|||||||
.size_full()
|
.size_full()
|
||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.flex_col()
|
||||||
.child(self.messages.clone())
|
.child(self.list.clone())
|
||||||
.child(
|
.child(self.form.clone())
|
||||||
div()
|
|
||||||
.flex_shrink_0()
|
|
||||||
.flex()
|
|
||||||
.items_center()
|
|
||||||
.gap_2()
|
|
||||||
.px_2()
|
|
||||||
.h_11()
|
|
||||||
.child(self.input.clone())
|
|
||||||
.child(
|
|
||||||
ButtonGroup::new("actions")
|
|
||||||
.large()
|
|
||||||
.child(Button::new("upload").label("Upload"))
|
|
||||||
.child(Button::new("send").label("Send")),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use prelude::FluentBuilder;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
get_client,
|
get_client,
|
||||||
states::signal::SignalRegistry,
|
states::metadata::{MetadataRegistry, Signal},
|
||||||
utils::{ago, show_npub},
|
utils::{ago, show_npub},
|
||||||
views::app::AddPanel,
|
views::app::AddPanel,
|
||||||
};
|
};
|
||||||
@@ -153,9 +153,12 @@ impl Chat {
|
|||||||
|
|
||||||
let mut async_cx = cx.to_async();
|
let mut async_cx = cx.to_async();
|
||||||
|
|
||||||
|
let client = get_client();
|
||||||
|
let signal = cx.global::<MetadataRegistry>();
|
||||||
|
|
||||||
|
if !signal.contains(public_key) {
|
||||||
cx.foreground_executor()
|
cx.foreground_executor()
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
let client = get_client();
|
|
||||||
let query = async_cx
|
let query = async_cx
|
||||||
.background_executor()
|
.background_executor()
|
||||||
.spawn(async move { client.database().metadata(public_key).await })
|
.spawn(async move { client.database().metadata(public_key).await })
|
||||||
@@ -169,16 +172,23 @@ impl Chat {
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
} else {
|
||||||
|
let reqs = signal.reqs.clone();
|
||||||
|
|
||||||
cx.update_global::<SignalRegistry, _>(|state, _cx| {
|
cx.foreground_executor()
|
||||||
state.add_to_queue(public_key);
|
.spawn(async move {
|
||||||
});
|
if let Err(e) = reqs.send(Signal::REQ(public_key)).await {
|
||||||
|
println!("Error: {}", e)
|
||||||
cx.observe_global::<SignalRegistry>(|chat, cx| {
|
}
|
||||||
chat.load_profile(cx);
|
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
|
cx.observe_global::<MetadataRegistry>(|view, cx| {
|
||||||
|
view.profile(cx);
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
public_key,
|
public_key,
|
||||||
last_seen,
|
last_seen,
|
||||||
@@ -187,12 +197,11 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_profile(&self, cx: &mut ViewContext<Self>) {
|
fn profile(&self, cx: &mut ViewContext<Self>) {
|
||||||
let public_key = self.public_key;
|
let public_key = self.public_key;
|
||||||
let async_metadata = self.metadata.clone();
|
let async_metadata = self.metadata.clone();
|
||||||
let mut async_cx = cx.to_async();
|
let mut async_cx = cx.to_async();
|
||||||
|
|
||||||
if cx.global::<SignalRegistry>().contains(self.public_key) {
|
|
||||||
cx.foreground_executor()
|
cx.foreground_executor()
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
let client = get_client();
|
let client = get_client();
|
||||||
@@ -211,7 +220,6 @@ impl Chat {
|
|||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Render for Chat {
|
impl Render for Chat {
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use chat::Chat;
|
use chat::Chat;
|
||||||
use coop_ui::{theme::ActiveTheme, v_flex, Collapsible, Icon, IconName, StyledExt};
|
use coop_ui::{theme::ActiveTheme, v_flex, Collapsible, Icon, IconName, StyledExt};
|
||||||
use gpui::*;
|
use gpui::*;
|
||||||
|
use itertools::Itertools;
|
||||||
use prelude::FluentBuilder;
|
use prelude::FluentBuilder;
|
||||||
|
use std::cmp::Reverse;
|
||||||
|
|
||||||
use crate::states::chat::ChatRegistry;
|
use crate::states::{account::AccountRegistry, chat::ChatRegistry};
|
||||||
|
|
||||||
pub mod chat;
|
pub mod chat;
|
||||||
|
|
||||||
@@ -19,7 +20,6 @@ impl Inbox {
|
|||||||
pub fn new(cx: &mut ViewContext<'_, Self>) -> Self {
|
pub fn new(cx: &mut ViewContext<'_, Self>) -> Self {
|
||||||
let chats = cx.new_model(|_| None);
|
let chats = cx.new_model(|_| None);
|
||||||
|
|
||||||
// Reload UI if global state changes
|
|
||||||
cx.observe_global::<ChatRegistry>(|inbox, cx| {
|
cx.observe_global::<ChatRegistry>(|inbox, cx| {
|
||||||
inbox.load(cx);
|
inbox.load(cx);
|
||||||
})
|
})
|
||||||
@@ -39,11 +39,15 @@ impl Inbox {
|
|||||||
|
|
||||||
// Read global chat registry
|
// Read global chat registry
|
||||||
let events = cx.global::<ChatRegistry>().get(cx);
|
let events = cx.global::<ChatRegistry>().get(cx);
|
||||||
|
let current_user = cx.global::<AccountRegistry>().get();
|
||||||
|
|
||||||
|
if let Some(public_key) = current_user {
|
||||||
if let Some(events) = events {
|
if let Some(events) = events {
|
||||||
let chats: Vec<View<Chat>> = events
|
let chats: Vec<View<Chat>> = events
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|event| cx.new_view(|cx| Chat::new(event, cx)))
|
.filter(|ev| ev.pubkey != public_key)
|
||||||
|
.sorted_by_key(|ev| Reverse(ev.created_at))
|
||||||
|
.map(|ev| cx.new_view(|cx| Chat::new(ev, cx)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
cx.update_model(&self.chats, |a, b| {
|
cx.update_model(&self.chats, |a, b| {
|
||||||
@@ -52,6 +56,7 @@ impl Inbox {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn set_loading(&mut self, cx: &mut ViewContext<Self>) {
|
fn set_loading(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
self.is_loading = false;
|
self.is_loading = false;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ pub enum IconName {
|
|||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
ArrowUp,
|
ArrowUp,
|
||||||
|
ArrowUpCircle,
|
||||||
Asterisk,
|
Asterisk,
|
||||||
Bell,
|
Bell,
|
||||||
BookOpen,
|
BookOpen,
|
||||||
@@ -73,6 +74,7 @@ pub enum IconName {
|
|||||||
ThumbsDown,
|
ThumbsDown,
|
||||||
ThumbsUp,
|
ThumbsUp,
|
||||||
TriangleAlert,
|
TriangleAlert,
|
||||||
|
Upload,
|
||||||
WindowClose,
|
WindowClose,
|
||||||
WindowMaximize,
|
WindowMaximize,
|
||||||
WindowMinimize,
|
WindowMinimize,
|
||||||
@@ -87,6 +89,7 @@ impl IconName {
|
|||||||
IconName::ArrowLeft => "icons/arrow-left.svg",
|
IconName::ArrowLeft => "icons/arrow-left.svg",
|
||||||
IconName::ArrowRight => "icons/arrow-right.svg",
|
IconName::ArrowRight => "icons/arrow-right.svg",
|
||||||
IconName::ArrowUp => "icons/arrow-up.svg",
|
IconName::ArrowUp => "icons/arrow-up.svg",
|
||||||
|
IconName::ArrowUpCircle => "icons/arrow-up-circle.svg",
|
||||||
IconName::Asterisk => "icons/asterisk.svg",
|
IconName::Asterisk => "icons/asterisk.svg",
|
||||||
IconName::Bell => "icons/bell.svg",
|
IconName::Bell => "icons/bell.svg",
|
||||||
IconName::BookOpen => "icons/book-open.svg",
|
IconName::BookOpen => "icons/book-open.svg",
|
||||||
@@ -149,6 +152,7 @@ impl IconName {
|
|||||||
IconName::ThumbsDown => "icons/thumbs-down.svg",
|
IconName::ThumbsDown => "icons/thumbs-down.svg",
|
||||||
IconName::ThumbsUp => "icons/thumbs-up.svg",
|
IconName::ThumbsUp => "icons/thumbs-up.svg",
|
||||||
IconName::TriangleAlert => "icons/triangle-alert.svg",
|
IconName::TriangleAlert => "icons/triangle-alert.svg",
|
||||||
|
IconName::Upload => "icons/upload.svg",
|
||||||
IconName::WindowClose => "icons/window-close.svg",
|
IconName::WindowClose => "icons/window-close.svg",
|
||||||
IconName::WindowMaximize => "icons/window-maximize.svg",
|
IconName::WindowMaximize => "icons/window-maximize.svg",
|
||||||
IconName::WindowMinimize => "icons/window-minimize.svg",
|
IconName::WindowMinimize => "icons/window-minimize.svg",
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ pub struct TextInput {
|
|||||||
pub(super) appearance: bool,
|
pub(super) appearance: bool,
|
||||||
pub(super) cleanable: bool,
|
pub(super) cleanable: bool,
|
||||||
pub(super) size: Size,
|
pub(super) size: Size,
|
||||||
|
pub(super) text_size: Size,
|
||||||
pub(super) rows: usize,
|
pub(super) rows: usize,
|
||||||
pattern: Option<regex::Regex>,
|
pattern: Option<regex::Regex>,
|
||||||
validate: Validate,
|
validate: Validate,
|
||||||
@@ -215,6 +216,7 @@ impl TextInput {
|
|||||||
prefix: None,
|
prefix: None,
|
||||||
suffix: None,
|
suffix: None,
|
||||||
size: Size::Medium,
|
size: Size::Medium,
|
||||||
|
text_size: Size::Medium,
|
||||||
pattern: None,
|
pattern: None,
|
||||||
validate: None,
|
validate: None,
|
||||||
rows: 2,
|
rows: 2,
|
||||||
@@ -333,6 +335,12 @@ impl TextInput {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the Input size
|
||||||
|
pub fn text_size(mut self, size: Size) -> Self {
|
||||||
|
self.text_size = size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the appearance of the input field.
|
/// Set the appearance of the input field.
|
||||||
pub fn appearance(mut self, appearance: bool) -> Self {
|
pub fn appearance(mut self, appearance: bool) -> Self {
|
||||||
self.appearance = appearance;
|
self.appearance = appearance;
|
||||||
@@ -1204,6 +1212,7 @@ impl Render for TextInput {
|
|||||||
.line_height(LINE_HEIGHT)
|
.line_height(LINE_HEIGHT)
|
||||||
.input_py(self.size)
|
.input_py(self.size)
|
||||||
.input_h(self.size)
|
.input_h(self.size)
|
||||||
|
.input_text_size(self.text_size)
|
||||||
.cursor_text()
|
.cursor_text()
|
||||||
.when(self.multi_line, |this| {
|
.when(self.multi_line, |this| {
|
||||||
this.on_action(cx.listener(Self::up))
|
this.on_action(cx.listener(Self::up))
|
||||||
|
|||||||
@@ -215,17 +215,22 @@ pub trait Sizable: Sized {
|
|||||||
/// Or a `Pixels` to set a custom size: `px(30.)`
|
/// Or a `Pixels` to set a custom size: `px(30.)`
|
||||||
fn with_size(self, size: impl Into<Size>) -> Self;
|
fn with_size(self, size: impl Into<Size>) -> Self;
|
||||||
|
|
||||||
/// Set to Size::Small
|
|
||||||
fn small(self) -> Self {
|
|
||||||
self.with_size(Size::Small)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set to Size::XSmall
|
/// Set to Size::XSmall
|
||||||
fn xsmall(self) -> Self {
|
fn xsmall(self) -> Self {
|
||||||
self.with_size(Size::XSmall)
|
self.with_size(Size::XSmall)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set to Size::Small
|
||||||
|
fn small(self) -> Self {
|
||||||
|
self.with_size(Size::Small)
|
||||||
|
}
|
||||||
|
|
||||||
/// Set to Size::Medium
|
/// Set to Size::Medium
|
||||||
|
fn medium(self) -> Self {
|
||||||
|
self.with_size(Size::Medium)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set to Size::Large
|
||||||
fn large(self) -> Self {
|
fn large(self) -> Self {
|
||||||
self.with_size(Size::Large)
|
self.with_size(Size::Large)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -527,8 +527,8 @@ impl From<ThemeColor> for Theme {
|
|||||||
} else {
|
} else {
|
||||||
"FreeMono".into()
|
"FreeMono".into()
|
||||||
},
|
},
|
||||||
radius: 4.0,
|
radius: 5.0,
|
||||||
shadow: true,
|
shadow: false,
|
||||||
scrollbar_show: ScrollbarShow::default(),
|
scrollbar_show: ScrollbarShow::default(),
|
||||||
colors,
|
colors,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user