From 975087c52e1d4baa5f93d66d2063fc4ae15f34de Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Fri, 10 Apr 2026 14:23:19 +0200 Subject: [PATCH] fix: linkify URLs in private messages URLs in message content were rendered as plain text. Added linkifyContent() that converts URLs to clickable links while preserving existing tags. Co-Authored-By: Claude Opus 4.6 (1M context) --- static/js/conversations.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/static/js/conversations.js b/static/js/conversations.js index aaef514..5b539cd 100644 --- a/static/js/conversations.js +++ b/static/js/conversations.js @@ -135,6 +135,30 @@ return tmp.textContent || tmp.innerText || ''; } + // ============================================================ + // UTIL: linkify URLs in HTML content + // ============================================================ + + function linkifyContent(html) { + if (!html) return html; + var tmp = document.createElement('div'); + tmp.innerHTML = html; + var walker = document.createTreeWalker(tmp, NodeFilter.SHOW_TEXT, null, false); + var textNodes = []; + while (walker.nextNode()) textNodes.push(walker.currentNode); + var urlRegex = /(https?:\/\/[^\s<>"']+)/g; + textNodes.forEach(function(node) { + if (node.parentNode && node.parentNode.tagName === 'A') return; + if (urlRegex.test(node.nodeValue)) { + var span = document.createElement('span'); + span.innerHTML = node.nodeValue.replace(urlRegex, '$1'); + node.parentNode.replaceChild(span, node); + } + urlRegex.lastIndex = 0; + }); + return tmp.innerHTML; + } + // ============================================================ // UTIL: avatar color from name hash // ============================================================ @@ -547,7 +571,7 @@ // Content var content = el('div', 'message-content'); - content.innerHTML = msg.content || ''; + content.innerHTML = linkifyContent(msg.content || ''); // Highlight search term if active if (state.searchHighlight) {