update new chat dialog

This commit is contained in:
2026-09-29 12:46:49 +07:00
parent 0a9301f131
commit 8073c97c5a
2 changed files with 81 additions and 49 deletions
+13 -9
View File
@@ -235,6 +235,17 @@ impl CommunityState {
None => BTreeMap::new(), None => BTreeMap::new(),
}; };
let relays = material
.relays
.iter()
.filter_map(|relay| RelayUrl::parse(relay).ok())
.collect();
let control_root = match &material.control_root {
Some(root) => Some(decode_hex_32(root)?),
None => None,
};
let mut channels = Vec::with_capacity(material.channels.len()); let mut channels = Vec::with_capacity(material.channels.len());
for grant in &material.channels { for grant in &material.channels {
@@ -260,17 +271,10 @@ impl CommunityState {
owner_salt: decode_hex_32(&material.owner_salt)?, owner_salt: decode_hex_32(&material.owner_salt)?,
community_root: decode_hex_32(&material.community_root)?, community_root: decode_hex_32(&material.community_root)?,
root_epoch: material.root_epoch, root_epoch: material.root_epoch,
control_root: match &material.control_root { control_root,
Some(root) => Some(decode_hex_32(root)?),
None => None,
},
control_pks, control_pks,
channels, channels,
relays: material relays,
.relays
.iter()
.filter_map(|relay| RelayUrl::parse(relay).ok())
.collect(),
heads: Vec::new(), heads: Vec::new(),
banned: BTreeSet::new(), banned: BTreeSet::new(),
cursors: BTreeMap::new(), cursors: BTreeMap::new(),
+38 -10
View File
@@ -5,19 +5,21 @@ use anyhow::Error;
use chat::{ChatRegistry, Room, RoomKind}; use chat::{ChatRegistry, Room, RoomKind};
use gpui::prelude::FluentBuilder; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, AppContext, Context, Entity, IntoElement, ParentElement, Render, SharedString, AnyElement, App, AppContext, Context, Entity, InteractiveElement, IntoElement, ParentElement,
Styled, Subscription, Task, WeakEntity, Window, div, px, uniform_list, Render, SharedString, StatefulInteractiveElement as _, Styled, Subscription, Task, WeakEntity,
Window, div, px, uniform_list,
}; };
use nostr_sdk::prelude::*; use nostr_sdk::prelude::*;
use person::PersonRegistry; use person::PersonRegistry;
use state::NostrRegistry; use state::NostrRegistry;
use theme::ActiveTheme; use theme::ActiveTheme;
use ui::avatar::Avatar;
use ui::button::{Button, ButtonVariants}; use ui::button::{Button, ButtonVariants};
use ui::dialog::DialogButtonProps; use ui::dialog::DialogButtonProps;
use ui::dock::{DockArea, DockPlacement, PanelHandle}; use ui::dock::{DockArea, DockPlacement, PanelHandle};
use ui::input::{Input, InputEvent, InputState}; use ui::input::{Input, InputEvent, InputState};
use ui::nav::Nav; use ui::nav::Nav;
use ui::{Disableable, IconName, Selectable, Sizable, WindowExtension, h_flex, v_flex}; use ui::{Disableable, IconName, Sizable, WindowExtension, h_flex, v_flex};
use crate::sidebar::nav_avatar; use crate::sidebar::nav_avatar;
@@ -341,7 +343,6 @@ impl NewChat {
.flatten() .flatten()
.enumerate() .enumerate()
.map(|(offset, public_key)| { .map(|(offset, public_key)| {
let selected = self.members.contains(public_key);
let profile = persons.read(cx).get(public_key, cx); let profile = persons.read(cx).get(public_key, cx);
let public_key = *public_key; let public_key = *public_key;
@@ -352,7 +353,6 @@ impl NewChat {
nav_avatar(Some(profile.avatar_seed()), profile.avatar(), cx), nav_avatar(Some(profile.avatar_seed()), profile.avatar(), cx),
|this, avatar| this.prefix(avatar), |this, avatar| this.prefix(avatar),
) )
.selected(selected)
.on_click(cx.listener(move |this, _event, _window, cx| { .on_click(cx.listener(move |this, _event, _window, cx| {
this.toggle_member(&public_key, cx); this.toggle_member(&public_key, cx);
})) }))
@@ -360,6 +360,35 @@ impl NewChat {
}) })
.collect() .collect()
} }
fn render_members(&self, cx: &mut Context<Self>) -> impl IntoElement {
let persons = PersonRegistry::global(cx);
h_flex()
.flex_wrap()
.gap_1()
.children(self.members.iter().map(|public_key| {
let profile = persons.read(cx).get(public_key, cx);
let public_key = *public_key;
let id = SharedString::from(format!("m-{}", public_key.to_hex()));
h_flex()
.id(id)
.gap_1()
.p_0p5()
.rounded_full()
.bg(cx.theme().ghost_element_background_alt)
.text_size(px(10.))
.hover(|this| this.bg(cx.theme().ghost_element_hover))
.when_some(profile.avatar(), |this, avatar| {
this.child(Avatar::from_source(avatar).xsmall().flex_shrink_0())
})
.child(div().max_w_32().truncate().child(profile.name()))
.on_click(cx.listener(move |this, _event, _window, cx| {
this.toggle_member(&public_key, cx);
}))
}))
}
} }
impl Render for NewChat { impl Render for NewChat {
@@ -370,8 +399,6 @@ impl Render for NewChat {
v_flex() v_flex()
.gap_3() .gap_3()
.child(
v_flex()
.child( .child(
h_flex() h_flex()
.gap_1() .gap_1()
@@ -389,12 +416,14 @@ impl Render for NewChat {
})), })),
), ),
) )
.when(!self.members.is_empty(), |this| {
this.child(self.render_members(cx))
})
.map(|this| { .map(|this| {
if let Some(error) = self.error.clone() { if let Some(error) = self.error.clone() {
this.child( this.child(
div() div()
.text_xs() .text_xs()
.text_center()
.text_color(cx.theme().text_danger) .text_color(cx.theme().text_danger)
.child(error), .child(error),
) )
@@ -406,8 +435,7 @@ impl Render for NewChat {
.child(notice), .child(notice),
) )
} }
}), })
)
.child( .child(
uniform_list( uniform_list(
"contacts", "contacts",