fix(timeline): Keep extremities a local event did not reference

This commit is contained in:
Erwan Leboucher authored and Ellis Git committed 2026-08-18 15:38:43 +00:00
1 parent a1c51adb04
commit 1d655fda53
2 files changed
+18 -4

No files matched your search

@@ -0,0 +1 @@
Fixed local events dropping forward extremities they did not reference. Contributed by @eleboucher.
+17 -4
View File
@@ -8,7 +8,7 @@ use conduwuit_core::{
};
use futures::{FutureExt, StreamExt};
use ruma::{
OwnedEventId, OwnedServerName, RoomId, UserId,
EventId, OwnedEventId, OwnedServerName, RoomId, UserId,
events::{
TimelineEventType,
room::{
@@ -112,14 +112,27 @@ impl super::Service {
let statehashid = self.services.state.append_to_state(&pdu, &room_id).await?;
trace!("State hash ID for {room_id}: {statehashid:?}");
// prev_events is capped at the room version's limit, so this PDU does not
// necessarily reference every extremity. Any it did not reference is still a
// head of the DAG and has to be kept.
let prev_events: HashSet<&EventId> = pdu.prev_events().collect();
let unreferenced: Vec<OwnedEventId> = self
.services
.state
.get_forward_extremities(&room_id)
.ready_filter(|extremity| !prev_events.contains(&**extremity))
.collect()
.await;
trace!("Generating raw ID for PDU {}", pdu.event_id());
let pdu_id = self
.append_pdu(
&pdu,
pdu_json,
// Since this PDU references all pdu_leaves we can update the leaves
// of the room
once(pdu.event_id()),
unreferenced
.iter()
.map(AsRef::as_ref)
.chain(once(pdu.event_id())),
state_lock,
&room_id,
)