add MSC2815 support, query param and error codes

https://github.com/matrix-org/matrix-spec-proposals/pull/2815

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-10-19 18:30:44 -04:00
parent 1c4eeb4c41
commit 9f6c48eea2
No known key found for this signature in database
3 changed files with 47 additions and 4 deletions

View File

@ -33,6 +33,19 @@ mod kind_serde;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ErrorKind {
/// M_UNREDACTED_CONTENT_DELETED and FI.MAU.MSC2815_UNREDACTED_CONTENT_DELETED
///
/// as per MSC2815
UnredactedContentDeleted {
/// fi.mau.msc2815.content_keep_ms
content_keep_ms: Option<Duration>,
},
/// M_UNREDACTED_CONTENT_NOT_RECEIVED and FI.MAU.MSC2815_UNREDACTED_CONTENT_NOT_RECEIVED
///
/// as per MSC2815
UnredactedContentNotReceived,
/// M_FORBIDDEN
#[non_exhaustive]
Forbidden {
@ -238,6 +251,10 @@ pub struct Extra(BTreeMap<String, JsonValue>);
impl AsRef<str> for ErrorKind {
fn as_ref(&self) -> &str {
match self {
// TODO: replace with M_UNREDACTED_CONTENT_DELETED when stabilised
Self::UnredactedContentDeleted { .. } => "FI.MAU.MSC2815_UNREDACTED_CONTENT_DELETED",
// TODO: replace with M_UNREDACTED_CONTENT_NOT_RECEIVED when stabilised
Self::UnredactedContentNotReceived => "FI.MAU.MSC2815_UNREDACTED_CONTENT_NOT_RECEIVED",
Self::Forbidden { .. } => "M_FORBIDDEN",
Self::UnknownToken { .. } => "M_UNKNOWN_TOKEN",
Self::MissingToken => "M_MISSING_TOKEN",

View File

@ -35,6 +35,17 @@ pub mod v3 {
/// The ID of the event.
#[ruma_api(path)]
pub event_id: OwnedEventId,
/// Query parameter to tell the server if it should return the redacted content of the
/// requested event
///
/// as per MSC2815: https://github.com/matrix-org/matrix-spec-proposals/pull/2815
#[ruma_api(query)]
#[serde(
skip_serializing_if = "Option::is_none",
alias = "fi.mau.msc2815.include_unredacted_content"
)]
pub include_unredacted_content: Option<bool>,
}
/// Response type for the `get_room_event` endpoint.
@ -47,8 +58,12 @@ pub mod v3 {
impl Request {
/// Creates a new `Request` with the given room ID and event ID.
pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId) -> Self {
Self { room_id, event_id }
pub fn new(
room_id: OwnedRoomId,
event_id: OwnedEventId,
include_unredacted_content: Option<bool>,
) -> Self {
Self { room_id, event_id, include_unredacted_content }
}
}

View File

@ -28,6 +28,17 @@ pub mod v1 {
/// The event ID to get.
#[ruma_api(path)]
pub event_id: OwnedEventId,
/// Query parameter to tell the server if it should return the redacted content of the
/// requested event
///
/// as per MSC2815: https://github.com/matrix-org/matrix-spec-proposals/pull/2815
#[ruma_api(query)]
#[serde(
skip_serializing_if = "Option::is_none",
alias = "fi.mau.msc2815.include_unredacted_content"
)]
pub include_unredacted_content: Option<bool>,
}
/// Response type for the `get_event` endpoint.
@ -46,8 +57,8 @@ pub mod v1 {
impl Request {
/// Creates a new `Request` with the given event id.
pub fn new(event_id: OwnedEventId) -> Self {
Self { event_id }
pub fn new(event_id: OwnedEventId, include_unredacted_content: Option<bool>) -> Self {
Self { event_id, include_unredacted_content }
}
}