Skip to content

Commit

Permalink
add MSC2815 support, query param and error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
girlbossceo committed Oct 19, 2024
1 parent 1c4eeb4 commit 9f6c48e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
17 changes: 17 additions & 0 deletions crates/ruma-client-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 17 additions & 2 deletions crates/ruma-client-api/src/room/get_room_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 }
}
}

Expand Down
15 changes: 13 additions & 2 deletions crates/ruma-federation-api/src/event/get_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 }
}
}

Expand Down

0 comments on commit 9f6c48e

Please sign in to comment.