Mercurial > libervia-backend
diff libervia/backend/plugins/plugin_xep_0444.py @ 4366:1ef32316a55e
plugin XEP-0444, storage: move `get_history_from_xmpp_id` to storage as it is generally useful.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 06 May 2025 00:33:57 +0200 |
parents | 5d2de6c1156d |
children |
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0444.py Tue May 06 00:21:24 2025 +0200 +++ b/libervia/backend/plugins/plugin_xep_0444.py Tue May 06 00:33:57 2025 +0200 @@ -75,33 +75,6 @@ def get_handler(self, client): return XEP_0444_Handler() - @aio - async def get_history_from_reaction_id( - self, client: SatXMPPEntity, message_elt: domish.Element, reaction_id: str - ) -> History | None: - """Retrieves history rows that match a specific reaction_id. - - The retrieval criteria vary based on the message type, according to XEP-0444. - - @param message_elt: The message element, used to determine the type of message. - @param reaction_id: The reaction ID to match in the history. - """ - profile_id = self.host.memory.storage.profiles[client.profile] - async with self.host.memory.storage.session() as session: - if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: - query = select(History).where( - History.profile_id == profile_id, History.stanza_id == reaction_id - ) - else: - query = select(History).where( - History.profile_id == profile_id, History.origin_id == reaction_id - ) - - result = await session.execute(query) - history = result.scalars().first() - - return history - async def _message_received_trigger( self, client: SatXMPPEntity, @@ -111,8 +84,9 @@ reactions_elt = next(message_elt.elements(NS_REACTIONS, "reactions"), None) if reactions_elt is not None: reaction_id = reactions_elt.getAttribute("id") - history = await self.get_history_from_reaction_id( - client, message_elt, reaction_id + message_type = message_elt.getAttribute("type") + history = await self.host.memory.storage.get_history_from_xmpp_id( + client, reaction_id, message_type ) if history is None: log.warning(