mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-07-30 07:18:36 -04:00
Merge remote-tracking branch 'upstream/release-v1.53'
This commit is contained in:
commit
d12ff25f13
148 changed files with 4222 additions and 2281 deletions
|
@ -13,10 +13,6 @@ if TYPE_CHECKING:
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def generate_fake_event_id() -> str:
|
||||
return "$fake_" + random_string(43)
|
||||
|
||||
|
||||
class RoomBatchHandler:
|
||||
def __init__(self, hs: "HomeServer"):
|
||||
self.hs = hs
|
||||
|
@ -184,11 +180,12 @@ class RoomBatchHandler:
|
|||
state_event_ids_at_start = []
|
||||
auth_event_ids = initial_auth_event_ids.copy()
|
||||
|
||||
# Make the state events float off on their own so we don't have a
|
||||
# bunch of `@mxid joined the room` noise between each batch
|
||||
prev_event_id_for_state_chain = generate_fake_event_id()
|
||||
# Make the state events float off on their own by specifying no
|
||||
# prev_events for the first one in the chain so we don't have a bunch of
|
||||
# `@mxid joined the room` noise between each batch.
|
||||
prev_event_ids_for_state_chain: List[str] = []
|
||||
|
||||
for state_event in state_events_at_start:
|
||||
for index, state_event in enumerate(state_events_at_start):
|
||||
assert_params_in_dict(
|
||||
state_event, ["type", "origin_server_ts", "content", "sender"]
|
||||
)
|
||||
|
@ -224,7 +221,10 @@ class RoomBatchHandler:
|
|||
content=event_dict["content"],
|
||||
outlier=True,
|
||||
historical=True,
|
||||
prev_event_ids=[prev_event_id_for_state_chain],
|
||||
# Only the first event in the chain should be floating.
|
||||
# The rest should hang off each other in a chain.
|
||||
allow_no_prev_events=index == 0,
|
||||
prev_event_ids=prev_event_ids_for_state_chain,
|
||||
# Make sure to use a copy of this list because we modify it
|
||||
# later in the loop here. Otherwise it will be the same
|
||||
# reference and also update in the event when we append later.
|
||||
|
@ -244,7 +244,10 @@ class RoomBatchHandler:
|
|||
event_dict,
|
||||
outlier=True,
|
||||
historical=True,
|
||||
prev_event_ids=[prev_event_id_for_state_chain],
|
||||
# Only the first event in the chain should be floating.
|
||||
# The rest should hang off each other in a chain.
|
||||
allow_no_prev_events=index == 0,
|
||||
prev_event_ids=prev_event_ids_for_state_chain,
|
||||
# Make sure to use a copy of this list because we modify it
|
||||
# later in the loop here. Otherwise it will be the same
|
||||
# reference and also update in the event when we append later.
|
||||
|
@ -255,7 +258,7 @@ class RoomBatchHandler:
|
|||
state_event_ids_at_start.append(event_id)
|
||||
auth_event_ids.append(event_id)
|
||||
# Connect all the state in a floating chain
|
||||
prev_event_id_for_state_chain = event_id
|
||||
prev_event_ids_for_state_chain = [event_id]
|
||||
|
||||
return state_event_ids_at_start
|
||||
|
||||
|
@ -263,7 +266,6 @@ class RoomBatchHandler:
|
|||
self,
|
||||
events_to_create: List[JsonDict],
|
||||
room_id: str,
|
||||
initial_prev_event_ids: List[str],
|
||||
inherited_depth: int,
|
||||
auth_event_ids: List[str],
|
||||
app_service_requester: Requester,
|
||||
|
@ -279,9 +281,6 @@ class RoomBatchHandler:
|
|||
events_to_create: List of historical events to create in JSON
|
||||
dictionary format.
|
||||
room_id: Room where you want the events persisted in.
|
||||
initial_prev_event_ids: These will be the prev_events for the first
|
||||
event created. Each event created afterwards will point to the
|
||||
previous event created.
|
||||
inherited_depth: The depth to create the events at (you will
|
||||
probably by calling inherit_depth_from_prev_ids(...)).
|
||||
auth_event_ids: Define which events allow you to create the given
|
||||
|
@ -293,11 +292,14 @@ class RoomBatchHandler:
|
|||
"""
|
||||
assert app_service_requester.app_service
|
||||
|
||||
prev_event_ids = initial_prev_event_ids.copy()
|
||||
# Make the historical event chain float off on its own by specifying no
|
||||
# prev_events for the first event in the chain which causes the HS to
|
||||
# ask for the state at the start of the batch later.
|
||||
prev_event_ids: List[str] = []
|
||||
|
||||
event_ids = []
|
||||
events_to_persist = []
|
||||
for ev in events_to_create:
|
||||
for index, ev in enumerate(events_to_create):
|
||||
assert_params_in_dict(ev, ["type", "origin_server_ts", "content", "sender"])
|
||||
|
||||
assert self.hs.is_mine_id(ev["sender"]), "User must be our own: %s" % (
|
||||
|
@ -321,6 +323,9 @@ class RoomBatchHandler:
|
|||
ev["sender"], app_service_requester.app_service
|
||||
),
|
||||
event_dict,
|
||||
# Only the first event in the chain should be floating.
|
||||
# The rest should hang off each other in a chain.
|
||||
allow_no_prev_events=index == 0,
|
||||
prev_event_ids=event_dict.get("prev_events"),
|
||||
auth_event_ids=auth_event_ids,
|
||||
historical=True,
|
||||
|
@ -372,7 +377,6 @@ class RoomBatchHandler:
|
|||
events_to_create: List[JsonDict],
|
||||
room_id: str,
|
||||
batch_id_to_connect_to: str,
|
||||
initial_prev_event_ids: List[str],
|
||||
inherited_depth: int,
|
||||
auth_event_ids: List[str],
|
||||
app_service_requester: Requester,
|
||||
|
@ -387,9 +391,6 @@ class RoomBatchHandler:
|
|||
room_id: Room where you want the events created in.
|
||||
batch_id_to_connect_to: The batch_id from the insertion event you
|
||||
want this batch to connect to.
|
||||
initial_prev_event_ids: These will be the prev_events for the first
|
||||
event created. Each event created afterwards will point to the
|
||||
previous event created.
|
||||
inherited_depth: The depth to create the events at (you will
|
||||
probably by calling inherit_depth_from_prev_ids(...)).
|
||||
auth_event_ids: Define which events allow you to create the given
|
||||
|
@ -438,7 +439,6 @@ class RoomBatchHandler:
|
|||
event_ids = await self.persist_historical_events(
|
||||
events_to_create=events_to_create,
|
||||
room_id=room_id,
|
||||
initial_prev_event_ids=initial_prev_event_ids,
|
||||
inherited_depth=inherited_depth,
|
||||
auth_event_ids=auth_event_ids,
|
||||
app_service_requester=app_service_requester,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue