Merge remote-tracking branch 'upstream/main' into conduwuit-changes

This commit is contained in:
strawberry 2024-04-18 19:45:17 -04:00
commit 5194ea1861
13 changed files with 117 additions and 10 deletions

View File

@ -46,6 +46,7 @@ unstable-msc2967 = []
unstable-msc3488 = []
unstable-msc3575 = []
unstable-msc3814 = []
unstable-msc3843 = []
unstable-msc3983 = []
unstable-msc4121 = []

View File

@ -195,6 +195,10 @@ pub enum ErrorKind {
current_version: Option<String>,
},
/// M_UNACTIONABLE
#[cfg(feature = "unstable-msc3843")]
Unactionable,
#[doc(hidden)]
_Custom { errcode: PrivOwnedStr, extra: Extra },
}
@ -269,6 +273,8 @@ impl AsRef<str> for ErrorKind {
Self::ConnectionFailed => "M_CONNECTION_FAILED",
Self::ConnectionTimeout => "M_CONNECTION_TIMEOUT",
Self::WrongRoomKeysVersion { .. } => "M_WRONG_ROOM_KEYS_VERSION",
#[cfg(feature = "unstable-msc3843")]
Self::Unactionable => "M_UNACTIONABLE",
Self::_Custom { errcode, .. } => &errcode.0,
}
}

View File

@ -250,6 +250,8 @@ impl<'de> Visitor<'de> for ErrorKindVisitor {
)
.map_err(de::Error::custom)?,
},
#[cfg(feature = "unstable-msc3843")]
ErrCode::Unactionable => ErrorKind::Unactionable,
ErrCode::_Custom(errcode) => ErrorKind::_Custom { errcode, extra },
})
}
@ -306,6 +308,8 @@ enum ErrCode {
ConnectionFailed,
ConnectionTimeout,
WrongRoomKeysVersion,
#[cfg(feature = "unstable-msc3843")]
Unactionable,
_Custom(PrivOwnedStr),
}

View File

@ -11,6 +11,8 @@ Breaking changes:
`m.room.power_levels`.
- Add support for endpoints that take an optional authentication
- Add support for endpoints that require authentication for appservices
- `deserialize_as_f64_or_string` has been extended to also support parsing integers, and renamed to
`deserialize_as_number_or_string` to reflect that.
Improvements:

View File

@ -26,8 +26,8 @@ pub use self::{
cow::deserialize_cow_str,
raw::Raw,
strings::{
btreemap_deserialize_v1_powerlevel_values, deserialize_as_f64_or_string,
deserialize_as_optional_f64_or_string, deserialize_v1_powerlevel, empty_string_as_none,
btreemap_deserialize_v1_powerlevel_values, deserialize_as_number_or_string,
deserialize_as_optional_number_or_string, deserialize_v1_powerlevel, empty_string_as_none,
none_as_empty_string,
},
};

View File

