diff --git a/libervia/backend/memory/sqla.py b/libervia/backend/memory/sqla.py index 4378ae75..22c8897d 100644 --- a/libervia/backend/memory/sqla.py +++ b/libervia/backend/memory/sqla.py @@ -731,6 +731,34 @@ class Storage: f"Can't store message, unexpected exception (uid: {data['uid']}): {e}" ) + @aio + async def add_thread( + self, + message_uid: str, + thread_id: str, + parent_id: str|None, + is_retroactive: bool, + ) -> None: + """Add a thread to a message. + + @param message_uid: Internal ID of the message (History.uid) to which the thread + is added. + @param thread_id: The thread ID to set. + @param parent_id: The parent message ID in the thread. + @param is_retroactive: Whether the thread ID was added after the message was sent. + Is is used when we want to relate a parent message to a new thread, when the + parent message didn't have a thread ID initially. + """ + async with self.session() as session: + thread = Thread( + thread_id=thread_id, + parent_id=parent_id, + is_retroactive=is_retroactive, + history_uid=message_uid, + ) + session.add(thread) + await session.commit() + ## Private values def _get_private_class(self, binary, profile):