mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
fix: Re-add support for custom room IDs
This commit is contained in:
@@ -9,8 +9,8 @@ use conduwuit::{
|
|||||||
use conduwuit_service::{Services, appservice::RegistrationInfo};
|
use conduwuit_service::{Services, appservice::RegistrationInfo};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, Int, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId, OwnedRoomId,
|
CanonicalJsonObject, CanonicalJsonValue, Int, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId,
|
||||||
OwnedUserId, RoomAliasId, RoomId, RoomVersionId, UserId,
|
OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, RoomVersionId, UserId,
|
||||||
api::client::room::{self, create_room},
|
api::client::room::{self, create_room},
|
||||||
assign,
|
assign,
|
||||||
events::{
|
events::{
|
||||||
@@ -87,7 +87,19 @@ pub(crate) async fn create_room_route(
|
|||||||
let room_version_rules = room_version.rules().unwrap();
|
let room_version_rules = room_version.rules().unwrap();
|
||||||
|
|
||||||
let room_id: Option<OwnedRoomId> = match room_version_rules.room_id_format {
|
let room_id: Option<OwnedRoomId> = match room_version_rules.room_id_format {
|
||||||
| RoomIdFormatVersion::V1 => Some(RoomId::new_v1(services.globals.server_name())),
|
| RoomIdFormatVersion::V1 => {
|
||||||
|
// Check for custom room ID field
|
||||||
|
if let Some(CanonicalJsonValue::String(room_id)) =
|
||||||
|
body.json_body.as_ref().unwrap().get("room_id")
|
||||||
|
{
|
||||||
|
Some(
|
||||||
|
RoomId::parse(room_id)
|
||||||
|
.map_err(|_| err!(Request(BadJson("Malformed custom room ID"))))?,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Some(RoomId::new_v1(services.globals.server_name()))
|
||||||
|
}
|
||||||
|
},
|
||||||
| _ => None,
|
| _ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -235,10 +247,8 @@ pub(crate) async fn create_room_route(
|
|||||||
.json_body
|
.json_body
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_object()
|
|
||||||
.unwrap()
|
|
||||||
.get("origin_server_ts")
|
.get("origin_server_ts")
|
||||||
.and_then(ruma::CanonicalJsonValue::as_integer)
|
.and_then(CanonicalJsonValue::as_integer)
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.and_then(|value: i64| value.try_into().ok())
|
.and_then(|value: i64| value.try_into().ok())
|
||||||
.map(MilliSecondsSinceUnixEpoch);
|
.map(MilliSecondsSinceUnixEpoch);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use axum::{
|
|||||||
};
|
};
|
||||||
use conduwuit::{Error, Result, err};
|
use conduwuit::{Error, Result, err};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonValue, DeviceId, OwnedDeviceId, OwnedServerName, OwnedUserId, ServerName,
|
CanonicalJsonObject, DeviceId, OwnedDeviceId, OwnedServerName, OwnedUserId, ServerName,
|
||||||
UserId, api::IncomingRequest,
|
UserId, api::IncomingRequest,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -47,7 +47,7 @@ pub(crate) struct Args<T> {
|
|||||||
|
|
||||||
/// Parsed JSON content.
|
/// Parsed JSON content.
|
||||||
/// None when body is not a valid string
|
/// None when body is not a valid string
|
||||||
pub(crate) json_body: Option<CanonicalJsonValue>,
|
pub(crate) json_body: Option<CanonicalJsonObject>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Args<T>
|
impl<T> Args<T>
|
||||||
@@ -127,7 +127,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Make a JSON copy of the body for use in handlers
|
// Make a JSON copy of the body for use in handlers
|
||||||
let json_body = serde_json::from_slice::<CanonicalJsonValue>(&body).ok();
|
let json_body = serde_json::from_slice::<CanonicalJsonObject>(&body).ok();
|
||||||
|
|
||||||
// Extract the query parameters and path
|
// Extract the query parameters and path
|
||||||
let Path(path): Path<Vec<String>> = parts.extract().await?;
|
let Path(path): Path<Vec<String>> = parts.extract().await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user