mirror of
https://github.com/element-hq/synapse.git
synced 2026-05-14 14:45:10 +00:00
Use room_version capability for state-DAG checks
Replace `isinstance(event, FrozenEventVMSC4242)` with `event.room_version.msc4242_state_dags` in the two places where the class check was used as a state-DAG capability check. This is the more correct mental model — the relevant question is whether the room version uses state DAGs, not which Python subclass we happen to have constructed — and it lets the next commit drop `FrozenEventVMSC4242` along with the rest of the class hierarchy. A `cast(FrozenEventVMSC4242, event)` keeps mypy happy until the Rust `Event` is wired in and gains a real `prev_state_events` getter.
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
import logging
|
||||
import random
|
||||
from http import HTTPStatus
|
||||
from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence
|
||||
from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence, cast
|
||||
|
||||
from canonicaljson import encode_canonical_json
|
||||
|
||||
@@ -1871,8 +1871,8 @@ class EventCreationHandler:
|
||||
|
||||
state_entry = await self.state.resolve_state_groups_for_events(
|
||||
event.room_id,
|
||||
event_ids=event.prev_state_events
|
||||
if isinstance(event, FrozenEventVMSC4242)
|
||||
event_ids=cast(FrozenEventVMSC4242, event).prev_state_events
|
||||
if event.room_version.msc4242_state_dags
|
||||
else event.prev_event_ids(),
|
||||
)
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ from typing import (
|
||||
Mapping,
|
||||
Optional,
|
||||
Sequence,
|
||||
cast,
|
||||
)
|
||||
|
||||
import attr
|
||||
@@ -314,8 +315,8 @@ class StateHandler:
|
||||
# their states - but I don't think that really matters; it just means we
|
||||
# might redundantly recalculate the state for this event later.)
|
||||
prev_event_ids = frozenset(
|
||||
event.prev_state_events
|
||||
if isinstance(event, FrozenEventVMSC4242)
|
||||
cast(FrozenEventVMSC4242, event).prev_state_events
|
||||
if event.room_version.msc4242_state_dags
|
||||
else event.prev_event_ids()
|
||||
)
|
||||
incomplete_prev_events = await self.store.get_partial_state_events(
|
||||
|
||||
Reference in New Issue
Block a user