From b99b3117952dabe933cd01ac1aa6e7440961aa0d Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Mon, 13 Dec 2021 16:09:09 +0000 Subject: [PATCH] Add some method stubs and add the OTKs and FBKs to the response --- synapse/appservice/scheduler.py | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py index 77194f41fd..8657aae7d0 100644 --- a/synapse/appservice/scheduler.py +++ b/synapse/appservice/scheduler.py @@ -48,7 +48,7 @@ This is all tied together by the AppServiceScheduler which DIs the required components. """ import logging -from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set +from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set, Tuple from synapse.appservice import ( ApplicationService, @@ -200,6 +200,20 @@ class _ServiceQueuer: one_time_key_counts: Optional[TransactionOneTimeKeyCounts] = None unused_fallback_keys: Optional[TransactionUnusedFallbackKeys] = None + if service.msc3202_transaction_extensions: + # Lazily compute the one-time key counts and fallback key + # usage states for the users which are mentioned in this + # transaction, as well as the appservice's sender. + interesting_users = self._determine_interesting_users_for_msc3202_otk_counts_and_fallback_keys( + service, events, ephemeral, to_device_messages_to_send + ) + ( + one_time_key_counts, + unused_fallback_keys, + ) = await self._compute_msc3202_otk_counts_and_fallback_keys( + interesting_users + ) + try: await self.txn_ctrl.send( service, @@ -214,6 +228,30 @@ class _ServiceQueuer: finally: self.requests_in_flight.discard(service.id) + def _determine_interesting_users_for_msc3202_otk_counts_and_fallback_keys( + self, + service: ApplicationService, + events: Iterable[EventBase], + ephemeral: Iterable[JsonDict], + to_device_messages: Iterable[JsonDict], + ) -> Set[str]: + """ + Given a list of the events, ephemeral messages and to-device messaeges, + compute a list of application services users that may have interesting + updates to the one-time key counts or fallback key usage. + """ + # OSTD implement me! + return set() + async def _compute_msc3202_otk_counts_and_fallback_keys( + self, users: Set[str] + ) -> Tuple[TransactionOneTimeKeyCounts, TransactionUnusedFallbackKeys]: + """ + Given a list of application service users that are interesting, + compute one-time key counts and fallback key usages for the users. + """ + # OSTD implement me! + return {}, {} + class _TransactionController: """Transaction manager.