mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
separate account_data service methods for room vs global events
Previously we were mashing everything together as RoomAccountDataEvent, even the global events. This technically worked, because of the hidden custom fields on the ruma event types, but it's confusing and easy to mess up. Separate methods with appropriate types are preferable.
This commit is contained in:
parent
6897f0ba34
commit
66210bc32d
16 changed files with 349 additions and 361 deletions
|
|
@ -7,8 +7,12 @@ use std::{
|
|||
};
|
||||
|
||||
use ruma::{
|
||||
events::{push_rules::PushRulesEvent, GlobalAccountDataEventType},
|
||||
events::{
|
||||
push_rules::PushRulesEvent, AnyGlobalAccountDataEvent,
|
||||
GlobalAccountDataEventType,
|
||||
},
|
||||
push::Ruleset,
|
||||
serde::Raw,
|
||||
EventId, OwnedRoomId, RoomId, UserId,
|
||||
};
|
||||
use tracing::{debug, error, info, info_span, warn, Instrument};
|
||||
|
|
@ -859,20 +863,15 @@ impl KeyValueDatabase {
|
|||
|
||||
let raw_rules_list = services()
|
||||
.account_data
|
||||
.get(
|
||||
None,
|
||||
.get_global(
|
||||
&user,
|
||||
GlobalAccountDataEventType::PushRules
|
||||
.to_string()
|
||||
.into(),
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
)
|
||||
.unwrap()
|
||||
.expect("Username is invalid");
|
||||
|
||||
let mut account_data =
|
||||
serde_json::from_str::<PushRulesEvent>(
|
||||
raw_rules_list.get(),
|
||||
)
|
||||
let mut account_data = raw_rules_list
|
||||
.deserialize_as::<PushRulesEvent>()
|
||||
.unwrap();
|
||||
let rules_list = &mut account_data.content.global;
|
||||
|
||||
|
|
@ -927,14 +926,12 @@ impl KeyValueDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
services().account_data.update(
|
||||
None,
|
||||
services().account_data.update_global(
|
||||
&user,
|
||||
GlobalAccountDataEventType::PushRules
|
||||
.to_string()
|
||||
.into(),
|
||||
&serde_json::to_value(account_data)
|
||||
.expect("to json value always works"),
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
&Raw::new(&account_data)
|
||||
.expect("json serialization should always succeed")
|
||||
.cast::<AnyGlobalAccountDataEvent>(),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -961,20 +958,15 @@ impl KeyValueDatabase {
|
|||
|
||||
let raw_rules_list = services()
|
||||
.account_data
|
||||
.get(
|
||||
None,
|
||||
.get_global(
|
||||
&user,
|
||||
GlobalAccountDataEventType::PushRules
|
||||
.to_string()
|
||||
.into(),
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
)
|
||||
.unwrap()
|
||||
.expect("Username is invalid");
|
||||
|
||||
let mut account_data =
|
||||
serde_json::from_str::<PushRulesEvent>(
|
||||
raw_rules_list.get(),
|
||||
)
|
||||
let mut account_data = raw_rules_list
|
||||
.deserialize_as::<PushRulesEvent>()
|
||||
.unwrap();
|
||||
|
||||
let user_default_rules = Ruleset::server_default(&user);
|
||||
|
|
@ -983,14 +975,12 @@ impl KeyValueDatabase {
|
|||
.global
|
||||
.update_with_server_default(user_default_rules);
|
||||
|
||||
services().account_data.update(
|
||||
None,
|
||||
services().account_data.update_global(
|
||||
&user,
|
||||
GlobalAccountDataEventType::PushRules
|
||||
.to_string()
|
||||
.into(),
|
||||
&serde_json::to_value(account_data)
|
||||
.expect("to json value always works"),
|
||||
&GlobalAccountDataEventType::PushRules,
|
||||
&Raw::new(&account_data)
|
||||
.expect("json serialization should always succeed")
|
||||
.cast::<AnyGlobalAccountDataEvent>(),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue