diff --git a/synapse/media/media_repository.py b/synapse/media/media_repository.py index edf8e82b5046..67a4ec79e41d 100644 --- a/synapse/media/media_repository.py +++ b/synapse/media/media_repository.py @@ -248,14 +248,14 @@ async def verify_can_upload(self, media_id: str, auth_user: UserID) -> None: if media is None: raise SynapseError(404, "Unknow media ID", errcode=Codes.NOT_FOUND) - if media["user_id"] != auth_user.to_string(): + if media.user_id != auth_user.to_string(): raise SynapseError( 403, "Only the creator of the media ID can upload to it", errcode=Codes.FORBIDDEN, ) - if media.get("media_length") is not None: + if media.media_length is not None: raise SynapseError( 409, "Media ID already has content", diff --git a/synapse/storage/databases/main/media_repository.py b/synapse/storage/databases/main/media_repository.py index 4e65f01074e2..334fc15a4365 100644 --- a/synapse/storage/databases/main/media_repository.py +++ b/synapse/storage/databases/main/media_repository.py @@ -50,13 +50,14 @@ class LocalMedia: media_id: str media_type: str - media_length: int + media_length: Optional[int] upload_name: str created_ts: int url_cache: Optional[str] last_access_ts: int quarantined_by: Optional[str] safe_from_quarantine: bool + user_id: Optional[str] @attr.s(slots=True, frozen=True, auto_attribs=True) @@ -222,6 +223,7 @@ async def get_local_media(self, media_id: str) -> Optional[LocalMedia]: url_cache=row[5], last_access_ts=row[6], safe_from_quarantine=row[7], + user_id=row[8], ) async def get_local_media_by_user_paginate( @@ -276,7 +278,8 @@ def get_local_media_by_user_paginate_txn( url_cache, last_access_ts, quarantined_by, - safe_from_quarantine + safe_from_quarantine, + user_id FROM local_media_repository WHERE user_id = ? ORDER BY {order_by_column} {order}, media_id ASC @@ -299,6 +302,7 @@ def get_local_media_by_user_paginate_txn( last_access_ts=row[6], quarantined_by=row[7], safe_from_quarantine=bool(row[8]), + user_id=row[9], ) for row in txn ]