diff --git a/app/static/js/app.js b/app/static/js/app.js index afa8fff..8a3effc 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -683,6 +683,9 @@ function createMessageElement(msg) { + + + ${contactsGeoCache[msg.sender] ? ` @@ -750,6 +753,40 @@ function replyTo(username) { input.focus(); } +/** + * Quote a user's message + * @param {string} username - Username to mention + * @param {string} content - Original message content to quote + */ +function quoteTo(username, content) { + const input = document.getElementById('messageInput'); + const maxQuoteBytes = 20; + + // Calculate UTF-8 byte length + const encoder = new TextEncoder(); + const contentBytes = encoder.encode(content); + + let quotedText; + if (contentBytes.length <= maxQuoteBytes) { + quotedText = content; + } else { + // Truncate to ~maxQuoteBytes, being careful with multi-byte characters + let truncated = ''; + let byteCount = 0; + for (const char of content) { + const charBytes = encoder.encode(char).length; + if (byteCount + charBytes > maxQuoteBytes) break; + truncated += char; + byteCount += charBytes; + } + quotedText = truncated + '...'; + } + + input.value = `@[${username}] "${quotedText}" `; + updateCharCounter(); + input.focus(); +} + /** * Load connection status */