ui: links open, and Copy text and Quote on every message
Links in chat did nothing. classify_link (vm/bbcode.rs) sorts an address
into a web page, a TeamSpeak server, a channel file or no link, and only
those reach TextRun.link. A click on a web link opens it through
App::open_url, the one place a platform without xdg-open can hook; one
whose text is not its address first shows where it goes (LinkDialog).
TeamSpeak links are copied until Voelin opens them. A right-click on a
link opens or copies it.
The hover bar was there only for messages a gateway knows. Every message
now has it, with Quote ("> Author: …" lines at the start of the
composer; TeamSpeak clients show [quote] as it is) and Copy text, and a
right-click menu. After Quote the composer has the focus, its cursor
below the quote, and grows to show the quote's lines: its field is one
line high, so an answer typed after clicking into it went into the
quote's last line. The bar keeps itself shown while the pointer is on
it or on the message's links and reactions: it reaches above its row,
where the row's hover ended, so its buttons could not be clicked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
17 files changed
+700
-169
No files matched your search
@@ -28,6 +28,12 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows
|
||||
- Other people's myTeamSpeak badges: up to three pictures after their name
|
||||
in the channel tree and the members panel, and their names on the member
|
||||
card (what each is for on hover).
|
||||
- Links in chat open in the browser; one whose text is not its address
|
||||
first shows where it goes. A right-click on a link opens or copies it;
|
||||
TeamSpeak links are copied for now.
|
||||
- Every message can be quoted into the composer (`> ` lines) and its text
|
||||
copied, from the actions on hover or a right-click menu, also on servers
|
||||
without a gateway.
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -865,6 +865,13 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
/// Open a page on the web in the browser. Pages open through here, so
|
||||
/// a platform without a desktop opener (Android) can open them its own
|
||||
/// way.
|
||||
pub(crate) fn open_url(&self, url: &str) -> std::io::Result<()> {
|
||||
open_target(std::ffi::OsStr::new(url))
|
||||
}
|
||||
|
||||
/// Nav.copy put text on the clipboard: one toast says so.
|
||||
pub fn copied(&mut self) {
|
||||
let text = self.copy_note.take().unwrap_or_else(|| "Copied".to_owned());
|
||||
|
||||
@@ -55,6 +55,10 @@ pub(super) fn wire(ui: &MainWindow) {
|
||||
bridge.on_create_topic(|key, title| {
|
||||
with_app(|app| app.create_topic(key, title.to_string()));
|
||||
});
|
||||
bridge.on_open_link(|link, masked| {
|
||||
with_app(|app| app.open_link_text(&link, masked)).unwrap_or_default().into()
|
||||
});
|
||||
bridge.on_quote_text(|author, text| crate::vm::chat::quote(&author, &text).into());
|
||||
bridge.on_open_member(|id| {
|
||||
with_app(|app| app.open_member(id));
|
||||
});
|
||||
|
||||
@@ -21,9 +21,10 @@ use voelin_core::{
|
||||
use voelin_gateway_proto::{ErrorCode, TopicInfo, feature};
|
||||
use voelin_model::{ChatMessage, ChatTarget, HostMessageMode, ServerDetails};
|
||||
|
||||
use crate::app::{App, Bridge, ChatLine, ChatTab, FileItem, Msg, PinItem, SessionView, Tab};
|
||||
use crate::app::{App, Bridge, ChatLine, ChatTab, FileItem, Msg, Nav, PinItem, SessionView, Tab};
|
||||
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
||||
use crate::vm;
|
||||
use crate::vm::bbcode::LinkKind;
|
||||
use crate::vm::chat::{LineCache, LineCtx, Previous};
|
||||
|
||||
/// Where the server's welcome and host message keep what their lines were
|
||||
@@ -350,7 +351,8 @@ impl App {
|
||||
}
|
||||
|
||||
/// What the server says to everyone who connects ([`server_texts`]) as
|
||||
/// the first lines of the server chat: by the server, without actions.
|
||||
/// the first lines of the server chat: by the server, without reactions
|
||||
/// or pins.
|
||||
fn server_lines(
|
||||
view: &SessionView,
|
||||
pictures: Option<&HashMap<String, PathBuf>>,
|
||||
@@ -545,6 +547,37 @@ impl App {
|
||||
vm::list::sync(&self.models.topic_messages, &self.lines_of(view, tab, false));
|
||||
}
|
||||
|
||||
/// A link in a message was clicked (`masked`: its text shows something
|
||||
/// else, [`vm::bbcode::is_masked`]). A page on the web opens in the
|
||||
/// browser, a masked one once the user saw where it goes (Nav.link-open);
|
||||
/// a TeamSpeak link is copied until Voelin opens them. Returns what to
|
||||
/// copy ("": nothing).
|
||||
pub(crate) fn open_link_text(&mut self, link: &str, masked: bool) -> String {
|
||||
match vm::bbcode::classify_link(link) {
|
||||
LinkKind::Web(url) if masked => {
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
let nav = ui.global::<Nav>();
|
||||
nav.set_link_host(vm::bbcode::link_host(&url).into());
|
||||
nav.set_link_url(url.into());
|
||||
nav.set_link_open(true);
|
||||
}
|
||||
String::new()
|
||||
}
|
||||
LinkKind::Web(url) => {
|
||||
if let Err(e) = self.open_url(&url) {
|
||||
self.set_status(format!("Cannot open the link: {e}"));
|
||||
}
|
||||
String::new()
|
||||
}
|
||||
LinkKind::Server(url) => {
|
||||
self.copy_note = Some("TeamSpeak links open in Voelin soon; copied".to_owned());
|
||||
url
|
||||
}
|
||||
// A file opens from its card.
|
||||
LinkKind::File | LinkKind::Refused => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
// Gateway features of a chat.
|
||||
|
||||
/// A request to the current session's gateway.
|
||||
|
||||
@@ -26,8 +26,11 @@
|
||||
//! after `friends`, else for the first other client, its card open),
|
||||
//! `channel-password` (the password dialog of the first locked channel,
|
||||
//! the sample's Officers; `channel-password:wrong` as after a refused
|
||||
//! one), `watch` (the first stream; with sample data the
|
||||
//! local test pattern in its place), `popout` (the same, popped out),
|
||||
//! one), `actions` (the last message's actions, as if hovered),
|
||||
//! `link-confirm[:<url>]` (the question before a masked link opens, by
|
||||
//! default the sample's raid board), `watch` (the first stream; with
|
||||
//! sample data the local test pattern in its place), `popout` (the same,
|
||||
//! popped out),
|
||||
//! `tab:<home|servers|chat|activity|you>` (phone layout); `friends[:<uid>]`,
|
||||
//! `messages[:<uid>]` (a private chat), `inbox` (offline messages),
|
||||
//! `library`, `events`, `event-form`, `search[:<text>]`,
|
||||
@@ -283,6 +286,12 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
"channel-password" => {
|
||||
with_app(|app| open_channel_password(app, arg == "wrong"));
|
||||
}
|
||||
// A screenshot cannot hover.
|
||||
"actions" => nav.set_show_actions(true),
|
||||
"link-confirm" => {
|
||||
let url = if arg.is_empty() { DEMO_RAID_BOARD } else { arg };
|
||||
with_app(|app| app.open_link_text(url, true));
|
||||
}
|
||||
"watch" | "popout" => {
|
||||
with_app(|app| {
|
||||
if switches.demo_ui { app.demo_watch() } else { app.watch_first_stream() }
|
||||
@@ -1103,6 +1112,8 @@ const DEMO_MUSIC_BANNER: &str = "https://nightfall.example/music.png";
|
||||
const DEMO_RAID_BANNER: &str = "https://nightfall.example/raid.png";
|
||||
/// A picture a message shows (`[img]`).
|
||||
const DEMO_LOOT_PICTURE: &str = "https://nightfall.example/loot.png";
|
||||
/// The sample's masked link (`VOELIN_OPEN=link-confirm`).
|
||||
const DEMO_RAID_BOARD: &str = "https://nightfall.example/raids";
|
||||
const DEMO_SERVER_ICON: u32 = 3_120_211_001;
|
||||
const DEMO_ADMIN_ICON: u32 = 3_120_211_002;
|
||||
const DEMO_MOD_ICON: u32 = 3_120_211_003;
|
||||
@@ -1454,9 +1465,10 @@ fn demo_chat(app: &mut App, session: u64) {
|
||||
DEMO,
|
||||
"Nova",
|
||||
1,
|
||||
"[b]Raid night[/b] moves from [s]20:00[/s] to [color=#ff8a3d]20:30[/color], sign up \
|
||||
on the [url=https://nightfall.example/raids]raid board[/url]."
|
||||
.into(),
|
||||
format!(
|
||||
"[b]Raid night[/b] moves from [s]20:00[/s] to [color=#ff8a3d]20:30[/color], \
|
||||
sign up on the [url={DEMO_RAID_BOARD}]raid board[/url]."
|
||||
),
|
||||
9,
|
||||
false,
|
||||
vec![react("👍", 4, true)],
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
//! - Bare addresses (`https://…`, `www.…`) are links, without the
|
||||
//! punctuation after them.
|
||||
//! - Links only go to the web, to TeamSpeak servers and to channel files
|
||||
//! ([`link_target`]): `[url=javascript:…]` is no link.
|
||||
//! ([`classify_link`]): `[url=javascript:…]` is no link.
|
||||
//! - Past [`MAX_DEPTH`] tags open at once or [`MAX_RUNS`] spans, a message
|
||||
//! is plain text.
|
||||
|
||||
@@ -264,35 +264,114 @@ fn trim_lines(blocks: &mut Vec<Block>) {
|
||||
blocks.drain(..start);
|
||||
}
|
||||
|
||||
/// Schemes a link may have: the web, TeamSpeak servers, channel files.
|
||||
const SCHEMES: [&str; 8] = [
|
||||
"https://",
|
||||
"http://",
|
||||
"ts3server://",
|
||||
"teamspeak://",
|
||||
"ts3file://",
|
||||
"tsfile://",
|
||||
"ts5file://",
|
||||
"ts6file://",
|
||||
];
|
||||
/// What a link is, and so what a click on it does.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum LinkKind {
|
||||
/// A page on the web, opened in the browser: the address with its scheme
|
||||
/// in lower case (`www.…` as `https://www.…`).
|
||||
Web(String),
|
||||
/// A TeamSpeak server: `ts3server://`, `teamspeak://` or an invite on
|
||||
/// `tmspk.gg`.
|
||||
Server(String),
|
||||
/// A channel's file (`ts3file://` and the like): the chat shows it as a
|
||||
/// card.
|
||||
File,
|
||||
/// No link: any other scheme (`javascript:`, `file:`, `data:`, `smb:`),
|
||||
/// a backslash (a Windows share, `\\host`, gets the user's credentials,
|
||||
/// and browsers read `\` as `/`, so the host would not be the one
|
||||
/// shown), spaces or control characters, or a leading `-` (an opener
|
||||
/// would read it as an option).
|
||||
Refused,
|
||||
}
|
||||
|
||||
/// Where a link may go: the web (`www.…` as `https://www.…`), TeamSpeak
|
||||
/// servers (`ts3server`, `teamspeak`) and channel files (`ts3file` and the
|
||||
/// like, which the chat shows as cards). Anything else (`javascript:`,
|
||||
/// `file:`, `data:`, an address with spaces) is no link.
|
||||
pub fn link_target(address: &str) -> Option<String> {
|
||||
const WEB: [&str; 2] = ["https://", "http://"];
|
||||
const SERVERS: [&str; 2] = ["ts3server://", "teamspeak://"];
|
||||
const FILES: [&str; 4] = ["ts3file://", "tsfile://", "ts5file://", "ts6file://"];
|
||||
|
||||
/// Hosts of TeamSpeak's invite links, which open a server.
|
||||
const INVITE_HOSTS: [&str; 2] = ["tmspk.gg", "www.tmspk.gg"];
|
||||
|
||||
/// What `address` links to. Only the web, TeamSpeak servers and channel
|
||||
/// files are links, so nothing else reaches the desktop's opener.
|
||||
pub fn classify_link(address: &str) -> LinkKind {
|
||||
let address = address.trim();
|
||||
if address.chars().any(|c| c.is_whitespace() || c.is_control()) {
|
||||
return None;
|
||||
if address.starts_with('-')
|
||||
|| address.contains('\\')
|
||||
|| address.chars().any(|c| c.is_whitespace() || c.is_control())
|
||||
{
|
||||
return LinkKind::Refused;
|
||||
}
|
||||
// The same length in bytes: an index of one is one of the other.
|
||||
let lower = address.to_ascii_lowercase();
|
||||
if lower.starts_with("www.") && address.len() > 4 {
|
||||
return Some(format!("https://{address}"));
|
||||
let (scheme, rest) = if lower.starts_with("www.") && lower.len() > 4 {
|
||||
("https://", address)
|
||||
} else if let Some(at) = lower.find("://") {
|
||||
(&lower[..at + 3], &address[at + 3..])
|
||||
} else {
|
||||
return LinkKind::Refused;
|
||||
};
|
||||
if host_of(rest).is_empty() {
|
||||
return LinkKind::Refused;
|
||||
}
|
||||
if WEB.contains(&scheme) {
|
||||
let url = format!("{scheme}{rest}");
|
||||
if INVITE_HOSTS.contains(&host_of(rest).to_ascii_lowercase().as_str()) {
|
||||
LinkKind::Server(url)
|
||||
} else {
|
||||
LinkKind::Web(url)
|
||||
}
|
||||
} else if SERVERS.contains(&scheme) {
|
||||
LinkKind::Server(format!("{scheme}{rest}"))
|
||||
} else if FILES.contains(&scheme) {
|
||||
LinkKind::File
|
||||
} else {
|
||||
LinkKind::Refused
|
||||
}
|
||||
}
|
||||
|
||||
/// The host of an address after its scheme: without the user before an
|
||||
/// `@`, the port and the path (`me@Example.org:8080/a` → `Example.org`).
|
||||
fn host_of(rest: &str) -> &str {
|
||||
let authority = rest.split(['/', '?', '#']).next().unwrap_or_default();
|
||||
let host = authority.rsplit_once('@').map_or(authority, |(_, host)| host);
|
||||
match host.strip_prefix('[') {
|
||||
// An IPv6 address, in brackets.
|
||||
Some(v6) => v6.split(']').next().unwrap_or_default(),
|
||||
None => host.split(':').next().unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The host a link goes to, in lower case (`https://me@Example.org:8080/a`
|
||||
/// → `example.org`): what a masked link's question shows.
|
||||
pub fn link_host(address: &str) -> String {
|
||||
let address = address.trim();
|
||||
let rest = address.find("://").map_or(address, |at| &address[at + 3..]);
|
||||
host_of(rest).to_lowercase()
|
||||
}
|
||||
|
||||
/// Whether a link's text shows something else than where it goes: a page's
|
||||
/// name (`[url=…]raid board[/url]`) or another address. Its own address
|
||||
/// (`[url]…[/url]`, a bare address, `www.…` for `https://www.…`) in any case
|
||||
/// and with or without a `/` at the end is not.
|
||||
pub fn is_masked(text: &str, link: &str) -> bool {
|
||||
fn bare(address: &str) -> String {
|
||||
let lower = address.trim().to_lowercase();
|
||||
let rest = WEB.iter().find_map(|s| lower.strip_prefix(s)).unwrap_or(&lower);
|
||||
rest.trim_end_matches('/').to_owned()
|
||||
}
|
||||
bare(text) != bare(link)
|
||||
}
|
||||
|
||||
/// Where a link may go ([`classify_link`]): the web (`www.…` as
|
||||
/// `https://www.…`), TeamSpeak servers and channel files (which the chat
|
||||
/// shows as cards). Anything else (`javascript:`, `file:`, `data:`, an
|
||||
/// address with spaces) is no link.
|
||||
pub fn link_target(address: &str) -> Option<String> {
|
||||
match classify_link(address) {
|
||||
LinkKind::Web(url) | LinkKind::Server(url) => Some(url),
|
||||
LinkKind::File => Some(address.trim().to_owned()),
|
||||
LinkKind::Refused => None,
|
||||
}
|
||||
SCHEMES
|
||||
.iter()
|
||||
.any(|s| lower.starts_with(s) && address.len() > s.len())
|
||||
.then(|| address.to_owned())
|
||||
}
|
||||
|
||||
/// An address on the web (`http`, `https`).
|
||||
@@ -971,6 +1050,104 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn link_kinds() {
|
||||
let web = |u: &str| LinkKind::Web(u.into());
|
||||
let server = |u: &str| LinkKind::Server(u.into());
|
||||
for (address, kind) in [
|
||||
("https://x.org/a?b=1#c", web("https://x.org/a?b=1#c")),
|
||||
("http://x.org", web("http://x.org")),
|
||||
("HTTPS://X.org/A", web("https://X.org/A")),
|
||||
(" https://x.org ", web("https://x.org")),
|
||||
("www.x.org/a", web("https://www.x.org/a")),
|
||||
("WWW.x.org", web("https://WWW.x.org")),
|
||||
("www.x.org/?to=https://y.org", web("https://www.x.org/?to=https://y.org")),
|
||||
("https://me@x.org:8443/", web("https://me@x.org:8443/")),
|
||||
("ts3server://ts.example?port=9987", server("ts3server://ts.example?port=9987")),
|
||||
("TeamSpeak://invite=abc", server("teamspeak://invite=abc")),
|
||||
("https://tmspk.gg/s/ts.example", server("https://tmspk.gg/s/ts.example")),
|
||||
("https://www.TMSPK.gg/abc", server("https://www.TMSPK.gg/abc")),
|
||||
("ts3file://a.png?serverUID=x&channel=1", LinkKind::File),
|
||||
("ts6file://a.png", LinkKind::File),
|
||||
] {
|
||||
assert_eq!(classify_link(address), kind, "{address}");
|
||||
}
|
||||
for address in [
|
||||
"",
|
||||
"www.",
|
||||
"https://",
|
||||
"https:///path",
|
||||
"https://?q",
|
||||
"javascript:alert(1)",
|
||||
"JavaScript://x.org/%0aalert(1)",
|
||||
"file:///etc/passwd",
|
||||
"data:text/html,<b>x</b>",
|
||||
"smb://host/share",
|
||||
"mailto:a@x.org",
|
||||
"\\\\host\\share",
|
||||
"https://x.org\\@y.org",
|
||||
"-https://x.org",
|
||||
"--help",
|
||||
"https://x.org/a b",
|
||||
"https://x.org/\u{7}",
|
||||
"https://x.org/\na",
|
||||
"x.org",
|
||||
] {
|
||||
assert_eq!(classify_link(address), LinkKind::Refused, "{address:?}");
|
||||
}
|
||||
// What a message links to is classified.
|
||||
assert_eq!(link_target("WWW.x.org").as_deref(), Some("https://WWW.x.org"));
|
||||
assert_eq!(link_target("ts3file://a.png").as_deref(), Some("ts3file://a.png"));
|
||||
assert_eq!(link_target("smb://host/share"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn link_hosts() {
|
||||
assert_eq!(link_host("https://me@Example.org:8443/a?b#c"), "example.org");
|
||||
assert_eq!(link_host("https://good.example@evil.example/"), "evil.example");
|
||||
assert_eq!(link_host("http://[::1]:80/"), "::1");
|
||||
assert_eq!(link_host("https://x.org"), "x.org");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn masked_links() {
|
||||
// Its own address is not masked, as the parser links it.
|
||||
for (text, link) in [
|
||||
("https://x.org", "https://x.org"),
|
||||
("www.x.org", "https://www.x.org"),
|
||||
("HTTPS://X.ORG/", "https://x.org"),
|
||||
("x.org/a", "https://x.org/a/"),
|
||||
] {
|
||||
assert!(!is_masked(text, link), "{text} → {link}");
|
||||
}
|
||||
for (text, link) in [
|
||||
("raid board", "https://x.org/raids"),
|
||||
("https://bank.example", "https://evil.example"),
|
||||
("bank.example", "https://bank.example.evil.example"),
|
||||
("", "https://x.org"),
|
||||
] {
|
||||
assert!(is_masked(text, link), "{text} → {link}");
|
||||
}
|
||||
// Spans as the parser makes them.
|
||||
let masked = |source: &str| {
|
||||
let doc = parse(source);
|
||||
doc.blocks[0]
|
||||
.spans
|
||||
.iter()
|
||||
.filter_map(|s| match s {
|
||||
Span::Text { text, style: Style { link: Some(link), .. } } => {
|
||||
Some(is_masked(text, link))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(masked("see https://x.org and www.y.org"), [false, false]);
|
||||
assert_eq!(masked("[url]https://x.org[/url]"), [false]);
|
||||
assert_eq!(masked("[url=https://x.org]the page[/url]"), [true]);
|
||||
assert_eq!(masked("[url=https://evil.example]https://x.org[/url]"), [true]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn case_and_nesting() {
|
||||
assert_eq!(spans("[B]x[/b]"), [styled("x", bold())]);
|
||||
|
||||
@@ -204,8 +204,15 @@ fn inks(color: Option<[u8; 3]>) -> (Color, Color) {
|
||||
}
|
||||
}
|
||||
|
||||
/// A run of `text` (or the emoji `emoji`) in `style`.
|
||||
fn run(text: &str, emoji: Option<String>, style: &Style, inks: (Color, Color)) -> TextRun {
|
||||
/// A run of `text` (or the emoji `emoji`) in `style`; `masked`: its link's
|
||||
/// text shows something else ([`bbcode::is_masked`]).
|
||||
fn run(
|
||||
text: &str,
|
||||
emoji: Option<String>,
|
||||
style: &Style,
|
||||
masked: bool,
|
||||
inks: (Color, Color),
|
||||
) -> TextRun {
|
||||
TextRun {
|
||||
text: text.into(),
|
||||
emoji: emoji.unwrap_or_default().into(),
|
||||
@@ -217,6 +224,7 @@ fn run(text: &str, emoji: Option<String>, style: &Style, inks: (Color, Color)) -
|
||||
ink_dark: inks.0,
|
||||
ink_light: inks.1,
|
||||
link: style.link.clone().unwrap_or_default().into(),
|
||||
masked,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,6 +255,7 @@ fn runs_of(spans: &[Span]) -> (Vec<TextRun>, bool) {
|
||||
match span {
|
||||
Span::Text { text, style } => {
|
||||
let inks = inks(style.color);
|
||||
let masked = style.link.as_deref().is_some_and(|l| bbcode::is_masked(text, l));
|
||||
let words = if style.code && text.graphemes(true).count() <= LONG_WORD {
|
||||
vec![emoji::Run { text: text.clone(), emoji: None }]
|
||||
} else {
|
||||
@@ -255,9 +264,11 @@ fn runs_of(spans: &[Span]) -> (Vec<TextRun>, bool) {
|
||||
for word in words {
|
||||
any_emoji |= word.emoji.is_some();
|
||||
match word.emoji {
|
||||
Some(key) => runs.push(run(&word.text, Some(key), style, inks)),
|
||||
Some(key) => runs.push(run(&word.text, Some(key), style, masked, inks)),
|
||||
None => runs.extend(
|
||||
pieces(&word.text).into_iter().map(|p| run(p, None, style, inks)),
|
||||
pieces(&word.text)
|
||||
.into_iter()
|
||||
.map(|p| run(p, None, style, masked, inks)),
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -265,7 +276,9 @@ fn runs_of(spans: &[Span]) -> (Vec<TextRun>, bool) {
|
||||
// A picture that is not shown: its address, as a link.
|
||||
Span::Image { url } => {
|
||||
let style = Style { link: Some(url.clone()), ..Style::default() };
|
||||
runs.extend(pieces(url).into_iter().map(|p| run(p, None, &style, inks(None))));
|
||||
runs.extend(
|
||||
pieces(url).into_iter().map(|p| run(p, None, &style, false, inks(None))),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -376,6 +389,21 @@ pub fn preview(message: &ChatMessage) -> (String, String) {
|
||||
(format!("{}: {text}", message.author_name), time_of(message.ts_ms))
|
||||
}
|
||||
|
||||
/// `text` by `author` as a quote to answer below: each line after `> `,
|
||||
/// the first with who said it ("> Nova: see you at 8\n> bring elixirs\n");
|
||||
/// "" for no text. TeamSpeak clients show `[quote]` as it is, so a quote
|
||||
/// is plain lines.
|
||||
pub fn quote(author: &str, text: &str) -> String {
|
||||
let mut out = String::new();
|
||||
for (i, line) in text.trim().lines().enumerate() {
|
||||
match i {
|
||||
0 if !author.is_empty() => out.push_str(&format!("> {author}: {line}\n")),
|
||||
_ => out.push_str(&format!("> {line}\n")),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The line of a stored message; `previous` is the line before it.
|
||||
pub fn history_line(
|
||||
message: &HistoryMessage,
|
||||
@@ -422,8 +450,8 @@ pub fn server_message(server: &str, text: &str) -> ChatMessage {
|
||||
}
|
||||
|
||||
/// A message of the server ([`server_message`]) as a line of the server
|
||||
/// chat: by the server, without a time or actions. `id` keeps what it was
|
||||
/// built from in the cache, apart from the messages'.
|
||||
/// chat: by the server, without a time, reactions or pins. `id` keeps what
|
||||
/// it was built from in the cache, apart from the messages'.
|
||||
pub fn server_line(server: &str, text: &str, id: i64, continued: bool, ctx: &LineCtx) -> ChatLine {
|
||||
let message = server_message(server, text);
|
||||
let previous = continued.then(|| Previous::of(&message));
|
||||
@@ -636,6 +664,7 @@ mod tests {
|
||||
(address.text.as_str(), address.link.as_str()),
|
||||
("https://x.org/raid", "https://x.org/raid")
|
||||
);
|
||||
assert!(!address.masked, "its own address");
|
||||
assert!(runs(&line, 3)[0].underline);
|
||||
assert!(runs(&line, 4).is_empty(), "a rule has no runs");
|
||||
// Code: a block per line, empty ones kept.
|
||||
@@ -650,6 +679,35 @@ mod tests {
|
||||
assert!(!relayed.rich && relayed.text == "[Nova] hi [1]" && relayed.link.is_empty());
|
||||
}
|
||||
|
||||
/// A link whose text is not its address asks before it opens: each of
|
||||
/// its runs says so.
|
||||
#[test]
|
||||
fn masked_link_runs() {
|
||||
let text = "on the [url=https://x.org/raids]raid board[/url], or www.x.org";
|
||||
let line = line(&message("A", text, 0), None);
|
||||
let links: Vec<(String, bool)> = runs(&line, 0)
|
||||
.iter()
|
||||
.filter(|r| !r.link.is_empty())
|
||||
.map(|r| (r.text.trim().to_owned(), r.masked))
|
||||
.collect();
|
||||
let masked = |t: &str| (t.to_owned(), true);
|
||||
assert_eq!(links, [masked("raid"), masked("board"), ("www.x.org".into(), false)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quotes() {
|
||||
assert_eq!(quote("Nova", "see you at 8"), "> Nova: see you at 8\n");
|
||||
assert_eq!(
|
||||
quote("Nova", "see you at 8\r\nbring elixirs\n\nok"),
|
||||
"> Nova: see you at 8\n> bring elixirs\n> \n> ok\n"
|
||||
);
|
||||
assert_eq!(quote("Nova", " \n "), "");
|
||||
assert_eq!(quote("", "hi"), "> hi\n");
|
||||
// A line's text is plain (BBCode read), a quote in it quoted again.
|
||||
let line = line(&message("Kairo", "[quote=Nova]bring [b]elixirs[/b][/quote]\nok", 0), None);
|
||||
assert_eq!(quote(&line.author, &line.text), "> Kairo: > Nova: bring elixirs\n> ok\n");
|
||||
}
|
||||
|
||||
/// A run does not wrap: long words (addresses) and long inline code
|
||||
/// are cut so the line can break inside them.
|
||||
#[test]
|
||||
|
||||
@@ -32,7 +32,7 @@ import { ServerLinks, EventsPage, EventDialog } from "screens/events.slint";
|
||||
import { NotificationsPanel, SearchPalette, Lightbox } from "screens/overlays.slint";
|
||||
import { MobileServers, ActivityPage, YouPage, PhoneSheet } from "screens/mobile.slint";
|
||||
import { MobileVoice } from "screens/mobile-voice.slint";
|
||||
import { BookmarkDialog, ShareDialog, ClientAudioDialog, ChannelPasswordDialog, PokeDialog, AboutDialog } from "screens/dialogs.slint";
|
||||
import { BookmarkDialog, ShareDialog, ClientAudioDialog, ChannelPasswordDialog, PokeDialog, LinkDialog, AboutDialog } from "screens/dialogs.slint";
|
||||
import { StudioBridge } from "studio-bridge.slint";
|
||||
import { StudioPage, MobileStudio } from "screens/studio.slint";
|
||||
|
||||
@@ -411,6 +411,10 @@ export component MainWindow inherits Window {
|
||||
done => { Nav.poke-open = false; }
|
||||
}
|
||||
|
||||
if !Bridge.myts.prompt && (Nav.link-open): LinkDialog {
|
||||
done => { Nav.link-open = false; }
|
||||
}
|
||||
|
||||
if !Bridge.myts.prompt && (Nav.about-open): AboutDialog {
|
||||
done => { Nav.about-open = false; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<!-- @license lucide-static v1.48.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-quote"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" />
|
||||
<path d="M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 567 B |
@@ -185,8 +185,10 @@ export struct TextRun {
|
||||
// text's own.
|
||||
ink-dark: color,
|
||||
ink-light: color,
|
||||
// Where it links to ("": nowhere).
|
||||
// Where it links to ("": nowhere), and whether its text shows something
|
||||
// else (a page's name, another address): asked about before it opens.
|
||||
link: string,
|
||||
masked: bool,
|
||||
}
|
||||
|
||||
// A block of a chat line (`vm::bbcode`): its runs, and what it is.
|
||||
@@ -1087,6 +1089,13 @@ export global Bridge {
|
||||
// A link to our voice channel (`ts3server://`) to hand to others; the
|
||||
// caller copies it (Nav.copy).
|
||||
callback invite() -> string;
|
||||
// A link in a message was clicked (`TextRun.link` and `masked`): Rust
|
||||
// opens a page on the web (a masked one after asking: Nav.link-open),
|
||||
// or gives back what the caller copies (a TeamSpeak link, for now).
|
||||
callback open-link(string, bool) -> string;
|
||||
// A message's text (`ChatLine.text`) by its author as a quote for the
|
||||
// composer: "> Author: line" and "> line" for the next ones.
|
||||
callback quote-text(string, string) -> string;
|
||||
// Nav.copy put text on the clipboard: Rust says so in the toast.
|
||||
callback copied();
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Images, Emoji, TextRun, TextBlock, ChatLine, EmojiCell } from "../bridge.slint";
|
||||
import { Nav } from "../nav.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
import { PopupMenu } from "overlay.slint";
|
||||
import { SearchBox } from "text-field.slint";
|
||||
import { ListView } from "std-widgets.slint";
|
||||
|
||||
// A word in its style, or an emoji. A Text draws no lines, so underline
|
||||
// (links too) and strike-through are 1 px rectangles over it.
|
||||
// (links too) and strike-through are 1 px rectangles over it. A click on a
|
||||
// link opens it (Nav.open-link); a right-click opens or copies it.
|
||||
component Run inherits Rectangle {
|
||||
in property <TextRun> run;
|
||||
in property <length> font-size;
|
||||
@@ -56,6 +59,30 @@ component Run inherits Rectangle {
|
||||
height: 1px;
|
||||
background: root.ink;
|
||||
}
|
||||
if run.link != "": TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { Nav.open-link(run.link, run.masked); }
|
||||
pointer-event(e) => {
|
||||
if e.button == PointerEventButton.right && e.kind == PointerEventKind.up {
|
||||
menu.show(self.mouse-x, self.mouse-y);
|
||||
}
|
||||
}
|
||||
menu := PopupMenu {
|
||||
x: 0;
|
||||
y: 0;
|
||||
entries: [
|
||||
{ text: @tr("Open link"), icon: Icons.external-link, enabled: true },
|
||||
{ text: @tr("Copy link"), icon: Icons.copy, enabled: true },
|
||||
];
|
||||
activated(i) => {
|
||||
if i == 0 {
|
||||
Nav.open-link(run.link, run.masked);
|
||||
} else {
|
||||
Nav.copy(run.link);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The words and emoji of a block flow and wrap like text.
|
||||
|
||||
@@ -16,6 +16,8 @@ export component TextField inherits Rectangle {
|
||||
// Drawn without its own background and border (inside a composer).
|
||||
in property <bool> bare;
|
||||
out property <bool> has-focus: input.has-focus;
|
||||
// How tall its text is: a quoted or pasted text can have several lines.
|
||||
out property <length> text-height: input.preferred-height;
|
||||
callback accepted(string);
|
||||
callback edited(string);
|
||||
callback key-pressed(KeyEvent) -> EventResult;
|
||||
@@ -28,6 +30,13 @@ export component TextField inherits Rectangle {
|
||||
input.select-all();
|
||||
}
|
||||
|
||||
// The focus, with the cursor after the text (to write below a quote).
|
||||
public function focus-end() {
|
||||
input.focus();
|
||||
input.select-all();
|
||||
input.clear-selection();
|
||||
}
|
||||
|
||||
property <length> margin: Theme.space-2;
|
||||
|
||||
min-width: 60px;
|
||||
|
||||
@@ -90,6 +90,7 @@ export global Icons {
|
||||
out property <image> play: @image-url("assets/icons/play.svg");
|
||||
out property <image> plus: @image-url("assets/icons/plus.svg");
|
||||
out property <image> puzzle: @image-url("assets/icons/puzzle.svg");
|
||||
out property <image> quote: @image-url("assets/icons/quote.svg");
|
||||
out property <image> radio: @image-url("assets/icons/radio.svg");
|
||||
out property <image> refresh-cw: @image-url("assets/icons/refresh-cw.svg");
|
||||
out property <image> screen-share: @image-url("assets/icons/screen-share.svg");
|
||||
|
||||
@@ -80,6 +80,9 @@ export global Nav {
|
||||
// The emoji picker over the composer, and the composer's text.
|
||||
in-out property <bool> emoji-open;
|
||||
in-out property <string> draft;
|
||||
// Counts requests for the composer to take the focus, its cursor at the
|
||||
// end (after a quote): the composer shown takes it.
|
||||
in-out property <int> compose-requests;
|
||||
in-out property <BookmarkForm> bookmark-form;
|
||||
in-out property <ShareForm> share-form;
|
||||
// Rust opens these two: a locked channel's password (its name, and
|
||||
@@ -89,6 +92,13 @@ export global Nav {
|
||||
in-out property <bool> channel-password-error;
|
||||
in-out property <bool> poke-open;
|
||||
in-out property <string> poke-name;
|
||||
// Rust asks before a masked link opens: its address and host.
|
||||
in-out property <bool> link-open;
|
||||
in-out property <string> link-url;
|
||||
in-out property <string> link-host;
|
||||
// The last message shows its actions as if hovered (VOELIN_OPEN=actions:
|
||||
// a screenshot cannot hover).
|
||||
in-out property <bool> show-actions;
|
||||
|
||||
// The bell's panel, the search (Ctrl+K) and its selected result, a
|
||||
// picture opened from the chat, the event and offline message forms,
|
||||
@@ -327,4 +337,15 @@ export global Nav {
|
||||
clip-requests += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// A link in a message: Rust opens it, asks first, or has it copied.
|
||||
public function open-link(link: string, masked: bool) {
|
||||
copy(Bridge.open-link(link, masked));
|
||||
}
|
||||
|
||||
// Quote a message at the start of the composer, then write after it.
|
||||
public function quote(author: string, text: string) {
|
||||
draft = Bridge.quote-text(author, text) + draft;
|
||||
compose-requests += 1;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ 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 } from "../components/index.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 {
|
||||
@@ -237,62 +237,84 @@ component ImageCard inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// Quick reactions, pin and "start a topic" on a hovered message.
|
||||
// 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 <int> key;
|
||||
in property <bool> pinned;
|
||||
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;
|
||||
row := HorizontalLayout {
|
||||
padding-left: 2px;
|
||||
padding-right: 2px;
|
||||
spacing: 0px;
|
||||
if Bridge.has-reactions: HorizontalLayout {
|
||||
// An ancestor of the buttons, so it stays hovered over them.
|
||||
area := TouchArea {
|
||||
row := HorizontalLayout {
|
||||
padding-left: 2px;
|
||||
padding-right: 2px;
|
||||
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 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 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 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); }
|
||||
}
|
||||
}
|
||||
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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,101 +324,146 @@ 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: body.preferred-height;
|
||||
background: line.marked ? Theme.accent-soft : hover.has-hover ? Theme.surface-2.transparentize(0.6) : transparent;
|
||||
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 {
|
||||
// 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 ? 2px : 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;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
spacing: 2px;
|
||||
if !line.continued: HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
body := HorizontalLayout {
|
||||
padding-left: Theme.space-6;
|
||||
padding-right: Theme.space-6;
|
||||
padding-top: line.continued ? 2px : Theme.space-5;
|
||||
padding-bottom: 2px;
|
||||
spacing: Theme.space-4;
|
||||
VerticalLayout {
|
||||
width: root.avatar;
|
||||
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;
|
||||
if !line.continued: Avatar {
|
||||
size: root.avatar;
|
||||
initials: line.initials;
|
||||
tint: line.tint;
|
||||
image: line.avatar;
|
||||
label: line.author;
|
||||
}
|
||||
}
|
||||
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 {
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
spacing: 2px;
|
||||
if !line.continued: HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
alignment: start;
|
||||
if file.preview.width > 0: ImageCard {
|
||||
key: line.key;
|
||||
file: file;
|
||||
Text {
|
||||
text: line.author;
|
||||
color: Theme.name-text;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-medium;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if file.preview.width == 0: FileCard {
|
||||
key: line.key;
|
||||
file: file;
|
||||
max-width: 440px;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if line.reactions.length > 0: VerticalLayout {
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-1;
|
||||
Reactions {
|
||||
key: line.key;
|
||||
model: line.reactions;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if root.actions && line.remote && hover.has-hover: MessageActions {
|
||||
bar := MessageActions {
|
||||
x: parent.width - self.width - Theme.space-6;
|
||||
y: -12px;
|
||||
key: line.key;
|
||||
pinned: line.pinned;
|
||||
y: root.first ? 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,8 +536,10 @@ export component MessageList inherits VerticalLayout {
|
||||
// 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 {
|
||||
for line[i] in root.model: MessageRow {
|
||||
line: line;
|
||||
show-actions: Nav.show-actions && i == root.model.length - 1;
|
||||
first: i == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -487,6 +556,9 @@ export component Composer inherits HorizontalLayout {
|
||||
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;
|
||||
@@ -499,7 +571,8 @@ export component Composer inherits HorizontalLayout {
|
||||
}
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
min-height: 48px;
|
||||
// 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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Dialogs: add/edit a server, share the screen, a client's volume, a
|
||||
// channel's password, a poke, About.
|
||||
// channel's password, a poke, a masked link, About.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
@@ -650,6 +650,72 @@ export component PokeDialog inherits Modal {
|
||||
}
|
||||
}
|
||||
|
||||
// Before a link opens whose text shows something else than its address:
|
||||
// where it really goes, its host first. Rust opens it (Nav.link-open).
|
||||
export component LinkDialog inherits Modal {
|
||||
callback done();
|
||||
title: @tr("Open this link?");
|
||||
subtitle: @tr("Its text does not show where it goes.");
|
||||
icon: Icons.external-link;
|
||||
card-width: 480px;
|
||||
card-height: 272px;
|
||||
dismissed => { done(); }
|
||||
|
||||
VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: Nav.link-host;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
overflow: elide;
|
||||
}
|
||||
// The whole address, a long one cut after a few lines.
|
||||
Rectangle {
|
||||
max-height: 72px;
|
||||
border-radius: Theme.radius-md;
|
||||
background: Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
clip: true;
|
||||
VerticalLayout {
|
||||
padding: Theme.space-3;
|
||||
Text {
|
||||
text: Nav.link-url;
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-secondary;
|
||||
wrap: word-wrap;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
Footer {
|
||||
Button {
|
||||
text: @tr("Cancel");
|
||||
clicked => { done(); }
|
||||
}
|
||||
Button {
|
||||
icon: Icons.copy;
|
||||
text: @tr("Copy link");
|
||||
clicked => {
|
||||
Nav.copy(Nav.link-url);
|
||||
done();
|
||||
}
|
||||
}
|
||||
Button {
|
||||
kind: ButtonKind.primary;
|
||||
icon: Icons.external-link;
|
||||
text: @tr("Open");
|
||||
clicked => {
|
||||
Nav.open-link(Nav.link-url, false);
|
||||
done();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bundled assets that need crediting where the app shows its notices.
|
||||
export component Credits inherits VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
|
||||
+12
-4
@@ -97,7 +97,7 @@ puts them on an inner `face`).
|
||||
| `IconButton` | button.slint | `icon`, `label` (screen readers), `tooltip` (default `label`, "" for none; on hover, also while disabled, desktop only), `checked`, `danger`, `round`, `filled`, `size`, `icon-size`, `tint`, `dot`, `count` (a neutral number at the top right, hidden at 0 or less); `clicked` |
|
||||
| `ActionButton` | button.slint | round button with a caption (Mute, Deafen, Go Live), no tooltip: `icon`, `text`, `checked`, `danger` |
|
||||
| `FocusRing` | button.slint | the accent ring of focused controls |
|
||||
| `TextField` | text-field.slint | `text`, `placeholder`, `input-type`, `icon`, `label`, `bare`, `read-only`; `accepted`, `edited`, `key-pressed`; `clear()`, `select-all()` |
|
||||
| `TextField` | text-field.slint | `text`, `placeholder`, `input-type`, `icon`, `label`, `bare`, `read-only`; out `has-focus`, `text-height` (the height of its lines); `accepted`, `edited`, `key-pressed`; `clear()`, `select-all()`, `focus-end()` (the cursor after the text) |
|
||||
| `SearchBox` | text-field.slint | a TextField with a magnifier and the Ctrl K hint (`show-shortcut`) |
|
||||
| `Kbd` | text-field.slint | a key cap |
|
||||
| `Field` | text-field.slint | `label` above a control (@children), `hint` below |
|
||||
@@ -129,7 +129,7 @@ puts them on an inner `face`).
|
||||
| `Modal` | overlay.slint | dialog with backdrop: `title`, `subtitle`, `icon`, `card-width`, `card-height`; `dismissed` (backdrop, Escape, ×) |
|
||||
| `Toast` | overlay.slint | `text`, `icon`, `timeout`, `shown` |
|
||||
| `ResizeHandle` | overlay.slint | drag to resize a side panel: `size` (two-way), `minimum`, `maximum`, `left` |
|
||||
| `RichText` | emoji.slint | text with formatting and inline emoji: `blocks` ([TextBlock]) of lines, quotes (a bar and the author), code (on a background), list items and rules; a block's `runs` ([TextRun]: bold, italic, underline, strike, code, the author's colour per theme, links in the accent colour) flow and wrap in a FlexboxLayout |
|
||||
| `RichText` | emoji.slint | text with formatting and inline emoji: `blocks` ([TextBlock]) of lines, quotes (a bar and the author), code (on a background), list items and rules; a block's `runs` ([TextRun]: bold, italic, underline, strike, code, the author's colour per theme, links underlined in the accent colour) flow and wrap in a FlexboxLayout; a click on a link opens it (`Nav.open-link`), a right-click shows Open link and Copy link |
|
||||
| `MessageText` | emoji.slint | a message's text (`line`: ChatLine): one `Text` when it has neither formatting nor emoji, else a `RichText`; a note for a blocked contact's. The chat, the pins drawer and the studio's chat use it |
|
||||
| `EmojiPicker` | emoji.slint | search, categories, virtualised grid; `picked(EmojiCell)`, `close` |
|
||||
| `ListView`, `ScrollView` | std-widgets | re-exported (virtualised lists) |
|
||||
@@ -146,7 +146,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) | 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. 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 | `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>]` | 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 is copied for now; 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 | `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, talk power, 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) |
|
||||
@@ -401,6 +401,12 @@ a second parser making the same Doc.
|
||||
- A line break starts a block. Bare `http(s)://` and `www.` addresses are
|
||||
links, without the punctuation after them. Links go only to the web,
|
||||
TeamSpeak servers and channel files: `[url=javascript:…]` is no link.
|
||||
`classify_link` says which (`LinkKind`: `Web`, `Server` for
|
||||
`ts3server://`, `teamspeak://` and `tmspk.gg` invites, `File`, `Refused`
|
||||
for other schemes, backslashes, spaces, control characters and a leading
|
||||
`-`); only those reach `TextRun.link`. A link whose text is not its own
|
||||
address (`[url=…]raid board[/url]`, another address) is masked
|
||||
(`is_masked`, `TextRun.masked`): it asks before it opens.
|
||||
- Colours are honoured, made readable on each theme (a contrast of 4.5:1 to
|
||||
the chat's background, keeping the hue).
|
||||
- Past 16 tags open at once or 1500 spans (or runs), a message is plain
|
||||
@@ -424,7 +430,9 @@ Environment variables (see `src/dev.rs`):
|
||||
- `VOELIN_OPEN=<what>[,<what>...]`: `home`, `server` (`server:chat`: the server chat), `settings[:voice|keybinds|streaming|privacy|appearance|profiles]` (`identities` is the same as `profiles`),
|
||||
`about`, `share[:live]`, `bookmark[:edit]`, `emoji`, `client`, `panel`, `no-panel`,
|
||||
`voice`, `pins`, `topics`, `topic:<id>`, `member`, `poke`,
|
||||
`channel-password[:wrong]`, `watch`, `popout`
|
||||
`channel-password[:wrong]`, `actions` (the last message's actions, as if
|
||||
hovered: a screenshot cannot hover), `link-confirm[:<url>]` (the question
|
||||
before a masked link opens, by default the sample's), `watch`, `popout`
|
||||
(the server page, above), `tab:<home|servers|chat|activity|you>` (phone
|
||||
layout); `friends[:<uid>]`, `messages[:<uid>]`, `inbox`, `offline`,
|
||||
`library`, `events`, `event-form`, `search[:<text>]`, `notifications`,
|
||||
|
||||
Reference in new issue
Block a user