Remove outdated TODOs, use StateEvent::from_id_value consistently
parent
234b226468
commit
86bb93f8cf
|
@ -545,7 +545,7 @@ async fn join_room_by_id_helper(
|
||||||
);
|
);
|
||||||
|
|
||||||
// It has enough fields to be called a proper event now
|
// It has enough fields to be called a proper event now
|
||||||
let join_event = dbg!(canon_json_stub);
|
let join_event = canon_json_stub;
|
||||||
|
|
||||||
let send_join_response = server_server::send_request(
|
let send_join_response = server_server::send_request(
|
||||||
&db.globals,
|
&db.globals,
|
||||||
|
@ -577,7 +577,7 @@ async fn join_room_by_id_helper(
|
||||||
.expect("a valid EventId can be converted to CanonicalJsonValue"),
|
.expect("a valid EventId can be converted to CanonicalJsonValue"),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok((event_id, serde_json::json!(value))) // TODO CanonicalJsonValue fixup?
|
Ok((event_id, serde_json::json!(value)))
|
||||||
};
|
};
|
||||||
|
|
||||||
let room_state = send_join_response.room_state.state.iter().map(add_event_id);
|
let room_state = send_join_response.room_state.state.iter().map(add_event_id);
|
||||||
|
@ -602,7 +602,8 @@ async fn join_room_by_id_helper(
|
||||||
)))) // Add join event we just created
|
)))) // Add join event we just created
|
||||||
.map(|r| {
|
.map(|r| {
|
||||||
let (event_id, value) = r?;
|
let (event_id, value) = r?;
|
||||||
serde_json::from_value::<StateEvent>(value.clone())
|
// TODO remove .clone when I remove debug logging
|
||||||
|
state_res::StateEvent::from_id_value(event_id.clone(), value.clone())
|
||||||
.map(|ev| (event_id, Arc::new(ev)))
|
.map(|ev| (event_id, Arc::new(ev)))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!("{}: {}", value, e);
|
warn!("{}: {}", value, e);
|
||||||
|
@ -642,7 +643,9 @@ async fn join_room_by_id_helper(
|
||||||
.expect("iterative auth check failed on resolved events");
|
.expect("iterative auth check failed on resolved events");
|
||||||
|
|
||||||
// This removes the control events that failed auth, leaving the resolved
|
// This removes the control events that failed auth, leaving the resolved
|
||||||
// to be mainline sorted
|
// to be mainline sorted. In the actual `state_res::StateResolution::resolve`
|
||||||
|
// function both are removed since these are all events we don't know of
|
||||||
|
// we must keep track of everything to add to our DB.
|
||||||
let events_to_sort = event_map
|
let events_to_sort = event_map
|
||||||
.keys()
|
.keys()
|
||||||
.filter(|id| {
|
.filter(|id| {
|
||||||
|
|
37
src/pdu.rs
37
src/pdu.rs
|
@ -252,22 +252,27 @@ impl From<&state_res::StateEvent> for PduEvent {
|
||||||
impl PduEvent {
|
impl PduEvent {
|
||||||
pub fn convert_for_state_res(&self) -> Arc<state_res::StateEvent> {
|
pub fn convert_for_state_res(&self) -> Arc<state_res::StateEvent> {
|
||||||
Arc::new(
|
Arc::new(
|
||||||
serde_json::from_value(json!({
|
// For consistency of eventId (just in case) we use the one
|
||||||
"event_id": self.event_id,
|
// generated by conduit for everything.
|
||||||
"room_id": self.room_id,
|
state_res::StateEvent::from_id_value(
|
||||||
"sender": self.sender,
|
self.event_id.clone(),
|
||||||
"origin_server_ts": self.origin_server_ts,
|
json!({
|
||||||
"type": self.kind,
|
"event_id": self.event_id,
|
||||||
"content": self.content,
|
"room_id": self.room_id,
|
||||||
"state_key": self.state_key,
|
"sender": self.sender,
|
||||||
"prev_events": self.prev_events,
|
"origin_server_ts": self.origin_server_ts,
|
||||||
"depth": self.depth,
|
"type": self.kind,
|
||||||
"auth_events": self.auth_events,
|
"content": self.content,
|
||||||
"redacts": self.redacts,
|
"state_key": self.state_key,
|
||||||
"unsigned": self.unsigned,
|
"prev_events": self.prev_events,
|
||||||
"hashes": self.hashes,
|
"depth": self.depth,
|
||||||
"signatures": self.signatures,
|
"auth_events": self.auth_events,
|
||||||
}))
|
"redacts": self.redacts,
|
||||||
|
"unsigned": self.unsigned,
|
||||||
|
"hashes": self.hashes,
|
||||||
|
"signatures": self.signatures,
|
||||||
|
}),
|
||||||
|
)
|
||||||
.expect("all conduit PDUs are state events"),
|
.expect("all conduit PDUs are state events"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ use std::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
|
sync::Arc,
|
||||||
time::{Duration, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
use trust_dns_resolver::AsyncResolver;
|
use trust_dns_resolver::AsyncResolver;
|
||||||
|
@ -551,7 +552,6 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
.iter()
|
.iter()
|
||||||
.map(|((ev, sk), v)| ((ev.clone(), sk.to_owned()), v.event_id.clone()))
|
.map(|((ev, sk), v)| ((ev.clone(), sk.to_owned()), v.event_id.clone()))
|
||||||
.collect::<BTreeMap<_, _>>(),
|
.collect::<BTreeMap<_, _>>(),
|
||||||
// TODO we may not want the auth events chained in here for resolution?
|
|
||||||
their_current_state
|
their_current_state
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_id, v)| ((v.kind(), v.state_key()), v.event_id()))
|
.map(|(_id, v)| ((v.kind(), v.state_key()), v.event_id()))
|
||||||
|
@ -750,10 +750,10 @@ pub fn get_user_devices_route<'a>(
|
||||||
|
|
||||||
/// Generates a correct eventId for the incoming pdu.
|
/// Generates a correct eventId for the incoming pdu.
|
||||||
///
|
///
|
||||||
/// Returns a `state_res::StateEvent` which can be converted freely and has accessor methods.
|
/// Returns a tuple of the new `EventId` and the PDU with the eventId inserted as a `serde_json::Value`.
|
||||||
fn process_incoming_pdu(pdu: &ruma::Raw<ruma::events::pdu::Pdu>) -> (EventId, serde_json::Value) {
|
fn process_incoming_pdu(pdu: &ruma::Raw<ruma::events::pdu::Pdu>) -> (EventId, serde_json::Value) {
|
||||||
let mut value = serde_json::from_str(pdu.json().get())
|
let mut value =
|
||||||
.expect("converting raw jsons to values always works");
|
serde_json::from_str(pdu.json().get()).expect("A Raw<...> is always valid JSON");
|
||||||
|
|
||||||
let event_id = EventId::try_from(&*format!(
|
let event_id = EventId::try_from(&*format!(
|
||||||
"${}",
|
"${}",
|
||||||
|
|
Loading…
Reference in New Issue