convert_to_outgoing_federation_event takes CanonicalJsonObj
parent
27e686f9ff
commit
c173ce43a5
|
@ -541,10 +541,7 @@ async fn join_room_by_id_helper(
|
||||||
federation::membership::create_join_event::v2::Request {
|
federation::membership::create_join_event::v2::Request {
|
||||||
room_id,
|
room_id,
|
||||||
event_id: &event_id,
|
event_id: &event_id,
|
||||||
pdu_stub: PduEvent::convert_to_outgoing_federation_event(
|
pdu_stub: PduEvent::convert_to_outgoing_federation_event(join_event.clone()),
|
||||||
serde_json::to_value(&join_event)
|
|
||||||
.expect("we just validated and ser/de this event"),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -385,8 +385,8 @@ impl Rooms {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the pdu.
|
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
|
||||||
pub fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result<Option<serde_json::Value>> {
|
pub fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result<Option<CanonicalJsonObject>> {
|
||||||
self.pduid_pdu.get(pdu_id)?.map_or(Ok(None), |pdu| {
|
self.pduid_pdu.get(pdu_id)?.map_or(Ok(None), |pdu| {
|
||||||
Ok(Some(
|
Ok(Some(
|
||||||
serde_json::from_slice(&pdu)
|
serde_json::from_slice(&pdu)
|
||||||
|
|
31
src/pdu.rs
31
src/pdu.rs
|
@ -5,6 +5,7 @@ use ruma::{
|
||||||
pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent,
|
pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent,
|
||||||
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
|
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
|
||||||
},
|
},
|
||||||
|
serde::{CanonicalJsonObject, CanonicalJsonValue},
|
||||||
EventId, Raw, RoomId, ServerKeyId, ServerName, UserId,
|
EventId, Raw, RoomId, ServerKeyId, ServerName, UserId,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -200,25 +201,25 @@ impl PduEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_to_outgoing_federation_event(
|
pub fn convert_to_outgoing_federation_event(
|
||||||
mut pdu_json: serde_json::Value,
|
mut pdu_json: CanonicalJsonObject,
|
||||||
) -> Raw<ruma::events::pdu::PduStub> {
|
) -> Raw<ruma::events::pdu::PduStub> {
|
||||||
if let Some(unsigned) = pdu_json
|
if let Some(CanonicalJsonValue::Object(unsigned)) = pdu_json.get_mut("unsigned") {
|
||||||
.as_object_mut()
|
unsigned.remove("transaction_id");
|
||||||
.expect("json is object")
|
|
||||||
.get_mut("unsigned")
|
|
||||||
{
|
|
||||||
unsigned
|
|
||||||
.as_object_mut()
|
|
||||||
.expect("unsigned is object")
|
|
||||||
.remove("transaction_id");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pdu_json
|
pdu_json.remove("event_id");
|
||||||
.as_object_mut()
|
|
||||||
.expect("json is object")
|
|
||||||
.remove("event_id");
|
|
||||||
|
|
||||||
serde_json::from_value::<Raw<_>>(pdu_json).expect("Raw::from_value always works")
|
// TODO: another option would be to convert it to a canonical string to validate size
|
||||||
|
// and return a Result<Raw<...>>
|
||||||
|
// serde_json::from_str::<Raw<_>>(
|
||||||
|
// ruma::serde::to_canonical_json_string(pdu_json).expect("CanonicalJson is valid serde_json::Value"),
|
||||||
|
// )
|
||||||
|
// .expect("Raw::from_value always works")
|
||||||
|
|
||||||
|
serde_json::from_value::<Raw<_>>(
|
||||||
|
serde_json::to_value(pdu_json).expect("CanonicalJson is valid serde_json::Value"),
|
||||||
|
)
|
||||||
|
.expect("Raw::from_value always works")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue