mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-05-09 23:04:48 +02:00
fix(chat): remove separator line in bubbles and use WebSocket for echo updates
Remove unnecessary border-top separator above action buttons in message bubbles. Replace 15s deferred loadMessages() after send with real-time echo updates via WebSocket — API now returns msg_id so optimistic message gets linked to DB record. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+5
-5
@@ -60,8 +60,8 @@ def recv_messages() -> Tuple[bool, str]:
|
||||
return True, "Messages are received automatically via events"
|
||||
|
||||
|
||||
def send_message(text: str, reply_to: Optional[str] = None, channel_index: int = 0) -> Tuple[bool, str]:
|
||||
"""Send a message to a channel."""
|
||||
def send_message(text: str, reply_to: Optional[str] = None, channel_index: int = 0) -> Tuple[bool, str, Optional[int]]:
|
||||
"""Send a message to a channel. Returns (success, message, msg_id)."""
|
||||
if reply_to:
|
||||
text = f"@[{reply_to}] {text}"
|
||||
|
||||
@@ -69,11 +69,11 @@ def send_message(text: str, reply_to: Optional[str] = None, channel_index: int =
|
||||
dm = _get_dm()
|
||||
result = dm.send_channel_message(channel_index, text)
|
||||
if result['success']:
|
||||
return True, result.get('message', 'Message sent')
|
||||
return False, result.get('error', 'Failed to send message')
|
||||
return True, result.get('message', 'Message sent'), result.get('id')
|
||||
return False, result.get('error', 'Failed to send message'), None
|
||||
except Exception as e:
|
||||
logger.error(f"send_message error: {e}")
|
||||
return False, str(e)
|
||||
return False, str(e), None
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
||||
+3
-2
@@ -601,7 +601,7 @@ def send_message():
|
||||
channel_idx = data.get('channel_idx', 0)
|
||||
|
||||
# Send message via meshcli
|
||||
success, message = cli.send_message(text, reply_to=reply_to, channel_index=channel_idx)
|
||||
success, message, msg_id = cli.send_message(text, reply_to=reply_to, channel_index=channel_idx)
|
||||
|
||||
if success:
|
||||
# v2: Echo tracking is handled automatically by DeviceManager events
|
||||
@@ -609,7 +609,8 @@ def send_message():
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'message': 'Message sent successfully',
|
||||
'channel_idx': channel_idx
|
||||
'channel_idx': channel_idx,
|
||||
'id': msg_id,
|
||||
}), 200
|
||||
else:
|
||||
return jsonify({
|
||||
|
||||
@@ -323,8 +323,6 @@ main {
|
||||
display: flex;
|
||||
gap: 0.25rem;
|
||||
margin-top: 0.5rem;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px solid var(--actions-border);
|
||||
}
|
||||
|
||||
/* Message Bubbles */
|
||||
|
||||
@@ -1320,8 +1320,11 @@ async function sendMessage() {
|
||||
if (data.success) {
|
||||
showNotification('Message sent', 'success');
|
||||
|
||||
// Schedule deferred reload to pick up echo data + replace optimistic msg with real one
|
||||
setTimeout(() => loadMessages(), 15000);
|
||||
// Replace optimistic ID with real DB id so echo WebSocket updates work
|
||||
if (data.id) {
|
||||
const wrapper = document.querySelector(`.message-wrapper[data-msg-id="${optimisticId}"]`);
|
||||
if (wrapper) wrapper.dataset.msgId = data.id;
|
||||
}
|
||||
} else {
|
||||
showNotification('Failed to send: ' + data.error, 'danger');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user