Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Require device_id in SyncConfig
Browse files Browse the repository at this point in the history
You should always have a device if you're syncing
  • Loading branch information
anoadragon453 committed Jan 25, 2022
1 parent 6a72c91 commit d4e6f35
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SyncConfig:
filter_collection: FilterCollection
is_guest: bool
request_key: SyncRequestKey
device_id: Optional[str]
device_id: str


@attr.s(slots=True, frozen=True, auto_attribs=True)
Expand Down Expand Up @@ -288,7 +288,7 @@ def __init__(self, hs: "HomeServer"):

# ExpiringCache((User, Device)) -> LruCache(user_id => event_id)
self.lazy_loaded_members_cache: ExpiringCache[
Tuple[str, Optional[str]], LruCache[str, str]
Tuple[str, str], LruCache[str, str]
] = ExpiringCache(
"lazy_loaded_members_cache",
self.clock,
Expand Down Expand Up @@ -833,7 +833,7 @@ async def compute_summary(
return summary

def get_lazy_loaded_members_cache(
self, cache_key: Tuple[str, Optional[str]]
self, cache_key: Tuple[str, str]
) -> LruCache[str, str]:
cache: Optional[LruCache[str, str]] = self.lazy_loaded_members_cache.get(
cache_key
Expand Down
3 changes: 3 additions & 0 deletions synapse/rest/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
user = requester.user
device_id = requester.device_id

# We must have a device ID, as this request is authenticated.
assert device_id

timeout = parse_integer(request, "timeout", default=0)
since = parse_string(request, "since")
set_presence = parse_string(
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/deviceinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get_to_device_stream_token(self):
async def get_new_messages_for_device(
self,
user_id: str,
device_id: Optional[str],
device_id: str,
last_stream_id: int,
current_stream_id: int,
limit: int = 100,
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_new_messages_for_device_txn(txn):

@trace
async def delete_messages_for_device(
self, user_id: str, device_id: Optional[str], up_to_stream_id: int
self, user_id: str, device_id: str, up_to_stream_id: int
) -> int:
"""
Args:
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_ban_wins_race_with_join(self):


def generate_sync_config(
user_id: str, device_id: Optional[str] = "device_id"
user_id: str, device_id: str = "device_id"
) -> SyncConfig:
"""Generate a sync config (with a unique request key)."""
global _request_key
Expand Down

0 comments on commit d4e6f35

Please sign in to comment.