only remove event_id field in room v1 and v2
no this doesnt make those rooms work, just a why not thing Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
0863bec098
commit
4be37fbe8d
5 changed files with 70 additions and 15 deletions
|
@ -526,9 +526,14 @@ pub(crate) async fn join_room_by_id_helper(
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// We don't leave the event id in the pdu because that's only allowed in v1 or
|
// We keep the "event_id" in the pdu only in v1 or
|
||||||
// v2 rooms
|
// v2 rooms
|
||||||
|
match room_version_id {
|
||||||
|
RoomVersionId::V1 | RoomVersionId::V2 => {},
|
||||||
|
_ => {
|
||||||
join_event_stub.remove("event_id");
|
join_event_stub.remove("event_id");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
||||||
// to be present
|
// to be present
|
||||||
|
@ -929,9 +934,14 @@ pub(crate) async fn join_room_by_id_helper(
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// We don't leave the event id in the pdu because that's only allowed in v1 or
|
// We keep the "event_id" in the pdu only in v1 or
|
||||||
// v2 rooms
|
// v2 rooms
|
||||||
|
match room_version_id {
|
||||||
|
RoomVersionId::V1 | RoomVersionId::V2 => {},
|
||||||
|
_ => {
|
||||||
join_event_stub.remove("event_id");
|
join_event_stub.remove("event_id");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
||||||
// to be present
|
// to be present
|
||||||
|
@ -1419,9 +1429,14 @@ async fn remote_leave_room(user_id: &UserId, room_id: &RoomId) -> Result<()> {
|
||||||
utils::millis_since_unix_epoch().try_into().expect("Timestamp is valid js_int value"),
|
utils::millis_since_unix_epoch().try_into().expect("Timestamp is valid js_int value"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
// We don't leave the event id in the pdu because that's only allowed in v1 or
|
|
||||||
// v2 rooms
|
// room v3 and above removed the "event_id" field from remote PDU format
|
||||||
|
match room_version_id {
|
||||||
|
RoomVersionId::V1 | RoomVersionId::V2 => {},
|
||||||
|
_ => {
|
||||||
leave_event_stub.remove("event_id");
|
leave_event_stub.remove("event_id");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
||||||
// to be present
|
// to be present
|
||||||
|
|
|
@ -202,7 +202,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
||||||
},
|
},
|
||||||
RoomVersionId::V11 => {}, // V11 removed the "creator" key
|
RoomVersionId::V11 => {}, // V11 removed the "creator" key
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Unexpected or unsupported room version {}", room_version);
|
warn!("Unexpected or unsupported room version {room_version}");
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::BadJson,
|
ErrorKind::BadJson,
|
||||||
"Unexpected or unsupported room version found",
|
"Unexpected or unsupported room version found",
|
||||||
|
@ -219,7 +219,6 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
||||||
content
|
content
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
// TODO: Add correct value for v11
|
|
||||||
let content = match room_version {
|
let content = match room_version {
|
||||||
RoomVersionId::V1
|
RoomVersionId::V1
|
||||||
| RoomVersionId::V2
|
| RoomVersionId::V2
|
||||||
|
@ -233,7 +232,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
||||||
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(sender_user.clone()),
|
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(sender_user.clone()),
|
||||||
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
|
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Unexpected or unsupported room version {}", room_version);
|
warn!("Unexpected or unsupported room version {room_version}");
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::BadJson,
|
ErrorKind::BadJson,
|
||||||
"Unexpected or unsupported room version found",
|
"Unexpected or unsupported room version found",
|
||||||
|
|
|
@ -49,7 +49,7 @@ use ruma::{
|
||||||
serde::{Base64, JsonObject, Raw},
|
serde::{Base64, JsonObject, Raw},
|
||||||
to_device::DeviceIdOrAllDevices,
|
to_device::DeviceIdOrAllDevices,
|
||||||
uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
|
uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
|
||||||
OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId, ServerName,
|
OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId, RoomVersionId, ServerName,
|
||||||
};
|
};
|
||||||
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
@ -1347,7 +1347,28 @@ pub async fn create_join_event_template_route(
|
||||||
|
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
|
// room v3 and above removed the "event_id" field from remote PDU format
|
||||||
|
match room_version_id {
|
||||||
|
RoomVersionId::V1 | RoomVersionId::V2 => {},
|
||||||
|
RoomVersionId::V3
|
||||||
|
| RoomVersionId::V4
|
||||||
|
| RoomVersionId::V5
|
||||||
|
| RoomVersionId::V6
|
||||||
|
| RoomVersionId::V7
|
||||||
|
| RoomVersionId::V8
|
||||||
|
| RoomVersionId::V9
|
||||||
|
| RoomVersionId::V10
|
||||||
|
| RoomVersionId::V11 => {
|
||||||
pdu_json.remove("event_id");
|
pdu_json.remove("event_id");
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
warn!("Unexpected or unsupported room version {room_version_id}");
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::BadJson,
|
||||||
|
"Unexpected or unsupported room version found",
|
||||||
|
));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
Ok(prepare_join_event::v1::Response {
|
Ok(prepare_join_event::v1::Response {
|
||||||
room_version: Some(room_version_id),
|
room_version: Some(room_version_id),
|
||||||
|
|
|
@ -18,7 +18,7 @@ use serde_json::{
|
||||||
};
|
};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::Error;
|
use crate::{services, Error};
|
||||||
|
|
||||||
/// Content hashes of a PDU.
|
/// Content hashes of a PDU.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
@ -281,7 +281,21 @@ impl PduEvent {
|
||||||
unsigned.remove("transaction_id");
|
unsigned.remove("transaction_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(room_id) = pdu_json.get("room_id").and_then(|val| RoomId::parse(val.as_str()?).ok()) {
|
||||||
|
if let Ok(room_version_id) = services().rooms.state.get_room_version(&room_id) {
|
||||||
|
// room v3 and above removed the "event_id" field from remote PDU format
|
||||||
|
match room_version_id {
|
||||||
|
RoomVersionId::V1 | RoomVersionId::V2 => {},
|
||||||
|
_ => {
|
||||||
pdu_json.remove("event_id");
|
pdu_json.remove("event_id");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
pdu_json.remove("event_id");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pdu_json.remove("event_id");
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: another option would be to convert it to a canonical string to validate
|
// TODO: another option would be to convert it to a canonical string to validate
|
||||||
// size and return a Result<Raw<...>>
|
// size and return a Result<Raw<...>>
|
||||||
|
|
|
@ -666,7 +666,13 @@ impl Service {
|
||||||
Error::bad_database("Failed to convert PDU to canonical JSON.")
|
Error::bad_database("Failed to convert PDU to canonical JSON.")
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
// room v3 and above removed the "event_id" field from remote PDU format
|
||||||
|
match room_version_id {
|
||||||
|
RoomVersionId::V1 | RoomVersionId::V2 => {},
|
||||||
|
_ => {
|
||||||
pdu_json.remove("event_id");
|
pdu_json.remove("event_id");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// Add origin because synapse likes that (and it's required in the spec)
|
// Add origin because synapse likes that (and it's required in the spec)
|
||||||
pdu_json.insert(
|
pdu_json.insert(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue