Skip to content

Commit

Permalink
implement MSC4210, bump ruwuma
Browse files Browse the repository at this point in the history
Signed-off-by: strawberry <[email protected]>
  • Loading branch information
girlbossceo committed Oct 26, 2024
1 parent d699161 commit 60d8419
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 62 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ version = "0.1.2"
[workspace.dependencies.ruma]
git = "https://github.com/girlbossceo/ruwuma"
#branch = "conduwuit-changes"
rev = "d7baeb7e5c3ae28e79ad3fe81c5e8b207a26cc73"
rev = "39c1addd37a4eed612ac1135edc2cccd9d331d5e"
features = [
"compat",
"rand",
Expand Down Expand Up @@ -346,6 +346,7 @@ features = [
"unstable-msc4121",
"unstable-msc4125",
"unstable-msc4186",
"unstable-msc4210", # remove legacy mentions
"unstable-extensible-events",
]

Expand Down
1 change: 1 addition & 0 deletions src/admin/debug/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub(super) async fn get_remote_pdu(
&server,
ruma::api::federation::event::get_event::v1::Request {
event_id: event_id.clone().into(),
include_unredacted_content: None,
},
)
.await
Expand Down
100 changes: 52 additions & 48 deletions src/api/client/push.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use axum::extract::State;
use conduit::err;
use conduit::{err, Err};
use ruma::{
api::client::{
error::ErrorKind,
push::{
delete_pushrule, get_pushers, get_pushrule, get_pushrule_actions, get_pushrule_enabled, get_pushrules_all,
set_pusher, set_pushrule, set_pushrule_actions, set_pushrule_enabled, RuleScope,
set_pusher, set_pushrule, set_pushrule_actions, set_pushrule_enabled,
},
},
events::{
push_rules::{PushRulesEvent, PushRulesEventContent},
GlobalAccountDataEventType,
},
push::{InsertPushRuleError, RemovePushRuleError, Ruleset},
push::{InsertPushRuleError, PredefinedContentRuleId, PredefinedOverrideRuleId, RemovePushRuleError, Ruleset},
CanonicalJsonObject, CanonicalJsonValue,
};
use service::Services;
Expand Down Expand Up @@ -43,7 +43,24 @@ pub(crate) async fn get_pushrules_all_route(
let account_data_content = serde_json::from_value::<PushRulesEventContent>(content_value.into())
.map_err(|e| err!(Database(warn!("Invalid push rules account data event in database: {e}"))))?;

let global_ruleset: Ruleset = account_data_content.global;
let mut global_ruleset = account_data_content.global;

// remove old deprecated mentions push rules as per MSC4210
#[allow(deprecated)]
{
use ruma::push::RuleKind::*;

global_ruleset
.remove(Override, PredefinedOverrideRuleId::ContainsDisplayName)
.ok();
global_ruleset
.remove(Override, PredefinedOverrideRuleId::RoomNotif)
.ok();

global_ruleset
.remove(Content, PredefinedContentRuleId::ContainsUserName)
.ok();
};

Ok(get_pushrules_all::v3::Response {
global: global_ruleset,
Expand All @@ -58,6 +75,15 @@ pub(crate) async fn get_pushrule_route(
) -> Result<get_pushrule::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

// remove old deprecated mentions push rules as per MSC4210
#[allow(deprecated)]
if body.rule_id.as_str() == PredefinedContentRuleId::ContainsUserName.as_str()
|| body.rule_id.as_str() == PredefinedOverrideRuleId::ContainsDisplayName.as_str()
|| body.rule_id.as_str() == PredefinedOverrideRuleId::RoomNotif.as_str()
{
return Err!(Request(NotFound("Push rule not found.")));
}

let event: PushRulesEvent = services
.account_data
.get_global(sender_user, GlobalAccountDataEventType::PushRules)
Expand All @@ -79,7 +105,7 @@ pub(crate) async fn get_pushrule_route(
}
}

/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}`
///
/// Creates a single specified push rule for this user.
pub(crate) async fn set_pushrule_route(
Expand All @@ -88,13 +114,6 @@ pub(crate) async fn set_pushrule_route(
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let body = body.body;

if body.scope != RuleScope::Global {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Scopes other than 'global' are not supported.",
));
}

let mut account_data: PushRulesEvent = services
.account_data
.get_global(sender_user, GlobalAccountDataEventType::PushRules)
Expand Down Expand Up @@ -145,19 +164,21 @@ pub(crate) async fn set_pushrule_route(
Ok(set_pushrule::v3::Response {})
}

/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
///
/// Gets the actions of a single specified push rule for this user.
pub(crate) async fn get_pushrule_actions_route(
State(services): State<crate::State>, body: Ruma<get_pushrule_actions::v3::Request>,
) -> Result<get_pushrule_actions::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

if body.scope != RuleScope::Global {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Scopes other than 'global' are not supported.",
));
// remove old deprecated mentions push rules as per MSC4210
#[allow(deprecated)]
if body.rule_id.as_str() == PredefinedContentRuleId::ContainsUserName.as_str()
|| body.rule_id.as_str() == PredefinedOverrideRuleId::ContainsDisplayName.as_str()
|| body.rule_id.as_str() == PredefinedOverrideRuleId::RoomNotif.as_str()
{
return Err!(Request(NotFound("Push rule not found.")));
}

let event: PushRulesEvent = services
Expand All @@ -178,21 +199,14 @@ pub(crate) async fn get_pushrule_actions_route(
})
}

/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
///
/// Sets the actions of a single specified push rule for this user.
pub(crate) async fn set_pushrule_actions_route(
State(services): State<crate::State>, body: Ruma<set_pushrule_actions::v3::Request>,
) -> Result<set_pushrule_actions::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

if body.scope != RuleScope::Global {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Scopes other than 'global' are not supported.",
));
}

let mut account_data: PushRulesEvent = services
.account_data
.get_global(sender_user, GlobalAccountDataEventType::PushRules)
Expand Down Expand Up @@ -221,19 +235,23 @@ pub(crate) async fn set_pushrule_actions_route(
Ok(set_pushrule_actions::v3::Response {})
}

/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
///
/// Gets the enabled status of a single specified push rule for this user.
pub(crate) async fn get_pushrule_enabled_route(
State(services): State<crate::State>, body: Ruma<get_pushrule_enabled::v3::Request>,
) -> Result<get_pushrule_enabled::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

if body.scope != RuleScope::Global {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Scopes other than 'global' are not supported.",
));
// remove old deprecated mentions push rules as per MSC4210
#[allow(deprecated)]
if body.rule_id.as_str() == PredefinedContentRuleId::ContainsUserName.as_str()
|| body.rule_id.as_str() == PredefinedOverrideRuleId::ContainsDisplayName.as_str()
|| body.rule_id.as_str() == PredefinedOverrideRuleId::RoomNotif.as_str()
{
return Ok(get_pushrule_enabled::v3::Response {
enabled: false,
});
}

let event: PushRulesEvent = services
Expand All @@ -254,21 +272,14 @@ pub(crate) async fn get_pushrule_enabled_route(
})
}

/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
///
/// Sets the enabled status of a single specified push rule for this user.
pub(crate) async fn set_pushrule_enabled_route(
State(services): State<crate::State>, body: Ruma<set_pushrule_enabled::v3::Request>,
) -> Result<set_pushrule_enabled::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

if body.scope != RuleScope::Global {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Scopes other than 'global' are not supported.",
));
}

let mut account_data: PushRulesEvent = services
.account_data
.get_global(sender_user, GlobalAccountDataEventType::PushRules)
Expand Down Expand Up @@ -297,21 +308,14 @@ pub(crate) async fn set_pushrule_enabled_route(
Ok(set_pushrule_enabled::v3::Response {})
}

/// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
/// # `DELETE /_matrix/client/r0/pushrules/global/{kind}/{ruleId}`
///
/// Deletes a single specified push rule for this user.
pub(crate) async fn delete_pushrule_route(
State(services): State<crate::State>, body: Ruma<delete_pushrule::v3::Request>,
) -> Result<delete_pushrule::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

if body.scope != RuleScope::Global {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Scopes other than 'global' are not supported.",
));
}

let mut account_data: PushRulesEvent = services
.account_data
.get_global(sender_user, GlobalAccountDataEventType::PushRules)
Expand Down
1 change: 1 addition & 0 deletions src/service/rooms/event_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ impl Service {
origin,
get_event::v1::Request {
event_id: (*next_id).to_owned(),
include_unredacted_content: None,
},
)
.await
Expand Down

0 comments on commit 60d8419

Please sign in to comment.