client-api: Use Raw for set_*_account_data::Request::data
This commit is contained in:
parent
bff34569cf
commit
60b2212a57
@ -1,5 +1,9 @@
|
|||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
Breaking changes:
|
||||||
|
|
||||||
|
* Use `Raw` for `config::set_*_account_data::Request::data`.
|
||||||
|
|
||||||
# 0.13.0
|
# 0.13.0
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
@ -6,8 +6,10 @@ pub mod v3 {
|
|||||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridaccount_datatype
|
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridaccount_datatype
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_events::{AnyGlobalAccountDataEventContent, GlobalAccountDataEventContent};
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use ruma_serde::Raw;
|
||||||
|
use serde_json::value::to_raw_value as to_raw_json_value;
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -38,7 +40,7 @@ pub mod v3 {
|
|||||||
///
|
///
|
||||||
/// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
|
/// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
|
||||||
#[ruma_api(body)]
|
#[ruma_api(body)]
|
||||||
pub data: &'a RawJsonValue,
|
pub data: Raw<AnyGlobalAccountDataEventContent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -49,7 +51,28 @@ pub mod v3 {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given data, event type and user ID.
|
/// Creates a new `Request` with the given data, event type and user ID.
|
||||||
pub fn new(data: &'a RawJsonValue, event_type: &'a str, user_id: &'a UserId) -> Self {
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// Since `Request` stores the request body in serialized form, this function can fail if
|
||||||
|
/// `T`s [`Serialize`][serde::Serialize] implementation can fail.
|
||||||
|
pub fn new<T: GlobalAccountDataEventContent>(
|
||||||
|
data: &'a T,
|
||||||
|
user_id: &'a UserId,
|
||||||
|
) -> serde_json::Result<Self> {
|
||||||
|
Ok(Self {
|
||||||
|
user_id,
|
||||||
|
event_type: data.event_type(),
|
||||||
|
data: Raw::from_json(to_raw_json_value(data)?),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new `Request` with the given raw data, event type and user ID.
|
||||||
|
pub fn new_raw(
|
||||||
|
data: Raw<AnyGlobalAccountDataEventContent>,
|
||||||
|
event_type: &'a str,
|
||||||
|
user_id: &'a UserId,
|
||||||
|
) -> Self {
|
||||||
Self { user_id, event_type, data }
|
Self { user_id, event_type, data }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,10 @@ pub mod v3 {
|
|||||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridroomsroomidaccount_datatype
|
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridroomsroomidaccount_datatype
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_events::{AnyRoomAccountDataEventContent, RoomAccountDataEventContent};
|
||||||
use ruma_identifiers::{RoomId, UserId};
|
use ruma_identifiers::{RoomId, UserId};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use ruma_serde::Raw;
|
||||||
|
use serde_json::value::to_raw_value as to_raw_json_value;
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -26,7 +28,7 @@ pub mod v3 {
|
|||||||
///
|
///
|
||||||
/// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
|
/// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
|
||||||
#[ruma_api(body)]
|
#[ruma_api(body)]
|
||||||
pub data: &'a RawJsonValue,
|
pub data: Raw<AnyRoomAccountDataEventContent>,
|
||||||
|
|
||||||
/// The event type of the account_data to set.
|
/// The event type of the account_data to set.
|
||||||
///
|
///
|
||||||
@ -53,8 +55,27 @@ pub mod v3 {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given data, event type, room ID and user ID.
|
/// Creates a new `Request` with the given data, event type, room ID and user ID.
|
||||||
pub fn new(
|
///
|
||||||
data: &'a RawJsonValue,
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// Since `Request` stores the request body in serialized form, this function can fail if
|
||||||
|
/// `T`s [`Serialize`][serde::Serialize] implementation can fail.
|
||||||
|
pub fn new<T: RoomAccountDataEventContent>(
|
||||||
|
data: &'a T,
|
||||||
|
room_id: &'a RoomId,
|
||||||
|
user_id: &'a UserId,
|
||||||
|
) -> serde_json::Result<Self> {
|
||||||
|
Ok(Self {
|
||||||
|
data: Raw::from_json(to_raw_json_value(data)?),
|
||||||
|
event_type: data.event_type(),
|
||||||
|
room_id,
|
||||||
|
user_id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new `Request` with the given raw data, event type, room ID and user ID.
|
||||||
|
pub fn new_raw(
|
||||||
|
data: Raw<AnyRoomAccountDataEventContent>,
|
||||||
event_type: &'a str,
|
event_type: &'a str,
|
||||||
room_id: &'a RoomId,
|
room_id: &'a RoomId,
|
||||||
user_id: &'a UserId,
|
user_id: &'a UserId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user