Mercurial > libervia-backend
comparison libervia/backend/memory/sqla.py @ 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 |
comparison
equal
deleted
inserted
replaced
4367:b93f95efe329 | 4368:2bdf0c16d852 |
---|---|
728 log.error(f"Can't store message {data['uid']!r} in history: {e}") | 728 log.error(f"Can't store message {data['uid']!r} in history: {e}") |
729 except Exception as e: | 729 except Exception as e: |
730 log.critical( | 730 log.critical( |
731 f"Can't store message, unexpected exception (uid: {data['uid']}): {e}" | 731 f"Can't store message, unexpected exception (uid: {data['uid']}): {e}" |
732 ) | 732 ) |
733 | |
734 @aio | |
735 async def add_thread( | |
736 self, | |
737 message_uid: str, | |
738 thread_id: str, | |
739 parent_id: str|None, | |
740 is_retroactive: bool, | |
741 ) -> None: | |
742 """Add a thread to a message. | |
743 | |
744 @param message_uid: Internal ID of the message (History.uid) to which the thread | |
745 is added. | |
746 @param thread_id: The thread ID to set. | |
747 @param parent_id: The parent message ID in the thread. | |
748 @param is_retroactive: Whether the thread ID was added after the message was sent. | |
749 Is is used when we want to relate a parent message to a new thread, when the | |
750 parent message didn't have a thread ID initially. | |
751 """ | |
752 async with self.session() as session: | |
753 thread = Thread( | |
754 thread_id=thread_id, | |
755 parent_id=parent_id, | |
756 is_retroactive=is_retroactive, | |
757 history_uid=message_uid, | |
758 ) | |
759 session.add(thread) | |
760 await session.commit() | |
733 | 761 |
734 ## Private values | 762 ## Private values |
735 | 763 |
736 def _get_private_class(self, binary, profile): | 764 def _get_private_class(self, binary, profile): |
737 """Get ORM class to use for private values""" | 765 """Get ORM class to use for private values""" |