# HG changeset patch # User Goffi # Date 1746484441 -7200 # Node ID 2bdf0c16d8528632018476cbdc17718bba5eec4f # Parent b93f95efe3291520ed79ad3f791d6c4040b70d8f storage: Add a `add_thread` method: This method is used to add a thread on an existing History record. rel 457 diff -r b93f95efe329 -r 2bdf0c16d852 libervia/backend/memory/sqla.py --- a/libervia/backend/memory/sqla.py Tue May 06 00:34:01 2025 +0200 +++ b/libervia/backend/memory/sqla.py Tue May 06 00:34:01 2025 +0200 @@ -731,6 +731,34 @@ 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):