Add the ability to hide a DM conversation (#52 follow-up)

Neither participant could get rid of a DM at all -- Leave/Delete were
both deliberately hidden for DMs during the initial build to sidestep
an edge case (removing a membership would break find_or_create_dm's
exactly-two-members assumption), but that left no way out whatsoever.

RoomMembership.hidden_at is a per-viewer display flag, not a
membership deletion: hiding a DM only sets it on your own membership
row, so it disappears from just your sidebar without touching the
other participant's copy or any messages. It's automatically cleared
(reappearing) in two cases: a new message arrives in the room
(broadcast_new_message), or find_or_create_dm resolves back to the
same room because either person re-opens it from the People list --
both count as the conversation being active again.

Also fixes two now-flaky tests (test_message_edit, test_reactions):
broadcast_new_message doing more work before returning shifted timing
enough to expose a pre-existing race where a per-user-channel frame
(desktop_notification/unread_update) could legitimately arrive before
a connection's own "joined" ack. Broadened their existing _recv()
noise-filtering helper (already used for member_updated) to cover
those types too, and used it at the two call sites that were reading
raw receive_json() instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-19 16:58:02 -06:00
co-authored by Claude Sonnet 5
parent 1d322d9516
commit 766883c992
10 changed files with 247 additions and 15 deletions
+11 -5
View File
@@ -9,13 +9,19 @@ def _unique(prefix: str) -> str:
return f"{prefix}-{uuid.uuid4().hex[:8]}"
_NOISE_TYPES = {"member_updated", "desktop_notification", "unread_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/offline-
notify noise -- another connection in the same room going online/
offline, or a per-user-channel side effect of an earlier offline
member's own message, can legitimately arrive right as a connection is
established, before its own "joined" ack. Not what these tests are
about."""
while True:
msg = ws.receive_json()
if msg.get("type") != "member_updated":
if msg.get("type") not in _NOISE_TYPES:
return msg
@@ -122,7 +128,7 @@ def test_reaction_broadcasts_to_other_room_members(ws_client):
)
with ws_client.websocket_connect("/ws/chat") as bob_ws:
bob_ws.send_json({"type": "join", "room_id": room["id"]})
assert bob_ws.receive_json()["type"] == "joined"
assert _recv(bob_ws)["type"] == "joined"
ws_client.post(
"/api/auth/login",