matrix-nio
matrix-nio copied to clipboard
somewhere > 1.57.1 matrix-synapse no longer returns `end` if no more pages in `room_messages()`
this causes nio to return a RoomMessageError() instead of a RoomMessagesResponse().
changing the schema fixes this for me. but unclear if there's a more appropriate solution.
diff --git a/nio/responses.py b/nio/responses.py
index e1fb6f2..20f1eb6 100644
--- a/nio/responses.py
+++ b/nio/responses.py
@@ -1204,7 +1204,7 @@ class RoomMessagesResponse(Response):
chunk: List[Union[Event, BadEventType]] = field()
start: str = field()
- end: str = field()
+ end: str = field(default=None)
@classmethod
@verify(Schemas.room_messages, RoomMessagesError)
@@ -1216,7 +1216,7 @@ class RoomMessagesResponse(Response):
# type: (...) -> Union[RoomMessagesResponse, ErrorResponse]
chunk: List[Union[Event, BadEventType]] = []
chunk = SyncResponse._get_room_events(parsed_dict["chunk"])
- return cls(room_id, chunk, parsed_dict["start"], parsed_dict["end"])
+ return cls(room_id, chunk, parsed_dict["start"], parsed_dict.get("end"))
@dataclass
diff --git a/nio/schemas.py b/nio/schemas.py
index 1c654bf..b535248 100644
--- a/nio/schemas.py
+++ b/nio/schemas.py
@@ -1093,7 +1093,7 @@ class Schemas:
"start": {"type": "string"},
"end": {"type": "string"},
},
- "required": ["chunk", "start", "end"],
+ "required": ["chunk", "start"],
}
room_context = {
Yeah that seems sensible, care to turn this into a PR?
sure, #343.