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:
Claude committed 2026-10-07 22:03:43 +00:00
1 parent 14ea206521
commit 2e3ddc11ec
7 files changed
+63 -11

No files matched your search

+2
View File
@@ -96,6 +96,8 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows
- The members panel shows a hand on those who need talk power to speak,
instead of everyone's talk power as a bare number (the member card still
has it).
- The chat header's pinned messages and topics are icon buttons with a
count, so the channel's topic has room.
### Fixed
+32 -6
View File
@@ -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 };
+2
View File
@@ -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();
}
+15
View File
@@ -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]
+4
View File
@@ -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;
+7 -4
View File
@@ -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); }
}
+1 -1
View File
@@ -153,7 +153,7 @@ comes from the engine's events; what a gateway adds is hidden without it.
| Part | `VOELIN_OPEN` | What it shows | Engine data |
|---|---|---|---|
| Chat | `server` (`server:chat`: the server chat), `actions`, `link-confirm[:<url>]`, `unread[:end]` | Header with Pinned Messages, Topics, the voice channel and the members button; chat tabs; messages grouped by author ("Today at 10:14"), avatars, BBCode formatting (see Formatting below), emoji, reactions with an add button, pin and topic marks, file cards with download; composer with attach, emoji and send. A link opens in the browser; one whose text is not its address (a masked link) first shows where it goes in `LinkDialog` (the host, the whole address; Open, Copy link, Cancel); a TeamSpeak link opens in Voelin (Adding a server: Links, below); a right-click on a link offers Open link and Copy link. Every message has actions on hover (`MessageActions`; `actions` shows the last one's): Quote (`> Author: …` lines at the start of the composer, which takes the focus to write below them and grows to show up to about eight lines) and Copy text, and with a gateway quick reactions, pin and Start a topic; a right-click on a message shows Copy text, Copy link (its first web address), Quote, and with a gateway React… and Pin. The server chat starts with the server's welcome message (and its host message when the server puts it in the chat log). Opens at the newest message and follows new ones while at the end. Scrolling up to within a screen of the top loads the page before, above the rows on screen, which stay in place (a spinner above the oldest message while it loads). The Older messages button there is for a chat too short to scroll, and for after a page that brought nothing (scrolling loads again once the list was a screen away). The voice view, the phone's voice screen and private chats load the same way. Messages count as read while their chat is on screen in the focused window; the chat tabs and the server rail count the others (not our own). A chat that comes on screen with new messages, or that is on screen when messages that came while away arrive (a stored or gateway page), shows a red line with New above the first (`NewDivider`) until the chat is left; while that line is above the view, a bar over the list says how many are new and since when (`UnreadBar`: "5 new messages since 10:14", Jump, and × to mark them read). Where each chat was read is kept on this device (the store's `chat_reads`), so the counts survive a restart: messages that came while away (a gateway's history) count as new | `ChatHistory` (and `Chat` for servers without history), `Presence` (welcome and host message), `AvatarReady`, `Transfer`, `Gateway` (pins; reactions arrive as stored messages); `Command::LoadOlderHistory`, `DownloadChatFile`, `UploadFile`, `GatewayRequest::React`, `Unreact`, `Pin`, `Unpin` |
| Chat | `server` (`server:chat`: the server chat), `actions`, `link-confirm[:<url>]`, `unread[:end]` | Header with the channel's topic, then icon buttons for Pinned messages and Topics (each with its count once the gateway sent them: asked for when the chat is shown), the voice channel and the members; chat tabs; messages grouped by author ("Today at 10:14"), avatars, BBCode formatting (see Formatting below), emoji, reactions with an add button, pin and topic marks, file cards with download; composer with attach, emoji and send. A link opens in the browser; one whose text is not its address (a masked link) first shows where it goes in `LinkDialog` (the host, the whole address; Open, Copy link, Cancel); a TeamSpeak link opens in Voelin (Adding a server: Links, below); a right-click on a link offers Open link and Copy link. Every message has actions on hover (`MessageActions`; `actions` shows the last one's): Quote (`> Author: …` lines at the start of the composer, which takes the focus to write below them and grows to show up to about eight lines) and Copy text, and with a gateway quick reactions, pin and Start a topic; a right-click on a message shows Copy text, Copy link (its first web address), Quote, and with a gateway React… and Pin. The server chat starts with the server's welcome message (and its host message when the server puts it in the chat log). Opens at the newest message and follows new ones while at the end. Scrolling up to within a screen of the top loads the page before, above the rows on screen, which stay in place (a spinner above the oldest message while it loads). The Older messages button there is for a chat too short to scroll, and for after a page that brought nothing (scrolling loads again once the list was a screen away). The voice view, the phone's voice screen and private chats load the same way. Messages count as read while their chat is on screen in the focused window; the chat tabs and the server rail count the others (not our own). A chat that comes on screen with new messages, or that is on screen when messages that came while away arrive (a stored or gateway page), shows a red line with New above the first (`NewDivider`) until the chat is left; while that line is above the view, a bar over the list says how many are new and since when (`UnreadBar`: "5 new messages since 10:14", Jump, and × to mark them read). Where each chat was read is kept on this device (the store's `chat_reads`), so the counts survive a restart: messages that came while away (a gateway's history) count as new | `ChatHistory` (and `Chat` for servers without history), `Presence` (welcome and host message), `AvatarReady`, `Transfer`, `Gateway` (pins; reactions arrive as stored messages); `Command::LoadOlderHistory`, `DownloadChatFile`, `UploadFile`, `GatewayRequest::React`, `Unreact`, `Pin`, `Unpin` |
| Members panel | `server` (`panel`, `no-panel`) | "Members — N" and a search; those streaming first (the people in our channel while the voice channel or a stream is shown), then each server group in the server's order with its icon, then those without a group. Rows: avatar with status, name, crown (admin groups), priority speaker, channel commander, recording, up to three myTeamSpeak badges, moderator role, a hand when their channel needs more talk power than they have ("Needs talk power to speak"; the member card has the number), what they do or the channel they are in. Resizable: the width is `ui.members_width` | `Presence`, `Groups`, `Talking`, `IconReady`, `PictureReady` |
| Member card | `member` | Description, groups, badges (up to three chips in the client's order, what each is for on hover; "Badge" for one the app does not know), talk power, country; private message, poke, friend, block; volume and mute for us | `ContactsChanged`, `PictureReady` (badges); `Command::SetContact`, `SetClientVolume`, `SetClientMuted`, `Poke` |
| Poke | `poke` (the first other member's, card open; after `friends` a contact's) | `PokeDialog`, from the member card, a friend's row and the direct message header: an optional message with a "12/100" count, Send off above 100 characters, Enter sends, Escape cancels | `Command::Poke` (trimmed, cut to 100 characters; the engine cuts too) |