1
0

fix type hint; make AppServiceTransaction instantiation a bit easier

This commit is contained in:
Andrew Morgan
2021-12-01 16:53:01 +00:00
parent dfa4c31803
commit dac2fedb4b
3 changed files with 7 additions and 9 deletions

View File

@@ -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.

View File

@@ -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(

View File

@@ -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(