tuwunel_api/client/push/
pushrules_rule_enabled.rs1use axum::extract::State;
2use ruma::api::client::push::{get_pushrule_enabled, set_pushrule_enabled};
3use tuwunel_core::{Err, Result, err};
4
5use crate::Ruma;
6
7pub(crate) async fn get_pushrule_enabled_route(
11 State(services): State<crate::State>,
12 body: Ruma<get_pushrule_enabled::v3::Request>,
13) -> Result<get_pushrule_enabled::v3::Response> {
14 let sender_user = body.sender_user();
15
16 if super::is_deprecated_mention_rule(body.rule_id.as_str()) {
17 return Ok(get_pushrule_enabled::v3::Response { enabled: false });
18 }
19
20 let event = super::load_push_rules(&services, sender_user).await?;
21
22 let enabled = event
23 .content
24 .global
25 .get(body.kind.clone(), &body.rule_id)
26 .map(ruma::push::AnyPushRuleRef::enabled)
27 .ok_or_else(|| err!(Request(NotFound("Push rule not found."))))?;
28
29 Ok(get_pushrule_enabled::v3::Response { enabled })
30}
31
32pub(crate) async fn set_pushrule_enabled_route(
36 State(services): State<crate::State>,
37 body: Ruma<set_pushrule_enabled::v3::Request>,
38) -> Result<set_pushrule_enabled::v3::Response> {
39 let sender_user = body.sender_user();
40 let mut account_data = super::load_push_rules(&services, sender_user).await?;
41
42 if account_data
43 .content
44 .global
45 .set_enabled(body.kind.clone(), &body.rule_id, body.enabled)
46 .is_err()
47 {
48 return Err!(Request(NotFound("Push rule not found.")));
49 }
50
51 super::save_push_rules(&services, sender_user, &account_data).await?;
52
53 Ok(set_pushrule_enabled::v3::Response {})
54}