-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Draft: Add proper state and state_groups to historical events so they return state from /context
(avatar/displayname) (MSC2716)
#10948
Changes from all commits
64448b3
f3174cd
6713a2a
97fa9a2
fa4f20d
4fea37e
8fb4d6f
96d9d11
b20fd16
0362887
cafb1dc
487754f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -610,29 +610,6 @@ async def create_event( | |
|
||
builder.internal_metadata.historical = historical | ||
|
||
# Strip down the auth_event_ids to only what we need to auth the event. | ||
# For example, we don't need extra m.room.member that don't match event.sender | ||
if auth_event_ids is not None: | ||
# If auth events are provided, prev events must be also. | ||
assert prev_event_ids is not None | ||
|
||
temp_event = await builder.build( | ||
prev_event_ids=prev_event_ids, | ||
auth_event_ids=auth_event_ids, | ||
depth=depth, | ||
) | ||
auth_events = await self.store.get_events_as_list(auth_event_ids) | ||
# Create a StateMap[str] | ||
auth_event_state_map = { | ||
(e.type, e.state_key): e.event_id for e in auth_events | ||
} | ||
# Actually strip down and use the necessary auth events | ||
auth_event_ids = self._event_auth_handler.compute_auth_events( | ||
event=temp_event, | ||
current_state_ids=auth_event_state_map, | ||
for_verification=False, | ||
) | ||
|
||
event, context = await self.create_new_client_event( | ||
builder=builder, | ||
requester=requester, | ||
|
@@ -939,6 +916,32 @@ async def create_new_client_event( | |
Tuple of created event, context | ||
""" | ||
|
||
# Strip down the auth_event_ids to only what we need to auth the event. | ||
# For example, we don't need extra m.room.member that don't match event.sender | ||
if auth_event_ids is not None: | ||
# If auth events are provided, prev events must be also. | ||
assert prev_event_ids is not None | ||
|
||
# Copy the full auth state before it stripped down | ||
full_state_ids_at_event = auth_event_ids.copy() | ||
|
||
temp_event = await builder.build( | ||
prev_event_ids=prev_event_ids, | ||
auth_event_ids=auth_event_ids, | ||
depth=depth, | ||
) | ||
auth_events = await self.store.get_events_as_list(auth_event_ids) | ||
# Create a StateMap[str] | ||
auth_event_state_map = { | ||
(e.type, e.state_key): e.event_id for e in auth_events | ||
} | ||
# Actually strip down and use the necessary auth events | ||
auth_event_ids = self._event_auth_handler.compute_auth_events( | ||
event=temp_event, | ||
current_state_ids=auth_event_state_map, | ||
for_verification=False, | ||
) | ||
|
||
if prev_event_ids is not None: | ||
assert ( | ||
len(prev_event_ids) <= 10 | ||
|
@@ -969,7 +972,13 @@ async def create_new_client_event( | |
event.internal_metadata.outlier = True | ||
context = EventContext.for_outlier() | ||
else: | ||
context = await self.state.compute_event_context(event) | ||
old_state = None | ||
# Define the state for historical messages while we know to get all of | ||
# state_groups setup properly when we `compute_event_context`. | ||
if builder.internal_metadata.is_historical() and full_state_ids_at_event: | ||
old_state = await self.store.get_events_as_list(full_state_ids_at_event) | ||
|
||
context = await self.state.compute_event_context(event, old_state=old_state) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you pull state from a So we want to define the state for the historical event as all of the state at that point in time( This does have the flaw where if you just insert a single historical event somewhere, it probably won't resolve the state correctly from Might be good to look at Also pretty inefficient not to share the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sharing |
||
|
||
if requester: | ||
context.app_service = requester.app_service | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this auth state stripping into
create_new_client_event
so we can copyfull_state_ids_at_event
before we strip and use it for theold_state
forstate_group
calculation duringcompute_event_context