diff --git a/app/routes/api.py b/app/routes/api.py index 42cbdc9..92110f9 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -96,10 +96,12 @@ def send_message(): }), 400 # MeshCore message length limit (~180-200 bytes for LoRa) - if len(text) > 200: + # Count UTF-8 bytes, not Unicode characters + byte_length = len(text.encode('utf-8')) + if byte_length > 200: return jsonify({ 'success': False, - 'error': f'Message too long ({len(text)} chars). Maximum 200 characters allowed due to LoRa constraints.' + 'error': f'Message too long ({byte_length} bytes). Maximum 200 bytes allowed due to LoRa constraints.' }), 400 reply_to = data.get('reply_to') diff --git a/app/static/js/app.js b/app/static/js/app.js index 208d327..a696ac3 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -398,21 +398,24 @@ function formatTime(timestamp) { } /** - * Update character counter + * Update character counter (counts UTF-8 bytes, not characters) */ function updateCharCounter() { const input = document.getElementById('messageInput'); const counter = document.getElementById('charCounter'); - const length = input.value.length; - const maxLength = 200; - counter.textContent = `${length} / ${maxLength}`; + // Count UTF-8 bytes, not Unicode characters + const encoder = new TextEncoder(); + const byteLength = encoder.encode(input.value).length; + const maxBytes = 200; + + counter.textContent = `${byteLength} / ${maxBytes}`; // Visual warning when approaching limit - if (length >= maxLength * 0.9) { + if (byteLength >= maxBytes * 0.9) { counter.classList.remove('text-muted', 'text-warning'); counter.classList.add('text-danger', 'fw-bold'); - } else if (length >= maxLength * 0.75) { + } else if (byteLength >= maxBytes * 0.75) { counter.classList.remove('text-muted', 'text-danger'); counter.classList.add('text-warning', 'fw-bold'); } else { diff --git a/app/templates/index.html b/app/templates/index.html index 6ef7a52..158fd44 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -31,7 +31,7 @@ class="form-control" placeholder="Type a message..." rows="2" - maxlength="200" + maxlength="500" required >