From 9d3c2e19f5cf450c489e5d5a5a763ea9f731371f Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 21 Mar 2024 16:08:30 -0400 Subject: [PATCH] Strip replies when calling EventHandler::getMarkdownBody() This matches previous behavior before e2eb6ab33c0a1ccf6685bacdb977057750626ec4 and including the markdown blockquote breaks edits. This also adds a test to ensure it does indeed get stripped. --- autotests/eventhandlertest.cpp | 8 ++++++++ src/eventhandler.cpp | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/autotests/eventhandlertest.cpp b/autotests/eventhandlertest.cpp index 7df92639a..cb3dde831 100644 --- a/autotests/eventhandlertest.cpp +++ b/autotests/eventhandlertest.cpp @@ -56,6 +56,7 @@ private Q_SLOTS: void genericBody(); void nullGenericBody(); void markdownBody(); + void markdownBodyReply(); void subtitle(); void nullSubtitle(); void mediaInfo(); @@ -301,6 +302,13 @@ void EventHandlerTest::markdownBody() QCOMPARE(eventHandler.getMarkdownBody(), QStringLiteral("This is an example\ntext message")); } +void EventHandlerTest::markdownBodyReply() +{ + EventHandler eventHandler(room, room->messageEvents().at(5).get()); + + QCOMPARE(eventHandler.getMarkdownBody(), QStringLiteral("reply")); +} + void EventHandlerTest::subtitle() { EventHandler eventHandler(room, room->messageEvents().at(0).get()); diff --git a/src/eventhandler.cpp b/src/eventhandler.cpp index 4b26411d7..c737d68f4 100644 --- a/src/eventhandler.cpp +++ b/src/eventhandler.cpp @@ -293,7 +293,10 @@ QString EventHandler::getMarkdownBody() const } const auto roomMessageEvent = eventCast(m_event); - return roomMessageEvent->plainBody(); + + QString plainBody = roomMessageEvent->plainBody(); + plainBody.remove(TextRegex::removeReply); + return plainBody; } QString EventHandler::getBody(const Quotient::RoomEvent *event, Qt::TextFormat format, bool stripNewlines) const