Refactor some canonical JSON code
This commit is contained in:
parent
a0457000ff
commit
af6fea3d4e
|
@ -213,7 +213,10 @@ impl PduEvent {
|
||||||
pub fn convert_to_outgoing_federation_event(
|
pub fn convert_to_outgoing_federation_event(
|
||||||
mut pdu_json: CanonicalJsonObject,
|
mut pdu_json: CanonicalJsonObject,
|
||||||
) -> Raw<ruma::events::pdu::Pdu> {
|
) -> Raw<ruma::events::pdu::Pdu> {
|
||||||
if let Some(CanonicalJsonValue::Object(unsigned)) = pdu_json.get_mut("unsigned") {
|
if let Some(unsigned) = pdu_json
|
||||||
|
.get_mut("unsigned")
|
||||||
|
.and_then(|val| val.as_object_mut())
|
||||||
|
{
|
||||||
unsigned.remove("transaction_id");
|
unsigned.remove("transaction_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -271,14 +271,13 @@ where
|
||||||
http_request = http_request.header(header.name.as_str(), &*header.value);
|
http_request = http_request.header(header.name.as_str(), &*header.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
match &mut json_body {
|
if let Some(json_body) = json_body.as_mut().and_then(|val| val.as_object_mut()) {
|
||||||
Some(CanonicalJsonValue::Object(json_body)) => {
|
|
||||||
let user_id = sender_user.clone().unwrap_or_else(|| {
|
let user_id = sender_user.clone().unwrap_or_else(|| {
|
||||||
UserId::parse_with_server_name("", db.globals.server_name())
|
UserId::parse_with_server_name("", db.globals.server_name())
|
||||||
.expect("we know this is valid")
|
.expect("we know this is valid")
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(initial_request) = json_body
|
if let Some(CanonicalJsonValue::Object(initial_request)) = json_body
|
||||||
.get("auth")
|
.get("auth")
|
||||||
.and_then(|auth| auth.as_object())
|
.and_then(|auth| auth.as_object())
|
||||||
.and_then(|auth| auth.get("session"))
|
.and_then(|auth| auth.get("session"))
|
||||||
|
@ -294,19 +293,12 @@ where
|
||||||
.flatten()
|
.flatten()
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
match initial_request {
|
for (key, value) in initial_request {
|
||||||
CanonicalJsonValue::Object(initial_request) => {
|
|
||||||
for (key, value) in initial_request.into_iter() {
|
|
||||||
json_body.entry(key).or_insert(value);
|
json_body.entry(key).or_insert(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body = serde_json::to_vec(json_body).expect("value to bytes can't fail");
|
body = serde_json::to_vec(json_body).expect("value to bytes can't fail");
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
let http_request = http_request.body(&*body).unwrap();
|
let http_request = http_request.body(&*body).unwrap();
|
||||||
debug!("{:?}", http_request);
|
debug!("{:?}", http_request);
|
||||||
|
|
Loading…
Reference in New Issue