Repository: LAION-AI/Open-Assistant
File: backend/oasst_backend/api/v1/messages.py (Python)

Code before:
    frontend_user: deps.FrontendUserId = Depends(deps.get_frontend_user_id),
    api_client: ApiClient = Depends(deps.get_api_client),
    db: Session = Depends(deps.get_db),
):
    """
    Get message with the most children from the tree of the provided message.
    """
    pr = PromptRepository(db, api_client, frontend_user=frontend_user)
    message = pr.fetch_message(message_id)
    message, children = pr.fetch_message_with_max_children(message.message_tree_id)
    return utils.prepare_tree([message, *children], message.id)


@router.delete("/{message_id}", status_code=HTTP_204_NO_CONTENT)
def mark_message_deleted(
    *,
    message_id: UUID,
    frontend_user: deps.FrontendUserId = Depends(deps.get_frontend_user_id),
    api_client: ApiClient = Depends(deps.get_trusted_api_client),
    db: Session = Depends(deps.get_db),
):
    pr = PromptRepository(db, api_client, frontend_user=frontend_user)
    pr.mark_messages_deleted(message_id)


@router.put("/{message_id}/reintroduce", status_code=HTTP_202_ACCEPTED)
def reintroduce_message(
    *,
    message_id: UUID,
    frontend_user: deps.FrontendUserId = Depends(deps.get_frontend_user_id),
    api_client: ApiClient = Depends(deps.get_api_client),
    db: Session = Depends(deps.get_db),
):
    pr = PromptRepository(db, api_client, frontend_user=frontend_user)
    pr.reintroduce_deleted_message(message_id)


@router.post("/{message_id}/emoji", status_code=HTTP_202_ACCEPTED)
def post_message_emoji(
    *,
    message_id: UUID,
    request: protocol.MessageEmojiRequest,
    api_client: ApiClient = Depends(deps.get_api_client),
) -> protocol.Message:
    """
    Toggle, add or remove message emoji.
    """

    @managed_tx_function(CommitMode.COMMIT)
    def emoji_tx(session: deps.Session):
        pr = PromptRepository(session, api_client, client_user=request.user)

Review comment (suggestion):
Could we call the command "restore" or simply "undelete"?
and maybe add `response_model=None,` to explicitly show that it does not return anything.

Code after:
    frontend_user: deps.FrontendUserId = Depends(deps.get_frontend_user_id),
    api_client: ApiClient = Depends(deps.get_api_client),
    db: Session = Depends(deps.get_db),
):
    """
    Get message with the most children from the tree of the provided message.
    """
    pr = PromptRepository(db, api_client, frontend_user=frontend_user)
    message = pr.fetch_message(message_id)
    message, children = pr.fetch_message_with_max_children(message.message_tree_id)
    return utils.prepare_tree([message, *children], message.id)


@router.delete("/{message_id}", status_code=HTTP_204_NO_CONTENT)
def mark_message_deleted(
    *,
    message_id: UUID,
    frontend_user: deps.FrontendUserId = Depends(deps.get_frontend_user_id),
    api_client: ApiClient = Depends(deps.get_trusted_api_client),
    db: Session = Depends(deps.get_db),
):
    pr = PromptRepository(db, api_client, frontend_user=frontend_user)
    pr.mark_messages_deleted(message_id)


@router.put("/{message_id}/undelete", status_code=HTTP_202_ACCEPTED, response_model=None)
def undelete_message(
    *,
    message_id: UUID,
    frontend_user: deps.FrontendUserId = Depends(deps.get_frontend_user_id),
    api_client: ApiClient = Depends(deps.get_api_client),
    db: Session = Depends(deps.get_db),
):
    pr = PromptRepository(db, api_client, frontend_user=frontend_user)
    pr.undelete_deleted_message(message_id)


@router.post("/{message_id}/emoji", status_code=HTTP_202_ACCEPTED)
def post_message_emoji(
    *,
    message_id: UUID,
    request: protocol.MessageEmojiRequest,
    api_client: ApiClient = Depends(deps.get_api_client),
) -> protocol.Message:
    """
    Toggle, add or remove message emoji.
    """

    @managed_tx_function(CommitMode.COMMIT)
    def emoji_tx(session: deps.Session):
        pr = PromptRepository(session, api_client, client_user=request.user)