add trash panel and re-tag stale cached rooms

This commit is contained in:
2026-11-13 21:22:42 +07:00
parent 3484c2c71b
commit eef4acc91f
8 changed files with 300 additions and 21 deletions
+10 -4
View File
@@ -173,14 +173,20 @@ impl Sidebar {
.collect()
}
/// The chat requests awaiting a response.
/// The chat requests awaiting a response, followed by the trash entry when
/// it holds messages that could not be decrypted.
pub(super) fn requests_rows(&self, cx: &App) -> Vec<SidebarRow> {
ChatRegistry::global(cx)
.read(cx)
let chat = ChatRegistry::global(cx).read(cx);
let mut rows: Vec<SidebarRow> = chat
.rooms(&RoomKind::Request, cx)
.into_iter()
.map(|room| SidebarRow::Room { room })
.collect()
.collect();
if chat.trashed_count(cx) > 0 {
rows.push(SidebarRow::Trash);
}
rows
}
/// The overlay with the create button and selection count.
+7 -3
View File
@@ -50,6 +50,8 @@ pub(super) struct RowsSignature {
/// Kinds of the rooms held by the cache; a request can turn ongoing with
/// no event or registry notify the sidebar can hear
room_kinds: Vec<(u64, RoomKind)>,
/// Size of the undecryptable-messages trash, which no notify reaches
trashed: usize,
}
/// Read the id and kind of every room row held by the given cache.
@@ -81,9 +83,10 @@ impl Sidebar {
("sidebar-list", None)
};
let request_count = ChatRegistry::global(cx)
.read(cx)
.count(&RoomKind::Request, cx);
let request_count = {
let chat = ChatRegistry::global(cx).read(cx);
chat.count(&RoomKind::Request, cx) + chat.trashed_count(cx)
};
v_flex()
.size_full()
@@ -218,6 +221,7 @@ impl Sidebar {
pinned_rooms: AppSettings::get_pinned_rooms(cx),
pinned_groups: AppSettings::get_pinned_groups(cx),
room_kinds: room_signature(&self.rows, cx),
trashed: ChatRegistry::global(cx).read(cx).trashed_count(cx),
};
if self.rows_dirty || self.rows_signature != signature {
+31 -1
View File
@@ -1,6 +1,6 @@
use std::ops::Range;
use chat::{Room, RoomKind};
use chat::{ChatRegistry, Room, RoomKind};
use common::TimestampExt;
use gpui::prelude::FluentBuilder;
use gpui::{
@@ -88,6 +88,8 @@ pub(super) enum SidebarRow {
Message {
hit: MessageHit,
},
/// Entry point to the trash panel, shown under requests
Trash,
/// A non-interactive label, such as a search results section.
Heading(&'static str),
Empty(&'static str),
@@ -411,6 +413,34 @@ impl Sidebar {
})
.into_any_element()
}
SidebarRow::Trash => {
let count = ChatRegistry::global(cx).read(cx).trashed_count(cx);
let dock = self.dock.clone();
Nav::new("sidebar-trash")
.label("Trash")
.text_sm()
.when(!hide_avatar, |this| {
this.prefix(Avatar::new(None).seed("trash").small())
})
.suffix(
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.child(SharedString::from(count.to_string())),
)
.on_click(move |_event, window, cx| {
let panel = chat_ui::trash::init(window, cx);
crate::dock::add_panel_to(
&dock,
PanelHandle::new(panel),
DockPlacement::Center,
window,
cx,
);
})
.into_any_element()
}
};
// Keep a small gap between rows so selected rows read as pills.
div().pb_0p5().child(element).into_any_element()