Fix group messages: push via WebSocket, not just DB queue

Group send_to_group was writing directly to sled DB, bypassing
the WS push. Connected clients never received group messages.

Now tries push_to_client() first (instant WS delivery),
falls back to DB queue if recipient is offline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-27 09:55:08 +04:00
parent fe2b7d8e8a
commit 5b21a0e58b

View File

@@ -184,8 +184,13 @@ async fn send_to_group(
for msg in &req.messages { for msg in &req.messages {
let to = normalize_fp(&msg.to); let to = normalize_fp(&msg.to);
if group.members.contains(&to) { if group.members.contains(&to) {
let key = format!("queue:{}:{}", to, uuid::Uuid::new_v4()); // Try WebSocket push first (instant), fall back to DB queue
state.db.messages.insert(key.as_bytes(), msg.message.as_slice())?; if state.push_to_client(&to, &msg.message).await {
tracing::debug!("Group '{}': pushed to {} via WS", name, to);
} else {
let key = format!("queue:{}:{}", to, uuid::Uuid::new_v4());
state.db.messages.insert(key.as_bytes(), msg.message.as_slice())?;
}
delivered += 1; delivered += 1;
} }
} }