Mercurial > libervia-backend
changeset 4368:2bdf0c16d852
storage: Add a `add_thread` method:
This method is used to add a thread on an existing History record.
rel 457
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 06 May 2025 00:34:01 +0200 |
parents | b93f95efe329 |
children | b74a76a8e168 |
files | libervia/backend/memory/sqla.py |
diffstat | 1 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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):