summary refs log tree commit diff
diff options
context:
space:
mode:
authorWill Hunt <will@half-shot.uk>2020-10-01 15:02:15 +0100
committerWill Hunt <will@half-shot.uk>2020-10-01 15:26:07 +0100
commit7fe855498b69a6fa0fdbb891ee7409bb12021948 (patch)
tree10d655ed9967b4b05c800cb9374d86f25cae7fe3
parentFixup types (diff)
downloadsynapse-7fe855498b69a6fa0fdbb891ee7409bb12021948.tar.xz
Move class to fix types
-rw-r--r--synapse/appservice/__init__.py88
-rw-r--r--synapse/appservice/api.py6
2 files changed, 45 insertions, 49 deletions
diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py

index 2a6a180665..f0db27fcda 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py
@@ -33,48 +33,6 @@ class ApplicationServiceState: UP = "up" -class AppServiceTransaction: - """Represents an application service transaction.""" - - def __init__( - self, - service: ApplicationService, - id: int, - events: List[EventBase], - ephemeral=None, - ): - self.service = service - self.id = id - self.events = events - self.ephemeral = ephemeral - - async def send(self, as_api: ApplicationServiceApi) -> bool: - """Sends this transaction using the provided AS API interface. - - Args: - as_api: The API to use to send. - Returns: - True if the transaction was sent. - """ - return await as_api.push_bulk( - service=self.service, - events=self.events, - ephemeral=self.ephemeral, - txn_id=self.id, - ) - - async def complete(self, store: "DataStore") -> None: - """Completes this transaction as successful. - - Marks this transaction ID on the application service and removes the - transaction contents from the database. - - Args: - store: The database store to operate on. - """ - await store.complete_appservice_txn(service=self.service, txn_id=self.id) - - class ApplicationService: """Defines an application service. This definition is mostly what is provided to the /register AS API. @@ -208,9 +166,7 @@ class ApplicationService: async def matches_user_in_member_list( self, room_id: str, store: DataStore, cache_context: _CacheContext ): - member_list = await store.get_users_in_room( - room_id - ) + member_list = await store.get_users_in_room(room_id) # check joined member events for user_id in member_list: @@ -330,3 +286,45 @@ class ApplicationService: dict_copy["token"] = "<redacted>" dict_copy["hs_token"] = "<redacted>" return "ApplicationService: %s" % (dict_copy,) + + +class AppServiceTransaction: + """Represents an application service transaction.""" + + def __init__( + self, + service: ApplicationService, + id: int, + events: List[EventBase], + ephemeral=None, + ): + self.service = service + self.id = id + self.events = events + self.ephemeral = ephemeral + + async def send(self, as_api: ApplicationServiceApi) -> bool: + """Sends this transaction using the provided AS API interface. + + Args: + as_api: The API to use to send. + Returns: + True if the transaction was sent. + """ + return await as_api.push_bulk( + service=self.service, + events=self.events, + ephemeral=self.ephemeral, + txn_id=self.id, + ) + + async def complete(self, store: "DataStore") -> None: + """Completes this transaction as successful. + + Marks this transaction ID on the application service and removes the + transaction contents from the database. + + Args: + store: The database store to operate on. + """ + await store.complete_appservice_txn(service=self.service, txn_id=self.id) diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py
index d405c1c7e3..aea6f7f814 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py
@@ -14,21 +14,19 @@ # limitations under the License. import logging import urllib -from typing import TYPE_CHECKING, Any, List, Optional +from typing import Any, List, Optional from prometheus_client import Counter from synapse.api.constants import EventTypes, ThirdPartyEntityKind from synapse.api.errors import CodeMessageException +from synapse.appservice import ApplicationService from synapse.events import EventBase from synapse.events.utils import serialize_event from synapse.http.client import SimpleHttpClient from synapse.types import JsonDict, ThirdPartyInstanceID from synapse.util.caches.response_cache import ResponseCache -if TYPE_CHECKING: - from synapse.appservice import ApplicationService - logger = logging.getLogger(__name__) sent_transactions_counter = Counter(