federation-api: Use Raw for messages in transactions::edu

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

View File

@ -6,8 +6,9 @@ use js_int::UInt;
use ruma_common::{ use ruma_common::{
encryption::DeviceKeys, presence::PresenceState, to_device::DeviceIdOrAllDevices, encryption::DeviceKeys, presence::PresenceState, to_device::DeviceIdOrAllDevices,
}; };
use ruma_events::{from_raw_json_value, receipt::Receipt, EventType}; use ruma_events::{from_raw_json_value, receipt::Receipt, AnyToDeviceEventContent, EventType};
use ruma_identifiers::{DeviceIdBox, EventId, RoomId, UserId}; use ruma_identifiers::{DeviceIdBox, EventId, RoomId, UserId};
use ruma_serde::Raw;
use serde::{de, Deserialize, Serialize}; use serde::{de, Deserialize, Serialize};
use serde_json::{value::RawValue as RawJsonValue, Value as JsonValue}; use serde_json::{value::RawValue as RawJsonValue, Value as JsonValue};
@ -255,19 +256,26 @@ pub struct DirectDeviceContent {
/// Unique utf8 string ID for the message, used for idempotency. /// Unique utf8 string ID for the message, used for idempotency.
pub message_id: String, pub message_id: String,
/// The contents of the messages to be sent. These are arranged in a map /// The contents of the messages to be sent.
/// of user IDs to a map of device IDs to message bodies. The device ID may ///
/// also be *, meaning all known devices for the user. /// These are arranged in a map of user IDs to a map of device IDs to message bodies. The
pub messages: BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Box<RawJsonValue>>>, /// device ID may also be *, meaning all known devices for the user.
pub messages: DirectDeviceMessages,
} }
impl DirectDeviceContent { impl DirectDeviceContent {
/// Creates a new `DirectDeviceContent` with an empty `messages` map. /// Creates a new `DirectDeviceContent` with an empty `messages` map.
pub fn new(sender: UserId, ev_type: EventType, message_id: String) -> Self { pub fn new(sender: UserId, ev_type: EventType, message_id: String) -> Self {
Self { sender, ev_type, message_id, messages: BTreeMap::new() } Self { sender, ev_type, message_id, messages: DirectDeviceMessages::new() }
} }
} }
/// Direct device message contents.
///
/// Represented as a map of `{ user-ids => { device-ids => message-content } }`.
pub type DirectDeviceMessages =
BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>;
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use js_int::uint; use js_int::uint;