Upgrade ruma to revision 237b42
parent
47f3263396
commit
f85ea2d549
|
@ -259,6 +259,7 @@ dependencies = [
|
|||
"ring",
|
||||
"rocket",
|
||||
"ruma",
|
||||
"ruma-events",
|
||||
"rusqlite",
|
||||
"rust-argon2",
|
||||
"rustls",
|
||||
|
@ -1968,7 +1969,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.4.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
|
@ -1988,8 +1989,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ruma-api"
|
||||
version = "0.18.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
version = "0.18.5"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
|
@ -2004,8 +2005,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ruma-api-macros"
|
||||
version = "0.18.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
version = "0.18.5"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
@ -2016,7 +2017,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-appservice-api"
|
||||
version = "0.4.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"ruma-api",
|
||||
"ruma-common",
|
||||
|
@ -2029,8 +2030,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.12.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
version = "0.12.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"bytes",
|
||||
|
@ -2050,7 +2051,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"js_int",
|
||||
|
@ -2064,8 +2065,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ruma-events"
|
||||
version = "0.24.5"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
version = "0.24.6"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"indoc",
|
||||
"js_int",
|
||||
|
@ -2080,8 +2081,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ruma-events-macros"
|
||||
version = "0.24.5"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
version = "0.24.6"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
@ -2092,7 +2093,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.3.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
|
@ -2107,7 +2108,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"paste",
|
||||
"rand 0.8.4",
|
||||
|
@ -2121,7 +2122,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers-macros"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"ruma-identifiers-validation",
|
||||
|
@ -2131,12 +2132,15 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-identity-service-api"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
|
@ -2149,7 +2153,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-push-gateway-api"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
|
@ -2164,7 +2168,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-serde"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
|
@ -2178,7 +2182,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-serde-macros"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
@ -2189,7 +2193,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-signatures"
|
||||
version = "0.9.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"ed25519-dalek",
|
||||
|
@ -2206,7 +2210,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-state-res"
|
||||
version = "0.4.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
|
||||
dependencies = [
|
||||
"itertools 0.10.1",
|
||||
"js_int",
|
||||
|
|
|
@ -19,7 +19,8 @@ rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle request
|
|||
|
||||
# Used for matrix spec type definitions and helpers
|
||||
#ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "a6a1224652912a957b09f136ec5da2686be6e0e2", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "237b423996c7ccef9fc6633de675d0026c55ac1f", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
ruma-events = { git = "https://github.com/ruma/ruma", rev = "237b423996c7ccef9fc6633de675d0026c55ac1f", features = ["compat", "unstable-exhaustive-types", "unstable-pdu", "unstable-pre-spec"] }
|
||||
#ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
#ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||
.map_or(Ok::<_, Error>(None), |s| {
|
||||
Ok(serde_json::from_value::<
|
||||
Raw<canonical_alias::CanonicalAliasEventContent>,
|
||||
>(s.content.clone())
|
||||
>(s.content_value())
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
|
@ -244,7 +244,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||
.room_state_get(&room_id, &EventType::RoomName, "")?
|
||||
.map_or(Ok::<_, Error>(None), |s| {
|
||||
Ok(serde_json::from_value::<Raw<name::NameEventContent>>(
|
||||
s.content.clone(),
|
||||
s.content_value(),
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -268,7 +268,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||
.map_or(Ok::<_, Error>(None), |s| {
|
||||
Ok(Some(
|
||||
serde_json::from_value::<Raw<topic::TopicEventContent>>(
|
||||
s.content.clone(),
|
||||
s.content_value(),
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -284,7 +284,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||
.map_or(Ok::<_, Error>(false), |s| {
|
||||
Ok(serde_json::from_value::<
|
||||
Raw<history_visibility::HistoryVisibilityEventContent>,
|
||||
>(s.content.clone())
|
||||
>(s.content_value())
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
|
@ -301,7 +301,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||
.map_or(Ok::<_, Error>(false), |s| {
|
||||
Ok(
|
||||
serde_json::from_value::<Raw<guest_access::GuestAccessEventContent>>(
|
||||
s.content.clone(),
|
||||
s.content_value(),
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -318,7 +318,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||
.map(|s| {
|
||||
Ok::<_, Error>(
|
||||
serde_json::from_value::<Raw<avatar::AvatarEventContent>>(
|
||||
s.content.clone(),
|
||||
s.content_value(),
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
|
|
@ -18,7 +18,6 @@ use ruma::{
|
|||
federation::{self, membership::create_invite},
|
||||
},
|
||||
events::{
|
||||
pdu::Pdu,
|
||||
room::{create::CreateEventContent, member},
|
||||
EventType,
|
||||
},
|
||||
|
@ -26,6 +25,7 @@ use ruma::{
|
|||
state_res::{self, RoomVersion},
|
||||
uint, EventId, RoomId, RoomVersionId, ServerName, UserId,
|
||||
};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
use std::{
|
||||
collections::{hash_map::Entry, BTreeMap, HashMap, HashSet},
|
||||
convert::{TryFrom, TryInto},
|
||||
|
@ -215,8 +215,7 @@ pub async fn kick_user_route(
|
|||
ErrorKind::BadState,
|
||||
"Cannot kick member that's not in the room.",
|
||||
))?
|
||||
.content
|
||||
.clone(),
|
||||
.content_value(),
|
||||
)
|
||||
.expect("Raw::from_value always works")
|
||||
.deserialize()
|
||||
|
@ -291,7 +290,7 @@ pub async fn ban_user_route(
|
|||
}),
|
||||
|event| {
|
||||
let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
|
||||
event.content.clone(),
|
||||
event.content_value(),
|
||||
)
|
||||
.expect("Raw::from_value always works")
|
||||
.deserialize()
|
||||
|
@ -357,8 +356,7 @@ pub async fn unban_user_route(
|
|||
ErrorKind::BadState,
|
||||
"Cannot unban a user who is not banned.",
|
||||
))?
|
||||
.content
|
||||
.clone(),
|
||||
.content_value(),
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -584,10 +582,9 @@ async fn join_room_by_id_helper(
|
|||
};
|
||||
|
||||
let mut join_event_stub =
|
||||
serde_json::from_str::<CanonicalJsonObject>(make_join_response.event.json().get())
|
||||
.map_err(|_| {
|
||||
Error::BadServerResponse("Invalid make_join event json received from server.")
|
||||
})?;
|
||||
serde_json::from_str::<CanonicalJsonObject>(make_join_response.event.get()).map_err(
|
||||
|_| Error::BadServerResponse("Invalid make_join event json received from server."),
|
||||
)?;
|
||||
|
||||
// TODO: Is origin needed?
|
||||
join_event_stub.insert(
|
||||
|
@ -653,7 +650,7 @@ async fn join_room_by_id_helper(
|
|||
federation::membership::create_join_event::v2::Request {
|
||||
room_id,
|
||||
event_id: &event_id,
|
||||
pdu: PduEvent::convert_to_outgoing_federation_event(join_event.clone()),
|
||||
pdu: PduEvent::convert_to_outgoing_federation_event(join_event.clone()).json(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
@ -787,14 +784,13 @@ async fn join_room_by_id_helper(
|
|||
|
||||
Ok(join_room_by_id::Response::new(room_id.clone()).into())
|
||||
}
|
||||
|
||||
fn validate_and_add_event_id(
|
||||
pdu: &Raw<Pdu>,
|
||||
pdu: &RawJsonValue,
|
||||
room_version: &RoomVersionId,
|
||||
pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, String>>>,
|
||||
db: &Database,
|
||||
) -> Result<(EventId, CanonicalJsonObject)> {
|
||||
let mut value = serde_json::from_str::<CanonicalJsonObject>(pdu.json().get()).map_err(|e| {
|
||||
let mut value = serde_json::from_str::<CanonicalJsonObject>(pdu.get()).map_err(|e| {
|
||||
error!("Invalid PDU in server response: {:?}: {:?}", pdu, e);
|
||||
Error::BadServerResponse("Invalid PDU in server response")
|
||||
})?;
|
||||
|
@ -884,7 +880,7 @@ pub(crate) async fn invite_helper<'a>(
|
|||
let create_event_content = create_event
|
||||
.as_ref()
|
||||
.map(|create_event| {
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone())
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|e| {
|
||||
|
@ -943,7 +939,7 @@ pub(crate) async fn invite_helper<'a>(
|
|||
let mut unsigned = BTreeMap::new();
|
||||
|
||||
if let Some(prev_pdu) = db.rooms.room_state_get(room_id, &kind, &state_key)? {
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone());
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content_value());
|
||||
unsigned.insert(
|
||||
"prev_sender".to_owned(),
|
||||
serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"),
|
||||
|
@ -1035,11 +1031,11 @@ pub(crate) async fn invite_helper<'a>(
|
|||
&db.globals,
|
||||
user_id.server_name(),
|
||||
create_invite::v2::Request {
|
||||
room_id: room_id.clone(),
|
||||
event_id: expected_event_id.clone(),
|
||||
room_version: room_version_id,
|
||||
event: PduEvent::convert_to_outgoing_federation_event(pdu_json.clone()),
|
||||
invite_room_state,
|
||||
room_id,
|
||||
event_id: &expected_event_id,
|
||||
room_version: &room_version_id,
|
||||
event: PduEvent::convert_to_outgoing_federation_event(pdu_json.clone()).json(),
|
||||
invite_room_state: &invite_room_state,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -60,8 +60,8 @@ pub async fn set_displayname_route(
|
|||
room.",
|
||||
)
|
||||
})?
|
||||
.content
|
||||
.clone(),
|
||||
.content_value()
|
||||
,
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -205,8 +205,8 @@ pub async fn set_avatar_url_route(
|
|||
room.",
|
||||
)
|
||||
})?
|
||||
.content
|
||||
.clone(),
|
||||
.content_value()
|
||||
,
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
|
|
@ -509,8 +509,8 @@ pub async fn upgrade_room_route(
|
|||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomCreate, "")?
|
||||
.ok_or_else(|| Error::bad_database("Found room without m.room.create event."))?
|
||||
.content
|
||||
.clone(),
|
||||
.content_value()
|
||||
,
|
||||
)
|
||||
.expect("Raw::from_value always works")
|
||||
.deserialize()
|
||||
|
@ -585,7 +585,7 @@ pub async fn upgrade_room_route(
|
|||
// Replicate transferable state events to the new room
|
||||
for event_type in transferable_state_events {
|
||||
let event_content = match db.rooms.room_state_get(&body.room_id, &event_type, "")? {
|
||||
Some(v) => v.content.clone(),
|
||||
Some(v) => v.content_value().clone(),
|
||||
None => continue, // Skipping missing events.
|
||||
};
|
||||
|
||||
|
@ -616,8 +616,8 @@ pub async fn upgrade_room_route(
|
|||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomPowerLevels, "")?
|
||||
.ok_or_else(|| Error::bad_database("Found room without m.room.create event."))?
|
||||
.content
|
||||
.clone(),
|
||||
.content_value()
|
||||
,
|
||||
)
|
||||
.expect("database contains invalid PDU")
|
||||
.deserialize()
|
||||
|
|
|
@ -112,13 +112,13 @@ pub async fn get_state_events_route(
|
|||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
||||
.map(|event| {
|
||||
serde_json::from_value::<HistoryVisibilityEventContent>(event.content.clone())
|
||||
.map_err(|_| {
|
||||
Error::bad_database(
|
||||
"Invalid room history visibility event in database.",
|
||||
)
|
||||
})
|
||||
.map(|e| e.history_visibility)
|
||||
serde_json::from_value::<HistoryVisibilityEventContent>(
|
||||
event.content_value(),
|
||||
)
|
||||
.map_err(|_| {
|
||||
Error::bad_database("Invalid room history visibility event in database.")
|
||||
})
|
||||
.map(|e| e.history_visibility)
|
||||
}),
|
||||
Some(Ok(HistoryVisibility::WorldReadable))
|
||||
)
|
||||
|
@ -164,13 +164,13 @@ pub async fn get_state_events_for_key_route(
|
|||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
||||
.map(|event| {
|
||||
serde_json::from_value::<HistoryVisibilityEventContent>(event.content.clone())
|
||||
.map_err(|_| {
|
||||
Error::bad_database(
|
||||
"Invalid room history visibility event in database.",
|
||||
)
|
||||
})
|
||||
.map(|e| e.history_visibility)
|
||||
serde_json::from_value::<HistoryVisibilityEventContent>(
|
||||
event.content_value(),
|
||||
)
|
||||
.map_err(|_| {
|
||||
Error::bad_database("Invalid room history visibility event in database.")
|
||||
})
|
||||
.map(|e| e.history_visibility)
|
||||
}),
|
||||
Some(Ok(HistoryVisibility::WorldReadable))
|
||||
)
|
||||
|
@ -190,7 +190,7 @@ pub async fn get_state_events_for_key_route(
|
|||
))?;
|
||||
|
||||
Ok(get_state_events_for_key::Response {
|
||||
content: serde_json::from_value(event.content.clone())
|
||||
content: serde_json::from_value(event.content_value())
|
||||
.map_err(|_| Error::bad_database("Invalid event content in database"))?,
|
||||
}
|
||||
.into())
|
||||
|
@ -220,13 +220,13 @@ pub async fn get_state_events_for_empty_key_route(
|
|||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
||||
.map(|event| {
|
||||
serde_json::from_value::<HistoryVisibilityEventContent>(event.content.clone())
|
||||
.map_err(|_| {
|
||||
Error::bad_database(
|
||||
"Invalid room history visibility event in database.",
|
||||
)
|
||||
})
|
||||
.map(|e| e.history_visibility)
|
||||
serde_json::from_value::<HistoryVisibilityEventContent>(
|
||||
event.content_value(),
|
||||
)
|
||||
.map_err(|_| {
|
||||
Error::bad_database("Invalid room history visibility event in database.")
|
||||
})
|
||||
.map(|e| e.history_visibility)
|
||||
}),
|
||||
Some(Ok(HistoryVisibility::WorldReadable))
|
||||
)
|
||||
|
@ -246,7 +246,7 @@ pub async fn get_state_events_for_empty_key_route(
|
|||
))?;
|
||||
|
||||
Ok(get_state_events_for_key::Response {
|
||||
content: serde_json::from_value(event.content.clone())
|
||||
content: serde_json::from_value(event.content_value())
|
||||
.map_err(|_| Error::bad_database("Invalid event content in database"))?,
|
||||
}
|
||||
.into())
|
||||
|
|
|
@ -289,7 +289,7 @@ async fn sync_helper(
|
|||
.map(|(_, pdu)| {
|
||||
let content = serde_json::from_value::<
|
||||
ruma::events::room::member::MemberEventContent,
|
||||
>(pdu.content.clone())
|
||||
>(pdu.content_value())
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?;
|
||||
|
||||
if let Some(state_key) = &pdu.state_key {
|
||||
|
@ -372,7 +372,7 @@ async fn sync_helper(
|
|||
)?
|
||||
.and_then(|pdu| {
|
||||
serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
||||
pdu.content.clone(),
|
||||
pdu.content_value(),
|
||||
)
|
||||
.expect("Raw::from_value always works")
|
||||
.deserialize()
|
||||
|
@ -432,13 +432,14 @@ async fn sync_helper(
|
|||
continue;
|
||||
}
|
||||
|
||||
let new_membership = serde_json::from_value::<
|
||||
Raw<ruma::events::room::member::MemberEventContent>,
|
||||
>(state_event.content.clone())
|
||||
.expect("Raw::from_value always works")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid PDU in database."))?
|
||||
.membership;
|
||||
let new_membership =
|
||||
serde_json::from_value::<
|
||||
Raw<ruma::events::room::member::MemberEventContent>,
|
||||
>(state_event.content_value().clone())
|
||||
.expect("Raw::from_value always works")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid PDU in database."))?
|
||||
.membership;
|
||||
|
||||
match new_membership {
|
||||
MembershipState::Join => {
|
||||
|
@ -739,7 +740,7 @@ async fn sync_helper(
|
|||
presence: sync_events::Presence {
|
||||
events: presence_updates
|
||||
.into_iter()
|
||||
.map(|(_, v)| Raw::from(v))
|
||||
.map(|(_, v)| Raw::new(&v).expect("Raw::new(PresenceEvent) always works"))
|
||||
.collect(),
|
||||
},
|
||||
account_data: sync_events::GlobalAccountData {
|
||||
|
|
|
@ -181,7 +181,7 @@ pub async fn send_push_notice(
|
|||
.rooms
|
||||
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
|
||||
.map(|ev| {
|
||||
serde_json::from_value(ev.content.clone())
|
||||
serde_json::from_value(ev.content_value())
|
||||
.map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
|
||||
})
|
||||
.transpose()?
|
||||
|
@ -321,7 +321,7 @@ async fn send_notice(
|
|||
let room_name = db
|
||||
.rooms
|
||||
.room_state_get(&event.room_id, &EventType::RoomName, "")?
|
||||
.map(|pdu| match pdu.content.get("name") {
|
||||
.map(|pdu| match pdu.content_value().get("name") {
|
||||
Some(serde_json::Value::String(s)) => {
|
||||
Some(Box::<RoomName>::try_from(&**s).expect("room name is valid"))
|
||||
}
|
||||
|
|
|
@ -252,7 +252,13 @@ impl Rooms {
|
|||
return Ok(HashMap::new());
|
||||
};
|
||||
|
||||
let auth_events = state_res::auth_types_for_event(kind, sender, state_key, content);
|
||||
let auth_events = state_res::auth_types_for_event(
|
||||
kind,
|
||||
sender,
|
||||
state_key,
|
||||
&serde_json::value::to_raw_value(&content).expect("content is valid raw value"),
|
||||
)
|
||||
.expect("content is valid json");
|
||||
|
||||
let mut sauthevents = auth_events
|
||||
.into_iter()
|
||||
|
@ -397,12 +403,14 @@ impl Rooms {
|
|||
serde_json::to_value(&pdu).expect("CanonicalJsonObj is a valid JsonValue"),
|
||||
) {
|
||||
if let Some(membership) =
|
||||
pdu.content.get("membership").and_then(|membership| {
|
||||
serde_json::from_value::<member::MembershipState>(
|
||||
membership.clone(),
|
||||
)
|
||||
.ok()
|
||||
})
|
||||
pdu.content_value()
|
||||
.get("membership")
|
||||
.and_then(|membership| {
|
||||
serde_json::from_value::<member::MembershipState>(
|
||||
membership.clone(),
|
||||
)
|
||||
.ok()
|
||||
})
|
||||
{
|
||||
if let Some(state_key) = pdu
|
||||
.state_key
|
||||
|
@ -1272,7 +1280,7 @@ impl Rooms {
|
|||
unsigned.insert(
|
||||
"prev_content".to_owned(),
|
||||
CanonicalJsonValue::Object(
|
||||
utils::to_canonical_object(prev_state.content.clone())
|
||||
utils::to_canonical_object(prev_state.content_value())
|
||||
.expect("event is valid, we just created it"),
|
||||
),
|
||||
);
|
||||
|
@ -1329,7 +1337,7 @@ impl Rooms {
|
|||
.rooms
|
||||
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
|
||||
.map(|ev| {
|
||||
serde_json::from_value(ev.content.clone())
|
||||
serde_json::from_value(ev.content_value())
|
||||
.map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
|
||||
})
|
||||
.transpose()?
|
||||
|
@ -1409,7 +1417,7 @@ impl Rooms {
|
|||
.expect("This state_key was previously validated");
|
||||
|
||||
let membership = serde_json::from_value::<member::MembershipState>(
|
||||
pdu.content
|
||||
pdu.content_value()
|
||||
.get("membership")
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
|
@ -1447,7 +1455,7 @@ impl Rooms {
|
|||
}
|
||||
}
|
||||
EventType::RoomMessage => {
|
||||
if let Some(body) = pdu.content.get("body").and_then(|b| b.as_str()) {
|
||||
if let Some(body) = pdu.content_value().get("body").and_then(|b| b.as_str()) {
|
||||
let mut batch = body
|
||||
.split_terminator(|c: char| !c.is_alphanumeric())
|
||||
.filter(|s| !s.is_empty())
|
||||
|
@ -1961,7 +1969,7 @@ impl Rooms {
|
|||
let create_event_content = create_event
|
||||
.as_ref()
|
||||
.map(|create_event| {
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone())
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|e| {
|
||||
|
@ -2000,7 +2008,7 @@ impl Rooms {
|
|||
let mut unsigned = unsigned.unwrap_or_default();
|
||||
if let Some(state_key) = &state_key {
|
||||
if let Some(prev_pdu) = self.room_state_get(room_id, &event_type, state_key)? {
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone());
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content_value());
|
||||
unsigned.insert(
|
||||
"prev_sender".to_owned(),
|
||||
serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"),
|
||||
|
@ -2350,7 +2358,7 @@ impl Rooms {
|
|||
.and_then(|create| {
|
||||
serde_json::from_value::<
|
||||
Raw<ruma::events::room::create::CreateEventContent>,
|
||||
>(create.content.clone())
|
||||
>(create.content_value())
|
||||
.expect("Raw::from_value always works")
|
||||
.deserialize()
|
||||
.ok()
|
||||
|
@ -2706,8 +2714,7 @@ impl Rooms {
|
|||
ErrorKind::BadState,
|
||||
"Cannot leave a room you are not a member of.",
|
||||
))?
|
||||
.content
|
||||
.clone(),
|
||||
.content_value(),
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -2793,10 +2800,9 @@ impl Rooms {
|
|||
};
|
||||
|
||||
let mut leave_event_stub =
|
||||
serde_json::from_str::<CanonicalJsonObject>(make_leave_response.event.json().get())
|
||||
.map_err(|_| {
|
||||
Error::BadServerResponse("Invalid make_leave event json received from server.")
|
||||
})?;
|
||||
serde_json::from_str::<CanonicalJsonObject>(make_leave_response.event.get()).map_err(
|
||||
|_| Error::BadServerResponse("Invalid make_leave event json received from server."),
|
||||
)?;
|
||||
|
||||
// TODO: Is origin needed?
|
||||
leave_event_stub.insert(
|
||||
|
@ -2847,7 +2853,7 @@ impl Rooms {
|
|||
federation::membership::create_leave_event::v2::Request {
|
||||
room_id,
|
||||
event_id: &event_id,
|
||||
pdu: PduEvent::convert_to_outgoing_federation_event(leave_event.clone()),
|
||||
pdu: PduEvent::convert_to_outgoing_federation_event(leave_event.clone()).json(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -656,7 +656,7 @@ impl Sending {
|
|||
),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
).into_json();
|
||||
pdu_jsons.push(raw);
|
||||
}
|
||||
SendingEventType::Edu(edu) => {
|
||||
|
|
37
src/pdu.rs
37
src/pdu.rs
|
@ -10,7 +10,7 @@ use ruma::{
|
|||
ServerSigningKeyId, UInt, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use serde_json::{json, value::RawValue as RawJsonValue};
|
||||
use std::{cmp::Ordering, collections::BTreeMap, convert::TryFrom};
|
||||
use tracing::warn;
|
||||
|
||||
|
@ -22,7 +22,7 @@ pub struct PduEvent {
|
|||
pub origin_server_ts: UInt,
|
||||
#[serde(rename = "type")]
|
||||
pub kind: EventType,
|
||||
pub content: serde_json::Value,
|
||||
pub content: Box<serde_json::value::RawValue>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub state_key: Option<String>,
|
||||
pub prev_events: Vec<EventId>,
|
||||
|
@ -37,6 +37,10 @@ pub struct PduEvent {
|
|||
}
|
||||
|
||||
impl PduEvent {
|
||||
pub fn content_value(&self) -> serde_json::Value {
|
||||
serde_json::from_str(self.content.get()).expect("from_str(self.content) always works")
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn redact(&mut self, reason: &PduEvent) -> crate::Result<()> {
|
||||
self.unsigned.clear();
|
||||
|
@ -59,8 +63,8 @@ impl PduEvent {
|
|||
_ => &[],
|
||||
};
|
||||
|
||||
let old_content = self
|
||||
.content
|
||||
let mut old_content = self.content_value();
|
||||
let old_content = old_content
|
||||
.as_object_mut()
|
||||
.ok_or_else(|| Error::bad_database("PDU in db has invalid content."))?;
|
||||
|
||||
|
@ -77,7 +81,8 @@ impl PduEvent {
|
|||
serde_json::to_value(reason).expect("to_value(PduEvent) always works"),
|
||||
);
|
||||
|
||||
self.content = new_content.into();
|
||||
self.content = serde_json::value::to_raw_value(&new_content)
|
||||
.expect("to_raw_value(serde_json::Map) always works");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -265,7 +270,7 @@ impl state_res::Event for PduEvent {
|
|||
&self.kind
|
||||
}
|
||||
|
||||
fn content(&self) -> &serde_json::Value {
|
||||
fn content(&self) -> &serde_json::value::RawValue {
|
||||
&self.content
|
||||
}
|
||||
|
||||
|
@ -281,10 +286,6 @@ impl state_res::Event for PduEvent {
|
|||
Box::new(self.prev_events.iter())
|
||||
}
|
||||
|
||||
fn depth(&self) -> &UInt {
|
||||
&self.depth
|
||||
}
|
||||
|
||||
fn auth_events(&self) -> Box<dyn DoubleEndedIterator<Item = &EventId> + '_> {
|
||||
Box::new(self.auth_events.iter())
|
||||
}
|
||||
|
@ -292,18 +293,6 @@ impl state_res::Event for PduEvent {
|
|||
fn redacts(&self) -> Option<&EventId> {
|
||||
self.redacts.as_ref()
|
||||
}
|
||||
|
||||
fn hashes(&self) -> &EventHash {
|
||||
&self.hashes
|
||||
}
|
||||
|
||||
fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>> {
|
||||
self.signatures.clone()
|
||||
}
|
||||
|
||||
fn unsigned(&self) -> &BTreeMap<String, serde_json::Value> {
|
||||
&self.unsigned
|
||||
}
|
||||
}
|
||||
|
||||
// These impl's allow us to dedup state snapshots when resolving state
|
||||
|
@ -329,9 +318,9 @@ impl Ord for PduEvent {
|
|||
///
|
||||
/// Returns a tuple of the new `EventId` and the PDU as a `BTreeMap<String, CanonicalJsonValue>`.
|
||||
pub(crate) fn gen_event_id_canonical_json(
|
||||
pdu: &Raw<ruma::events::pdu::Pdu>,
|
||||
pdu: &RawJsonValue,
|
||||
) -> crate::Result<(EventId, CanonicalJsonObject)> {
|
||||
let value = serde_json::from_str(pdu.json().get()).map_err(|e| {
|
||||
let value = serde_json::from_str(pdu.get()).map_err(|e| {
|
||||
warn!("Error parsing incoming event {:?}: {:?}", pdu, e);
|
||||
Error::BadServerResponse("Invalid PDU in server response")
|
||||
})?;
|
||||
|
|
|
@ -39,7 +39,6 @@ use ruma::{
|
|||
},
|
||||
directory::{IncomingFilter, IncomingRoomNetwork},
|
||||
events::{
|
||||
pdu::Pdu,
|
||||
receipt::{ReceiptEvent, ReceiptEventContent},
|
||||
room::{
|
||||
create::CreateEventContent,
|
||||
|
@ -55,6 +54,7 @@ use ruma::{
|
|||
uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, ServerName,
|
||||
ServerSigningKeyId,
|
||||
};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
use std::{
|
||||
collections::{btree_map, hash_map, BTreeMap, BTreeSet, HashMap, HashSet},
|
||||
convert::{TryFrom, TryInto},
|
||||
|
@ -1071,7 +1071,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
|
|||
// and lexically by event_id.
|
||||
println!("{}", event_id);
|
||||
Ok((
|
||||
0,
|
||||
ruma::int!(0),
|
||||
MilliSecondsSinceUnixEpoch(
|
||||
eventid_info
|
||||
.get(event_id)
|
||||
|
@ -1154,7 +1154,7 @@ fn handle_outlier_pdu<'a>(
|
|||
// 3. check content hash, redact if doesn't match
|
||||
|
||||
let create_event_content =
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone())
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|e| {
|
||||
|
@ -1320,7 +1320,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
}
|
||||
|
||||
let create_event_content =
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone())
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|e| {
|
||||
|
@ -1627,7 +1627,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
&incoming_pdu.kind,
|
||||
&incoming_pdu.sender,
|
||||
incoming_pdu.state_key.as_deref(),
|
||||
&incoming_pdu.content,
|
||||
&incoming_pdu.content_value(),
|
||||
)
|
||||
.map_err(|_| "Failed to get_auth_events.".to_owned())?;
|
||||
|
||||
|
@ -2387,7 +2387,7 @@ pub fn get_event_route(
|
|||
Ok(get_event::v1::Response {
|
||||
origin: db.globals.server_name().to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||
pdu: PduEvent::convert_to_outgoing_federation_event(event),
|
||||
pdu: PduEvent::convert_to_outgoing_federation_event(event).into_json(),
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
@ -2458,7 +2458,7 @@ pub fn get_missing_events_route(
|
|||
)
|
||||
.map_err(|_| Error::bad_database("Invalid prev_events content in pdu in db."))?,
|
||||
);
|
||||
events.push(PduEvent::convert_to_outgoing_federation_event(pdu));
|
||||
events.push(PduEvent::convert_to_outgoing_federation_event(pdu).into_json());
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
@ -2512,6 +2512,7 @@ pub fn get_event_authorization_route(
|
|||
auth_chain: auth_chain_ids
|
||||
.filter_map(|id| db.rooms.get_pdu_json(&id).ok()?)
|
||||
.map(PduEvent::convert_to_outgoing_federation_event)
|
||||
.map(Raw::into_json)
|
||||
.collect(),
|
||||
}
|
||||
.into())
|
||||
|
@ -2562,6 +2563,7 @@ pub fn get_room_state_route(
|
|||
db.rooms.get_pdu_json(&id).unwrap().unwrap(),
|
||||
)
|
||||
})
|
||||
.map(Raw::into_json)
|
||||
.collect();
|
||||
|
||||
let auth_chain_ids = get_auth_chain(&body.room_id, vec![Arc::new(body.event_id.clone())], &db)?;
|
||||
|
@ -2574,6 +2576,7 @@ pub fn get_room_state_route(
|
|||
))
|
||||
})
|
||||
.filter_map(|r| r.ok())
|
||||
.map(Raw::into_json)
|
||||
.collect(),
|
||||
pdus,
|
||||
}
|
||||
|
@ -2669,7 +2672,7 @@ pub fn create_join_event_template_route(
|
|||
let create_event_content = create_event
|
||||
.as_ref()
|
||||
.map(|create_event| {
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone())
|
||||
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|e| {
|
||||
|
@ -2735,7 +2738,7 @@ pub fn create_join_event_template_route(
|
|||
let mut unsigned = BTreeMap::new();
|
||||
|
||||
if let Some(prev_pdu) = db.rooms.room_state_get(&body.room_id, &kind, &state_key)? {
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone());
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content_value());
|
||||
unsigned.insert(
|
||||
"prev_sender".to_owned(),
|
||||
serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"),
|
||||
|
@ -2799,10 +2802,8 @@ pub fn create_join_event_template_route(
|
|||
|
||||
Ok(create_join_event_template::v1::Response {
|
||||
room_version: Some(room_version_id),
|
||||
event: serde_json::from_value::<Raw<_>>(
|
||||
serde_json::to_value(pdu_json).expect("CanonicalJson is valid serde_json::Value"),
|
||||
)
|
||||
.expect("Raw::from_value always works"),
|
||||
event: serde_json::value::to_raw_value(&pdu_json)
|
||||
.expect("CanonicalJson is valid raw value"),
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
@ -2810,7 +2811,7 @@ pub fn create_join_event_template_route(
|
|||
async fn create_join_event(
|
||||
db: &DatabaseGuard,
|
||||
room_id: &RoomId,
|
||||
pdu: &Raw<ruma::events::pdu::Pdu>,
|
||||
pdu: &RawJsonValue,
|
||||
) -> Result<RoomState> {
|
||||
if !db.globals.allow_federation() {
|
||||
return Err(Error::bad_config("Federation is disabled."));
|
||||
|
@ -2894,11 +2895,13 @@ async fn create_join_event(
|
|||
auth_chain: auth_chain_ids
|
||||
.filter_map(|id| db.rooms.get_pdu_json(&id).ok().flatten())
|
||||
.map(PduEvent::convert_to_outgoing_federation_event)
|
||||
.map(Raw::into_json)
|
||||
.collect(),
|
||||
state: state_ids
|
||||
.iter()
|
||||
.filter_map(|(_, id)| db.rooms.get_pdu_json(id).ok().flatten())
|
||||
.map(PduEvent::convert_to_outgoing_federation_event)
|
||||
.map(Raw::into_json)
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
@ -2947,7 +2950,7 @@ pub async fn create_join_event_v2_route(
|
|||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_invite_route(
|
||||
db: DatabaseGuard,
|
||||
body: Ruma<create_invite::v2::Request>,
|
||||
body: Ruma<create_invite::v2::Request<'_>>,
|
||||
) -> ConduitResult<create_invite::v2::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
return Err(Error::bad_config("Federation is disabled."));
|
||||
|
@ -3014,10 +3017,11 @@ pub async fn create_invite_route(
|
|||
|
||||
let mut invite_state = body.invite_room_state.clone();
|
||||
|
||||
let mut event = serde_json::from_str::<serde_json::Map<String, serde_json::Value>>(
|
||||
&body.event.json().to_string(),
|
||||
)
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid invite event bytes."))?;
|
||||
let mut event =
|
||||
serde_json::from_str::<serde_json::Map<String, serde_json::Value>>(body.event.get())
|
||||
.map_err(|_| {
|
||||
Error::BadRequest(ErrorKind::InvalidParam, "Invalid invite event bytes.")
|
||||
})?;
|
||||
|
||||
event.insert("event_id".to_owned(), "$dummy".into());
|
||||
|
||||
|
@ -3044,7 +3048,7 @@ pub async fn create_invite_route(
|
|||
db.flush()?;
|
||||
|
||||
Ok(create_invite::v2::Response {
|
||||
event: PduEvent::convert_to_outgoing_federation_event(signed_event),
|
||||
event: PduEvent::convert_to_outgoing_federation_event(signed_event).into_json(),
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
@ -3280,13 +3284,13 @@ pub(crate) async fn fetch_required_signing_keys(
|
|||
// Gets a list of servers for which we don't have the signing key yet. We go over
|
||||
// the PDUs and either cache the key or add it to the list that needs to be retrieved.
|
||||
fn get_server_keys_from_cache(
|
||||
pdu: &Raw<Pdu>,
|
||||
pdu: &RawJsonValue,
|
||||
servers: &mut BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, QueryCriteria>>,
|
||||
room_version: &RoomVersionId,
|
||||
pub_key_map: &mut RwLockWriteGuard<'_, BTreeMap<String, BTreeMap<String, String>>>,
|
||||
db: &Database,
|
||||
) -> Result<()> {
|
||||
let value = serde_json::from_str::<CanonicalJsonObject>(pdu.json().get()).map_err(|e| {
|
||||
let value = serde_json::from_str::<CanonicalJsonObject>(pdu.get()).map_err(|e| {
|
||||
error!("Invalid PDU in server response: {:?}: {:?}", pdu, e);
|
||||
Error::BadServerResponse("Invalid PDU in server response")
|
||||
})?;
|
||||
|
|
Loading…
Reference in New Issue