diff --git a/crates/ruma-events/CHANGELOG.md b/crates/ruma-events/CHANGELOG.md index 8ffbd401..3b119a06 100644 --- a/crates/ruma-events/CHANGELOG.md +++ b/crates/ruma-events/CHANGELOG.md @@ -9,6 +9,8 @@ Breaking changes: * The `new` constructor now also has a body parameter * Rename `*ToDeviceEventContent` structs to `ToDevice*Content` * Remove unneeded redacted event content enums +* Update `reply` and `html_reply` types to `impl Display` on `RoomMessageEventContent`'s reply + constructors Improvements: diff --git a/crates/ruma-events/src/room/message.rs b/crates/ruma-events/src/room/message.rs index 18b8b017..d73337da 100644 --- a/crates/ruma-events/src/room/message.rs +++ b/crates/ruma-events/src/room/message.rs @@ -1,6 +1,6 @@ //! Types for the `m.room.message` event. -use std::borrow::Cow; +use std::{borrow::Cow, fmt}; use indoc::formatdoc; use js_int::UInt; @@ -81,10 +81,10 @@ impl RoomMessageEventContent { } /// Creates a plain text reply to a message. - pub fn text_reply_plain(reply: impl Into, original_message: &RoomMessageEvent) -> Self { + pub fn text_reply_plain(reply: impl fmt::Display, original_message: &RoomMessageEvent) -> Self { let quoted = get_plain_quote_fallback(original_message); - let body = format!("{}\n\n{}", quoted, reply.into()); + let body = format!("{}\n\n{}", quoted, reply); Self { relates_to: Some(Relation::Reply { @@ -96,15 +96,15 @@ impl RoomMessageEventContent { /// Creates a html text reply to a message. pub fn text_reply_html( - reply: impl Into, - html_reply: impl Into, + reply: impl fmt::Display, + html_reply: impl fmt::Display, original_message: &RoomMessageEvent, ) -> Self { let quoted = get_plain_quote_fallback(original_message); let quoted_html = get_html_quote_fallback(original_message); - let body = format!("{}\n\n{}", quoted, reply.into()); - let html_body = format!("{}\n\n{}", quoted_html, html_reply.into()); + let body = format!("{}\n\n{}", quoted, reply); + let html_body = format!("{}\n\n{}", quoted_html, html_reply); Self { relates_to: Some(Relation::Reply { @@ -116,12 +116,12 @@ impl RoomMessageEventContent { /// Creates a plain text notice reply to a message. pub fn notice_reply_plain( - reply: impl Into, + reply: impl fmt::Display, original_message: &RoomMessageEvent, ) -> Self { let quoted = get_plain_quote_fallback(original_message); - let body = format!("{}\n\n{}", quoted, reply.into()); + let body = format!("{}\n\n{}", quoted, reply); Self { relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id: original_message.event_id.clone() }, @@ -132,15 +132,15 @@ impl RoomMessageEventContent { /// Creates a html text notice reply to a message. pub fn notice_reply_html( - reply: impl Into, - html_reply: impl Into, + reply: impl fmt::Display, + html_reply: impl fmt::Display, original_message: &RoomMessageEvent, ) -> Self { let quoted = get_plain_quote_fallback(original_message); let quoted_html = get_html_quote_fallback(original_message); - let body = format!("{}\n\n{}", quoted, reply.into()); - let html_body = format!("{}\n\n{}", quoted_html, html_reply.into()); + let body = format!("{}\n\n{}", quoted, reply); + let html_body = format!("{}\n\n{}", quoted_html, html_reply); Self { relates_to: Some(Relation::Reply {