comparison libervia/backend/memory/sqla.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 0d7bb4df2343
children b93f95efe329
comparison
equal deleted inserted replaced
4365:f6672bc80897 4366:1ef32316a55e
491 else: 491 else:
492 if dest: 492 if dest:
493 return History.dest == jid_.userhost() 493 return History.dest == jid_.userhost()
494 else: 494 else:
495 return History.source == jid_.userhost() 495 return History.source == jid_.userhost()
496
497 @aio
498 async def get_history_from_xmpp_id(
499 self, client: SatXMPPEntity, message_id: str, message_type: str|None
500 ) -> History | None:
501 """Retrieves history row that match a specific message ID.
502
503 The retrieval criteria vary based on the message type.
504
505 @param message_type: The type of the message (one of C.MESS_TYPE_*)
506 @param message_id: the ID of the message, XEP-0359's stanza-id is used for
507 groupchat, origin-id from the same XEP otherwise.
508 @return: History instance with messages, subjects and threads, if any found, None
509 otherwise.
510 """
511 profile_id = self.profiles[client.profile]
512 async with self.session() as session:
513 if message_type == C.MESS_TYPE_GROUPCHAT:
514 query = select(History).where(
515 History.profile_id == profile_id, History.stanza_id == message_id
516 )
517 else:
518 query = select(History).where(
519 History.profile_id == profile_id, History.origin_id == message_id
520 )
521
522 query = (
523 query
524 .outerjoin(History.messages)
525 .outerjoin(History.subjects)
526 .outerjoin(History.thread)
527 .options(
528 contains_eager(History.messages),
529 contains_eager(History.subjects),
530 contains_eager(History.thread),
531 )
532 )
533
534 result = await session.execute(query)
535 history = result.scalars().first()
536
537 return history
538
496 539
497 @aio 540 @aio
498 async def history_get( 541 async def history_get(
499 self, 542 self,
500 from_jid: Optional[jid.JID], 543 from_jid: Optional[jid.JID],