Files
VoelinClient/crates/voelin-ui/ui/screens/chat.slint
T
selikhovandClaude Opus 5.5 49d656ead0 WIP: voice grid sizing, more sample chat (interrupted by a session limit)
Saved as found when the agent stopped; app.slint still carries a
diagnostic min-width of 1600px that must be reverted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 01:42:18 +03:00

734 lines
26 KiB
Plaintext

// The chat: header, chat tabs, the compact voice bar, messages
// (virtualised) with reactions, pins and file cards, and the composer with
// the emoji picker and the file attachment.
import { Theme } from "../theme.slint";
import { Icons } from "../icons.slint";
import { Bridge, ChatLine, ReactionItem, FileItem, Images } from "../bridge.slint";
import { Nav } from "../nav.slint";
import { Icon, IconButton, Avatar, Chip, TabItem, TextField, RichText, Banner, Button, ButtonKind, Spinner, Tooltip, SpeakingBars, ListView } from "../components/index.slint";
// The header of the main area: an icon, a title and a description, and
// actions (@children) at the right.
export component PageHeader inherits Rectangle {
in property <image> icon: Icons.hash;
in property <string> title;
in property <string> description;
min-height: 60px;
border-width: 0px;
HorizontalLayout {
padding-left: Theme.space-6;
padding-right: Theme.space-4;
spacing: Theme.space-4;
Icon {
source: root.icon;
size: 26px;
tint: Theme.text-secondary;
y: (parent.height - self.height) / 2;
}
Text {
text: root.title;
font-size: Theme.font-xl;
font-weight: Theme.weight-semibold;
color: Theme.text;
vertical-alignment: center;
overflow: elide;
max-width: self.preferred-width;
}
if root.description != "": Rectangle {
width: 1px;
height: 22px;
y: (parent.height - self.height) / 2;
background: Theme.border-strong;
}
Text {
text: root.description;
font-size: Theme.font-sm;
color: Theme.text-muted;
vertical-alignment: center;
horizontal-stretch: 1;
overflow: elide;
}
@children
}
Rectangle {
y: parent.height - 1px;
height: 1px;
background: Theme.border;
}
}
// The voice connection as one strip: where we are, who talks, and the
// controls. Shown over the chat while voice is connected.
export component VoiceBar inherits Rectangle {
height: 46px;
background: Theme.surface-2.transparentize(0.25);
accessible-role: AccessibleRole.groupbox;
accessible-label: @tr("Voice");
Rectangle {
y: parent.height - 1px;
height: 1px;
background: Theme.border;
}
HorizontalLayout {
padding-left: Theme.space-5;
padding-right: Theme.space-3;
spacing: Theme.space-3;
Rectangle {
width: 8px;
height: 8px;
y: (parent.height - self.height) / 2;
border-radius: 4px;
background: Bridge.voice-connected ? Theme.success : Theme.warning;
}
VerticalLayout {
alignment: center;
Text {
text: Bridge.voice-connected ? @tr("Voice connected") : @tr("Connecting…");
color: Bridge.voice-connected ? Theme.success : Theme.warning;
font-size: Theme.font-xs;
font-weight: Theme.weight-semibold;
}
Text {
text: Bridge.own-channel != "" ? Bridge.own-channel + " / " + Bridge.server-title : Bridge.server-title;
color: Theme.text-muted;
font-size: Theme.font-xs;
overflow: elide;
}
}
// Who is talking right now.
Rectangle {
horizontal-stretch: 1;
HorizontalLayout {
alignment: start;
padding-left: Theme.space-3;
spacing: -6px;
for member in Bridge.members: Rectangle {
width: member.talking ? 28px : 0px;
visible: member.talking;
Avatar {
size: 26px;
initials: member.initials;
tint: member.tint;
image: member.avatar;
speaking: true;
label: member.name;
}
}
}
}
if Bridge.transmitting: VerticalLayout {
alignment: center;
SpeakingBars { }
}
IconButton {
icon: Bridge.input-muted ? Icons.mic-off : Icons.mic;
label: Bridge.input-muted ? @tr("Microphone off") : @tr("Microphone on");
checked: Bridge.input-muted;
danger: true;
size: 32px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Bridge.set-input-muted(!Bridge.input-muted); }
}
IconButton {
icon: Bridge.output-muted ? Icons.headphone-off : Icons.headphones;
label: Bridge.output-muted ? @tr("Sound off") : @tr("Sound on");
checked: Bridge.output-muted;
danger: true;
size: 32px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Bridge.set-output-muted(!Bridge.output-muted); }
}
if Bridge.streams-available && Bridge.can-share: IconButton {
icon: Icons.monitor-up;
label: Bridge.share-state == "live" ? @tr("Sharing") : @tr("Share screen");
checked: Bridge.share-state == "live";
size: 32px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Nav.open-share(); }
}
IconButton {
icon: Icons.layout-grid;
label: @tr("Voice channel");
checked: Nav.voice-grid;
size: 32px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Nav.voice-grid = !Nav.voice-grid; }
}
IconButton {
icon: Icons.phone-off;
label: @tr("Disconnect");
size: 32px;
icon-size: Theme.icon-sm;
tint: Theme.danger;
y: (parent.height - self.height) / 2;
clicked => { Bridge.disconnect-voice(); }
}
}
}
// The emoji under a message; clicking one adds or removes ours.
component Reactions inherits HorizontalLayout {
in property <int> key;
in property <[ReactionItem]> model;
spacing: Theme.space-2;
alignment: start;
for reaction in root.model: Rectangle {
width: pill.preferred-width + 16px;
height: 24px;
border-radius: Theme.radius-pill;
background: reaction.me ? Theme.accent-soft : Theme.surface-2;
border-width: 1px;
border-color: reaction.me ? Theme.accent : Theme.border;
accessible-role: AccessibleRole.button;
accessible-label: @tr("{} reacted {} times", reaction.text, reaction.count);
accessible-checkable: true;
accessible-checked: reaction.me;
accessible-action-default => { Bridge.react(root.key, reaction.text); }
TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => { Bridge.react(root.key, reaction.text); }
}
pill := HorizontalLayout {
spacing: Theme.space-2;
alignment: center;
if reaction.key != "": Image {
width: 15px;
height: 15px;
source: Images.emoji(reaction.key);
y: (parent.height - self.height) / 2;
}
if reaction.key == "": Text {
text: reaction.text;
font-size: Theme.font-sm;
vertical-alignment: center;
}
Text {
text: reaction.count;
color: reaction.me ? Theme.accent-text : Theme.text-secondary;
font-size: Theme.font-xs;
font-weight: Theme.weight-semibold;
vertical-alignment: center;
}
}
}
}
// A file a message links: name, size or progress, and a download button.
component FileCard inherits Rectangle {
in property <int> key;
in property <FileItem> file;
height: 56px;
border-radius: Theme.radius-md;
background: Theme.surface-2;
border-width: 1px;
border-color: file.state == "failed" ? Theme.danger : Theme.border;
accessible-role: AccessibleRole.groupbox;
accessible-label: file.name;
HorizontalLayout {
padding: Theme.space-3;
spacing: Theme.space-3;
Rectangle {
width: 34px;
height: 34px;
y: (parent.height - self.height) / 2;
border-radius: Theme.radius-sm;
background: Theme.accent-soft;
Icon {
source: file.picture ? Icons.image : Icons.file-text;
size: Theme.icon-md;
tint: Theme.accent-text;
}
}
VerticalLayout {
alignment: center;
horizontal-stretch: 1;
spacing: 2px;
Text {
text: file.name;
color: Theme.text;
font-weight: Theme.weight-medium;
overflow: elide;
}
Text {
text: file.detail;
color: file.state == "failed" ? Theme.danger : Theme.text-muted;
font-size: Theme.font-xs;
overflow: elide;
}
if file.state == "running": Rectangle {
height: 3px;
border-radius: 1.5px;
background: Theme.surface-4;
Rectangle {
x: 0;
width: parent.width * file.progress;
height: parent.height;
border-radius: parent.border-radius;
background: Theme.accent;
}
}
}
if file.state != "running": IconButton {
icon: file.state == "done" ? Icons.folder-open : Icons.download;
label: file.state == "done" ? @tr("Downloaded") : @tr("Download {}", file.name);
y: (parent.height - self.height) / 2;
clicked => { Bridge.download-file(root.key, file.index); }
}
if file.state == "running": Spinner {
size: 18px;
y: (parent.height - self.height) / 2;
}
}
}
// Quick reactions, pin and "start a topic" on a hovered message.
component MessageActions inherits Rectangle {
in property <int> key;
in property <bool> pinned;
width: row.preferred-width;
height: 30px;
border-radius: Theme.radius-md;
background: Theme.surface-3;
border-width: 1px;
border-color: Theme.border-strong;
row := HorizontalLayout {
padding-left: 2px;
padding-right: 2px;
spacing: 0px;
if Bridge.has-reactions: HorizontalLayout {
spacing: 0px;
for quick in ["1f44d", "2764", "1f389", "1f602", "1f440"]: Rectangle {
width: 26px;
accessible-role: AccessibleRole.button;
accessible-label: @tr("React");
accessible-action-default => { Bridge.react(root.key, Images.emoji-text(quick)); }
Image {
width: 16px;
height: 16px;
source: Images.emoji(quick);
}
TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => { Bridge.react(root.key, Images.emoji-text(quick)); }
}
}
}
if Bridge.has-reactions: IconButton {
icon: Icons.smile-plus;
label: @tr("More emoji");
size: 26px;
icon-size: Theme.icon-sm;
clicked => {
Nav.react-key = root.key;
Nav.emoji-open = true;
}
}
if Bridge.has-pins: IconButton {
icon: Icons.pin;
label: root.pinned ? @tr("Unpin") : @tr("Pin");
checked: root.pinned;
size: 26px;
icon-size: Theme.icon-sm;
clicked => { Bridge.pin(root.key, !root.pinned); }
}
if Bridge.has-topics: IconButton {
icon: Icons.messages-square;
label: @tr("Start a topic");
size: 26px;
icon-size: Theme.icon-sm;
clicked => { Nav.start-topic(root.key); }
}
}
}
// One message; `continued` lines (same author just before) omit the header.
export component MessageRow inherits Rectangle {
in property <ChatLine> line;
// The pins and topic lists show messages without their actions.
in property <bool> actions: true;
property <length> avatar: 40px;
min-height: body.preferred-height;
background: line.marked ? Theme.accent-soft : hover.has-hover ? Theme.surface-2.transparentize(0.6) : transparent;
accessible-role: AccessibleRole.list-item;
accessible-label: line.author + ": " + line.text;
accessible-description: line.time;
hover := TouchArea {
// Let clicks through to the buttons inside.
mouse-cursor: MouseCursor.default;
}
body := HorizontalLayout {
padding-left: Theme.space-6;
padding-right: Theme.space-6;
padding-top: line.continued ? 1px : Theme.space-4;
padding-bottom: 1px;
spacing: Theme.space-4;
VerticalLayout {
width: root.avatar;
alignment: start;
if !line.continued: Avatar {
size: root.avatar;
initials: line.initials;
tint: line.tint;
image: line.avatar;
label: line.author;
}
}
VerticalLayout {
horizontal-stretch: 1;
spacing: 2px;
if !line.continued: HorizontalLayout {
spacing: Theme.space-3;
alignment: start;
Text {
text: line.author;
color: line.relayed ? Theme.accent-text : Theme.name-text;
font-size: Theme.font-md;
font-weight: Theme.weight-semibold;
vertical-alignment: center;
}
Text {
text: line.time;
color: Theme.text-muted;
font-size: Theme.font-xs;
vertical-alignment: center;
}
if line.relayed: Chip {
text: @tr("via relay");
icon: Icons.radio;
tint: Theme.accent-text;
y: (parent.height - self.height) / 2;
}
if line.pinned: Chip {
text: @tr("pinned");
icon: Icons.pin;
tint: Theme.warning;
y: (parent.height - self.height) / 2;
}
if line.topic != "": Chip {
text: line.topic;
icon: Icons.messages-square;
tint: Theme.accent-text;
y: (parent.height - self.height) / 2;
}
}
if line.blocked: Text {
text: @tr("Message from a blocked contact.");
color: Theme.text-disabled;
font-size: Theme.font-sm;
font-italic: true;
}
if !line.blocked && !line.rich && line.text != "": Text {
text: line.text;
color: Theme.text;
wrap: word-wrap;
}
if !line.blocked && line.rich: RichText {
runs: line.runs;
emoji-size: line.jumbo ? 44px : Theme.font-body * 1.4;
}
if line.files.length > 0 && !line.blocked: VerticalLayout {
padding-top: Theme.space-2;
padding-bottom: Theme.space-1;
spacing: Theme.space-2;
for file in line.files: FileCard {
key: line.key;
file: file;
max-width: 420px;
}
}
if line.reactions.length > 0: VerticalLayout {
padding-top: Theme.space-2;
padding-bottom: Theme.space-1;
Reactions {
key: line.key;
model: line.reactions;
}
}
}
}
if root.actions && line.remote && hover.has-hover: MessageActions {
x: parent.width - self.width - Theme.space-6;
y: -12px;
key: line.key;
pinned: line.pinned;
}
}
// The messages of the current chat (or of an open topic).
component MessageList inherits VerticalLayout {
in property <[ChatLine]> model;
in property <bool> older;
if Bridge.local-history: Rectangle {
height: 30px;
background: Theme.warning-soft;
HorizontalLayout {
padding-left: Theme.space-6;
spacing: Theme.space-2;
Icon {
source: Icons.hard-drive;
size: 14px;
tint: Theme.warning;
y: (parent.height - self.height) / 2;
}
Text {
text: @tr("Only messages seen by this device.");
color: Theme.warning;
font-size: Theme.font-xs;
vertical-alignment: center;
}
}
}
if root.older && Bridge.more-history: Rectangle {
height: 40px;
HorizontalLayout {
alignment: center;
Button {
small: true;
icon: Icons.chevron-up;
text: Bridge.loading-history ? @tr("Loading…") : @tr("Older messages");
enabled: !Bridge.loading-history;
y: (parent.height - self.height) / 2;
clicked => { Bridge.load-older(); }
}
}
}
ListView {
vertical-stretch: 1;
// A long chat must not make the window taller: the list scrolls.
preferred-height: 0px;
accessible-label: @tr("Messages");
for line in root.model: MessageRow {
line: line;
}
}
}
// The composer: emoji, attachment and the text field.
component Composer inherits HorizontalLayout {
in property <string> placeholder;
in property <bool> topic;
padding: Theme.space-4;
padding-left: Theme.space-5;
padding-right: Theme.space-5;
spacing: Theme.space-3;
Rectangle {
horizontal-stretch: 1;
min-height: 48px;
border-radius: Theme.radius-lg;
background: Theme.surface-2;
border-width: 1px;
border-color: input.has-focus ? Theme.accent : Theme.border;
HorizontalLayout {
padding-left: Theme.space-3;
padding-right: Theme.space-2;
spacing: Theme.space-2;
IconButton {
icon: Icons.paperclip;
label: @tr("Attach a file");
y: (parent.height - self.height) / 2;
clicked => { Bridge.attach-file(); }
}
input := TextField {
text <=> Nav.draft;
bare: true;
placeholder: root.placeholder;
label: @tr("Message");
accepted(text) => {
if text != "" {
if root.topic {
Bridge.send-topic-message(text);
} else {
Bridge.send-message(text);
}
self.clear();
}
}
}
IconButton {
icon: Icons.smile;
label: @tr("Emoji");
checked: Nav.emoji-open;
y: (parent.height - self.height) / 2;
clicked => {
Nav.react-key = 0;
Nav.emoji-open = !Nav.emoji-open;
}
}
IconButton {
icon: Icons.send;
label: @tr("Send");
round: true;
enabled: input.text != "";
tint: input.text != "" ? Theme.on-accent : Theme.text-muted;
filled: input.text != "";
y: (parent.height - self.height) / 2;
clicked => {
if input.text != "" {
if root.topic {
Bridge.send-topic-message(input.text);
} else {
Bridge.send-message(input.text);
}
input.clear();
}
}
}
}
}
}
// Tabs, messages and the composer of the current chat.
export component ChatView inherits VerticalLayout {
// Hide the header (mobile shows its own).
in property <bool> header: true;
property <string> tab-title: Bridge.current-tab >= 0 && Bridge.current-tab < Bridge.tabs.length ? Bridge.tabs[Bridge.current-tab].title : "";
property <string> tab-name: Bridge.current-tab >= 0 && Bridge.current-tab < Bridge.tabs.length ? Bridge.tabs[Bridge.current-tab].name : "";
property <int> tab-kind: Bridge.current-tab >= 0 && Bridge.current-tab < Bridge.tabs.length ? Bridge.tabs[Bridge.current-tab].kind : 0;
property <string> tab-topic: Bridge.current-tab >= 0 && Bridge.current-tab < Bridge.tabs.length ? Bridge.tabs[Bridge.current-tab].topic : "";
if root.header: PageHeader {
icon: root.tab-kind == 1 ? Icons.hash : root.tab-kind == 2 ? Icons.at-sign : Icons.message-square;
title: root.tab-name;
description: root.tab-topic != "" ? root.tab-topic : Bridge.server-title;
if Bridge.presence-source != "": Chip {
text: Bridge.presence-source;
icon: Icons.radio;
tint: Theme.accent-text;
y: (parent.height - self.height) / 2;
}
if Bridge.has-pins: IconButton {
icon: Icons.pin;
label: @tr("Pinned messages");
checked: Nav.pins-open;
y: (parent.height - self.height) / 2;
clicked => { Nav.show-pins(!Nav.pins-open); }
}
if Bridge.has-topics: IconButton {
icon: Icons.messages-square;
label: @tr("Topics");
checked: Nav.topics-open;
y: (parent.height - self.height) / 2;
clicked => { Nav.show-topics(!Nav.topics-open); }
}
if !Bridge.viewer-open && !Nav.right-panel-open && Bridge.streams.length > 0: Button {
small: true;
icon: Icons.monitor-up;
text: @tr("Streams ({})", Bridge.streams.length);
y: (parent.height - self.height) / 2;
clicked => { Nav.right-panel-open = true; }
}
IconButton {
icon: Icons.users;
label: @tr("Members and streams");
checked: Nav.right-panel-open;
y: (parent.height - self.height) / 2;
clicked => { Nav.right-panel-open = !Nav.right-panel-open; }
}
}
if Bridge.crash-notice != "": Rectangle {
HorizontalLayout {
padding: Theme.space-3;
padding-left: Theme.space-5;
padding-right: Theme.space-5;
Banner {
text: Bridge.crash-notice;
Button {
small: true;
text: @tr("Open folder");
y: (parent.height - self.height) / 2;
clicked => { Bridge.open-crash-folder(); }
}
Button {
small: true;
kind: ButtonKind.danger;
text: @tr("Delete");
y: (parent.height - self.height) / 2;
clicked => { Bridge.delete-crash-reports(); }
}
IconButton {
icon: Icons.x;
label: @tr("Dismiss");
size: 28px;
y: (parent.height - self.height) / 2;
clicked => { Bridge.dismiss-crash-notice(); }
}
}
}
}
// Chat tabs: server chat, channel chats, private chats.
Rectangle {
height: Theme.control-height + 4px;
accessible-role: AccessibleRole.tab-list;
accessible-label: @tr("Chats");
Rectangle {
y: parent.height - 1px;
height: 1px;
background: Theme.border;
}
HorizontalLayout {
padding-left: Theme.space-5;
alignment: start;
for tab[i] in Bridge.tabs: TabItem {
text: tab.title;
selected: Bridge.current-tab == i;
badge: tab.unread;
closable: tab.kind == 1;
clicked => { Bridge.select-tab(i); }
close => { Bridge.close-tab(i); }
}
}
}
if Bridge.voice-connected || Bridge.voice-connecting: VoiceBar { }
// The open topic replaces the chat.
if Bridge.current-topic >= 0: Rectangle {
height: 44px;
background: Theme.surface-2.transparentize(0.4);
HorizontalLayout {
padding-left: Theme.space-4;
padding-right: Theme.space-4;
spacing: Theme.space-3;
IconButton {
icon: Icons.arrow-left;
label: @tr("Back to the chat");
size: 28px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Bridge.open-topic(-1); }
}
Icon {
source: Icons.messages-square;
size: Theme.icon-sm;
tint: Theme.accent-text;
y: (parent.height - self.height) / 2;
}
Text {
text: Bridge.topic-title;
color: Theme.text;
font-weight: Theme.weight-semibold;
vertical-alignment: center;
horizontal-stretch: 1;
overflow: elide;
}
}
}
if Bridge.current-topic >= 0: MessageList {
vertical-stretch: 1;
model: Bridge.topic-messages;
}
if Bridge.current-topic < 0: MessageList {
vertical-stretch: 1;
model: Bridge.messages;
older: true;
}
Composer {
topic: Bridge.current-topic >= 0;
placeholder: Bridge.current-topic >= 0 ? @tr("Reply in {}", Bridge.topic-title)
: root.tab-title != "" ? @tr("Message {}", root.tab-title) : @tr("Message");
}
}