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
+20
View File
@@ -53,6 +53,7 @@ from app.services.room_service import (
DuplicateRoomError,
InsufficientRoleError,
MembershipNotFoundError,
NotADmError,
OwnerMustTransferError,
RoomIsPrivateError,
RoomNotFoundError,
@@ -63,6 +64,7 @@ from app.services.room_service import (
delete_room,
find_or_create_dm,
get_room,
hide_dm,
join_room,
leave_room,
list_member_rooms,
@@ -260,6 +262,24 @@ async def leave_room_endpoint(
raise HTTPException(status_code=404, detail="Not a member of this room")
@router.post("/{room_id}/hide", status_code=204)
async def hide_dm_endpoint(
room_id: uuid.UUID,
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
await require_room_member(room_id, current_user, db)
try:
room = await get_room(db, room_id)
await hide_dm(db, room, current_user.id)
except RoomNotFoundError:
raise HTTPException(status_code=404, detail="Room not found")
except NotADmError:
raise HTTPException(status_code=400, detail="Only DMs can be hidden")
except MembershipNotFoundError:
raise HTTPException(status_code=404, detail="Not a member of this room")
@router.post("/{room_id}/read", status_code=204)
async def mark_room_read_endpoint(
room_id: uuid.UUID,