Files
VoelinClient/crates/voelin-ui/ui/screens/friends.slint
T
selikhovandClaude Opus 5.5 a8a2409cb8 Private chat tabs named after the peer; form, Library and phone fixes
A private chat's tab took the name of whoever wrote the first message
of a batch (our own name when we wrote first) or the raw unique id: it
is the peer's name now. The event form's fields keep together, the
Library shows sample recordings without the user's folder in sample
mode, and the phone's Friends page is not titled twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 13:57:08 +03:00

445 lines
17 KiB
Plaintext

// Friends: the contacts (friend, blocked or neutral), where each is now
// (server, channel, away, streaming), and what can be done with them:
// message, poke, join their channel, watch their stream, the relation, a
// note, their volume.
import { Theme } from "../theme.slint";
import { Icons } from "../icons.slint";
import { Bridge, ContactItem } from "../bridge.slint";
import { Nav, Page } from "../nav.slint";
import { Icon, Button, ButtonKind, IconButton, Avatar, Status, Chip, LiveBadge, SegmentedTabs, SearchBox, TextField, Slider, Divider, Field, ListView, ScrollView } from "../components/index.slint";
// One contact: avatar, name, what they do and where, quick actions.
component ContactRow inherits Rectangle {
in property <ContactItem> person;
height: 64px * Theme.font-scale;
border-radius: Theme.radius-md;
background: person.selected ? Theme.accent-soft : touch.has-hover ? Theme.surface-3 : transparent;
border-width: person.selected ? 1px : 0px;
border-color: Theme.accent;
accessible-role: AccessibleRole.list-item;
accessible-label: person.name;
accessible-description: person.status;
accessible-item-selectable: true;
accessible-item-selected: person.selected;
accessible-action-default => { Bridge.select-contact(person.uid); }
touch := TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => { Bridge.select-contact(root.person.uid); }
double-clicked => { Bridge.contact-action(root.person.uid, "message"); }
}
opacity: person.relation == "blocked" ? 0.7 : 1.0;
HorizontalLayout {
padding-left: Theme.space-3;
padding-right: Theme.space-3;
spacing: Theme.space-4;
VerticalLayout {
alignment: center;
Avatar {
size: 44px;
initials: root.person.initials;
tint: root.person.tint;
image: root.person.avatar;
label: root.person.name;
status: !root.person.online ? Status.offline : root.person.away ? Status.idle : Status.online;
}
}
VerticalLayout {
alignment: center;
horizontal-stretch: 1;
spacing: 1px;
HorizontalLayout {
spacing: Theme.space-2;
alignment: start;
Text {
text: root.person.name;
color: root.person.relation == "friend" ? Theme.name-text : Theme.text;
font-size: Theme.font-md;
font-weight: Theme.weight-semibold;
overflow: elide;
}
if root.person.relation == "blocked": Chip {
text: @tr("Blocked");
icon: Icons.ban;
tint: Theme.danger;
y: (parent.height - self.height) / 2;
}
if root.person.streaming: LiveBadge {
y: (parent.height - self.height) / 2;
}
}
Text {
text: root.person.status;
color: root.person.online ? Theme.text-secondary : Theme.text-muted;
font-size: Theme.font-sm;
overflow: elide;
}
if root.person.place != "": Text {
text: root.person.place;
color: Theme.text-muted;
font-size: Theme.font-xs;
overflow: elide;
}
}
if root.person.relation != "blocked": HorizontalLayout {
spacing: Theme.space-1;
IconButton {
icon: Icons.message-square;
label: @tr("Message {}", root.person.name);
filled: true;
round: true;
size: 34px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Bridge.contact-action(root.person.uid, "message"); }
}
if root.person.reachable: IconButton {
icon: Icons.hand;
label: @tr("Poke {}", root.person.name);
filled: true;
round: true;
size: 34px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Bridge.contact-action(root.person.uid, "poke"); }
}
if root.person.online: IconButton {
icon: Icons.log-in;
label: @tr("Join {}'s channel", root.person.name);
filled: true;
round: true;
size: 34px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Bridge.contact-action(root.person.uid, "join"); }
}
if root.person.streaming: IconButton {
icon: Icons.monitor;
label: @tr("Watch {}'s stream", root.person.name);
filled: true;
round: true;
size: 34px;
icon-size: Theme.icon-sm;
tint: Theme.live;
y: (parent.height - self.height) / 2;
clicked => { Bridge.contact-action(root.person.uid, "watch"); }
}
}
}
}
// The contacts with tabs and a search.
export component FriendsPage inherits VerticalLayout {
in property <bool> compact;
padding: compact ? Theme.space-4 : Theme.space-6;
spacing: Theme.space-4;
// The phone's top bar names the page.
if !root.compact: HorizontalLayout {
spacing: Theme.space-4;
if !root.compact: Icon {
source: Icons.users;
size: 30px;
tint: Theme.accent-text;
y: (parent.height - self.height) / 2;
}
Text {
text: @tr("Friends");
font-size: Theme.font-2xl;
font-weight: Theme.weight-bold;
color: Theme.text;
vertical-alignment: center;
}
if !root.compact: SegmentedTabs {
max-width: 420px;
y: (parent.height - self.height) / 2;
model: [@tr("Online — {}", Bridge.contacts-online), @tr("All — {}", Bridge.contacts-all), @tr("Blocked — {}", Bridge.contacts-blocked)];
current-index: Nav.friends-tab;
label: @tr("Which contacts");
selected(i) => {
Nav.friends-tab = i;
Bridge.friends-tab(i);
}
}
if !root.compact: Rectangle {
horizontal-stretch: 1;
}
if !root.compact: SearchBox {
max-width: 280px;
height: 38px;
y: (parent.height - self.height) / 2;
show-shortcut: false;
placeholder: @tr("Search contacts");
label: @tr("Search contacts");
edited(text) => { Bridge.search-contacts(text); }
}
}
if root.compact: SegmentedTabs {
model: [@tr("Online"), @tr("All"), @tr("Blocked")];
current-index: Nav.friends-tab;
label: @tr("Which contacts");
selected(i) => {
Nav.friends-tab = i;
Bridge.friends-tab(i);
}
}
if root.compact: SearchBox {
height: 38px;
show-shortcut: false;
placeholder: @tr("Search contacts");
label: @tr("Search contacts");
edited(text) => { Bridge.search-contacts(text); }
}
if Bridge.contacts.length == 0: VerticalLayout {
spacing: Theme.space-2;
padding-top: Theme.space-6;
alignment: start;
Text {
text: Nav.friends-tab == 0 ? @tr("None of your friends is online right now.")
: Nav.friends-tab == 2 ? @tr("You have blocked no one.")
: @tr("No contacts yet.");
color: Theme.text-secondary;
font-size: Theme.font-lg;
horizontal-alignment: center;
}
Text {
text: @tr("Open a person's card in a server's members panel to add them as a friend or to block them. Friends show up here on every server they are on.");
color: Theme.text-muted;
wrap: word-wrap;
horizontal-alignment: center;
}
HorizontalLayout {
alignment: center;
padding-top: Theme.space-3;
Button {
icon: Icons.server;
text: @tr("Go to a server");
clicked => { Nav.show(Page.server); }
}
}
}
ListView {
vertical-stretch: 1;
accessible-role: AccessibleRole.list;
accessible-label: @tr("Contacts");
for person in Bridge.contacts: VerticalLayout {
padding-bottom: Theme.space-1;
ContactRow {
person: person;
}
}
}
}
// Everything about the selected contact (the right panel).
export component ContactPanel inherits Rectangle {
property <ContactItem> c: Bridge.contact;
sv := ScrollView {
VerticalLayout {
width: sv.visible-width;
padding: Theme.space-5;
spacing: Theme.space-4;
alignment: start;
HorizontalLayout {
alignment: end;
IconButton {
icon: Icons.x;
label: @tr("Close");
size: 28px;
icon-size: Theme.icon-sm;
clicked => { Bridge.select-contact(""); }
}
}
HorizontalLayout {
alignment: center;
Avatar {
size: 84px;
initials: root.c.initials;
tint: root.c.tint;
image: root.c.avatar;
label: root.c.name;
status: !root.c.online ? Status.offline : root.c.away ? Status.idle : Status.online;
}
}
VerticalLayout {
spacing: Theme.space-1;
Text {
text: root.c.name;
color: Theme.text;
font-size: Theme.font-xl;
font-weight: Theme.weight-semibold;
horizontal-alignment: center;
overflow: elide;
}
Text {
text: root.c.status;
color: root.c.online ? Theme.success : Theme.text-muted;
font-size: Theme.font-sm;
horizontal-alignment: center;
wrap: word-wrap;
}
}
HorizontalLayout {
alignment: center;
spacing: Theme.space-2;
if root.c.relation == "friend": Chip {
text: @tr("Friend");
icon: Icons.user-check;
tint: Theme.success;
}
if root.c.relation == "blocked": Chip {
text: @tr("Blocked");
icon: Icons.ban;
tint: Theme.danger;
}
if root.c.streaming: LiveBadge { }
}
HorizontalLayout {
spacing: Theme.space-2;
Button {
horizontal-stretch: 1;
small: true;
icon: Icons.message-square;
text: @tr("Message");
enabled: root.c.relation != "blocked";
clicked => { Bridge.contact-action(root.c.uid, "message"); }
}
Button {
horizontal-stretch: 1;
small: true;
icon: Icons.hand;
text: @tr("Poke");
enabled: root.c.reachable;
clicked => { Bridge.contact-action(root.c.uid, "poke"); }
}
}
HorizontalLayout {
spacing: Theme.space-2;
Button {
horizontal-stretch: 1;
small: true;
icon: Icons.log-in;
text: @tr("Join");
enabled: root.c.online;
clicked => { Bridge.contact-action(root.c.uid, "join"); }
}
Button {
horizontal-stretch: 1;
small: true;
icon: Icons.monitor;
text: @tr("Watch");
enabled: root.c.streaming;
clicked => { Bridge.contact-action(root.c.uid, "watch"); }
}
}
Divider { }
Text {
text: root.c.online ? @tr("Where") : @tr("Last seen");
color: Theme.text;
font-weight: Theme.weight-semibold;
}
for spot in root.c.spots: HorizontalLayout {
spacing: Theme.space-3;
Icon {
source: Icons.server;
size: Theme.icon-sm;
tint: Theme.text-secondary;
y: (parent.height - self.height) / 2;
}
Text {
text: spot;
color: Theme.text-secondary;
font-size: Theme.font-sm;
horizontal-stretch: 1;
wrap: word-wrap;
}
}
if root.c.spots.length == 0: Text {
text: root.c.place != "" ? root.c.place : @tr("Not seen on your servers yet.");
color: Theme.text-muted;
font-size: Theme.font-sm;
wrap: word-wrap;
}
Divider { }
Field {
label: @tr("Note");
hint: @tr("Only on this device. Press Enter to keep it.");
TextField {
text: root.c.note;
placeholder: @tr("Add a note");
icon: Icons.pencil;
label: @tr("Note about {}", root.c.name);
accepted(text) => { Bridge.contact-note(root.c.uid, text); }
}
}
VerticalLayout {
spacing: Theme.space-2;
HorizontalLayout {
Text {
text: @tr("Volume for me");
color: Theme.text-secondary;
font-size: Theme.font-sm;
horizontal-stretch: 1;
}
Text {
text: @tr("{}%", round(root.c.volume));
color: Theme.text-muted;
font-size: Theme.font-xs;
}
}
HorizontalLayout {
spacing: Theme.space-2;
IconButton {
icon: root.c.muted ? Icons.volume-x : Icons.volume-2;
label: root.c.muted ? @tr("Unmute for me") : @tr("Mute for me");
checked: root.c.muted;
danger: true;
size: 30px;
icon-size: Theme.icon-sm;
clicked => { Bridge.contact-action(root.c.uid, "mute"); }
}
Slider {
horizontal-stretch: 1;
minimum: 0;
maximum: 400;
step: 5;
value: root.c.volume;
enabled: !root.c.muted;
label: @tr("Volume of {}", root.c.name);
released(v) => { Bridge.contact-volume(root.c.uid, v); }
}
}
}
Divider { }
VerticalLayout {
spacing: Theme.space-2;
Button {
icon: root.c.relation == "friend" ? Icons.user-x : Icons.user-plus;
text: root.c.relation == "friend" ? @tr("Remove friend") : @tr("Add friend");
centered: false;
clicked => { Bridge.contact-action(root.c.uid, root.c.relation == "friend" ? "neutral" : "friend"); }
}
Button {
kind: root.c.relation == "blocked" ? ButtonKind.secondary : ButtonKind.danger;
icon: Icons.ban;
text: root.c.relation == "blocked" ? @tr("Unblock") : @tr("Block");
centered: false;
clicked => { Bridge.contact-action(root.c.uid, root.c.relation == "blocked" ? "neutral" : "block"); }
}
Button {
kind: ButtonKind.ghost;
icon: Icons.trash-2;
text: @tr("Forget this contact");
centered: false;
clicked => { Bridge.contact-action(root.c.uid, "remove"); }
}
}
if root.c.since != "": Text {
text: root.c.since;
color: Theme.text-muted;
font-size: Theme.font-xs;
horizontal-alignment: center;
}
}
}
}