From 839e26e4a30120248486a5fa81611d7d943c7475 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Sun, 4 Oct 2026 10:32:10 +0000 Subject: [PATCH] feat: send links as [URL]...[/URL] like the native clients Native TeamSpeak clients wrap links in [URL] tags when sending and only link tagged ones, so a bare URL typed in the web client stayed plain text for them. Chat and offline messages now wrap bare http(s) URLs; links that are already tagged are left alone. Also stops the collected-URLs list from picking up "[/URL]" as part of a link, by sharing the renderer's URL pattern. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/App.tsx | 10 ++++------ web/src/lib/bbcode.tsx | 9 ++++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index be25a23..3798cc4 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -143,7 +143,7 @@ import { GreenteaSpeakChrome, isGreenteaSpeakTheme, } from "./themes/greenteaspeak"; -import { renderBbcode } from "./lib/bbcode"; +import { BARE_URL_REGEX, renderBbcode, wrapUrls } from "./lib/bbcode"; import { parseChannelName, spacerDisplayName } from "./lib/spacer"; import { applyParkedGatewayEvent, @@ -575,8 +575,6 @@ function loadCollectedUrls(): CollectedUrl[] { } } -const URL_REGEX = /https?:\/\/[^\s<>"]+/g; - type LogLevel = "critical" | "error" | "warning" | "info" | "debug"; interface ClientLogEntry { @@ -6962,7 +6960,7 @@ function AppInner() { }; const recordUrlsFromMessage = (message: string, sender: string) => { - const found = message.match(URL_REGEX); + const found = message.match(BARE_URL_REGEX); if (!found) return; const now = Date.now(); setCollectedUrls((prev) => { @@ -8991,7 +8989,7 @@ function AppInner() { }, [chatInput, designTheme, connected]); const handleSendChat = () => { - const message = chatInput.trim(); + const message = wrapUrls(chatInput.trim()); if (!message) return; if (activeTab === "channel") { socketRef.current?.send(JSON.stringify({ type: "sendChatMessage", message })); @@ -9408,7 +9406,7 @@ function AppInner() { }; const handleSendOfflineMessage = (clientUid: string, subject: string, message: string) => { - socketRef.current?.send(JSON.stringify({ type: "sendOfflineMessage", clientUid, subject, message })); + socketRef.current?.send(JSON.stringify({ type: "sendOfflineMessage", clientUid, subject, message: wrapUrls(message) })); }; const handleClientContextMenu = ( diff --git a/web/src/lib/bbcode.tsx b/web/src/lib/bbcode.tsx index 72e3837..79bc701 100644 --- a/web/src/lib/bbcode.tsx +++ b/web/src/lib/bbcode.tsx @@ -7,7 +7,9 @@ import { Fragment, type ReactNode } from "react"; // render as plain text ([img] as a link, so it never loads a remote image). const TAG_REGEX = /\[(\/?)(b|i|u|s|url|img|color)(?:=([^\]]*))?\]/gi; -const BARE_URL_REGEX = /https?:\/\/[^\s<>"\[\]]+/g; +export const BARE_URL_REGEX = /https?:\/\/[^\s<>"\[\]]+/g; +// An already-tagged link (left alone) or a bare URL (wrapped). +const WRAP_REGEX = new RegExp(`(\\[(url|img)(?:=[^\\]]*)?\\][\\s\\S]*?\\[\\/\\2\\])|${BARE_URL_REGEX.source}`, "gi"); const COLOR_REGEX = /^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z]+)$/i; interface Node { @@ -99,3 +101,8 @@ export function renderBbcode(text: string): ReactNode { if (last < text.length) stack[stack.length - 1].children.push(text.slice(last)); return render(root, 0); } + +// Outgoing: native clients send links as [URL]...[/URL] and only link those. +export function wrapUrls(text: string): string { + return text.replace(WRAP_REGEX, (m, tagged) => (tagged ? m : `[URL]${m}[/URL]`)); +}