Messages count as read only while their chat is on screen (Nav.chat-shown) in the focused window: winit's focus events, through slint's unstable-winit-030 on the desktop; Android counts a chat on screen as read. A tab keeps the newest message read and counts what came after it, not our own. Entering a tab with new messages puts a red New line above the first one until the tab is left (so does a stored or gateway page that brings them while the tab is on screen), and while that line is above the view a bar over the list counts them, with Jump and Mark as read. voelin-store migration 5 adds chat_reads (Store::chat_read, set_chat_read, chat_reads). Markers are loaded once a session's server is known and written when a tab is left, marked read, its session ends and on exit, never per message; a restart counts what came while away again, gateway pages included. Dev switch VOELIN_OPEN=unread[:end]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
977 lines
38 KiB
Plaintext
977 lines
38 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, MessageText, Banner, Button, ButtonKind, Spinner, Tooltip, ListView, BannerPicture, PopupMenu, MenuEntry } from "../components/index.slint";
|
|
|
|
// A compact title and actions over the optional channel background.
|
|
export component PageHeader inherits Rectangle {
|
|
in property <image> icon: Icons.hash;
|
|
in property <image> banner;
|
|
in property <string> title;
|
|
in property <string> description;
|
|
min-height: 60px;
|
|
border-width: 0px;
|
|
clip: true;
|
|
if root.banner.width > 0: BannerPicture { source: root.banner; }
|
|
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: root.banner.width > 0 ? Theme.text : Theme.text-muted;
|
|
vertical-alignment: center;
|
|
horizontal-stretch: 1;
|
|
overflow: elide;
|
|
}
|
|
@children
|
|
}
|
|
Rectangle {
|
|
y: parent.height - 1px;
|
|
height: 1px;
|
|
background: Theme.border;
|
|
}
|
|
}
|
|
|
|
// The emoji under a message; clicking one adds or removes ours, the last
|
|
// pill picks another.
|
|
export component Reactions inherits HorizontalLayout {
|
|
in property <int> key;
|
|
in property <[ReactionItem]> model;
|
|
spacing: Theme.space-3;
|
|
alignment: start;
|
|
for reaction in root.model: Rectangle {
|
|
width: pill.preferred-width + 22px;
|
|
height: 30px;
|
|
border-radius: Theme.radius-pill;
|
|
background: reaction.me ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : Theme.surface-2;
|
|
border-width: 1px;
|
|
border-color: reaction.me ? Theme.accent : Theme.border-strong;
|
|
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); }
|
|
area := TouchArea {
|
|
mouse-cursor: MouseCursor.pointer;
|
|
clicked => { Bridge.react(root.key, reaction.text); }
|
|
}
|
|
pill := HorizontalLayout {
|
|
spacing: Theme.space-3;
|
|
alignment: center;
|
|
if reaction.key != "": Image {
|
|
width: 18px;
|
|
height: 18px;
|
|
source: Images.emoji(reaction.key);
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
if reaction.key == "": Text {
|
|
text: reaction.text;
|
|
font-size: Theme.font-body;
|
|
vertical-alignment: center;
|
|
}
|
|
Text {
|
|
text: reaction.count;
|
|
color: reaction.me ? Theme.accent-text : Theme.text-secondary;
|
|
font-size: Theme.font-sm;
|
|
font-weight: Theme.weight-semibold;
|
|
vertical-alignment: center;
|
|
}
|
|
}
|
|
}
|
|
if Bridge.has-reactions: Rectangle {
|
|
width: 40px;
|
|
height: 30px;
|
|
border-radius: Theme.radius-pill;
|
|
background: add.has-hover ? Theme.surface-3 : Theme.surface-2;
|
|
border-width: 1px;
|
|
border-color: Theme.border-strong;
|
|
accessible-role: AccessibleRole.button;
|
|
accessible-label: @tr("Add a reaction");
|
|
accessible-action-default => {
|
|
Nav.react-key = root.key;
|
|
Nav.emoji-open = true;
|
|
}
|
|
Icon {
|
|
source: Icons.smile-plus;
|
|
size: 18px;
|
|
tint: Theme.text-secondary;
|
|
}
|
|
add := TouchArea {
|
|
mouse-cursor: MouseCursor.pointer;
|
|
clicked => {
|
|
Nav.react-key = root.key;
|
|
Nav.emoji-open = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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: 64px;
|
|
border-radius: Theme.radius-lg;
|
|
background: Theme.surface-2;
|
|
border-width: 1px;
|
|
border-color: file.state == "failed" ? Theme.danger : Theme.border-strong;
|
|
accessible-role: AccessibleRole.groupbox;
|
|
accessible-label: file.name;
|
|
HorizontalLayout {
|
|
padding: Theme.space-3;
|
|
padding-left: Theme.space-4;
|
|
spacing: Theme.space-4;
|
|
// A document in red, a picture in blue (as in the profile panel's
|
|
// shared files and the design's file cards).
|
|
Rectangle {
|
|
width: 40px;
|
|
height: 40px;
|
|
y: (parent.height - self.height) / 2;
|
|
border-radius: Theme.radius-md;
|
|
background: file.picture ? Theme.accent-soft : Theme.danger-soft;
|
|
Icon {
|
|
source: file.picture ? Icons.image : Icons.file-text;
|
|
size: Theme.icon-md;
|
|
tint: file.picture ? Theme.accent-text : Theme.danger;
|
|
}
|
|
}
|
|
VerticalLayout {
|
|
alignment: center;
|
|
horizontal-stretch: 1;
|
|
spacing: 2px;
|
|
Text {
|
|
text: file.name;
|
|
color: Theme.text;
|
|
font-size: Theme.font-md;
|
|
font-weight: Theme.weight-medium;
|
|
overflow: elide;
|
|
}
|
|
Text {
|
|
text: file.detail;
|
|
color: file.state == "failed" ? Theme.danger : Theme.text-secondary;
|
|
font-size: Theme.font-sm;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
// A picture a message links, shown inline (downloaded into memory); a
|
|
// click opens it larger.
|
|
component ImageCard inherits Rectangle {
|
|
in property <int> key;
|
|
in property <FileItem> file;
|
|
// As wide as the column allows, up to 520 px, keeping the picture's
|
|
// shape (at most 340 px high).
|
|
property <float> ratio: file.preview.height > 0 ? file.preview.width / file.preview.height : 1.6;
|
|
max-width: min(520px, 340px * ratio);
|
|
preferred-width: self.max-width;
|
|
height: min(self.width, self.max-width) / ratio;
|
|
border-radius: Theme.radius-lg;
|
|
clip: true;
|
|
background: Theme.surface-2;
|
|
border-width: 1px;
|
|
border-color: touch.has-hover ? Theme.border-strong : Theme.border;
|
|
accessible-role: AccessibleRole.image;
|
|
accessible-label: file.name;
|
|
accessible-action-default => { Nav.open-picture(root.key, root.file.index); }
|
|
Image {
|
|
width: parent.width;
|
|
height: parent.height;
|
|
source: root.file.preview;
|
|
image-fit: cover;
|
|
}
|
|
touch := TouchArea {
|
|
mouse-cursor: MouseCursor.pointer;
|
|
clicked => { Nav.open-picture(root.key, root.file.index); }
|
|
}
|
|
}
|
|
|
|
// What can be done with a hovered message: with a gateway quick reactions,
|
|
// pin and "start a topic"; quote it into the composer and copy its text.
|
|
// Every row has one, its buttons made only while `shown`. It reaches above
|
|
// its row, where the row's own hover ends: `hovered` keeps it shown there.
|
|
component MessageActions inherits Rectangle {
|
|
in property <ChatLine> line;
|
|
in property <bool> shown;
|
|
out property <bool> hovered: area.has-hover;
|
|
visible: shown;
|
|
width: row.preferred-width;
|
|
height: 30px;
|
|
border-radius: Theme.radius-md;
|
|
background: Theme.surface-3;
|
|
border-width: 1px;
|
|
border-color: Theme.border-strong;
|
|
// An ancestor of the buttons, so it stays hovered over them.
|
|
area := TouchArea {
|
|
row := HorizontalLayout {
|
|
padding-left: 2px;
|
|
padding-right: 2px;
|
|
spacing: 0px;
|
|
if root.shown && root.line.remote && 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.line.key, Images.emoji-text(quick)); }
|
|
Image {
|
|
width: 16px;
|
|
height: 16px;
|
|
source: Images.emoji(quick);
|
|
}
|
|
TouchArea {
|
|
mouse-cursor: MouseCursor.pointer;
|
|
clicked => { Bridge.react(root.line.key, Images.emoji-text(quick)); }
|
|
}
|
|
}
|
|
}
|
|
if root.shown && root.line.remote && Bridge.has-reactions: IconButton {
|
|
icon: Icons.smile-plus;
|
|
label: @tr("More emoji");
|
|
size: 26px;
|
|
icon-size: Theme.icon-sm;
|
|
clicked => {
|
|
Nav.react-key = root.line.key;
|
|
Nav.emoji-open = true;
|
|
}
|
|
}
|
|
if root.shown && root.line.remote && Bridge.has-pins: IconButton {
|
|
icon: Icons.pin;
|
|
label: root.line.pinned ? @tr("Unpin") : @tr("Pin");
|
|
checked: root.line.pinned;
|
|
size: 26px;
|
|
icon-size: Theme.icon-sm;
|
|
clicked => { Bridge.pin(root.line.key, !root.line.pinned); }
|
|
}
|
|
if root.shown && root.line.remote && 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.line.key); }
|
|
}
|
|
if root.shown && root.line.text != "": IconButton {
|
|
icon: Icons.quote;
|
|
label: @tr("Quote");
|
|
size: 26px;
|
|
icon-size: Theme.icon-sm;
|
|
clicked => { Nav.quote(root.line.author, root.line.text); }
|
|
}
|
|
if root.shown && root.line.text != "": IconButton {
|
|
icon: Icons.copy;
|
|
label: @tr("Copy text");
|
|
size: 26px;
|
|
icon-size: Theme.icon-sm;
|
|
clicked => { Nav.copy(root.line.text); }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Where the messages not read yet start: a red line with "New" at its end.
|
|
component NewDivider inherits HorizontalLayout {
|
|
padding-left: Theme.space-6;
|
|
padding-right: Theme.space-6;
|
|
padding-top: Theme.space-3;
|
|
Rectangle {
|
|
horizontal-stretch: 1;
|
|
Rectangle {
|
|
height: 1px;
|
|
background: Theme.danger;
|
|
}
|
|
}
|
|
Rectangle {
|
|
width: new.preferred-width + 2 * Theme.space-2;
|
|
height: 16px;
|
|
border-radius: Theme.radius-xs;
|
|
background: Theme.danger;
|
|
accessible-role: AccessibleRole.text;
|
|
accessible-label: @tr("New messages");
|
|
new := Text {
|
|
text: @tr("New");
|
|
color: Theme.on-accent;
|
|
font-size: Theme.font-xs;
|
|
font-weight: Theme.weight-bold;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
// The actions as if hovered (VOELIN_OPEN=actions).
|
|
in property <bool> show-actions;
|
|
// The list's first row: its actions go inside it, not above, where the
|
|
// list ends.
|
|
in property <bool> first;
|
|
property <length> avatar: 44px;
|
|
// Something to do: text to copy and quote, or what a gateway adds.
|
|
property <bool> can-act: root.actions && !line.blocked && (line.text != "" || line.remote);
|
|
// The pointer on the message or on its actions (above its top).
|
|
property <bool> active: hover.has-hover || bar.hovered;
|
|
min-height: column.preferred-height;
|
|
background: line.marked ? Theme.accent-soft : root.active ? Theme.surface-2.transparentize(0.6) : transparent;
|
|
accessible-role: AccessibleRole.list-item;
|
|
accessible-label: line.author + ": " + line.text;
|
|
accessible-description: line.time;
|
|
// The message's own buttons (links, reactions, files) are inside it,
|
|
// so it stays hovered over them and the actions stay shown.
|
|
hover := TouchArea {
|
|
mouse-cursor: MouseCursor.default;
|
|
// A right-click: the message's menu.
|
|
pointer-event(e) => {
|
|
if root.can-act && e.button == PointerEventButton.right && e.kind == PointerEventKind.up {
|
|
menu.show(self.mouse-x, self.mouse-y);
|
|
}
|
|
}
|
|
column := VerticalLayout {
|
|
if line.unread-start: NewDivider { }
|
|
HorizontalLayout {
|
|
padding-left: Theme.space-6;
|
|
padding-right: Theme.space-6;
|
|
padding-top: line.continued ? 2px : line.unread-start ? Theme.space-3 : Theme.space-5;
|
|
padding-bottom: 2px;
|
|
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: Theme.name-text;
|
|
font-size: Theme.font-lg;
|
|
font-weight: Theme.weight-medium;
|
|
vertical-alignment: center;
|
|
}
|
|
Text {
|
|
text: line.time;
|
|
color: Theme.text-muted;
|
|
font-size: Theme.font-sm;
|
|
vertical-alignment: center;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
MessageText {
|
|
line: line;
|
|
font-size: Theme.font-md;
|
|
}
|
|
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: HorizontalLayout {
|
|
alignment: start;
|
|
if file.preview.width > 0: ImageCard {
|
|
key: line.key;
|
|
file: file;
|
|
}
|
|
if file.preview.width == 0: FileCard {
|
|
key: line.key;
|
|
file: file;
|
|
max-width: 440px;
|
|
}
|
|
}
|
|
}
|
|
if line.reactions.length > 0: VerticalLayout {
|
|
padding-top: Theme.space-2;
|
|
padding-bottom: Theme.space-1;
|
|
Reactions {
|
|
key: line.key;
|
|
model: line.reactions;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Below the "New" divider (`NewDivider`) when the message has one.
|
|
bar := MessageActions {
|
|
x: parent.width - self.width - Theme.space-6;
|
|
y: root.first || line.unread-start ? (line.unread-start ? Theme.space-3 + 16px : 0px) + 2px : -12px;
|
|
line: line;
|
|
shown: root.can-act && (root.active || root.show-actions);
|
|
}
|
|
// The menu's entries: Copy link only with a link, react and pin only
|
|
// with a gateway (`activated` counts as if all were there).
|
|
property <MenuEntry> copy-entry: { text: @tr("Copy text"), icon: Icons.copy, enabled: line.text != "" };
|
|
property <MenuEntry> link-entry: { text: @tr("Copy link"), icon: Icons.link, enabled: true };
|
|
property <MenuEntry> quote-entry: { text: @tr("Quote"), icon: Icons.quote, enabled: line.text != "" };
|
|
property <MenuEntry> react-entry: { text: @tr("React…"), icon: Icons.smile-plus, enabled: Bridge.has-reactions, separator: true };
|
|
property <MenuEntry> pin-entry: { text: line.pinned ? @tr("Unpin") : @tr("Pin"), icon: Icons.pin, enabled: Bridge.has-pins };
|
|
menu := PopupMenu {
|
|
x: 0;
|
|
y: 0;
|
|
entries: line.remote
|
|
? (line.link != "" ? [root.copy-entry, root.link-entry, root.quote-entry, root.react-entry, root.pin-entry] : [root.copy-entry, root.quote-entry, root.react-entry, root.pin-entry])
|
|
: (line.link != "" ? [root.copy-entry, root.link-entry, root.quote-entry] : [root.copy-entry, root.quote-entry]);
|
|
activated(i) => {
|
|
let entry = i >= 1 && line.link == "" ? i + 1 : i;
|
|
if entry == 0 {
|
|
Nav.copy(line.text);
|
|
} else if entry == 1 {
|
|
Nav.copy(line.link);
|
|
} else if entry == 2 {
|
|
Nav.quote(line.author, line.text);
|
|
} else if entry == 3 {
|
|
Nav.react-key = line.key;
|
|
Nav.emoji-open = true;
|
|
} else {
|
|
Bridge.pin(line.key, !line.pinned);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Over a chat whose "New" divider is above the view: how many messages
|
|
// are new and since when, a jump to the first, and Mark as read.
|
|
component UnreadBar inherits Rectangle {
|
|
callback jump();
|
|
height: 36px;
|
|
border-radius: Theme.radius-pill;
|
|
background: Theme.surface-3;
|
|
border-width: 1px;
|
|
border-color: Theme.border-popup;
|
|
HorizontalLayout {
|
|
padding-left: Theme.space-5;
|
|
padding-right: Theme.space-2;
|
|
spacing: Theme.space-3;
|
|
Rectangle {
|
|
width: 8px;
|
|
height: 8px;
|
|
y: (parent.height - self.height) / 2;
|
|
border-radius: 4px;
|
|
background: Theme.danger;
|
|
}
|
|
Text {
|
|
text: @tr("{n} new message since {}" | "{n} new messages since {}" % Bridge.unread-count, Bridge.unread-since);
|
|
color: Theme.text;
|
|
font-size: Theme.font-sm;
|
|
font-weight: Theme.weight-semibold;
|
|
vertical-alignment: center;
|
|
horizontal-stretch: 1;
|
|
overflow: elide;
|
|
}
|
|
Button {
|
|
small: true;
|
|
kind: ButtonKind.primary;
|
|
icon: Icons.arrow-up;
|
|
text: @tr("Jump");
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { root.jump(); }
|
|
}
|
|
IconButton {
|
|
icon: Icons.x;
|
|
label: @tr("Mark as read");
|
|
size: 28px;
|
|
icon-size: Theme.icon-sm;
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { Bridge.mark-read(); }
|
|
}
|
|
}
|
|
}
|
|
|
|
// The top of a chat with older messages: the button that loads them, or a
|
|
// spinner while they load.
|
|
component OlderRow inherits HorizontalLayout {
|
|
callback load();
|
|
height: 40px;
|
|
alignment: center;
|
|
if Bridge.loading-history: Spinner {
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
if !Bridge.loading-history: Button {
|
|
small: true;
|
|
icon: Icons.chevron-up;
|
|
text: @tr("Older messages");
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { root.load(); }
|
|
}
|
|
}
|
|
|
|
// The messages of the current chat (or of an open topic). The list starts
|
|
// at the newest message and follows new ones while it is at the end;
|
|
// scrolling up stops that until the end is reached again. With `older`,
|
|
// scrolling to within a screen of the top loads the page before, and the
|
|
// rows on screen stay where they are while it comes in above them. The
|
|
// button above the oldest message is for a chat too short to scroll, and
|
|
// for after a page that brought nothing. While the "New" divider is above
|
|
// the view, a bar over the list says how many messages are new.
|
|
export component MessageList inherits VerticalLayout {
|
|
in property <[ChatLine]> model;
|
|
in property <bool> older;
|
|
property <bool> follow: true;
|
|
property <length> end: min(0px, list.visible-height - list.content-height);
|
|
property <length> scrolled: list.content-y;
|
|
// While a page of older messages loads: how many rows there are from
|
|
// the top of the view to the end (rows, not pixels: the list places
|
|
// rows by their average height), and the row count then (-1: no page
|
|
// to make room for).
|
|
property <float> keep;
|
|
property <int> kept-rows: -1;
|
|
// The page came in and the view went back to `keep` (`restored`). The
|
|
// list then places the rows by their real heights, a little off: the
|
|
// view goes back up to twice more (`settle`), until it stays put.
|
|
property <int> settle;
|
|
property <length> restored;
|
|
// A page brought nothing (the gateway may be away): no more loading by
|
|
// scrolling until the list is a screen away from where that was.
|
|
property <bool> paused;
|
|
property <length> paused-at;
|
|
function rows-to-end() -> float {
|
|
return list.content-height > 0 ? root.model.length * (list.content-y + list.content-height) / list.content-height : 0;
|
|
}
|
|
function restore() {
|
|
root.restored = max(root.end, min(0px, list.content-height * (root.keep / root.model.length - 1)));
|
|
list.content-y = root.restored;
|
|
}
|
|
function load() {
|
|
root.keep = root.rows-to-end();
|
|
root.kept-rows = root.follow ? -1 : root.model.length;
|
|
Bridge.load-older();
|
|
}
|
|
// Scrolled up to within a screen of the top, and no page on its way or
|
|
// still to be placed.
|
|
function load-near-top() {
|
|
if root.older && Bridge.more-history && !Bridge.loading-history && !root.paused && !root.follow && root.kept-rows < 0 && list.content-y > -list.visible-height {
|
|
root.load();
|
|
}
|
|
}
|
|
changed end => {
|
|
if root.follow {
|
|
list.content-y = root.end;
|
|
} else if root.kept-rows >= 0 && root.model.length != root.kept-rows && root.model.length > 0 {
|
|
// Older rows came in above: back to the rows that were shown.
|
|
root.restore();
|
|
root.settle = 2;
|
|
root.kept-rows = Bridge.loading-history ? root.model.length : -1;
|
|
root.load-near-top();
|
|
}
|
|
}
|
|
changed scrolled => {
|
|
// After a longer chat the list can leave a short one's first rows
|
|
// above the view (it places rows by their estimated heights).
|
|
if root.scrolled < root.end - 1px {
|
|
list.content-y = root.end;
|
|
}
|
|
root.follow = root.scrolled <= root.end + 2px;
|
|
if root.settle > 0 && root.scrolled != root.restored {
|
|
root.settle -= 1;
|
|
root.restore();
|
|
} else if root.follow {
|
|
root.kept-rows = -1;
|
|
} else if root.kept-rows >= 0 && root.model.length == root.kept-rows {
|
|
// Scrolled while the page loads: keep this place instead.
|
|
root.keep = root.rows-to-end();
|
|
}
|
|
if root.paused && abs(root.scrolled - root.paused-at) > list.visible-height {
|
|
root.paused = false;
|
|
}
|
|
root.load-near-top();
|
|
}
|
|
property <bool> loading: Bridge.loading-history;
|
|
changed loading => {
|
|
if !root.loading && root.kept-rows >= 0 && root.model.length == root.kept-rows {
|
|
root.paused = true;
|
|
root.paused-at = list.content-y;
|
|
root.kept-rows = -1;
|
|
}
|
|
}
|
|
// Another chat (another tab, or another server's tab at the same
|
|
// place): start at its end, with nothing of the last one's loading.
|
|
function reset() {
|
|
root.follow = true;
|
|
root.kept-rows = -1;
|
|
root.settle = 0;
|
|
root.paused = false;
|
|
list.content-y = root.end;
|
|
}
|
|
property <int> tab: Bridge.current-tab;
|
|
changed tab => { root.reset(); }
|
|
property <int> server: Bridge.current-server;
|
|
changed server => { root.reset(); }
|
|
// Scroll to where row `index` is, a third down the view. Rows differ in
|
|
// height, so this is the place of an average row (as the standard list
|
|
// estimates it).
|
|
function jump-to(index: int) {
|
|
if root.older && root.model.length > 0 {
|
|
root.settle = 0;
|
|
list.content-y = max(root.end, min(0px, list.visible-height / 3 - index * list.content-height / root.model.length));
|
|
}
|
|
}
|
|
// A pinned message was jumped to (the row is highlighted).
|
|
property <int> jumps: Bridge.jump-requests;
|
|
changed jumps => { root.jump-to(Bridge.jump-index); }
|
|
// The "New" divider is above the view (as estimated for a jump).
|
|
property <bool> new-above: root.older && Bridge.unread-index >= 0 && root.model.length > 0
|
|
&& list.content-y + Bridge.unread-index * list.content-height / root.model.length < 0;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
// An empty chat: the button on its own.
|
|
if root.older && Bridge.more-history && root.model.length == 0: OlderRow {
|
|
load => { root.load(); }
|
|
}
|
|
Rectangle {
|
|
vertical-stretch: 1;
|
|
// A long chat must not make the window taller: the list scrolls.
|
|
preferred-height: 0px;
|
|
list := ListView {
|
|
width: parent.width;
|
|
height: parent.height;
|
|
accessible-label: @tr("Messages");
|
|
// Scrolled by hand: the view is where the user put it.
|
|
scrolled => { root.settle = 0; }
|
|
for line[i] in root.model: VerticalLayout {
|
|
if i == 0 && root.older && Bridge.more-history: OlderRow {
|
|
load => { root.load(); }
|
|
}
|
|
MessageRow {
|
|
line: line;
|
|
show-actions: Nav.show-actions && i == root.model.length - 1;
|
|
first: i == 0;
|
|
}
|
|
}
|
|
}
|
|
if root.new-above: UnreadBar {
|
|
x: Theme.space-5;
|
|
y: Theme.space-3;
|
|
width: parent.width - 2 * Theme.space-5;
|
|
jump => { root.jump-to(Bridge.unread-index); }
|
|
}
|
|
}
|
|
}
|
|
|
|
// The composer: a round attach button, the text field with the emoji
|
|
// picker and send.
|
|
export component Composer inherits HorizontalLayout {
|
|
in property <string> placeholder;
|
|
in property <bool> topic;
|
|
// Files can be attached (channel chats).
|
|
in property <bool> attach: true;
|
|
in property <bool> enabled: true;
|
|
padding: Theme.space-4;
|
|
padding-left: Theme.space-5;
|
|
padding-right: Theme.space-5;
|
|
spacing: Theme.space-3;
|
|
// A message was quoted (Nav.quote): write the answer below it.
|
|
property <int> requests: Nav.compose-requests;
|
|
changed requests => { input.focus-end(); }
|
|
// Files go to the channel's file browser and a link into the chat.
|
|
if !root.topic && root.attach: IconButton {
|
|
icon: Icons.plus;
|
|
label: @tr("Attach a file");
|
|
round: true;
|
|
filled: true;
|
|
size: 44px;
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { Bridge.attach-file(); }
|
|
}
|
|
Rectangle {
|
|
horizontal-stretch: 1;
|
|
// A quote's lines all show, up to about eight.
|
|
min-height: max(48px, min(input.text-height + Theme.space-5, 160px));
|
|
border-radius: Theme.radius-lg;
|
|
background: Theme.surface-2;
|
|
border-width: 1px;
|
|
border-color: input.has-focus ? Theme.accent : Theme.border-strong;
|
|
HorizontalLayout {
|
|
padding-left: Theme.space-5;
|
|
padding-right: Theme.space-2;
|
|
spacing: Theme.space-2;
|
|
input := TextField {
|
|
text <=> Nav.draft;
|
|
bare: true;
|
|
enabled: root.enabled;
|
|
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.accent-text;
|
|
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 : "";
|
|
property <image> tab-banner: Bridge.current-tab >= 0 && Bridge.current-tab < Bridge.tabs.length ? Bridge.tabs[Bridge.current-tab].banner : @image-url("");
|
|
|
|
if root.header: PageHeader {
|
|
banner: root.tab-banner;
|
|
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;
|
|
// Only when the chat does not come through our voice connection
|
|
// (an invisible observer or a relay).
|
|
if Bridge.presence-source != "" && !Bridge.voice-connected: Chip {
|
|
text: Bridge.presence-source;
|
|
icon: Icons.radio;
|
|
tint: Theme.accent-text;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
if Bridge.has-pins: Button {
|
|
icon: Icons.pin;
|
|
text: @tr("Pinned Messages");
|
|
checked: Nav.pins-open;
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { Nav.show-pins(!Nav.pins-open); }
|
|
}
|
|
if Bridge.has-topics: Button {
|
|
icon: Icons.book-open;
|
|
text: @tr("Topics");
|
|
checked: Nav.topics-open;
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { Nav.show-topics(!Nav.topics-open); }
|
|
}
|
|
// The voice channel we are in, with the people and the streams.
|
|
if Bridge.voice-connected: IconButton {
|
|
icon: Icons.volume-2;
|
|
label: @tr("Voice channel");
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { Nav.show-voice(true); }
|
|
}
|
|
IconButton {
|
|
icon: Icons.users;
|
|
label: @tr("Members");
|
|
checked: Nav.right-panel-open && !Nav.pins-open && !Nav.topics-open;
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { Nav.toggle-members(); }
|
|
}
|
|
}
|
|
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); }
|
|
}
|
|
}
|
|
}
|
|
// 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");
|
|
}
|
|
}
|