refactor: Replace re-serialization with plain coercion

This commit is contained in:
Andriy Kushnir (Orhideous) 2022-11-28 01:43:17 +02:00 committed by Nyaaori
parent f814e8e5cc
commit e3dcb668cf
No known key found for this signature in database
GPG key ID: E7819C3ED4D1F82E

View file

@ -1106,14 +1106,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));
}