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

Commit f1f3fb0

Browse files
committed
Pass inherit_depth all the way down the line which we define only when prev_event query param is used
1 parent afa5e5d commit f1f3fb0

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

synapse/events/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def is_state(self):
100100
async def build(
101101
self,
102102
prev_event_ids: List[str],
103-
overriding_prev_events: Literal[False] = False,
104103
auth_event_ids: Optional[List[str]],
104+
inherit_depth: bool = False,
105105
) -> EventBase:
106106
"""Transform into a fully signed and hashed event
107107
@@ -135,7 +135,7 @@ async def build(
135135

136136
old_depth = await self._store.get_max_depth_of(prev_event_ids)
137137
# If backfilling old message, let's just use the same depth of what we're inserting next to
138-
if overriding_prev_events:
138+
if inherit_depth:
139139
depth = old_depth
140140
# Otherwise, progress the depth as normal
141141
else:

synapse/handlers/message.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ async def create_event(
438438
event_dict: dict,
439439
txn_id: Optional[str] = None,
440440
prev_event_ids: Optional[List[str]] = None,
441+
inherit_depth: bool = False,
441442
auth_event_ids: Optional[List[str]] = None,
442443
require_consent: bool = True,
443444
) -> Tuple[EventBase, EventContext]:
@@ -525,6 +526,7 @@ async def create_event(
525526
builder=builder,
526527
requester=requester,
527528
prev_event_ids=prev_event_ids,
529+
inherit_depth=inherit_depth,
528530
auth_event_ids=auth_event_ids,
529531
)
530532

@@ -682,6 +684,7 @@ async def create_and_send_nonmember_event(
682684
self,
683685
requester: Requester,
684686
event_dict: dict,
687+
inherit_depth: bool = False,
685688
ratelimit: bool = True,
686689
txn_id: Optional[str] = None,
687690
ignore_shadow_ban: bool = False,
@@ -741,7 +744,7 @@ async def create_and_send_nonmember_event(
741744
prev_events = event_dict["prev_events"]
742745

743746
event, context = await self.create_event(
744-
requester, event_dict, txn_id=txn_id, prev_event_ids=prev_events
747+
requester, event_dict, txn_id=txn_id, prev_event_ids=prev_events, inherit_depth=inherit_depth
745748
)
746749

747750
assert self.hs.is_mine_id(event.sender), "User must be our own: %s" % (
@@ -772,6 +775,7 @@ async def create_new_client_event(
772775
builder: EventBuilder,
773776
requester: Optional[Requester] = None,
774777
prev_event_ids: Optional[List[str]] = None,
778+
inherit_depth: bool = False,
775779
auth_event_ids: Optional[List[str]] = None,
776780
) -> Tuple[EventBase, EventContext]:
777781
"""Create a new event for a local client
@@ -794,10 +798,7 @@ async def create_new_client_event(
794798
Tuple of created event, context
795799
"""
796800

797-
overriding_prev_events = False
798801
if prev_event_ids is not None:
799-
overriding_prev_events = True
800-
801802
assert len(prev_event_ids) <= 10, (
802803
"Attempting to create an event with %i prev_events"
803804
% (len(prev_event_ids),)
@@ -816,7 +817,7 @@ async def create_new_client_event(
816817

817818
event = await builder.build(
818819
prev_event_ids=prev_event_ids,
819-
overriding_prev_events=overriding_prev_events,
820+
inherit_depth=inherit_depth,
820821
auth_event_ids=auth_event_ids,
821822
)
822823
context = await self.state.compute_event_context(event)

synapse/rest/client/v1/room.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,11 @@ async def on_POST(self, request, room_id, event_type, txn_id=None):
233233
"sender": requester.user.to_string(),
234234
}
235235

236+
inherit_depth = False
236237
if prev_events:
237238
event_dict["prev_events"] = prev_events
239+
# If backfilling old messages, let's just use the same depth of what we're inserting next to
240+
inherit_depth = True
238241

239242
# TODO: Put app_service logic back in place once we figure out how to make the Complement tests
240243
# run as an app service
@@ -246,7 +249,7 @@ async def on_POST(self, request, room_id, event_type, txn_id=None):
246249
event,
247250
_,
248251
) = await self.event_creation_handler.create_and_send_nonmember_event(
249-
requester, event_dict, txn_id=txn_id
252+
requester, event_dict, txn_id=txn_id, inherit_depth=inherit_depth
250253
)
251254
event_id = event.event_id
252255
except ShadowBanError:

0 commit comments

Comments
 (0)