diff options
author | Mathieu Velten <mathieuv@matrix.org> | 2023-06-27 00:39:10 +0200 |
---|---|---|
committer | Mathieu Velten <mathieuv@matrix.org> | 2023-06-27 09:49:42 +0200 |
commit | e25c15ea0f8c7356600c4ade27f7d92a420bea31 (patch) | |
tree | 40e4435cf01622e639bc88fd767ba88ddef705fd /synapse/storage/databases | |
parent | Bump serde_json from 1.0.97 to 1.0.99 (#15832) (diff) | |
download | synapse-mv/msc3944.tar.xz |
Implements part of MSC 3944 by dropping cancelled&duplicated `m.room_key_request` github/mv/msc3944 mv/msc3944
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r-- | synapse/storage/databases/main/deviceinbox.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/deviceinbox.py b/synapse/storage/databases/main/deviceinbox.py index b471fcb064..c08cc53661 100644 --- a/synapse/storage/databases/main/deviceinbox.py +++ b/synapse/storage/databases/main/deviceinbox.py @@ -27,6 +27,7 @@ from typing import ( ) from synapse.api.constants import EventContentFields +from synapse.api.errors import StoreError from synapse.logging import issue9533_logger from synapse.logging.opentracing import ( SynapseTags, @@ -891,6 +892,46 @@ class DeviceInboxWorkerStore(SQLBaseStore): ], ) + async def delete_device_message(self, stream_id: int) -> bool: + """Delete a specific device message from the message inbox. + + Args: + stream_id: the stream ID identifying the message. + Returns: + True if the message has been deleted, False if it didn't exist. + """ + try: + await self.db_pool.simple_delete_one( + "device_inbox", + keyvalues={"stream_id": stream_id}, + desc="delete_device_message", + ) + except StoreError: + # Deletion failed because device message does not exist + return False + return True + + async def get_all_device_messages( + self, + user_id: str, + device_id: str, + ) -> List[Tuple[int, str]]: + """Get all device messages in the inbox from a specific device. + + Args: + user_id: the user ID of the device we want to query. + device_id: the device ID of the device we want to query. + Returns: + A list of (stream ID, message content) tuples. + """ + rows = await self.db_pool.simple_select_list( + table="device_inbox", + keyvalues={"user_id": user_id, "device_id": device_id}, + retcols=("stream_id", "message_json"), + desc="get_all_device_messages", + ) + return [(r["stream_id"], r["message_json"]) for r in rows] + class DeviceInboxBackgroundUpdateStore(SQLBaseStore): DEVICE_INBOX_STREAM_ID = "device_inbox_stream_drop" |