mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-07-24 02:30:34 -04:00
Add helper to parse an enum from query args & use it. (#14956)
The `parse_enum` helper pulls an enum value from the query string (by delegating down to the parse_string helper with values generated from the enum). This is used to pull out "f" and "b" in most places and then we thread the resulting Direction enum throughout more code.
This commit is contained in:
parent
230a831c73
commit
1182ae5063
25 changed files with 176 additions and 96 deletions
|
@ -27,6 +27,7 @@ from typing_extensions import TypedDict
|
|||
|
||||
import synapse.events.snapshot
|
||||
from synapse.api.constants import (
|
||||
Direction,
|
||||
EventContentFields,
|
||||
EventTypes,
|
||||
GuestAccess,
|
||||
|
@ -1487,7 +1488,7 @@ class TimestampLookupHandler:
|
|||
requester: Requester,
|
||||
room_id: str,
|
||||
timestamp: int,
|
||||
direction: str,
|
||||
direction: Direction,
|
||||
) -> Tuple[str, int]:
|
||||
"""Find the closest event to the given timestamp in the given direction.
|
||||
If we can't find an event locally or the event we have locally is next to a gap,
|
||||
|
@ -1498,7 +1499,7 @@ class TimestampLookupHandler:
|
|||
room_id: Room to fetch the event from
|
||||
timestamp: The point in time (inclusive) we should navigate from in
|
||||
the given direction to find the closest event.
|
||||
direction: ["f"|"b"] to indicate whether we should navigate forward
|
||||
direction: indicates whether we should navigate forward
|
||||
or backward from the given timestamp to find the closest event.
|
||||
|
||||
Returns:
|
||||
|
@ -1533,13 +1534,13 @@ class TimestampLookupHandler:
|
|||
local_event_id, allow_none=False, allow_rejected=False
|
||||
)
|
||||
|
||||
if direction == "f":
|
||||
if direction == Direction.FORWARDS:
|
||||
# We only need to check for a backward gap if we're looking forwards
|
||||
# to ensure there is nothing in between.
|
||||
is_event_next_to_backward_gap = (
|
||||
await self.store.is_event_next_to_backward_gap(local_event)
|
||||
)
|
||||
elif direction == "b":
|
||||
elif direction == Direction.BACKWARDS:
|
||||
# We only need to check for a forward gap if we're looking backwards
|
||||
# to ensure there is nothing in between
|
||||
is_event_next_to_forward_gap = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue