feat: improve chat state

This commit is contained in:
2025-02-10 09:03:29 +07:00
parent 6805ed8be5
commit c4573ef1da
13 changed files with 171 additions and 181 deletions

View File

@@ -26,7 +26,6 @@ anyhow.workspace = true
serde.workspace = true
serde_json.workspace = true
itertools.workspace = true
chrono.workspace = true
dirs.workspace = true
rust-embed.workspace = true
smol.workspace = true

View File

@@ -75,7 +75,7 @@ fn main() {
async fn process_batch(client: &Client, events: &[Cow<'_, Event>]) {
let sig = Signature::from_str(FAKE_SIG).unwrap();
let mut buffer: HashSet<PublicKey> = HashSet::with_capacity(100);
let mut buffer: HashSet<PublicKey> = HashSet::with_capacity(20);
for event in events.iter() {
if let Ok(UnwrappedGift { mut rumor, sender }) =

View File

@@ -1,9 +1,9 @@
use async_utility::task::spawn;
use chat_state::room::Room;
use chat_state::room::{LastSeen, Room};
use common::{
constants::IMAGE_SERVICE,
profile::NostrProfile,
utils::{compare, message_time, nip96_upload},
utils::{compare, nip96_upload},
};
use gpui::{
div, img, list, prelude::FluentBuilder, px, white, AnyElement, App, AppContext, Context,
@@ -207,7 +207,7 @@ impl Chat {
Some(Message::new(
member,
ev.content.into(),
message_time(ev.created_at).into(),
LastSeen(ev.created_at).human_readable(),
))
} else {
None
@@ -237,7 +237,7 @@ impl Chat {
Message::new(
member,
event.content.clone().into(),
message_time(event.created_at).into(),
LastSeen(event.created_at).human_readable(),
)
})
})
@@ -334,7 +334,7 @@ impl Chat {
let message = Message::new(
this.owner.clone(),
content.to_string().into(),
message_time(Timestamp::now()).into(),
LastSeen(Timestamp::now()).human_readable(),
);
// Update message list

View File

@@ -22,12 +22,10 @@ pub struct Relays {
impl Relays {
pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self {
let relays = cx.new(|_| {
let mut list = Vec::with_capacity(10);
list.push(Url::parse("wss://auth.nostr1.com").unwrap());
list.push(Url::parse("wss://relay.0xchat.com").unwrap());
list
vec![
Url::parse("wss://auth.nostr1.com").unwrap(),
Url::parse("wss://relay.0xchat.com").unwrap(),
]
});
let input = cx.new(|cx| {
@@ -186,7 +184,7 @@ impl Render for Relays {
"relays",
total,
move |_, range, _window, cx| {
let mut items = Vec::with_capacity(total);
let mut items = Vec::new();
for ix in range {
let item = relays.get(ix).unwrap().clone().to_string();

View File

@@ -40,7 +40,7 @@ pub struct Compose {
impl Compose {
pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self {
let contacts = cx.new(|_| Vec::with_capacity(200));
let contacts = cx.new(|_| Vec::new());
let selected = cx.new(|_| HashSet::new());
let user_input = cx.new(|cx| {
@@ -157,7 +157,10 @@ impl Compose {
let content = message.to_string();
// Get room title from user's input
let title = Tag::title(self.title_input.read(cx).text().to_string());
let title = Tag::custom(
TagKind::Subject,
vec![self.title_input.read(cx).text().to_string()],
);
// Get all pubkeys
let current_user = current_user.public_key();

View File

@@ -1,6 +1,5 @@
use crate::views::app::{AddPanel, PanelKind};
use chat_state::registry::ChatRegistry;
use common::utils::message_ago;
use gpui::{
div, img, percentage, prelude::FluentBuilder, px, relative, Context, InteractiveElement,
IntoElement, ParentElement, Render, SharedString, StatefulInteractiveElement, Styled,
@@ -75,9 +74,7 @@ impl Inbox {
} else {
this.children(inbox.rooms.iter().map(|model| {
let room = model.read(cx);
let id = room.id;
let room_id: SharedString = id.to_string().into();
let ago: SharedString = message_ago(room.last_seen).into();
let room_id: SharedString = room.id.to_string().into();
div()
.id(room_id)
@@ -115,11 +112,14 @@ impl Inbox {
div()
.flex_shrink_0()
.text_color(cx.theme().base.step(cx, ColorScaleStep::ELEVEN))
.child(ago),
.child(room.last_seen.ago()),
)
.on_click(cx.listener(move |this, _, window, cx| {
this.action(id, window, cx);
}))
.on_click({
let id = room.id;
cx.listener(move |this, _, window, cx| {
this.action(id, window, cx);
})
})
}))
}
})