From 023b89ad41c4e05ff56cad80cde122afa780f476 Mon Sep 17 00:00:00 2001 From: Oliver Stanley Date: Wed, 14 Jun 2023 10:41:40 +0100 Subject: [PATCH] Add hide all chats endpoint (#3423) --- .../server/oasst_inference_server/routes/chats.py | 12 ++++++++++++ .../oasst_inference_server/user_chat_repository.py | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/inference/server/oasst_inference_server/routes/chats.py b/inference/server/oasst_inference_server/routes/chats.py index 6b098bfc2f..44890217ab 100644 --- a/inference/server/oasst_inference_server/routes/chats.py +++ b/inference/server/oasst_inference_server/routes/chats.py @@ -355,3 +355,15 @@ async def handle_update_chat( except Exception: logger.exception("Error when updating chat") return fastapi.Response(status_code=500) + + +@router.put("/hide_all") +async def handle_hide_all_chats( + ucr: deps.UserChatRepository = fastapi.Depends(deps.create_user_chat_repository), +) -> fastapi.Response: + """Allows the client to hide all the user's chats.""" + try: + await ucr.hide_all_chats() + except Exception: + logger.exception("Error when hiding chats") + return fastapi.Response(status_code=500) diff --git a/inference/server/oasst_inference_server/user_chat_repository.py b/inference/server/oasst_inference_server/user_chat_repository.py index b7d6564a5d..7b6e9848fa 100644 --- a/inference/server/oasst_inference_server/user_chat_repository.py +++ b/inference/server/oasst_inference_server/user_chat_repository.py @@ -324,3 +324,9 @@ async def update_chat( chat.active_thread_tail_message_id = active_thread_tail_message_id await self.session.commit() + + async def hide_all_chats(self) -> None: + chats = await self.get_chats(include_hidden=False) + for chat in chats: + chat.hidden = True + await self.session.commit()