Fix DM recipient never seeing the new conversation (#52 follow-up)

start_dm_endpoint created the room and membership correctly but never
sent the room_added signal every other "you're now in a room" path
(add_member) already sends -- without it, GET /rooms/mine is only
fetched once at app mount, so a DM started against an already-open
client stayed completely invisible until a manual reload. The
recipient still got an offline push/desktop notification (that path
is independent, via _notify_offline_members), just nothing to
actually open when they went looking in an already-loaded session.

Added a test mirroring the existing add_member broadcast test exactly
(recipient connected but never joined any room channel, proving the
signal alone is what tells their client the room exists) -- it failed
before this fix and passes now.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-19 16:22:40 -06:00
co-authored by Claude Sonnet 5
parent f3f59ad822
commit 1d322d9516
2 changed files with 31 additions and 1 deletions
+22
View File
@@ -146,6 +146,28 @@ def test_add_member_notifies_target_user_via_websocket(ws_client_factory, monkey
assert received == {"type": "room_added", "room_id": room["id"]}
def test_start_dm_notifies_other_participant_via_websocket(ws_client_factory):
# A production report: bob had no idea a DM existed until he reloaded --
# find_or_create_dm was creating the room/membership correctly but never
# sending this signal, unlike every other "you're now in a room" path
# (add_member, above). Same shape as that test: bob is only ever
# "connected," never "joined," proving the signal alone is what tells
# his client the room exists at all.
instance1 = ws_client_factory()
instance2 = ws_client_factory()
alice = _register_ws(instance1, _unique("alice"))
bob = _register_ws(instance2, _unique("bob"))
with instance2.websocket_connect("/ws/chat") as bob_ws:
resp = instance1.post("/api/rooms/dm", json={"other_user_id": bob["id"]})
assert resp.status_code == 201, resp.text
room = resp.json()
received = bob_ws.receive_json()
assert received == {"type": "room_added", "room_id": room["id"]}
def test_profile_update_notifies_room_members_via_websocket(ws_client_factory, monkeypatch):
# Only reaches clients that have the room's own channel joined --
# exactly the case where a stale avatar/display name would actually be