mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
add type-safe accessors to account_data service
This commit is contained in:
parent
b82458a460
commit
88ad596e8d
12 changed files with 202 additions and 179 deletions
|
|
@ -7,9 +7,7 @@ use std::{
|
|||
};
|
||||
|
||||
use ruma::{
|
||||
events::{push_rules::PushRulesEventContent, GlobalAccountDataEventType},
|
||||
push::Ruleset,
|
||||
serde::Raw,
|
||||
events::push_rules::PushRulesEventContent, push::Ruleset, serde::Raw,
|
||||
EventId, OwnedRoomId, RoomId, UserId,
|
||||
};
|
||||
use tracing::{debug, error, info, info_span, warn, Instrument};
|
||||
|
|
@ -860,16 +858,12 @@ impl KeyValueDatabase {
|
|||
|
||||
let raw_rules_list = services()
|
||||
.account_data
|
||||
.get_global(
|
||||
&user,
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
)
|
||||
.get_global::<PushRulesEventContent>(&user)
|
||||
.unwrap()
|
||||
.expect("Username is invalid");
|
||||
|
||||
let mut account_data = raw_rules_list
|
||||
.deserialize_as::<PushRulesEventContent>()
|
||||
.unwrap();
|
||||
let mut account_data =
|
||||
raw_rules_list.deserialize().unwrap();
|
||||
let rules_list = &mut account_data.global;
|
||||
|
||||
//content rule
|
||||
|
|
@ -925,8 +919,7 @@ impl KeyValueDatabase {
|
|||
|
||||
services().account_data.update_global(
|
||||
&user,
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
&Raw::new(&account_data.into())
|
||||
&Raw::new(&account_data)
|
||||
.expect("json serialization should always succeed"),
|
||||
)?;
|
||||
}
|
||||
|
|
@ -954,16 +947,12 @@ impl KeyValueDatabase {
|
|||
|
||||
let raw_rules_list = services()
|
||||
.account_data
|
||||
.get_global(
|
||||
&user,
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
)
|
||||
.get_global::<PushRulesEventContent>(&user)
|
||||
.unwrap()
|
||||
.expect("Username is invalid");
|
||||
|
||||
let mut account_data = raw_rules_list
|
||||
.deserialize_as::<PushRulesEventContent>()
|
||||
.unwrap();
|
||||
let mut account_data =
|
||||
raw_rules_list.deserialize().unwrap();
|
||||
|
||||
let user_default_rules = Ruleset::server_default(&user);
|
||||
account_data
|
||||
|
|
@ -972,8 +961,7 @@ impl KeyValueDatabase {
|
|||
|
||||
services().account_data.update_global(
|
||||
&user,
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
&Raw::new(&account_data.into())
|
||||
&Raw::new(&account_data)
|
||||
.expect("json serialization should always succeed"),
|
||||
)?;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue