From 27a3e704658f576f672448fc928c9ff2d22c2c92 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 27 Sep 2021 13:01:50 +0200 Subject: [PATCH] events: Don't return body as part of MessageType::data --- crates/ruma-events/src/room/message.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ruma-events/src/room/message.rs b/crates/ruma-events/src/room/message.rs index 2b8f509f..8cefa2ff 100644 --- a/crates/ruma-events/src/room/message.rs +++ b/crates/ruma-events/src/room/message.rs @@ -255,12 +255,18 @@ impl MessageType { /// Returns the associated data. /// + /// The returned JSON object won't contain the `msgtype` and `body` fields, use + /// [`.msgtype()`][Self::msgtype] / [`.body()`](Self::body) to access those. + /// /// Prefer to use the public variants of `MessageType` where possible; this method is meant to /// be used for custom message types only. pub fn data(&self) -> Cow<'_, JsonObject> { fn serialize(obj: &T) -> JsonObject { match serde_json::to_value(obj).expect("message type serialization to succeed") { - JsonValue::Object(obj) => obj, + JsonValue::Object(mut obj) => { + obj.remove("body"); + obj + } _ => panic!("all message types must serialize to objects"), } }