client-api: Use Raw for messages in send_event_to_device
This commit is contained in:
parent
750fe3f1f6
commit
dd1fc704bd
@ -1,12 +1,12 @@
|
|||||||
//! [PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-sendtodevice-eventtype-txnid)
|
//! [PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-sendtodevice-eventtype-txnid)
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_common::to_device::DeviceIdOrAllDevices;
|
use ruma_common::to_device::DeviceIdOrAllDevices;
|
||||||
use ruma_events::EventType;
|
use ruma_events::AnyToDeviceEventContent;
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -21,19 +21,17 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// Type of event being sent to each device.
|
/// Type of event being sent to each device.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub event_type: EventType,
|
pub event_type: &'a str,
|
||||||
|
|
||||||
/// A request identifier unique to the access token used to send the request.
|
/// A request identifier unique to the access token used to send the request.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub txn_id: &'a str,
|
pub txn_id: &'a str,
|
||||||
|
|
||||||
/// A map of users to devices to a content for a message event to be
|
/// Messages to send.
|
||||||
/// sent to the user's device. Individual message events can be sent
|
///
|
||||||
/// to devices, but all events must be of the same type.
|
/// Different message events can be sent to different devices in the same request, but all
|
||||||
/// The content's type for this field will be updated in a future
|
/// events within one request must be of the same type.
|
||||||
/// release, until then you can create a value using
|
pub messages: Messages,
|
||||||
/// `serde_json::value::to_raw_value`.
|
|
||||||
pub messages: BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Box<RawJsonValue>>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -43,12 +41,8 @@ ruma_api! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given event type, transaction ID and messages.
|
/// Creates a new `Request` with the given event type, transaction ID and raw messages.
|
||||||
pub fn new(
|
pub fn new_raw(event_type: &'a str, txn_id: &'a str, messages: Messages) -> Self {
|
||||||
event_type: EventType,
|
|
||||||
txn_id: &'a str,
|
|
||||||
messages: BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Box<RawJsonValue>>>,
|
|
||||||
) -> Self {
|
|
||||||
Self { event_type, txn_id, messages }
|
Self { event_type, txn_id, messages }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,3 +53,8 @@ impl Response {
|
|||||||
Self
|
Self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Messages to send in a send-to-device request.
|
||||||
|
///
|
||||||
|
/// Represented as a map of `{ user-ids => { device-ids => message-content } }`.
|
||||||
|
pub type Messages = BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user