From b51b0c54f911101195d999afe564059bbc889b25 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 15 Jun 2021 10:14:19 +0200 Subject: [PATCH] federation-api: Use Raw for messages in transactions::edu --- .../src/transactions/edu.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/ruma-federation-api/src/transactions/edu.rs b/crates/ruma-federation-api/src/transactions/edu.rs index d8ecc457..19a35c71 100644 --- a/crates/ruma-federation-api/src/transactions/edu.rs +++ b/crates/ruma-federation-api/src/transactions/edu.rs @@ -6,8 +6,9 @@ use js_int::UInt; use ruma_common::{ 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_serde::Raw; use serde::{de, Deserialize, Serialize}; 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. pub message_id: String, - /// The contents of the messages to be sent. These are arranged in a map - /// 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. - pub messages: BTreeMap>>, + /// The contents of the messages to be sent. + /// + /// These are arranged in a map 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. + pub messages: DirectDeviceMessages, } impl DirectDeviceContent { /// Creates a new `DirectDeviceContent` with an empty `messages` map. 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>>; + #[cfg(test)] mod test { use js_int::uint;