Fix formatting and grouping of state_event items

This commit is contained in:
Devin Ragotzy 2020-11-03 18:51:37 -05:00
parent 471ae2cbb4
commit f45cb2963a

View File

@ -20,6 +20,8 @@ struct EventIdHelper {
event_id: EventId,
}
/// This feature is turned on in conduit but off when the tests run because
/// we rely on the EventId to check the state-res.
#[cfg(feature = "gen-eventid")]
fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
use std::convert::TryFrom;
@ -31,6 +33,7 @@ fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
.map_err(de::Error::custom)
}
/// Only turned on for testing where we need to keep the ID.
#[cfg(not(feature = "gen-eventid"))]
fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
use std::convert::TryFrom;
@ -130,45 +133,6 @@ impl<'de> de::Deserialize<'de> for StateEvent {
}
}
/// This feature is turned on in conduit but off when the tests run because
/// we rely on the EventId to check the state-res.
#[cfg(feature = "gen-eventid")]
fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
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)
}
/// Only turned on for testing where we need to keep the ID.
#[cfg(not(feature = "gen-eventid"))]
fn event_id<E: de::Error>(json: &RawJsonValue) -> Result<EventId, E> {
use std::convert::TryFrom;
Ok(match from_raw_json_value::<EventIdHelper, E>(&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<EventId>,
pub room_id: &'a RoomId,
pub content: &'a serde_json::Value,
pub state_key: Option<String>,
pub sender: &'a UserId,
}
impl StateEvent {
pub fn from_id_value(id: EventId, json: serde_json::Value) -> Result<Self, serde_json::Error> {
Ok(Self::Full(