events: Add reply fallback to emotes

This commit is contained in:
Kévin Commaille 2022-06-21 09:17:22 +02:00 committed by Kévin Commaille
parent 9b2117cbf6
commit 8fc6a55877

View File

@ -188,7 +188,8 @@ impl RoomMessageEventContent {
/// Create a new reply with the given message and optionally forwards the [`Relation::Thread`]. /// Create a new reply with the given message and optionally forwards the [`Relation::Thread`].
/// ///
/// If `message` is a text or notice message, it is modified to include the rich reply fallback. /// If `message` is a text, an emote or a notice message, it is modified to include the rich
/// reply fallback.
#[cfg(feature = "unstable-msc3440")] #[cfg(feature = "unstable-msc3440")]
pub fn reply( pub fn reply(
message: MessageType, message: MessageType,
@ -205,6 +206,15 @@ impl RoomMessageEventContent {
MessageType::Text(TextMessageEventContent::html(body, html_body)) MessageType::Text(TextMessageEventContent::html(body, html_body))
} }
MessageType::Emote(EmoteMessageEventContent { body, formatted, .. }) => {
let (body, html_body) = reply::plain_and_formatted_reply_body(
body,
formatted.map(|f| f.body),
original_message,
);
MessageType::Emote(EmoteMessageEventContent::html(body, html_body))
}
MessageType::Notice(NoticeMessageEventContent { body, formatted, .. }) => { MessageType::Notice(NoticeMessageEventContent { body, formatted, .. }) => {
let (body, html_body) = reply::plain_and_formatted_reply_body( let (body, html_body) = reply::plain_and_formatted_reply_body(
body, body,
@ -239,8 +249,8 @@ impl RoomMessageEventContent {
/// thread is created. If it doesn't, a new thread with `previous_message` as the root is /// thread is created. If it doesn't, a new thread with `previous_message` as the root is
/// created. /// created.
/// ///
/// If `message` is a text or notice message, and this is a reply in the thread, it is modified /// If `message` is a text, an emote or a notice message, and this is a reply in the thread, it
/// to include the rich reply fallback. /// is modified to include the rich reply fallback.
#[cfg(feature = "unstable-msc3440")] #[cfg(feature = "unstable-msc3440")]
pub fn for_thread( pub fn for_thread(
message: MessageType, message: MessageType,
@ -259,6 +269,15 @@ impl RoomMessageEventContent {
MessageType::Text(TextMessageEventContent::html(body, html_body)) MessageType::Text(TextMessageEventContent::html(body, html_body))
} }
MessageType::Emote(EmoteMessageEventContent { body, formatted, .. }) => {
let (body, html_body) = reply::plain_and_formatted_reply_body(
body,
formatted.map(|f| f.body),
previous_message,
);
MessageType::Emote(EmoteMessageEventContent::html(body, html_body))
}
MessageType::Notice(NoticeMessageEventContent { body, formatted, .. }) => { MessageType::Notice(NoticeMessageEventContent { body, formatted, .. }) => {
let (body, html_body) = reply::plain_and_formatted_reply_body( let (body, html_body) = reply::plain_and_formatted_reply_body(
body, body,