Skip to content

Commit

Permalink
Remove origin field from transactions and pdus
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoesters committed Aug 13, 2020
1 parent c1b4b77 commit a9c83c6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ruma-events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ trybuild = "1.0.31"
[[bench]]
name = "event_deserialize"
harness = false

[features]
unstable-pre-spec = []
6 changes: 6 additions & 0 deletions ruma-events/src/pdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct RoomV1Pdu {
/// The user id of the user who sent this event.
pub sender: UserId,

#[cfg(not(feature = "unstable-pre-spec"))]
/// The `server_name` of the homeserver that created this event.
pub origin: String,

Expand Down Expand Up @@ -96,6 +97,7 @@ pub struct RoomV3Pdu {
/// The user id of the user who sent this event.
pub sender: UserId,

#[cfg(not(feature = "unstable-pre-spec"))]
/// The `server_name` of the homeserver that created this event.
pub origin: String,

Expand Down Expand Up @@ -172,6 +174,7 @@ pub struct RoomV1PduStub {
/// The user id of the user who sent this event.
pub sender: UserId,

#[cfg(not(feature = "unstable-pre-spec"))]
/// The `server_name` of the homeserver that created this event.
pub origin: String,

Expand Down Expand Up @@ -226,6 +229,7 @@ impl RoomV1PduStub {
event_id,
room_id,
sender: self.sender,
#[cfg(not(feature = "unstable-pre-spec"))]
origin: self.origin,
origin_server_ts: self.origin_server_ts,
kind: self.kind,
Expand All @@ -248,6 +252,7 @@ pub struct RoomV3PduStub {
/// The user id of the user who sent this event.
pub sender: UserId,

#[cfg(not(feature = "unstable-pre-spec"))]
/// The `server_name` of the homeserver that created this event.
pub origin: String,

Expand Down Expand Up @@ -301,6 +306,7 @@ impl RoomV3PduStub {
RoomV3Pdu {
room_id,
sender: self.sender,
#[cfg(not(feature = "unstable-pre-spec"))]
origin: self.origin,
origin_server_ts: self.origin_server_ts,
kind: self.kind,
Expand Down
10 changes: 10 additions & 0 deletions ruma-events/tests/pdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ruma_events::{
use ruma_identifiers::{event_id, room_id, server_key_id, server_name, user_id};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn serialize_stub_as_v1() {
let mut signatures = BTreeMap::new();
Expand Down Expand Up @@ -74,6 +75,7 @@ fn serialize_stub_as_v1() {
assert_eq!(to_json_value(&pdu_stub).unwrap(), json);
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn serialize_stub_as_v3() {
let mut signatures = BTreeMap::new();
Expand Down Expand Up @@ -127,6 +129,7 @@ fn serialize_stub_as_v3() {
assert_eq!(to_json_value(&pdu_stub).unwrap(), json);
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn deserialize_stub_as_v1() {
let json = json!({
Expand Down Expand Up @@ -184,6 +187,7 @@ fn deserialize_stub_as_v1() {
}
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn deserialize_stub_as_v3() {
let json = json!({
Expand Down Expand Up @@ -227,6 +231,7 @@ fn deserialize_stub_as_v3() {
}
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn serialize_pdu_as_v1() {
let mut signatures = BTreeMap::new();
Expand Down Expand Up @@ -294,6 +299,7 @@ fn serialize_pdu_as_v1() {
assert_eq!(to_json_value(&pdu).unwrap(), json);
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn serialize_pdu_as_v3() {
let mut signatures = BTreeMap::new();
Expand Down Expand Up @@ -349,6 +355,7 @@ fn serialize_pdu_as_v3() {
assert_eq!(to_json_value(&pdu_stub).unwrap(), json);
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn test_deserialize_pdu_as_v1() {
let json = json!({
Expand Down Expand Up @@ -408,6 +415,7 @@ fn test_deserialize_pdu_as_v1() {
}
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn deserialize_pdu_as_v3() {
let json = json!({
Expand Down Expand Up @@ -452,6 +460,7 @@ fn deserialize_pdu_as_v3() {
}
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn convert_v1_stub_to_pdu() {
let mut signatures = BTreeMap::new();
Expand Down Expand Up @@ -528,6 +537,7 @@ fn convert_v1_stub_to_pdu() {
);
}

#[cfg(not(feature = "unstable-pre-spec"))]
#[test]
fn convert_v3_stub_to_pdu() {
let mut signatures = BTreeMap::new();
Expand Down
2 changes: 0 additions & 2 deletions ruma-federation-api/src/membership/create_join_event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use serde::{Deserialize, Serialize};
/// Full state of the room.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RoomState {
/// The resident server's DNS name.
pub origin: String,
/// The full set of authorization events that make up the state of the room,
/// and their authorization events, recursively.
pub auth_chain: Vec<Raw<Pdu>>,
Expand Down
14 changes: 5 additions & 9 deletions ruma-federation-api/src/serde/room_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ mod tests {
let response = json!([
200,
{
"origin": "example.com",
"auth_chain": [],
"state": []
}
Expand All @@ -81,17 +80,15 @@ mod tests {

assert_matches!(
parsed,
RoomState { origin, auth_chain, state }
if origin == "example.com"
&& auth_chain.is_empty()
RoomState { auth_chain, state }
if auth_chain.is_empty()
&& state.is_empty()
);
}

#[test]
fn test_serialize_response() {
let room_state =
RoomState { origin: "matrix.org".into(), auth_chain: Vec::new(), state: Vec::new() };
let room_state = RoomState { auth_chain: Vec::new(), state: Vec::new() };

let serialized = serialize(&room_state, serde_json::value::Serializer).unwrap();
let expected = to_json_value(&json!(
Expand Down Expand Up @@ -139,9 +136,8 @@ mod tests {
let json = json!([200, {"origin": "", "auth_chain": [], "state": []}, 200]);
assert_matches!(
deserialize(json).unwrap(),
RoomState { origin, auth_chain, state }
if origin == ""
&& auth_chain.is_empty()
RoomState { auth_chain, state }
if auth_chain.is_empty()
&& state.is_empty()
);
}
Expand Down

0 comments on commit a9c83c6

Please sign in to comment.