From 36bc8bf73a3246173d8b5c70628d6735402ef7e1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Sep 2021 20:27:57 +0200 Subject: [PATCH] federation-api: Replace Raw with Box --- crates/ruma-federation-api/CHANGELOG.md | 4 ++++ .../src/authorization/get_event_authorization/v1.rs | 7 +++---- .../src/backfill/get_backfill/v1.rs | 8 ++++---- crates/ruma-federation-api/src/event/get_event/v1.rs | 8 ++++---- .../src/event/get_missing_events/v1.rs | 8 ++++---- .../src/event/get_room_state/v1.rs | 10 +++++----- .../src/knock/create_knock_event_template/v1.rs | 7 +++---- .../src/membership/create_invite/v1.rs | 7 ++++--- .../src/membership/create_invite/v2.rs | 11 ++++++----- .../src/membership/create_join_event.rs | 7 +++---- .../src/membership/create_join_event/v1.rs | 10 +++++----- .../src/membership/create_join_event/v2.rs | 10 +++++----- .../src/membership/create_join_event_template/v1.rs | 8 ++++---- .../src/membership/create_leave_event/v2.rs | 10 +++++----- .../src/membership/get_leave_event/v1.rs | 8 ++++---- .../src/transactions/send_transaction_message/v1.rs | 4 ++-- 16 files changed, 65 insertions(+), 62 deletions(-) diff --git a/crates/ruma-federation-api/CHANGELOG.md b/crates/ruma-federation-api/CHANGELOG.md index 40027960..2efe349d 100644 --- a/crates/ruma-federation-api/CHANGELOG.md +++ b/crates/ruma-federation-api/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Breaking changes: + +* Replace `Raw` with `Box` + # 0.3.1 Bug fixes: diff --git a/crates/ruma-federation-api/src/authorization/get_event_authorization/v1.rs b/crates/ruma-federation-api/src/authorization/get_event_authorization/v1.rs index 5a6f7c0d..c21c48fa 100644 --- a/crates/ruma-federation-api/src/authorization/get_event_authorization/v1.rs +++ b/crates/ruma-federation-api/src/authorization/get_event_authorization/v1.rs @@ -1,9 +1,8 @@ //! [GET /_matrix/federation/v1/event_auth/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-event-auth-roomid-eventid) use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, RoomId}; -use ruma_serde::Raw; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -28,7 +27,7 @@ ruma_api! { response: { /// The full set of authorization events that make up the state of the room, /// and their authorization events, recursively. - pub auth_chain: Vec>, + pub auth_chain: Vec>, } } @@ -41,7 +40,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given auth chain. - pub fn new(auth_chain: Vec>) -> Self { + pub fn new(auth_chain: Vec>) -> Self { Self { auth_chain } } } diff --git a/crates/ruma-federation-api/src/backfill/get_backfill/v1.rs b/crates/ruma-federation-api/src/backfill/get_backfill/v1.rs index b3ac682e..261a8290 100644 --- a/crates/ruma-federation-api/src/backfill/get_backfill/v1.rs +++ b/crates/ruma-federation-api/src/backfill/get_backfill/v1.rs @@ -3,9 +3,9 @@ use js_int::UInt; use ruma_api::ruma_api; use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, RoomId, ServerNameBox}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -39,7 +39,7 @@ ruma_api! { pub origin_server_ts: MilliSecondsSinceUnixEpoch, /// List of persistent updates to rooms. - pub pdus: Vec>, + pub pdus: Vec>, } } @@ -61,7 +61,7 @@ impl Response { pub fn new( origin: ServerNameBox, origin_server_ts: MilliSecondsSinceUnixEpoch, - pdus: Vec>, + pdus: Vec>, ) -> Self { Self { origin, origin_server_ts, pdus } } diff --git a/crates/ruma-federation-api/src/event/get_event/v1.rs b/crates/ruma-federation-api/src/event/get_event/v1.rs index c505e57d..2ea3d72b 100644 --- a/crates/ruma-federation-api/src/event/get_event/v1.rs +++ b/crates/ruma-federation-api/src/event/get_event/v1.rs @@ -2,9 +2,9 @@ use ruma_api::ruma_api; use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, ServerNameBox}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -31,7 +31,7 @@ ruma_api! { /// The event. #[serde(rename = "pdus", with = "ruma_serde::single_element_seq")] - pub pdu: Raw, + pub pdu: Box, } } @@ -47,7 +47,7 @@ impl Response { pub fn new( origin: ServerNameBox, origin_server_ts: MilliSecondsSinceUnixEpoch, - pdu: Raw, + pdu: Box, ) -> Self { Self { origin, origin_server_ts, pdu } } diff --git a/crates/ruma-federation-api/src/event/get_missing_events/v1.rs b/crates/ruma-federation-api/src/event/get_missing_events/v1.rs index 6eaa531b..3cae74cf 100644 --- a/crates/ruma-federation-api/src/event/get_missing_events/v1.rs +++ b/crates/ruma-federation-api/src/event/get_missing_events/v1.rs @@ -2,9 +2,9 @@ use js_int::{uint, UInt}; use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, RoomId}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -39,7 +39,7 @@ ruma_api! { #[derive(Default)] response: { /// The missing PDUs. - pub events: Vec>, + pub events: Vec>, } } @@ -62,7 +62,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given events. - pub fn new(events: Vec>) -> Self { + pub fn new(events: Vec>) -> Self { Self { events } } } diff --git a/crates/ruma-federation-api/src/event/get_room_state/v1.rs b/crates/ruma-federation-api/src/event/get_room_state/v1.rs index d1e9417a..dfb8ac6a 100644 --- a/crates/ruma-federation-api/src/event/get_room_state/v1.rs +++ b/crates/ruma-federation-api/src/event/get_room_state/v1.rs @@ -1,9 +1,9 @@ //! [GET /_matrix/federation/v1/state/{roomId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-state-roomid) use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, RoomId}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -28,10 +28,10 @@ ruma_api! { response: { /// The full set of authorization events that make up the state of the /// room, and their authorization events, recursively. - pub auth_chain: Vec>, + pub auth_chain: Vec>, /// The fully resolved state of the room at the given event. - pub pdus: Vec>, + pub pdus: Vec>, } } @@ -44,7 +44,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given auth chain and room state. - pub fn new(auth_chain: Vec>, pdus: Vec>) -> Self { + pub fn new(auth_chain: Vec>, pdus: Vec>) -> Self { Self { auth_chain, pdus } } } diff --git a/crates/ruma-federation-api/src/knock/create_knock_event_template/v1.rs b/crates/ruma-federation-api/src/knock/create_knock_event_template/v1.rs index a7afb255..c27daf97 100644 --- a/crates/ruma-federation-api/src/knock/create_knock_event_template/v1.rs +++ b/crates/ruma-federation-api/src/knock/create_knock_event_template/v1.rs @@ -1,9 +1,8 @@ //! [GET /_matrix/federation/v1/make_knock/{roomId}/{userId}](https://spec.matrix.org/unstable/server-server-api/#get_matrixfederationv1make_knockroomiduserid) use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{RoomId, RoomVersionId, UserId}; -use ruma_serde::Raw; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -38,7 +37,7 @@ ruma_api! { /// An unsigned template event. /// /// May differ between room versions. - pub event: Raw, + pub event: Box, } } @@ -51,7 +50,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room version ID and event. - pub fn new(room_version: RoomVersionId, event: Raw) -> Self { + pub fn new(room_version: RoomVersionId, event: Box) -> Self { Self { room_version, event } } } diff --git a/crates/ruma-federation-api/src/membership/create_invite/v1.rs b/crates/ruma-federation-api/src/membership/create_invite/v1.rs index 2cb3820a..66ca87bc 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v1.rs @@ -2,10 +2,11 @@ use ruma_api::ruma_api; use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_events::{pdu::Pdu, room::member::MemberEventContent, AnyStrippedStateEvent, EventType}; +use ruma_events::{room::member::MemberEventContent, AnyStrippedStateEvent, EventType}; use ruma_identifiers::{EventId, RoomId, ServerName, UserId}; use ruma_serde::Raw; use serde::{Deserialize, Serialize}; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -54,7 +55,7 @@ ruma_api! { /// The signed invite event. #[ruma_api(body)] #[serde(with = "crate::serde::v1_pdu")] - pub event: Raw, + pub event: Box, } } @@ -129,7 +130,7 @@ impl<'a> From> for Request<'a> { impl Response { /// Creates a new `Response` with the given invite event. - pub fn new(event: Raw) -> Self { + pub fn new(event: Box) -> Self { Self { event } } } diff --git a/crates/ruma-federation-api/src/membership/create_invite/v2.rs b/crates/ruma-federation-api/src/membership/create_invite/v2.rs index 058f8f4f..3d657390 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v2.rs @@ -1,9 +1,10 @@ //! [PUT /_matrix/federation/v2/invite/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-invite-roomid-eventid) use ruma_api::ruma_api; -use ruma_events::{pdu::Pdu, AnyStrippedStateEvent}; +use ruma_events::AnyStrippedStateEvent; use ruma_identifiers::{EventId, RoomId, RoomVersionId}; use ruma_serde::Raw; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -28,7 +29,7 @@ ruma_api! { pub room_version: RoomVersionId, /// The invite event which needs to be signed. - pub event: Raw, + pub event: Box, /// An optional list of simplified events to help the receiver of the invite identify the room. pub invite_room_state: Vec>, @@ -36,7 +37,7 @@ ruma_api! { response: { /// The signed invite event. - pub event: Raw, + pub event: Box, } } @@ -47,7 +48,7 @@ impl Request { room_id: RoomId, event_id: EventId, room_version: RoomVersionId, - event: Raw, + event: Box, invite_room_state: Vec>, ) -> Self { Self { room_id, event_id, room_version, event, invite_room_state } @@ -56,7 +57,7 @@ impl Request { impl Response { /// Creates a new `Response` with the given invite event. - pub fn new(event: Raw) -> Self { + pub fn new(event: Box) -> Self { Self { event } } } diff --git a/crates/ruma-federation-api/src/membership/create_join_event.rs b/crates/ruma-federation-api/src/membership/create_join_event.rs index 21443afb..9cd47356 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event.rs @@ -3,9 +3,8 @@ pub mod v1; pub mod v2; -use ruma_events::pdu::Pdu; -use ruma_serde::Raw; use serde::{Deserialize, Serialize}; +use serde_json::value::RawValue as RawJsonValue; /// Full state of the room. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -18,10 +17,10 @@ pub struct RoomState { /// The full set of authorization events that make up the state of the room, /// and their authorization events, recursively. - pub auth_chain: Vec>, + pub auth_chain: Vec>, /// The room state. - pub state: Vec>, + pub state: Vec>, } #[cfg(feature = "unstable-pre-spec")] diff --git a/crates/ruma-federation-api/src/membership/create_join_event/v1.rs b/crates/ruma-federation-api/src/membership/create_join_event/v1.rs index f7758553..cfed6809 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event/v1.rs @@ -1,9 +1,9 @@ //! [PUT /_matrix/federation/v1/send_join/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.3#put-matrix-federation-v1-send-join-roomid-eventid) use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, RoomId}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; use super::RoomState; @@ -30,7 +30,7 @@ ruma_api! { /// The PDU. #[ruma_api(body)] - pub pdu: Raw, + pub pdu: Box, } response: { @@ -42,8 +42,8 @@ ruma_api! { } impl<'a> Request<'a> { - /// Creates a new `Request` from the given room ID, event ID and `Pdu`. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: Raw) -> Self { + /// Creates a new `Request` from the given room ID, event ID and PDU. + pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: Box) -> Self { Self { room_id, event_id, pdu } } } diff --git a/crates/ruma-federation-api/src/membership/create_join_event/v2.rs b/crates/ruma-federation-api/src/membership/create_join_event/v2.rs index 29777fe2..1768f56b 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event/v2.rs @@ -1,9 +1,9 @@ //! [PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-send-join-roomid-eventid) use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, RoomId}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; use super::RoomState; @@ -30,7 +30,7 @@ ruma_api! { /// The PDU. #[ruma_api(body)] - pub pdu: Raw, + pub pdu: Box, } response: { @@ -41,8 +41,8 @@ ruma_api! { } impl<'a> Request<'a> { - /// Creates a new `Request` from the given room ID, event ID and `Pdu`. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: Raw) -> Self { + /// Creates a new `Request` from the given room ID, event ID and PDU. + pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: Box) -> Self { Self { room_id, event_id, pdu } } } diff --git a/crates/ruma-federation-api/src/membership/create_join_event_template/v1.rs b/crates/ruma-federation-api/src/membership/create_join_event_template/v1.rs index 1442de19..f6658109 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event_template/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event_template/v1.rs @@ -1,9 +1,9 @@ //! [GET /_matrix/federation/v1/make_join/{roomId}/{userId}](https://matrix.org/docs/spec/server_server/r0.1.3#get-matrix-federation-v1-make-join-roomid-userid) use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{RoomId, RoomVersionId, UserId}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -38,7 +38,7 @@ ruma_api! { pub room_version: Option, /// An unsigned template event. - pub event: Raw, + pub event: Box, } } @@ -59,7 +59,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given template event. - pub fn new(event: Raw) -> Self { + pub fn new(event: Box) -> Self { Self { room_version: None, event } } } diff --git a/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs b/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs index 2a593387..b1a55d99 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs @@ -1,9 +1,9 @@ //! [PUT /_matrix/federation/v2/send_leave/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-send-leave-roomid-eventid) use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, RoomId}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -28,7 +28,7 @@ ruma_api! { /// The PDU. #[ruma_api(body)] - pub pdu: Raw, + pub pdu: Box, } #[derive(Default)] @@ -36,8 +36,8 @@ ruma_api! { } impl<'a> Request<'a> { - /// Creates a new `Request` from the given room ID, event ID and `Pdu`. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: Raw) -> Self { + /// Creates a new `Request` from the given room ID, event ID and PDU. + pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: Box) -> Self { Self { room_id, event_id, pdu } } } diff --git a/crates/ruma-federation-api/src/membership/get_leave_event/v1.rs b/crates/ruma-federation-api/src/membership/get_leave_event/v1.rs index 5d48eb71..c3a243ed 100644 --- a/crates/ruma-federation-api/src/membership/get_leave_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/get_leave_event/v1.rs @@ -1,9 +1,9 @@ //! [GET /_matrix/federation/v1/make_leave/{roomId}/{userId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-make-leave-roomid-userid) use ruma_api::ruma_api; -use ruma_events::pdu::Pdu; use ruma_identifiers::{RoomId, RoomVersionId, UserId}; -use ruma_serde::Raw; + +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata: { @@ -32,7 +32,7 @@ ruma_api! { /// An unsigned template event. Note that events have a different format depending on the /// room version - check the room version specification for precise event formats. - pub event: Raw, + pub event: Box, } } @@ -49,7 +49,7 @@ impl Response { /// Creates a new `Response` with: /// * the version of the room where the server is trying to leave. /// * an unsigned template event. - pub fn new(room_version: Option, event: Raw) -> Self { + pub fn new(room_version: Option, event: Box) -> Self { Self { room_version, event } } } diff --git a/crates/ruma-federation-api/src/transactions/send_transaction_message/v1.rs b/crates/ruma-federation-api/src/transactions/send_transaction_message/v1.rs index bc8b1405..cd1698a0 100644 --- a/crates/ruma-federation-api/src/transactions/send_transaction_message/v1.rs +++ b/crates/ruma-federation-api/src/transactions/send_transaction_message/v1.rs @@ -4,9 +4,9 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, ServerName}; use ruma_serde::Raw; +use serde_json::value::RawValue as RawJsonValue; use crate::transactions::edu::Edu; @@ -36,7 +36,7 @@ ruma_api! { /// /// Must not be more than 50 items. #[cfg_attr(feature = "unstable-pre-spec", serde(default, skip_serializing_if = "<[_]>::is_empty"))] - pub pdus: &'a [Raw], + pub pdus: &'a [Box], /// List of ephemeral messages. ///