fix: media thumbnail calculation and appservice detection

This commit is contained in:
Timo Kösters 2021-03-23 19:46:54 +01:00
parent 3ea7d162db
commit 46d8f36a2c
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
5 changed files with 29 additions and 13 deletions

View file

@ -1,4 +1,5 @@
use crate::Error;
use log::error;
use ruma::{
events::{
pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent,
@ -322,8 +323,11 @@ impl Ord for PduEvent {
/// Returns a tuple of the new `EventId` and the PDU as a `BTreeMap<String, CanonicalJsonValue>`.
pub(crate) fn gen_event_id_canonical_json(
pdu: &Raw<ruma::events::pdu::Pdu>,
) -> (EventId, CanonicalJsonObject) {
let value = serde_json::from_str(pdu.json().get()).expect("A Raw<...> is always valid JSON");
) -> crate::Result<(EventId, CanonicalJsonObject)> {
let value = serde_json::from_str(pdu.json().get()).map_err(|e| {
error!("{:?}: {:?}", pdu, e);
Error::BadServerResponse("Invalid PDU in server response")
})?;
let event_id = EventId::try_from(&*format!(
"${}",
@ -332,7 +336,7 @@ pub(crate) fn gen_event_id_canonical_json(
))
.expect("ruma's reference hashes are valid event ids");
(event_id, value)
Ok((event_id, value))
}
/// Build the start of a PDU in order to add it to the `Database`.