wip: refactor

This commit is contained in:
2025-01-02 20:57:59 +07:00
parent 51b392a845
commit 17dc98402f
9 changed files with 63 additions and 46 deletions

View File

@@ -84,7 +84,7 @@ async fn main() {
_ = client.connect().await; _ = client.connect().await;
// Signal // Signal
let (signal_tx, mut signal_rx) = mpsc::channel::<Signal>(4000); // TODO: adjust? let (signal_tx, mut signal_rx) = mpsc::channel::<Signal>(4096); // TODO: adjust?
let (mta_tx, mut mta_rx) = mpsc::unbounded_channel::<PublicKey>(); let (mta_tx, mut mta_rx) = mpsc::unbounded_channel::<PublicKey>();
// Re use sender // Re use sender

View File

@@ -1,4 +1,3 @@
use async_utility::task::spawn;
use gpui::*; use gpui::*;
use nostr_sdk::prelude::*; use nostr_sdk::prelude::*;
use std::time::Duration; use std::time::Duration;
@@ -41,19 +40,21 @@ impl AccountRegistry {
.pubkey(public_key) .pubkey(public_key)
.limit(0); .limit(0);
spawn(async move { cx.background_executor()
// Subscribe for all messages .spawn(async move {
if client // Subscribe for all messages
.subscribe_with_id(all_messages_sub_id, vec![all_messages], Some(opts)) if client
.await .subscribe_with_id(all_messages_sub_id, vec![all_messages], Some(opts))
.is_ok()
{
// Subscribe for new message
_ = client
.subscribe_with_id(new_message_sub_id, vec![new_message], None)
.await .await
} .is_ok()
}); {
// Subscribe for new message
_ = client
.subscribe_with_id(new_message_sub_id, vec![new_message], None)
.await
}
})
.detach();
} }
}) })
.detach(); .detach();

View File

