summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-12-01 16:53:01 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2021-12-01 17:13:49 +0000
commitdac2fedb4b9005918fbfafee374fb7e5b64f8ed7 (patch)
tree03bc1e05465d006f22ff4a0ca48473d42707d0a0
parentgeneralise sending application service transactions and allow to-device (diff)
downloadsynapse-dac2fedb4b9005918fbfafee374fb7e5b64f8ed7.tar.xz
fix type hint; make AppServiceTransaction instantiation a bit easier
-rw-r--r--synapse/appservice/__init__.py8
-rw-r--r--synapse/appservice/api.py4
-rw-r--r--synapse/storage/databases/main/appservice.py4
3 files changed, 7 insertions, 9 deletions
diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py
index 0ca8b2ae40..6a070e61cc 100644
--- a/synapse/appservice/__init__.py
+++ b/synapse/appservice/__init__.py
@@ -328,14 +328,14 @@ class AppServiceTransaction:
         service: ApplicationService,
         id: int,
         events: List[EventBase],
-        ephemeral: List[JsonDict],
-        to_device_messages: List[JsonDict],
+        ephemeral: Optional[List[JsonDict]] = None,
+        to_device_messages: Optional[List[JsonDict]] = None,
     ):
         self.service = service
         self.id = id
         self.events = events
-        self.ephemeral = ephemeral
-        self.to_device_messages = to_device_messages
+        self.ephemeral = ephemeral or []
+        self.to_device_messages = to_device_messages or []
 
     async def send(self, as_api: "ApplicationServiceApi") -> bool:
         """Sends this transaction using the provided AS API interface.
diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py
index e0509efe2a..62f977de2c 100644
--- a/synapse/appservice/api.py
+++ b/synapse/appservice/api.py
@@ -13,7 +13,7 @@
 # limitations under the License.
 import logging
 import urllib
-from typing import TYPE_CHECKING, List, Optional, Tuple
+from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
 
 from prometheus_client import Counter
 
@@ -235,7 +235,7 @@ class ApplicationServiceApi(SimpleHttpClient):
         uri = service.url + ("/transactions/%s" % urllib.parse.quote(str(txn_id)))
 
         # Never send ephemeral events to appservices that do not support it
-        body = {"events": events}
+        body: Dict[str, Union[List[EventBase], List[JsonDict]]] = {"events": events}
 
         if service.supports_ephemeral:
             body.update(
diff --git a/synapse/storage/databases/main/appservice.py b/synapse/storage/databases/main/appservice.py
index 20d91f3a7e..3c86d54612 100644
--- a/synapse/storage/databases/main/appservice.py
+++ b/synapse/storage/databases/main/appservice.py
@@ -331,9 +331,7 @@ class ApplicationServiceTransactionWorkerStore(
 
         events = await self.get_events_as_list(event_ids)
 
-        return AppServiceTransaction(
-            service=service, id=entry["txn_id"], events=events, ephemeral=[]
-        )
+        return AppServiceTransaction(service=service, id=entry["txn_id"], events=events)
 
     def _get_last_txn(self, txn, service_id: Optional[str]) -> int:
         txn.execute(