pub mod v3 {
use ruma_common::{
api::{request, response, Metadata},
events::{
AnyGlobalAccountDataEventContent, GlobalAccountDataEventContent,
GlobalAccountDataEventType,
},
metadata,
serde::Raw,
OwnedUserId,
};
use serde_json::value::to_raw_value as to_raw_json_value;
const METADATA: Metadata = metadata! {
method: PUT,
rate_limited: false,
authentication: AccessToken,
history: {
1.0 => "/_matrix/client/r0/user/:user_id/account_data/:event_type",
1.1 => "/_matrix/client/v3/user/:user_id/account_data/:event_type",
}
};
#[request(error = crate::Error)]
pub struct Request {
#[ruma_api(path)]
pub user_id: OwnedUserId,
#[ruma_api(path)]
pub event_type: GlobalAccountDataEventType,
#[ruma_api(body)]
pub data: Raw<AnyGlobalAccountDataEventContent>,
}
#[response(error = crate::Error)]
#[derive(Default)]
pub struct Response {}
impl Request {
pub fn new<T>(user_id: OwnedUserId, data: &T) -> 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(
user_id: OwnedUserId,
event_type: GlobalAccountDataEventType,
data: Raw<AnyGlobalAccountDataEventContent>,
) -> Self {
Self { user_id, event_type, data }
}
}
impl Response {
pub fn new() -> Self {
Self {}
}
}
}