mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-06 04:35:00 -04:00
Send to-device messages to application services (#11215)
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
b7282fe7d1
commit
64ec45fc1b
14 changed files with 856 additions and 162 deletions
|
@ -198,6 +198,7 @@ class ApplicationServiceTransactionWorkerStore(
|
|||
service: ApplicationService,
|
||||
events: List[EventBase],
|
||||
ephemeral: List[JsonDict],
|
||||
to_device_messages: List[JsonDict],
|
||||
) -> AppServiceTransaction:
|
||||
"""Atomically creates a new transaction for this application service
|
||||
with the given list of events. Ephemeral events are NOT persisted to the
|
||||
|
@ -207,6 +208,7 @@ class ApplicationServiceTransactionWorkerStore(
|
|||
service: The service who the transaction is for.
|
||||
events: A list of persistent events to put in the transaction.
|
||||
ephemeral: A list of ephemeral events to put in the transaction.
|
||||
to_device_messages: A list of to-device messages to put in the transaction.
|
||||
|
||||
Returns:
|
||||
A new transaction.
|
||||
|
@ -237,7 +239,11 @@ class ApplicationServiceTransactionWorkerStore(
|
|||
(service.id, new_txn_id, event_ids),
|
||||
)
|
||||
return AppServiceTransaction(
|
||||
service=service, id=new_txn_id, events=events, ephemeral=ephemeral
|
||||
service=service,
|
||||
id=new_txn_id,
|
||||
events=events,
|
||||
ephemeral=ephemeral,
|
||||
to_device_messages=to_device_messages,
|
||||
)
|
||||
|
||||
return await self.db_pool.runInteraction(
|
||||
|
@ -330,7 +336,11 @@ class ApplicationServiceTransactionWorkerStore(
|
|||
events = await self.get_events_as_list(event_ids)
|
||||
|
||||
return AppServiceTransaction(
|
||||
service=service, id=entry["txn_id"], events=events, ephemeral=[]
|
||||
service=service,
|
||||
id=entry["txn_id"],
|
||||
events=events,
|
||||
ephemeral=[],
|
||||
to_device_messages=[],
|
||||
)
|
||||
|
||||
def _get_last_txn(self, txn, service_id: Optional[str]) -> int:
|
||||
|
@ -391,7 +401,7 @@ class ApplicationServiceTransactionWorkerStore(
|
|||
async def get_type_stream_id_for_appservice(
|
||||
self, service: ApplicationService, type: str
|
||||
) -> int:
|
||||
if type not in ("read_receipt", "presence"):
|
||||
if type not in ("read_receipt", "presence", "to_device"):
|
||||
raise ValueError(
|
||||
"Expected type to be a valid application stream id type, got %s"
|
||||
% (type,)
|
||||
|
@ -415,16 +425,16 @@ class ApplicationServiceTransactionWorkerStore(
|
|||
"get_type_stream_id_for_appservice", get_type_stream_id_for_appservice_txn
|
||||
)
|
||||
|
||||
async def set_type_stream_id_for_appservice(
|
||||
async def set_appservice_stream_type_pos(
|
||||
self, service: ApplicationService, stream_type: str, pos: Optional[int]
|
||||
) -> None:
|
||||
if stream_type not in ("read_receipt", "presence"):
|
||||
if stream_type not in ("read_receipt", "presence", "to_device"):
|
||||
raise ValueError(
|
||||
"Expected type to be a valid application stream id type, got %s"
|
||||
% (stream_type,)
|
||||
)
|
||||
|
||||
def set_type_stream_id_for_appservice_txn(txn):
|
||||
def set_appservice_stream_type_pos_txn(txn):
|
||||
stream_id_type = "%s_stream_id" % stream_type
|
||||
txn.execute(
|
||||
"UPDATE application_services_state SET %s = ? WHERE as_id=?"
|
||||
|
@ -433,7 +443,7 @@ class ApplicationServiceTransactionWorkerStore(
|
|||
)
|
||||
|
||||
await self.db_pool.runInteraction(
|
||||
"set_type_stream_id_for_appservice", set_type_stream_id_for_appservice_txn
|
||||
"set_appservice_stream_type_pos", set_appservice_stream_type_pos_txn
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue