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;
// 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>();
// Re use sender

View File

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

View File

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

View File

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

View File

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

View File

@@ -6,9 +6,11 @@ use prelude::FluentBuilder;
use ui::{
button::Button,
dock::{Panel, PanelEvent, PanelState},
indicator::Indicator,
popup_menu::PopupMenu,
scroll::ScrollbarAxis,
v_flex, StyledExt,
theme::ActiveTheme,
v_flex, Sizable, StyledExt,
};
use crate::get_client;
@@ -120,8 +122,25 @@ impl Render for ContactPanel {
.w_full()
.gap_1()
.p_2()
.when_some(self.contacts.read(cx).as_ref(), |this, contacts| {
this.children(contacts.clone())
.map(|this| {
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| {
if let Some(picture) = metadata.picture.clone() {
this.flex_shrink_0().child(
img(format!("{}/?url={}&w=72&h=72&n=-1", IMAGE_SERVICE, picture))
.size_6()
.rounded_full()
.object_fit(ObjectFit::Cover),
img(format!(
"{}/?url={}&w=72&h=72&fit=cover&mask=circle&n=-1",
IMAGE_SERVICE, picture
))
.size_6(),
)
} else {
this.flex_shrink_0()

View File

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

View File

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