Continue redesign for the v1 stable release #5
@@ -333,19 +333,18 @@ impl ChatRegistry {
|
||||
/// Emit an open room event.
|
||||
///
|
||||
/// If the room is new, add it to the registry.
|
||||
pub fn emit_room(&mut self, room: WeakEntity<Room>, cx: &mut Context<Self>) {
|
||||
if let Some(room) = room.upgrade() {
|
||||
pub fn emit_room(&mut self, room: &Entity<Room>, cx: &mut Context<Self>) {
|
||||
// Get the room's ID.
|
||||
let id = room.read(cx).id;
|
||||
|
||||
// If the room is new, add it to the registry.
|
||||
if !self.rooms.iter().any(|r| r.read(cx).id == id) {
|
||||
self.rooms.insert(0, room);
|
||||
self.rooms.insert(0, room.to_owned());
|
||||
}
|
||||
|
||||
// Emit the open room event.
|
||||
cx.emit(ChatEvent::OpenRoom(id));
|
||||
}
|
||||
}
|
||||
|
||||
/// Close a room.
|
||||
pub fn close_room(&mut self, id: u64, cx: &mut Context<Self>) {
|
||||
|
||||
@@ -75,7 +75,7 @@ pub struct Sidebar {
|
||||
contact_list: Entity<Option<Vec<PublicKey>>>,
|
||||
|
||||
/// Async tasks
|
||||
tasks: SmallVec<[Task<()>; 1]>,
|
||||
tasks: SmallVec<[Task<Result<(), Error>>; 1]>,
|
||||
|
||||
/// Event subscriptions
|
||||
_subscriptions: SmallVec<[Subscription; 1]>,
|
||||
@@ -118,11 +118,11 @@ impl Sidebar {
|
||||
}
|
||||
}
|
||||
InputEvent::Focus => {
|
||||
this.set_input_focus(cx);
|
||||
this.set_input_focus(window, cx);
|
||||
this.get_contact_list(window, cx);
|
||||
}
|
||||
InputEvent::Blur => {
|
||||
this.set_input_focus(cx);
|
||||
this.set_input_focus(window, cx);
|
||||
}
|
||||
};
|
||||
}),
|
||||
@@ -168,16 +168,16 @@ impl Sidebar {
|
||||
Ok(contacts) => {
|
||||
this.update(cx, |this, cx| {
|
||||
this.set_contact_list(contacts, cx);
|
||||
})
|
||||
.ok();
|
||||
})?;
|
||||
}
|
||||
Err(e) => {
|
||||
cx.update(|window, cx| {
|
||||
window.push_notification(Notification::error(e.to_string()), cx);
|
||||
})
|
||||
.ok();
|
||||
})?;
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ impl Sidebar {
|
||||
}
|
||||
|
||||
/// Get all selected public keys in the sidebar.
|
||||
fn selected(&self, cx: &Context<Self>) -> HashSet<PublicKey> {
|
||||
fn get_selected(&self, cx: &Context<Self>) -> HashSet<PublicKey> {
|
||||
self.selected_pkeys.read(cx).clone()
|
||||
}
|
||||
|
||||
@@ -322,26 +322,24 @@ impl Sidebar {
|
||||
let signer_pkey = nostr.read(cx).signer_pkey(cx);
|
||||
|
||||
// Get all selected public keys
|
||||
let receivers = self.selected(cx);
|
||||
let receivers = self.get_selected(cx);
|
||||
|
||||
let task: Task<Result<(), Error>> = cx.spawn_in(window, async move |this, cx| {
|
||||
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||
let public_key = signer_pkey.await?;
|
||||
|
||||
// Create a new room and emit it
|
||||
async_chat.update_in(cx, |this, _window, cx| {
|
||||
let room = cx.new(|_| Room::new(public_key, receivers).kind(RoomKind::Ongoing));
|
||||
this.emit_room(&room, cx);
|
||||
})?;
|
||||
|
||||
// Reset the find panel
|
||||
this.update_in(cx, |this, window, cx| {
|
||||
this.reset(window, cx);
|
||||
})?;
|
||||
|
||||
// Create a new room and emit it
|
||||
async_chat.update_in(cx, |this, _window, cx| {
|
||||
let room = cx.new(|_| Room::new(public_key, receivers).kind(RoomKind::Ongoing));
|
||||
this.emit_room(room.downgrade(), cx);
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
});
|
||||
|
||||
task.detach();
|
||||
}));
|
||||
}
|
||||
|
||||
/// Get the active filter.
|
||||
@@ -369,11 +367,11 @@ impl Sidebar {
|
||||
.enumerate()
|
||||
.map(|(ix, item)| {
|
||||
let room = item.read(cx);
|
||||
let weak_room = item.downgrade();
|
||||
let room_clone = item.clone();
|
||||
let public_key = room.display_member(cx).public_key();
|
||||
let handler = cx.listener(move |_this, _ev, _window, cx| {
|
||||
ChatRegistry::global(cx).update(cx, |s, cx| {
|
||||
s.emit_room(weak_room.clone(), cx);
|
||||
s.emit_room(&room_clone, cx);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -628,12 +626,14 @@ impl Render for Sidebar {
|
||||
.gap_1()
|
||||
.overflow_y_hidden()
|
||||
.when(show_find_panel, |this| {
|
||||
this.gap_2()
|
||||
this.gap_3()
|
||||
.when_some(self.find_results.read(cx).as_ref(), |this, results| {
|
||||
this.child(
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.gap_1()
|
||||
.flex_1()
|
||||
.border_b_1()
|
||||
.border_color(cx.theme().border_variant)
|
||||
.child(
|
||||
div()
|
||||
.text_xs()
|
||||
@@ -657,7 +657,7 @@ impl Render for Sidebar {
|
||||
.when_some(self.contact_list.read(cx).as_ref(), |this, contacts| {
|
||||
this.child(
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.gap_1()
|
||||
.flex_1()
|
||||
.child(
|
||||
div()
|
||||
@@ -708,6 +708,7 @@ impl Render for Sidebar {
|
||||
.label(button_label)
|
||||
.primary()
|
||||
.small()
|
||||
.shadow_lg()
|
||||
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||
this.create_room(window, cx);
|
||||
})),
|
||||
|
||||
Reference in New Issue
Block a user