pub mod v3 {
use ruma_common::{
api::ruma_api,
events::{
AnyGlobalAccountDataEventContent, GlobalAccountDataEventContent,
GlobalAccountDataEventType,
},
serde::Raw,
UserId,
};
use serde_json::value::to_raw_value as to_raw_json_value;
ruma_api! {
metadata: {
description: "Sets global account data.",
method: PUT,
name: "set_global_account_data",
r0_path: "/_matrix/client/r0/user/:user_id/account_data/:event_type",
stable_path: "/_matrix/client/v3/user/:user_id/account_data/:event_type",
rate_limited: false,
authentication: AccessToken,
added: 1.0,
}
request: {
#[ruma_api(path)]
pub user_id: &'a UserId,
#[ruma_api(path)]
pub event_type: GlobalAccountDataEventType,
#[ruma_api(body)]
pub data: Raw<AnyGlobalAccountDataEventContent>,
}
#[derive(Default)]
response: {}
error: crate::Error
}
impl<'a> Request<'a> {
pub fn new<T>(data: &'a T, user_id: &'a UserId) -> serde_json::Result<Self>
where
T: GlobalAccountDataEventContent,
{
Ok(Self {
user_id,
event_type: data.event_type(),
data: Raw::from_json(to_raw_json_value(data)?),
})
}
pub fn new_raw(
data: Raw<AnyGlobalAccountDataEventContent>,
event_type: GlobalAccountDataEventType,
user_id: &'a UserId,
) -> Self {
Self { user_id, event_type, data }
}
}
impl Response {
pub fn new() -> Self {
Self {}
}
}
}