Fix DM presence indicator never updating live (#63)

The sidebar shows every DM's online/offline dot at once, but the only
existing signal for a presence change (member_updated) is broadcast to
a room's own channel, which Presence only delivers to a connection that
currently has that specific room joined -- never true for a DM sitting
unopened in the sidebar. Add a dedicated per-user broadcast
(dm_presence_update) sent to each of a user's DM partners on their own
per-user channel whenever their global online/offline state changes, so
the sidebar dot updates without needing that DM to be the open room.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 20:41:57 -06:00
co-authored by Claude Sonnet 5
parent d42bf114dd
commit 4cc3823adf
7 changed files with 142 additions and 5 deletions
+9 -5
View File
@@ -8,13 +8,17 @@ def _unique(prefix: str) -> str:
return f"{prefix}-{uuid.uuid4().hex[:8]}"
_NOISE_TYPES = {"member_updated", "dm_presence_update"}
def _recv(ws) -> dict:
"""Reads the next frame, transparently discarding member_updated
presence-change broadcasts -- another connection in the same room going
online/offline is real, expected noise these tests aren't about."""
"""Reads the next frame, transparently discarding presence-change
broadcasts (member_updated, and #63's dm_presence_update) -- another
connection sharing a room or a DM going online/offline is real,
expected noise these tests aren't about."""
while True:
msg = ws.receive_json()
if msg.get("type") != "member_updated":
if msg.get("type") not in _NOISE_TYPES:
return msg
@@ -201,7 +205,7 @@ def test_new_message_notifies_recipient_who_hid_the_dm_via_websocket(ws_client_f
alice_ws.send_json({"type": "join", "room_id": room["id"]})
assert alice_ws.receive_json()["type"] == "joined"
received = bob_ws.receive_json()
received = _recv(bob_ws)
assert received == {"type": "room_added", "room_id": room["id"]}