fix: improve code when skipping /state_ids
@@ -1027,20 +1027,8 @@ pub fn handle_incoming_pdu<'a>(
.map_err(|_| "Failed talking to db".to_owned())?
.map(|shortstatehash| db.rooms.state_full_ids(shortstatehash).ok())
.flatten();
- if let Some(mut state) = state {
- if db
- .rooms
- .get_pdu(prev_event)
- .ok()
- .flatten()
- .ok_or_else(|| "Could not find prev event, but we know the state.".to_owned())?
- .state_key
- .is_some()
- {
- state.insert(prev_event.clone());
- }
- state_at_incoming_event = Some(
- fetch_and_handle_events(
+ if let Some(state) = state {
+ let mut state = fetch_and_handle_events(
db,
origin,
&state.into_iter().collect::<Vec<_>>(),
@@ -1061,8 +1049,15 @@ pub fn handle_incoming_pdu<'a>(
pdu,
)
})
- .collect(),
- );
+ .collect::<HashMap<_, _>>();
+
+ let prev_pdu = db.rooms.get_pdu(prev_event).ok().flatten().ok_or_else(|| {
+ "Could not find prev event, but we know the state.".to_owned()
+ })?;
+
+ if let Some(state_key) = &prev_pdu.state_key {
+ state.insert((prev_pdu.kind.clone(), state_key.clone()), prev_pdu);
+ }
}
// TODO: set incoming_auth_events?
}
