ui: pins and topics as icon buttons with a count in the chat header
The labelled Pinned Messages and Topics buttons took about 300 px of the header, so the channel's topic was cut first. They are icon buttons now, named in their tooltip, with how many pins and topics the chat has (Bridge.pins-count and topics-count, -1 until the gateway answered). The counts are asked for when a chat comes on screen (a tab, a server, a gateway that connects, another server after a delete), not only when a drawer opens, so they show before. An answer for a chat that was closed meanwhile is dropped, instead of reopening it as a tab named Server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
1 parent
14ea206521
commit
2e3ddc11ec
7 files changed
+63
-11
No files matched your search
@@ -122,6 +122,7 @@ impl App {
|
||||
};
|
||||
if focus {
|
||||
view.current_tab = index;
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
}
|
||||
self.refresh_chat();
|
||||
@@ -138,6 +139,7 @@ impl App {
|
||||
if let Some(id) = self.current {
|
||||
self.fetch_previews(id);
|
||||
}
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
@@ -154,6 +156,7 @@ impl App {
|
||||
let tab = view.tabs.remove(index);
|
||||
view.current_tab = view.current_tab.min(view.tabs.len() - 1);
|
||||
self.engine.send(Command::CloseChat { session: id as u64, target: tab.target });
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
@@ -546,6 +549,8 @@ impl App {
|
||||
bridge.set_has_topics(view.gateway_has(feature::TOPICS));
|
||||
bridge.set_pins_loading(!tab.pins_loaded && view.gateway_has(feature::PINS));
|
||||
bridge.set_topics_loading(!tab.topics_loaded && view.gateway_has(feature::TOPICS));
|
||||
bridge.set_pins_count(vm::chat::known_count(tab.pins_loaded, tab.pins.len()));
|
||||
bridge.set_topics_count(vm::chat::known_count(tab.topics_loaded, tab.topics.len()));
|
||||
let pins: Vec<PinItem> = tab
|
||||
.pins
|
||||
.iter()
|
||||
@@ -778,7 +783,12 @@ impl App {
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
match update {
|
||||
GatewayUpdate::Connected { capabilities, .. }
|
||||
| GatewayUpdate::Capabilities { capabilities } => view.gateway_caps = capabilities,
|
||||
| GatewayUpdate::Capabilities { capabilities } => {
|
||||
view.gateway_caps = capabilities;
|
||||
if current {
|
||||
self.prefetch_counts();
|
||||
}
|
||||
}
|
||||
GatewayUpdate::Disconnected { .. } => {
|
||||
view.gateway_caps.clear();
|
||||
for tab in &mut view.tabs {
|
||||
@@ -786,9 +796,11 @@ impl App {
|
||||
tab.topics_loaded = false;
|
||||
}
|
||||
}
|
||||
// Answers to our requests: a chat closed while they were on
|
||||
// their way (prefetch_counts asks on every change of chat) stays
|
||||
// closed.
|
||||
GatewayUpdate::Pins { target, pins } => {
|
||||
let index = Self::tab_for(view, &target, || "Server".into());
|
||||
let tab = &mut view.tabs[index];
|
||||
let Some(tab) = view.tabs.iter_mut().find(|t| t.target == target) else { return };
|
||||
tab.pins_loaded = true;
|
||||
tab.pins = pins.into_iter().map(|p| pin_row(tab.take_key(), p)).collect();
|
||||
tab.pins.sort_by_key(|p| -p.ts_ms);
|
||||
@@ -805,9 +817,9 @@ impl App {
|
||||
view.tabs[index].pins.retain(|p| p.message.remote_id != Some(message_id));
|
||||
}
|
||||
GatewayUpdate::Topics { target, topics } => {
|
||||
let index = Self::tab_for(view, &target, || "Server".into());
|
||||
view.tabs[index].topics = topics;
|
||||
view.tabs[index].topics_loaded = true;
|
||||
let Some(tab) = view.tabs.iter_mut().find(|t| t.target == target) else { return };
|
||||
tab.topics = topics;
|
||||
tab.topics_loaded = true;
|
||||
}
|
||||
GatewayUpdate::Topic { topic } => {
|
||||
let index = Self::tab_for(view, &topic.target.clone(), || "Server".into());
|
||||
@@ -897,6 +909,20 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
/// Ask the gateway for the current chat's pins and topics until it sent
|
||||
/// them, so the header counts them before their drawers are opened.
|
||||
pub(crate) fn prefetch_counts(&self) {
|
||||
let Some(view) = self.view() else { return };
|
||||
let Some(tab) = view.tabs.get(view.current_tab) else { return };
|
||||
if !tab.pins_loaded && view.gateway_has(feature::PINS) {
|
||||
self.gateway(GatewayRequest::Pins { target: tab.target.clone() });
|
||||
}
|
||||
if !tab.topics_loaded && view.gateway_has(feature::TOPICS) {
|
||||
let target = tab.target.clone();
|
||||
self.gateway(GatewayRequest::Topics { target, include_archived: false });
|
||||
}
|
||||
}
|
||||
|
||||
/// Open the pins of the current chat (loading them once).
|
||||
pub(crate) fn open_pins(&mut self) {
|
||||
let Some(view) = self.view() else { return };
|
||||
|
||||
@@ -259,6 +259,7 @@ impl App {
|
||||
/// Show a server, and observe it.
|
||||
pub(crate) fn select_server(&mut self, id: i64) {
|
||||
self.current = Some(id);
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
self.refresh_all();
|
||||
self.observe(id);
|
||||
@@ -343,6 +344,7 @@ impl App {
|
||||
self.gateways_looked_up.remove(&id);
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.current = self.bookmarks.first().map(|b| b.id);
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
self.refresh_all();
|
||||
}
|
||||
|
||||
@@ -433,6 +433,12 @@ pub fn tab_name<'a>(title: &'a str, target: &ChatTarget) -> &'a str {
|
||||
}
|
||||
}
|
||||
|
||||
/// The count on the chat header's pins or topics button: `n`, or `-1`
|
||||
/// (none shown) until the gateway answered.
|
||||
pub fn known_count(loaded: bool, n: usize) -> i32 {
|
||||
if loaded { i32::try_from(n).unwrap_or(i32::MAX) } else { -1 }
|
||||
}
|
||||
|
||||
/// A chat's last message for a list of chats, on one line ("Mira: the
|
||||
/// banner I promised: guild-banner.png"), and when it came.
|
||||
pub fn preview(message: &ChatMessage) -> (String, String) {
|
||||
@@ -837,6 +843,15 @@ mod tests {
|
||||
assert_eq!(tab_name("@home", &ChatTarget::Channel(4)), "@home");
|
||||
}
|
||||
|
||||
/// The header counts pins and topics only once the gateway sent them.
|
||||
#[test]
|
||||
fn counts_are_unknown_until_loaded() {
|
||||
assert_eq!(known_count(false, 0), -1);
|
||||
assert_eq!(known_count(false, 3), -1);
|
||||
assert_eq!(known_count(true, 0), 0);
|
||||
assert_eq!(known_count(true, 3), 3);
|
||||
}
|
||||
|
||||
/// A run does not wrap: long words (addresses) and long inline code
|
||||
/// are cut so the line can break inside them.
|
||||
#[test]
|
||||
|
||||
@@ -901,6 +901,10 @@ export global Bridge {
|
||||
in property <bool> has-pins;
|
||||
in property <bool> has-reactions;
|
||||
in property <bool> has-topics;
|
||||
// How many pins and topics the current chat has, for the header's
|
||||
// buttons; -1 until the gateway answered.
|
||||
in property <int> pins-count: -1;
|
||||
in property <int> topics-count: -1;
|
||||
// The pins drawer.
|
||||
in property <[PinItem]> pins;
|
||||
in property <bool> pins-loading;
|
||||
|
||||
@@ -845,17 +845,20 @@ export component ChatView inherits VerticalLayout {
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
if Bridge.has-pins: Button {
|
||||
// Icons with a count, so the channel's topic has the room.
|
||||
if Bridge.has-pins: IconButton {
|
||||
icon: Icons.pin;
|
||||
text: @tr("Pinned Messages");
|
||||
label: @tr("Pinned messages");
|
||||
checked: Nav.pins-open;
|
||||
count: Bridge.pins-count;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.show-pins(!Nav.pins-open); }
|
||||
}
|
||||
if Bridge.has-topics: Button {
|
||||
if Bridge.has-topics: IconButton {
|
||||
icon: Icons.book-open;
|
||||
text: @tr("Topics");
|
||||
label: @tr("Topics");
|
||||
checked: Nav.topics-open;
|
||||
count: Bridge.topics-count;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.show-topics(!Nav.topics-open); }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user