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

Commit 8f8c1a0

Browse files
committed
WIP: Connect state_chain to prev_event and the batch to the state_chain so everyhting is valid
We are going to lose the benefit of keeping the join noise out of the timeline. And will probably have to hide "historical" state on the client.
1 parent 5faebbd commit 8f8c1a0

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

synapse/handlers/room_batch.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ async def persist_state_events_at_start(
153153
self,
154154
state_events_at_start: List[JsonDict],
155155
room_id: str,
156+
initial_prev_event_ids: List[str],
156157
initial_state_event_ids: List[str],
157158
app_service_requester: Requester,
158159
) -> List[str]:
@@ -178,10 +179,8 @@ async def persist_state_events_at_start(
178179
state_event_ids_at_start = []
179180
state_event_ids = initial_state_event_ids.copy()
180181

181-
# Make the state events float off on their own by specifying no
182-
# prev_events for the first one in the chain so we don't have a bunch of
183-
# `@mxid joined the room` noise between each batch.
184-
prev_event_ids_for_state_chain: List[str] = []
182+
# TODO: Here
183+
prev_event_ids_for_state_chain: List[str] = initial_prev_event_ids
185184

186185
for index, state_event in enumerate(state_events_at_start):
187186
assert_params_in_dict(
@@ -269,6 +268,7 @@ async def persist_historical_events(
269268
events_to_create: List[JsonDict],
270269
room_id: str,
271270
inherited_depth: int,
271+
state_chain_event_id_to_connect_to: str,
272272
initial_state_event_ids: List[str],
273273
app_service_requester: Requester,
274274
) -> List[str]:
@@ -301,10 +301,8 @@ async def persist_historical_events(
301301
# We expect the last event in a historical batch to be an batch event
302302
assert events_to_create[-1]["type"] == EventTypes.MSC2716_BATCH
303303

304-
# Make the historical event chain float off on its own by specifying no
305-
# prev_events for the first event in the chain which causes the HS to
306-
# ask for the state at the start of the batch later.
307-
prev_event_ids: List[str] = []
304+
# TODO: Here
305+
prev_event_ids: List[str] = [state_chain_event_id_to_connect_to]
308306

309307
event_ids = []
310308
events_to_persist = []
@@ -390,6 +388,7 @@ async def handle_batch_of_events(
390388
events_to_create: List[JsonDict],
391389
room_id: str,
392390
batch_id_to_connect_to: str,
391+
state_chain_event_id_to_connect_to: str,
393392
inherited_depth: int,
394393
initial_state_event_ids: List[str],
395394
app_service_requester: Requester,
@@ -458,6 +457,7 @@ async def handle_batch_of_events(
458457
events_to_create=events_to_create,
459458
room_id=room_id,
460459
inherited_depth=inherited_depth,
460+
state_chain_event_id_to_connect_to=state_chain_event_id_to_connect_to,
461461
initial_state_event_ids=initial_state_event_ids,
462462
app_service_requester=app_service_requester,
463463
)

synapse/rest/client/room_batch.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ async def on_POST(
153153
await self.room_batch_handler.persist_state_events_at_start(
154154
state_events_at_start=body["state_events_at_start"],
155155
room_id=room_id,
156+
initial_prev_event_ids=prev_event_ids_from_query,
156157
initial_state_event_ids=state_event_ids,
157158
app_service_requester=requester,
158159
)
@@ -222,6 +223,8 @@ async def on_POST(
222223
room_id=room_id,
223224
batch_id_to_connect_to=batch_id_to_connect_to,
224225
inherited_depth=inherited_depth,
226+
# Connect the historical batch to the state chain
227+
state_chain_event_id_to_connect_to=state_event_ids_at_start[-1],
225228
initial_state_event_ids=state_event_ids,
226229
app_service_requester=requester,
227230
)

tests/handlers/test_federation_event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,9 @@ async def get_event(destination: str, event_id: str, timeout=None):
10411041
# It all works when I add a prev_event for the floating
10421042
# insertion event but the event no longer floats.
10431043
# It's able to resolve state at the prev_events though.
1044-
# prev_event_ids=[event_before.event_id],
1045-
allow_no_prev_events=True,
1046-
prev_event_ids=[],
1044+
prev_event_ids=[event_before.event_id],
1045+
# allow_no_prev_events=True,
1046+
# prev_event_ids=[],
10471047
auth_event_ids=historical_base_auth_event_ids,
10481048
state_event_ids=historical_state_event_ids,
10491049
depth=inherited_depth,

0 commit comments

Comments
 (0)