client-api: Reorder fields and ctor parameters for account data endpoints

This commit is contained in:
Jonas Platte 2022-08-18 18:43:47 +02:00
parent 2b4ac40981
commit 661f6e60bd
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
3 changed files with 25 additions and 24 deletions

View File

@ -11,6 +11,7 @@ Breaking changes:
* Since `backward` and `forward` are equivalent to `from_end` and `from_start`, those are removed * Since `backward` and `forward` are equivalent to `from_end` and `from_start`, those are removed
* A new method `.from()` was added to easily set this field after initial construction * A new method `.from()` was added to easily set this field after initial construction
* `receipt::create_receipt` uses its own `ReceiptType` * `receipt::create_receipt` uses its own `ReceiptType`
* Reorder parameters in `{set_global_account_data, set_room_account_data}::Request::{new, new_raw}`
Improvements: Improvements:

View File

@ -61,7 +61,7 @@ pub mod v3 {
/// ///
/// Since `Request` stores the request body in serialized form, this function can fail if /// Since `Request` stores the request body in serialized form, this function can fail if
/// `T`s [`Serialize`][serde::Serialize] implementation can fail. /// `T`s [`Serialize`][serde::Serialize] implementation can fail.
pub fn new<T>(data: &'a T, user_id: &'a UserId) -> serde_json::Result<Self> pub fn new<T>(user_id: &'a UserId, data: &'a T) -> serde_json::Result<Self>
where where
T: GlobalAccountDataEventContent, T: GlobalAccountDataEventContent,
{ {
@ -74,9 +74,9 @@ pub mod v3 {
/// Creates a new `Request` with the given raw data, event type and user ID. /// Creates a new `Request` with the given raw data, event type and user ID.
pub fn new_raw( pub fn new_raw(
data: Raw<AnyGlobalAccountDataEventContent>,
event_type: GlobalAccountDataEventType,
user_id: &'a UserId, user_id: &'a UserId,
event_type: GlobalAccountDataEventType,
data: Raw<AnyGlobalAccountDataEventContent>,
) -> Self { ) -> Self {
Self { user_id, event_type, data } Self { user_id, event_type, data }
} }

View File

@ -28,11 +28,15 @@ pub mod v3 {
} }
request: { request: {
/// Arbitrary JSON to store as config data. /// The ID of the user to set account_data for.
/// ///
/// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`. /// The access token must be authorized to make requests for this user ID.
#[ruma_api(body)] #[ruma_api(path)]
pub data: Raw<AnyRoomAccountDataEventContent>, pub user_id: &'a UserId,
/// The ID of the room to set account_data on.
#[ruma_api(path)]
pub room_id: &'a RoomId,
/// The event type of the account_data to set. /// The event type of the account_data to set.
/// ///
@ -40,15 +44,11 @@ pub mod v3 {
#[ruma_api(path)] #[ruma_api(path)]
pub event_type: RoomAccountDataEventType, pub event_type: RoomAccountDataEventType,
/// The ID of the room to set account_data on. /// Arbitrary JSON to store as config data.
#[ruma_api(path)]
pub room_id: &'a RoomId,
/// The ID of the user to set account_data for.
/// ///
/// The access token must be authorized to make requests for this user ID. /// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
#[ruma_api(path)] #[ruma_api(body)]
pub user_id: &'a UserId, pub data: Raw<AnyRoomAccountDataEventContent>,
} }
#[derive(Default)] #[derive(Default)]
@ -65,29 +65,29 @@ pub mod v3 {
/// Since `Request` stores the request body in serialized form, this function can fail if /// Since `Request` stores the request body in serialized form, this function can fail if
/// `T`s [`Serialize`][serde::Serialize] implementation can fail. /// `T`s [`Serialize`][serde::Serialize] implementation can fail.
pub fn new<T>( pub fn new<T>(
data: &'a T,
room_id: &'a RoomId,
user_id: &'a UserId, user_id: &'a UserId,
room_id: &'a RoomId,
data: &'a T,
) -> serde_json::Result<Self> ) -> serde_json::Result<Self>
where where
T: RoomAccountDataEventContent, T: RoomAccountDataEventContent,
{ {
Ok(Self { Ok(Self {
data: Raw::from_json(to_raw_json_value(data)?),
event_type: data.event_type(),
room_id,
user_id, user_id,
room_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, room ID and user ID. /// Creates a new `Request` with the given raw data, event type, room ID and user ID.
pub fn new_raw( pub fn new_raw(
data: Raw<AnyRoomAccountDataEventContent>,
event_type: RoomAccountDataEventType,
room_id: &'a RoomId,
user_id: &'a UserId, user_id: &'a UserId,
room_id: &'a RoomId,
event_type: RoomAccountDataEventType,
data: Raw<AnyRoomAccountDataEventContent>,
) -> Self { ) -> Self {
Self { data, event_type, room_id, user_id } Self { user_id, room_id, event_type, data }
} }
} }