mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-14 20:56:49 +00:00
fix: Don't accidentally continue with fallback room version
Fixes a potential issue where continuwuity correctly defaults to room v1 when encountering an unknown room version, but then fails to *stop* processing when it encounters the room version it doesn't actually understand.
This commit is contained in:
1 parent
f1755dd36f
commit
8f0c7a99d7
2 files changed
+33
-14
No files matched your search
@@ -1,4 +1,7 @@
|
||||
use ruma::{CanonicalJsonObject, OwnedEventId, room_version_rules::RoomVersionRules};
|
||||
use ruma::{
|
||||
CanonicalJsonObject, EventId, OwnedEventId,
|
||||
room_version_rules::{EventIdFormatVersion, RoomVersionRules},
|
||||
};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use crate::{Result, err};
|
||||
@@ -24,8 +27,11 @@ pub fn gen_event_id(
|
||||
value: &CanonicalJsonObject,
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Result<OwnedEventId> {
|
||||
assert_ne!(
|
||||
room_version_rules.event_id_format,
|
||||
EventIdFormatVersion::V1,
|
||||
"Continuwuity does not support PDU v1"
|
||||
);
|
||||
let reference_hash = ruma::signatures::reference_hash(value, room_version_rules)?;
|
||||
let event_id: OwnedEventId = format!("${reference_hash}").try_into()?;
|
||||
|
||||
Ok(event_id)
|
||||
Ok(EventId::new_v2_or_v3(&reference_hash)?)
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use conduwuit::{
|
||||
Err, Result, err,
|
||||
Err, Error, Result, err,
|
||||
matrix::event::{gen_event_id, gen_event_id_canonical_json},
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use ruma::{
|
||||
CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, RoomId,
|
||||
RoomVersionId, room_version_rules::RoomVersionRules,
|
||||
RoomVersionId,
|
||||
api::error::{ErrorKind, IncompatibleRoomVersionErrorData},
|
||||
room_version_rules::RoomVersionRules,
|
||||
};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
@@ -102,14 +104,25 @@ impl super::Service {
|
||||
|
||||
let room_version_rules = match room_version_rules {
|
||||
| Some(r) => r,
|
||||
| None => &self
|
||||
.services
|
||||
.state
|
||||
.get_room_version(&room_id)
|
||||
.await
|
||||
.unwrap_or(RoomVersionId::V1)
|
||||
.rules()
|
||||
.expect("room version must be supported"),
|
||||
| None => {
|
||||
let room_version = self
|
||||
.services
|
||||
.state
|
||||
.get_room_version(&room_id)
|
||||
.await
|
||||
.map_err(|_| err!(Request(NotFound("no version associated with room ID"))))?;
|
||||
if matches!(room_version, RoomVersionId::V1 | RoomVersionId::V2) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::IncompatibleRoomVersion(
|
||||
IncompatibleRoomVersionErrorData::new(room_version),
|
||||
),
|
||||
"Room version is too old.",
|
||||
));
|
||||
}
|
||||
&room_version
|
||||
.rules()
|
||||
.expect("room version must be supported")
|
||||
},
|
||||
};
|
||||
|
||||
let (event_id, value) =
|
||||
|
||||
Reference in new issue
Block a user