@@ -22,7 +22,6 @@ impl MetadataRegistry {
if !seens.contains(&public_key) { if !seens.contains(&public_key) {
seens.push(public_key); seens.push(public_key);
drop(seens); drop(seens);
if let Some(metadata) = metadata { if let Some(metadata) = metadata {

View File

@@ -57,12 +57,10 @@ impl RenderOnce for RoomMessage {
if let Some(picture) = metadata.picture { if let Some(picture) = metadata.picture {
this.child( this.child(
img(format!( img(format!(
"{}/?url={}&w=100&h=100&n=-1", "{}/?url={}&w=100&h=100&fit=cover&mask=circle&n=-1",
IMAGE_SERVICE, picture IMAGE_SERVICE, picture
)) ))
.size_8() .size_8(),
.rounded_full()
.object_fit(ObjectFit::Cover),
) )
} else { } else {
this.child(img("brand/avatar.png").size_8().rounded_full()) this.child(img("brand/avatar.png").size_8().rounded_full())

View File

@@ -64,44 +64,45 @@ impl ContactListItem {
impl Render for ContactListItem { impl Render for ContactListItem {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let fallback = show_npub(self.public_key, 16); let fallback = show_npub(self.public_key, 16);
let mut content = div().h_10().text_sm(); let mut content = div()
.w_full()
.h_10()
.px_2()
.flex()
.items_center()
.gap_2()
.text_sm();
if let Some(metadata) = self.metadata.read(cx).as_ref() { if let Some(metadata) = self.metadata.read(cx).as_ref() {
content = content content = content
.flex()
.items_center()
.gap_2()
.map(|this| { .map(|this| {
if let Some(picture) = metadata.picture.clone() { if let Some(picture) = metadata.picture.clone() {
this.child( this.flex_shrink_0().child(
img(format!("{}/?url={}&w=72&h=72&n=-1", IMAGE_SERVICE, picture)) img(format!(
.size_8() "{}/?url={}&w=72&h=72&fit=cover&mask=circle&n=-1",
.rounded_full() IMAGE_SERVICE, picture
.object_fit(ObjectFit::Cover), ))
.size_8(),
) )
} else { } else {
this.child(img("brand/avatar.png").size_8().rounded_full()) this.flex_shrink_0()
.child(img("brand/avatar.png").size_8().rounded_full())
} }
}) })
.map(|this| { .map(|this| {
if let Some(display_name) = metadata.display_name.clone() { if let Some(display_name) = metadata.display_name.clone() {
this.child(display_name) this.flex_1().child(display_name)
} else { } else {
this.child(fallback) this.flex_1().child(fallback)
} }
}) })
} else { } else {
content = content content = content
.flex()
.items_center()
.gap_2()
.child(img("brand/avatar.png").size_8().rounded_full()) .child(img("brand/avatar.png").size_8().rounded_full())
.child(fallback) .child(fallback)
} }
div() div()
.w_full()
.px_2()
.rounded_md() .rounded_md()
.hover(|this| { .hover(|this| {
this.bg(cx.theme().muted) this.bg(cx.theme().muted)

View File

@@ -6,9 +6,11 @@ use prelude::FluentBuilder;
use ui::{ use ui::{
button::Button, button::Button,
dock::{Panel, PanelEvent, PanelState}, dock::{Panel, PanelEvent, PanelState},
indicator::Indicator,
popup_menu::PopupMenu, popup_menu::PopupMenu,
scroll::ScrollbarAxis, scroll::ScrollbarAxis,
v_flex, StyledExt, theme::ActiveTheme,
v_flex, Sizable, StyledExt,
}; };
use crate::get_client; use crate::get_client;
@@ -120,8 +122,25 @@ impl Render for ContactPanel {
.w_full() .w_full()
.gap_1() .gap_1()
.p_2() .p_2()
.when_some(self.contacts.read(cx).as_ref(), |this, contacts| { .map(|this| {
this.children(contacts.clone()) if let Some(contacts) = self.contacts.read(cx).as_ref() {
this.children(contacts.clone())
} else {
this.w_full()
.h_40()
.flex()
.items_center()
.justify_center()
.child(
div()
.flex()
.items_center()
.gap_1p5()
.text_color(cx.theme().muted_foreground)
.child(Indicator::new().small())
.child(div().text_xs().child("Loading")),
)
}
}) })
} }
} }

View File

@@ -95,10 +95,11 @@ impl Render for InboxListItem {
.map(|this| { .map(|this| {
if let Some(picture) = metadata.picture.clone() { if let Some(picture) = metadata.picture.clone() {
this.flex_shrink_0().child( this.flex_shrink_0().child(
img(format!("{}/?url={}&w=72&h=72&n=-1", IMAGE_SERVICE, picture)) img(format!(
.size_6() "{}/?url={}&w=72&h=72&fit=cover&mask=circle&n=-1",
.rounded_full() IMAGE_SERVICE, picture
.object_fit(ObjectFit::Cover), ))
.size_6(),
) )
} else { } else {
this.flex_shrink_0() this.flex_shrink_0()

View File

@@ -45,8 +45,6 @@ impl Inbox {
let keys = m.event.tags.public_keys().copied().collect::<Vec<_>>(); let keys = m.event.tags.public_keys().copied().collect::<Vec<_>>();
let new_id = get_room_id(&m.event.pubkey, &keys); let new_id = get_room_id(&m.event.pubkey, &keys);
drop(keys);
!current_rooms.iter().any(|id| id == &new_id) !current_rooms.iter().any(|id| id == &new_id)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View File

@@ -82,7 +82,7 @@ impl Render for Sidebar {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
v_flex() v_flex()
.scrollable(self.view_id, ScrollbarAxis::Vertical) .scrollable(self.view_id, ScrollbarAxis::Vertical)
.pt_3() .py_3()
.gap_3() .gap_3()
.child( .child(
v_flex() v_flex()