@ -52,8 +52,8 @@ where
/// Take either a floating point number or a string and deserialize to an floating-point number.
///
/// To be used like this:
/// `#[serde(deserialize_with = "deserialize_as_f64_or_string")]`
pub fn deserialize_as_f64_or_string<'de, D>(de: D) -> Result<f64, D::Error>
/// `#[serde(deserialize_with = "deserialize_as_number_or_string")]`
pub fn deserialize_as_number_or_string<'de, D>(de: D) -> Result<f64, D::Error>
where
D: Deserializer<'de>,
{
@ -80,6 +80,28 @@ where
Ok(v)
}
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
where
E: de::Error,
{
if v <= (f64::MAX as u64) {
Ok(v as f64)
} else {
Err(E::custom("u64 is too large to fit into a f64"))
}
}
fn visit_i64<E>(self, v: i64) -> Result<Self::Value, E>
where
E: de::Error,
{
if v <= (f64::MAX as i64) && v >= (f64::MIN as i64) {
Ok(v as f64)
} else {
Err(E::custom("i64 is too large to fit into a f64"))
}
}
fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E> {
v.parse().map_err(E::custom)
}
@ -89,16 +111,16 @@ where
}
#[derive(Deserialize)]
struct F64OrStringWrapper(#[serde(deserialize_with = "deserialize_as_f64_or_string")] f64);
struct NumberOrStringWrapper(#[serde(deserialize_with = "deserialize_as_number_or_string")] f64);
/// Deserializes an `Option<f64>` as encoded as a f64 or a string.
pub fn deserialize_as_optional_f64_or_string<'de, D>(
/// Deserializes an `Option<f64>` from an encoded f64 or string or integer (i64 or u64).
pub fn deserialize_as_optional_number_or_string<'de, D>(
deserializer: D,
) -> Result<Option<f64>, D::Error>
where
D: Deserializer<'de>,
{
Ok(Option::<F64OrStringWrapper>::deserialize(deserializer)?.map(|w| w.0))
Ok(Option::<NumberOrStringWrapper>::deserialize(deserializer)?.map(|w| w.0))
}
/// Take either an integer number or a string and deserialize to an integer number.

View File

@ -5,7 +5,7 @@
use std::{collections::BTreeMap, error::Error, fmt, str::FromStr};
#[cfg(feature = "compat-tag-info")]
use ruma_common::serde::deserialize_as_optional_f64_or_string;
use ruma_common::serde::deserialize_as_optional_number_or_string;
use ruma_common::serde::deserialize_cow_str;
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
@ -180,7 +180,7 @@ pub struct TagInfo {
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(
feature = "compat-tag-info",
serde(default, deserialize_with = "deserialize_as_optional_f64_or_string")
serde(default, deserialize_with = "deserialize_as_optional_number_or_string")
)]
pub order: Option<f64>,
}
@ -233,6 +233,9 @@ mod tests {
let json = json!({ "order": null });
assert_eq!(from_json_value::<TagInfo>(json).unwrap(), TagInfo::default());
let json = json!({ "order": 1 });
assert_eq!(from_json_value::<TagInfo>(json).unwrap(), TagInfo { order: Some(1.) });
let json = json!({ "order": 0.42 });
assert_eq!(from_json_value::<TagInfo>(json).unwrap(), TagInfo { order: Some(0.42) });

View File

@ -10,6 +10,8 @@ Improvements:
* Implement `From<SpaceHierarchyParentSummary>` for `SpaceHierarchyChildSummary`
* Add unstable support for optional `via` field on the `create_invite` endpoint request from
MSC4125 behind the `unstable-msc4125` feature.
* Add unstable support for the `report_content` endpoint from MSC3843 behind the
`unstable-msc3843` feature.
# 0.8.0

View File

@ -26,6 +26,7 @@ unstable-exhaustive-types = []
unstable-msc2448 = []
unstable-msc3618 = []
unstable-msc3723 = []
unstable-msc3843 = []
unstable-msc4125 = []
unstable-unspecified = []

View File

@ -23,6 +23,7 @@ pub mod knock;
pub mod membership;
pub mod openid;
pub mod query;
pub mod room;
pub mod space;
pub mod thirdparty;
pub mod transactions;

View File

@ -0,0 +1,4 @@
//! Server room endpoints.
#[cfg(feature = "unstable-msc3843")]
pub mod report_content;

View File

@ -0,0 +1,56 @@
//! `GET /_matrix/federation/*/rooms/{roomId}/report/{eventId}`
//!
//! Send a request to report an event originating from another server.
pub mod msc3843 {
//! `MSC3843` ([MSC])
//!
//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3843
use ruma_common::{
api::{request, response, Metadata},
metadata, OwnedEventId, OwnedRoomId,
};
const METADATA: Metadata = metadata! {
method: POST,
rate_limited: false,
authentication: ServerSignatures,
history: {
unstable => "/_matrix/federation/unstable/org.matrix.msc3843/rooms/:room_id/report/:event_id",
}
};
/// Request type for the `report_content` endpoint.
#[request]
pub struct Request {
/// The room ID that the reported event was sent in.
#[ruma_api(path)]
pub room_id: OwnedRoomId,
/// The event being reported.
#[ruma_api(path)]
pub event_id: OwnedEventId,
/// The reason that the event is being reported.
pub reason: String,
}
/// Response type for the `report_content` endpoint.
#[response]
pub struct Response {}
impl Request {
/// Creates a `Request` with the given room ID, event ID and reason.
pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, reason: String) -> Self {
Self { room_id, event_id, reason }
}
}
impl Response {
/// Creates a new empty `Response`.
pub fn new() -> Self {
Self {}
}
}
}

View File

@ -260,6 +260,7 @@ unstable-msc3575 = ["ruma-client-api?/unstable-msc3575"]
unstable-msc3618 = ["ruma-federation-api?/unstable-msc3618"]
unstable-msc3723 = ["ruma-federation-api?/unstable-msc3723"]
unstable-msc3814 = ["ruma-client-api?/unstable-msc3814"]
unstable-msc3843 = ["ruma-client-api?/unstable-msc3843", "ruma-federation-api?/unstable-msc3843"]
unstable-msc3927 = ["ruma-events?/unstable-msc3927"]
unstable-msc3930 = ["ruma-common/unstable-msc3930"]
unstable-msc3931 = ["ruma-common/unstable-msc3931"]
@ -309,14 +310,18 @@ __ci = [
"unstable-msc3618",
"unstable-msc3723",
"unstable-msc3814",
"unstable-msc3843",
"unstable-msc3927",
"unstable-msc3930",
"unstable-msc3931",
"unstable-msc3932",
"unstable-msc3954",
"unstable-msc3955",
"unstable-msc3956",
"unstable-msc3983",
"unstable-msc4075",
"unstable-msc4121",
"unstable-msc4125",
]
[dependencies]