diff --git a/src/state_event.rs b/src/state_event.rs index 1f86c000..477af7b5 100644 --- a/src/state_event.rs +++ b/src/state_event.rs @@ -20,6 +20,42 @@ struct EventIdHelper { event_id: EventId, } +#[cfg(feature = "gen-eventid")] +fn event_id(json: &RawJsonValue) -> Result { + use std::convert::TryFrom; + EventId::try_from(format!( + "${}", + reference_hash(&from_raw_json_value(&json)?, &RoomVersionId::Version6) + .map_err(de::Error::custom)?, + )) + .map_err(de::Error::custom) +} + +#[cfg(not(feature = "gen-eventid"))] +fn event_id(json: &RawJsonValue) -> Result { + use std::convert::TryFrom; + Ok(match from_raw_json_value::(&json) { + Ok(id) => id.event_id, + Err(_) => { + // panic!("NOT DURING TESTS"); + EventId::try_from(format!( + "${}", + reference_hash(&from_raw_json_value(&json)?, &RoomVersionId::Version6) + .map_err(de::Error::custom)?, + )) + .map_err(de::Error::custom)? + } + }) +} + +pub struct Requester<'a> { + pub prev_event_ids: Vec, + pub room_id: &'a RoomId, + pub content: &'a serde_json::Value, + pub state_key: Option, + pub sender: &'a UserId, +} + #[derive(Clone, Debug)] pub enum StateEvent { Full(EventId, Pdu),