diff --git a/src/api/client/message.rs b/src/api/client/message.rs index bcaf7cfe9..2bb3cbbc0 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -1,6 +1,8 @@ use axum::extract::State; use conduwuit::{ - Err, Error, Result, at, debug_warn, + Err, Error, Result, at, + config::experiments::ToggledExperiment, + debug_warn, matrix::{ event::{Event, Matches}, pdu::PduCount, @@ -315,21 +317,29 @@ where if server_ignored { // the sender's server is ignored, so ignore this event - return Err(Error::BadRequest( - ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()), - "The sender's server is ignored by this server.", - )); + return if services.config.experiments.msc4406.is_enabled() { + Err(Error::BadRequest( + ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()), + "The sender's server is ignored by this server.", + )) + } else { + Err!(Request(NotFound("This event's sender's homeserver is ignored by this server."))) + }; } if user_ignored && !services.config.send_messages_from_ignored_users_to_client { // the recipient of this PDU has the sender ignored, and we're not // configured to send ignored messages to clients - return Err(Error::BadRequest( - ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender( - event.sender().to_owned(), - )), - "You have ignored this sender.", - )); + return if services.config.experiments.msc4406.is_enabled() { + Err(Error::BadRequest( + ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender( + event.sender().to_owned(), + )), + "You have ignored this sender.", + )) + } else { + Err!(Request(NotFound("You have ignored the sender of this event."))) + }; } Ok(false) diff --git a/src/core/config/experiments.rs b/src/core/config/experiments.rs index f647ed889..5d67ef994 100644 --- a/src/core/config/experiments.rs +++ b/src/core/config/experiments.rs @@ -68,6 +68,24 @@ pub struct Experiments { /// default: false #[serde(default)] pub msc4174: SimpleExperiment, + /// MSC4406: `M_SENDER_IGNORED` error code + /// + /// Introduces a new error code that explicitly informs clients the reason + /// they cannot access an event if it is sent by an ignored user. Without + /// this proposal, clients will simply get a "not found" or "forbidden" + /// error when requesting events sent by users that have been ignored, which + /// leads to replies being shown as "this message could not be found". + /// The new error code allows clients to distinguish unknown/forbidden + /// events from ignored senders, allowing them to display an error message + /// like "you have blocked this sender" instead. + /// + /// Requires a supporting client to be useful. + /// + /// https://github.com/matrix-org/matrix-spec-proposals/pull/4406 + /// + /// default: false + #[serde(default)] + pub msc4406: SimpleExperiment, /// MSC4484: Server Administration OAuth Scope /// /// Adds a new OAuth2 scope that explicitly grants a token temporary