diff --git a/Cargo.toml b/Cargo.toml index 23d9af1b..0f151557 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,15 +22,20 @@ maplit = "1.0.2" thiserror = "1.0.20" tracing-subscriber = "0.2.11" +[dependencies.ruma] +git = "https://github.com/ruma/ruma" +rev = "648c3f5732db7524d967e472ec587fd33fa992e9" +features = ["client-api", "federation-api", "appservice-api"] + #[dependencies.ruma] #path = "../ruma/ruma" #features = ["client-api", "federation-api", "appservice-api"] -[dependencies.ruma] -git = "https://github.com/timokoesters/ruma" -branch = "timo-fed-fixes" -#rev = "aff914050eb297bd82b8aafb12158c88a9e480e1" -features = ["client-api", "federation-api", "appservice-api"] +# [dependencies.ruma] +# git = "https://github.com/timokoesters/ruma" +# branch = "timo-fed-fixes" +# #rev = "aff914050eb297bd82b8aafb12158c88a9e480e1" +# features = ["client-api", "federation-api", "appservice-api"] [features] unstable-pre-spec = ["ruma/unstable-pre-spec"] diff --git a/src/lib.rs b/src/lib.rs index 3658640c..e07bf2e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,7 +110,7 @@ impl StateResolution { .unwrap(); // update event_map to include the fetched events - event_map.extend(events.into_iter().map(|ev| (ev.event_id().clone(), ev))); + event_map.extend(events.into_iter().map(|ev| (ev.event_id(), ev))); // at this point our event_map == store there should be no missing events tracing::debug!("event map size: {}", event_map.len()); @@ -338,7 +338,7 @@ impl StateResolution { // This return value is the key used for sorting events, // events are then sorted by power level, time, // and lexically by event_id. - (-*pl, *ev.origin_server_ts(), ev.event_id().clone()) + (-*pl, *ev.origin_server_ts(), ev.event_id()) }) } diff --git a/src/state_event.rs b/src/state_event.rs index bfbf2c72..ad1a0594 100644 --- a/src/state_event.rs +++ b/src/state_event.rs @@ -9,7 +9,7 @@ use ruma::{ }, EventId, RoomId, RoomVersionId, ServerName, UserId, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::time::SystemTime; pub struct Requester<'a> { @@ -118,11 +118,21 @@ impl StateEvent { }, } } - pub fn event_id(&self) -> &EventId { + pub fn event_id(&self) -> EventId { + use std::convert::TryFrom; + match self { Self::Full(ev) => match ev { - Pdu::RoomV1Pdu(ev) => &ev.event_id, - Pdu::RoomV3Pdu(ev) => ev.event_id.as_ref().expect("RoomV3Pdu did not have an event id"), + Pdu::RoomV1Pdu(ev) => ev.event_id.clone(), + Pdu::RoomV3Pdu(ev) => { + let value = serde_json::to_value(ev).expect("all ruma pdus are json values"); + EventId::try_from(&*format!( + "${}", + ruma::signatures::reference_hash(&value, &self.room_version()) + .expect("ruma can calculate reference hashes") + )) + .expect("ruma's reference hashes are valid event ids") + } }, Self::Sync(_ev) => panic!("Stubs don't have an event id"), } @@ -337,3 +347,23 @@ impl StateEvent { } } } + +// fn process_incoming_pdu( +// pdu: &ruma::Raw, +// version: &ruma::RoomVersionId, +// ) -> (EventId, serde_json::Value) { +// let mut value = serde_json::to_value(pdu.json().get()).expect("all ruma pdus are json values"); +// let event_id = EventId::try_from(&*format!( +// "${}", +// ruma::signatures::reference_hash(&value, version) +// .expect("ruma can calculate reference hashes") +// )) +// .expect("ruma's reference hashes are valid event ids"); + +// value +// .as_object_mut() +// .expect("ruma pdus are json objects") +// .insert("event_id".to_owned(), event_id.to_string().into()); + +// (event_id, value) +// }