Private
Public Access
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:
@@ -113,15 +113,23 @@ async def create_room_endpoint(
|
||||
@router.post("/dm", response_model=RoomRead, status_code=201)
|
||||
async def start_dm_endpoint(
|
||||
data: StartDmRequest,
|
||||
request: Request,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
try:
|
||||
return await find_or_create_dm(db, current_user.id, data.other_user_id)
|
||||
room = await find_or_create_dm(db, current_user.id, data.other_user_id)
|
||||
except CannotDmSelfError:
|
||||
raise HTTPException(status_code=400, detail="Cannot start a DM with yourself")
|
||||
except TargetUserNotFoundError:
|
||||
raise HTTPException(status_code=404, detail="No user with that ID")
|
||||
# Same signal add_member sends -- without it, the other participant's
|
||||
# already-open client has no way to know this DM exists until they
|
||||
# reload: GET /rooms/mine is only fetched once at app mount. Sent
|
||||
# unconditionally (not just on genuine creation) since re-finding an
|
||||
# existing DM and refreshing their room list again is harmless.
|
||||
await broadcast_room_added(request.app.state.broadcaster, data.other_user_id, room)
|
||||
return room
|
||||
|
||||
|
||||
@router.get("", response_model=list[RoomListItem])
|
||||
|
||||
Reference in New Issue
Block a user