feat(child): auto create parent-child conversations

This commit is contained in:
ChengCan
2026-04-30 00:58:07 +08:00
parent d21ff85807
commit 74a4819f82
6 changed files with 221 additions and 8 deletions

View File

@@ -217,6 +217,28 @@ def create_parent_child_message(
)
def ensure_parent_child_conversation(
db: Session,
*,
parent_user_id: int,
child_id: int,
) -> int:
child_row = assert_parent_child_access(db, user_id=parent_user_id, child_id=child_id)
parent_row = _get_parent_row(db, parent_user_id)
if not parent_row:
raise HTTPException(status_code=404, detail="parent not found")
return _get_or_create_conversation(
db=db,
conversation_type=PARENT_CHILD_CONVERSATION_TYPE,
participant_a_type=CHILD_PARTICIPANT_TYPE,
participant_a_id=str(child_id),
participant_b_type=PARENT_PARTICIPANT_TYPE,
participant_b_id=str(parent_user_id),
pair_key=f"{child_id}:{parent_user_id}",
)
def create_device_message(
db: Session,
*,