update greeter panel
This commit is contained in:
@@ -10,6 +10,7 @@ use gpui::{
|
|||||||
StatefulInteractiveElement, Styled, Subscription, Task, WeakEntity, Window, div, px, svg,
|
StatefulInteractiveElement, Styled, Subscription, Task, WeakEntity, Window, div, px, svg,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
use person::PersonRegistry;
|
||||||
use smallvec::{SmallVec, smallvec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::{NostrRegistry, StateEvent};
|
use state::{NostrRegistry, StateEvent};
|
||||||
use theme::{ActiveTheme, TextStyle, Typeset as _, button_radius};
|
use theme::{ActiveTheme, TextStyle, Typeset as _, button_radius};
|
||||||
@@ -57,13 +58,14 @@ pub struct GreeterPanel {
|
|||||||
/// The coalesced reload scheduled after registry updates
|
/// The coalesced reload scheduled after registry updates
|
||||||
refresh_task: Option<Task<Result<(), Error>>>,
|
refresh_task: Option<Task<Result<(), Error>>>,
|
||||||
/// Event subscriptions
|
/// Event subscriptions
|
||||||
_subscriptions: SmallVec<[Subscription; 2]>,
|
_subscriptions: SmallVec<[Subscription; 3]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GreeterPanel {
|
impl GreeterPanel {
|
||||||
fn new(dock: WeakEntity<DockArea>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
fn new(dock: WeakEntity<DockArea>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let chat = ChatRegistry::global(cx);
|
let chat = ChatRegistry::global(cx);
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let wot = PersonRegistry::global(cx).read(cx).wot();
|
||||||
|
|
||||||
let mut subscriptions = smallvec![];
|
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(
|
subscriptions.push(
|
||||||
// Reload soon after rooms load, messages arrive, or requests change
|
// Reload soon after rooms load, messages arrive, or requests change
|
||||||
cx.observe(&chat, |this, _, cx| {
|
cx.observe(&chat, |this, _, cx| {
|
||||||
@@ -176,17 +185,35 @@ impl GreeterPanel {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_requests(&mut self, cx: &mut Context<Self>) -> Option<AnyElement> {
|
fn render_requests(&mut self, cx: &mut Context<Self>) -> AnyElement {
|
||||||
if self.requests.is_empty() {
|
// Spam requests stay out of the greeter entirely
|
||||||
return None;
|
let requests: Vec<_> = self
|
||||||
}
|
.requests
|
||||||
|
.iter()
|
||||||
|
.filter(|(room, _)| !room.read(cx).is_spam(cx))
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
|
||||||
let dock = self.dock.clone();
|
let dock = self.dock.clone();
|
||||||
|
|
||||||
let rows: Vec<AnyElement> = self
|
let rows: Vec<AnyElement> = if requests.is_empty() {
|
||||||
.requests
|
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()
|
.iter()
|
||||||
.take(SECTION_SIZE)
|
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, (room, preview))| {
|
.map(|(index, (room, preview))| {
|
||||||
let room = room.clone();
|
let room = room.clone();
|
||||||
@@ -280,16 +307,15 @@ impl GreeterPanel {
|
|||||||
)
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
Some(
|
|
||||||
GroupBox::new()
|
GroupBox::new()
|
||||||
.id("requests")
|
.id("requests")
|
||||||
.title("Requests")
|
.title("Requests")
|
||||||
.fill()
|
.fill()
|
||||||
.child(v_flex().gap_0().w_full().children(rows))
|
.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> {
|
fn render_follow_ups(&mut self, cx: &mut Context<Self>) -> Option<AnyElement> {
|
||||||
@@ -503,7 +529,7 @@ impl Render for GreeterPanel {
|
|||||||
.size_full()
|
.size_full()
|
||||||
.p_2()
|
.p_2()
|
||||||
.gap_6()
|
.gap_6()
|
||||||
.children(self.render_requests(cx))
|
.child(self.render_requests(cx))
|
||||||
.children(self.render_follow_ups(cx))
|
.children(self.render_follow_ups(cx))
|
||||||
.child(self.render_find_friends(cx)),
|
.child(self.render_find_friends(cx)),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user