mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
use event content in account_data service api instead of full events
This eliminates the possibility of passing an event that has a mismatching type, reducing the space of possible invalid states.
This commit is contained in:
parent
66210bc32d
commit
b82458a460
15 changed files with 277 additions and 240 deletions
|
|
@ -7,10 +7,7 @@ use std::{
|
|||
};
|
||||
|
||||
use ruma::{
|
||||
events::{
|
||||
push_rules::PushRulesEvent, AnyGlobalAccountDataEvent,
|
||||
GlobalAccountDataEventType,
|
||||
},
|
||||
events::{push_rules::PushRulesEventContent, GlobalAccountDataEventType},
|
||||
push::Ruleset,
|
||||
serde::Raw,
|
||||
EventId, OwnedRoomId, RoomId, UserId,
|
||||
|
|
@ -871,9 +868,9 @@ impl KeyValueDatabase {
|
|||
.expect("Username is invalid");
|
||||
|
||||
let mut account_data = raw_rules_list
|
||||
.deserialize_as::<PushRulesEvent>()
|
||||
.deserialize_as::<PushRulesEventContent>()
|
||||
.unwrap();
|
||||
let rules_list = &mut account_data.content.global;
|
||||
let rules_list = &mut account_data.global;
|
||||
|
||||
//content rule
|
||||
{
|
||||
|
|
@ -929,9 +926,8 @@ impl KeyValueDatabase {
|
|||
services().account_data.update_global(
|
||||
&user,
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
&Raw::new(&account_data)
|
||||
.expect("json serialization should always succeed")
|
||||
.cast::<AnyGlobalAccountDataEvent>(),
|
||||
&Raw::new(&account_data.into())
|
||||
.expect("json serialization should always succeed"),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -966,21 +962,19 @@ impl KeyValueDatabase {
|
|||
.expect("Username is invalid");
|
||||
|
||||
let mut account_data = raw_rules_list
|
||||
.deserialize_as::<PushRulesEvent>()
|
||||
.deserialize_as::<PushRulesEventContent>()
|
||||
.unwrap();
|
||||
|
||||
let user_default_rules = Ruleset::server_default(&user);
|
||||
account_data
|
||||
.content
|
||||
.global
|
||||
.update_with_server_default(user_default_rules);
|
||||
|
||||
services().account_data.update_global(
|
||||
&user,
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
&Raw::new(&account_data)
|
||||
.expect("json serialization should always succeed")
|
||||
.cast::<AnyGlobalAccountDataEvent>(),
|
||||
&Raw::new(&account_data.into())
|
||||
.expect("json serialization should always succeed"),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue