update greeter panel

This commit is contained in:
2026-10-20 18:16:58 +07:00
parent 4bb658f4f5
commit dd81b95e36
+39 -13
View File
@@ -10,6 +10,7 @@ use gpui::{
StatefulInteractiveElement, Styled, Subscription, Task, WeakEntity, Window, div, px, svg,
};
use nostr_sdk::prelude::*;
use person::PersonRegistry;
use smallvec::{SmallVec, smallvec};
use state::{NostrRegistry, StateEvent};
use theme::{ActiveTheme, TextStyle, Typeset as _, button_radius};
@@ -57,13 +58,14 @@ pub struct GreeterPanel {
/// The coalesced reload scheduled after registry updates
refresh_task: Option<Task<Result<(), Error>>>,
/// Event subscriptions
_subscriptions: SmallVec<[Subscription; 2]>,
_subscriptions: SmallVec<[Subscription; 3]>,
}
impl GreeterPanel {
fn new(dock: WeakEntity<DockArea>, window: &mut Window, cx: &mut Context<Self>) -> Self {
let chat = ChatRegistry::global(cx);
let nostr = NostrRegistry::global(cx);
let wot = PersonRegistry::global(cx).read(cx).wot();
let mut subscriptions = smallvec![];
@@ -76,6 +78,13 @@ impl GreeterPanel {
}),
);
subscriptions.push(
// Redraw when the web of trust loads or changes
cx.subscribe(&wot, |_, _, _, cx| {
cx.notify();
}),
);
subscriptions.push(
// Reload soon after rooms load, messages arrive, or requests change
cx.observe(&chat, |this, _, cx| {
@@ -176,17 +185,35 @@ impl GreeterPanel {
}));
}
fn render_requests(&mut self, cx: &mut Context<Self>) -> Option<AnyElement> {
if self.requests.is_empty() {
return None;
}
fn render_requests(&mut self, cx: &mut Context<Self>) -> AnyElement {
// Spam requests stay out of the greeter entirely
let requests: Vec<_> = self
.requests
.iter()
.filter(|(room, _)| !room.read(cx).is_spam(cx))
.cloned()
.collect();
let dock = self.dock.clone();
let rows: Vec<AnyElement> = self
.requests
let rows: Vec<AnyElement> = if requests.is_empty() {
vec![
h_flex()
.h_16()
.w_full()
.justify_center()
.border_1()
.border_dashed()
.border_color(cx.theme().border)
.rounded(px(button_radius()))
.text_style(TextStyle::Caption)
.text_color(cx.theme().text_faint)
.child("No chat requests")
.into_any_element(),
]
} else {
requests
.iter()
.take(SECTION_SIZE)
.enumerate()
.map(|(index, (room, preview))| {
let room = room.clone();
@@ -280,16 +307,15 @@ impl GreeterPanel {
)
.into_any_element()
})
.collect();
.collect()
};
Some(
GroupBox::new()
.id("requests")
.title("Requests")
.fill()
.child(v_flex().gap_0().w_full().children(rows))
.into_any_element(),
)
.into_any_element()
}
fn render_follow_ups(&mut self, cx: &mut Context<Self>) -> Option<AnyElement> {
@@ -503,7 +529,7 @@ impl Render for GreeterPanel {
.size_full()
.p_2()
.gap_6()
.children(self.render_requests(cx))
.child(self.render_requests(cx))
.children(self.render_follow_ups(cx))
.child(self.render_find_friends(cx)),
)