From 4b191a93112a420b6b06bbcd38bd829bb4e8ba20 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sat, 2 May 2020 09:24:09 +0200 Subject: [PATCH] improvement: set default push rules on register --- src/client_server.rs | 33 +++++++++++++++++++++++++++++++++ src/ruma_wrapper.rs | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/client_server.rs b/src/client_server.rs index 31ecb4ee..58c5bda1 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -168,6 +168,39 @@ pub fn register_route( let token = utils::random_string(TOKEN_LENGTH); data.token_replace(&user_id, &device_id, token.clone()); + // Initial data + data.room_userdata_update( + None, + &user_id, + EduEvent::PushRules(ruma_events::push_rules::PushRulesEvent { + content: ruma_events::push_rules::PushRulesEventContent { + global: ruma_events::push_rules::Ruleset { + content: vec![], + override_rules: vec![], + room: vec![], + sender: vec![], + underride: vec![ruma_events::push_rules::ConditionalPushRule { + actions: vec![ + ruma_events::push_rules::Action::Notify, + ruma_events::push_rules::Action::SetTweak( + ruma_events::push_rules::Tweak::Highlight { value: false }, + ), + ], + default: true, + enabled: true, + rule_id: ".m.rule.message".to_owned(), + conditions: vec![ruma_events::push_rules::PushCondition::EventMatch( + ruma_events::push_rules::EventMatchCondition { + key: "type".to_owned(), + pattern: "m.room.message".to_owned(), + }, + )], + }], + }, + }, + }), + ); + MatrixResult(Ok(register::Response { access_token: Some(token), user_id, diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs index eec9d84b..753edea4 100644 --- a/src/ruma_wrapper.rs +++ b/src/ruma_wrapper.rs @@ -92,7 +92,7 @@ impl<'a, T: Endpoint> FromData<'a> for Ruma { }), Err(e) => { warn!("{:?}", e); - Failure((Status::InternalServerError, ())) + Failure((Status::BadRequest, ())) } } })