refactor: Replace re-serialization with plain coercion

This commit is contained in:
Andriy Kushnir (Orhideous) 2022-11-28 01:43:17 +02:00
parent f13673e2b0
commit 5c0b0cdc64
No known key found for this signature in database
GPG key ID: 62E078AB621B0D15

View file

@ -1108,14 +1108,14 @@ fn get_missing_events(
// event's prev_events.
stop_at_events.insert(queued_events[i].clone());
let prev_events = pdu
.get("prev_events")
.ok_or_else(|| Error::bad_database("Event in db has no prev_events field."))?;
queued_events.extend_from_slice(
&serde_json::from_value::<Vec<OwnedEventId>>(
serde_json::to_value(pdu.get("prev_events").cloned().ok_or_else(|| {
Error::bad_database("Event in db has no prev_events field.")
})?)
.expect("canonical json is valid json value"),
)
.map_err(|_| Error::bad_database("Invalid prev_events content in pdu in db."))?,
&serde_json::from_value::<Vec<OwnedEventId>>(prev_events.clone().into()).map_err(
|_| Error::bad_database("Invalid prev_events content in pdu in db."),
)?,
);
events.push(PduEvent::convert_to_outgoing_federation_event(pdu));
}