client-api: Use Raw for messages in send_event_to_device

This commit is contained in:
Jonas Platte 2021-06-15 10:07:24 +02:00
parent 750fe3f1f6
commit dd1fc704bd
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -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 ruma_api::ruma_api;
use ruma_common::to_device::DeviceIdOrAllDevices;
use ruma_events::EventType;
use ruma_events::AnyToDeviceEventContent;
use ruma_identifiers::UserId;
use serde_json::value::RawValue as RawJsonValue;
use ruma_serde::Raw;
ruma_api! {
metadata: {
@ -21,19 +21,17 @@ ruma_api! {
request: {
/// Type of event being sent to each device.
#[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.
#[ruma_api(path)]
pub txn_id: &'a str,
/// A map of users to devices to a content for a message event to be
/// sent to the user's device. Individual message events can be sent
/// to devices, but all events must be of the same type.
/// The content's type for this field will be updated in a future
/// release, until then you can create a value using
/// `serde_json::value::to_raw_value`.
pub messages: BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Box<RawJsonValue>>>,
/// Messages to send.
///
/// Different message events can be sent to different devices in the same request, but all
/// events within one request must be of the same type.
pub messages: Messages,
}
#[derive(Default)]
@ -43,12 +41,8 @@ ruma_api! {
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given event type, transaction ID and messages.
pub fn new(
event_type: EventType,
txn_id: &'a str,
messages: BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Box<RawJsonValue>>>,
) -> Self {
/// Creates a new `Request` with the given event type, transaction ID and raw messages.
pub fn new_raw(event_type: &'a str, txn_id: &'a str, messages: Messages) -> Self {
Self { event_type, txn_id, messages }
}
}
@ -59,3 +53,8 @@ impl Response {
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>>>;