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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-10-04 10:32:10 +00:00
1 parent e37e090ab2
commit 839e26e4a3
2 files changed
+12 -7

No files matched your search

+4 -6
View File
@@ -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 = (
+8 -1
View File
@@ -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]`));
}