From 4d2994d3b6f44bddcccef5139692bde498fb8495 Mon Sep 17 00:00:00 2001 From: James Graham Date: Sat, 16 Nov 2024 14:16:46 +0000 Subject: [PATCH] Add some helper functions to allow the editing of the message type and plain body. This is useful as for example in NeoChat we have slash commands where these are modified and I want to do it after event creation --- Quotient/events/roommessageevent.cpp | 12 ++++++++++++ Quotient/events/roommessageevent.h | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/Quotient/events/roommessageevent.cpp b/Quotient/events/roommessageevent.cpp index e2ae7c34..e41a26d6 100644 --- a/Quotient/events/roommessageevent.cpp +++ b/Quotient/events/roommessageevent.cpp @@ -193,6 +193,18 @@ std::unique_ptr RoomMessageEvent::content() const return {}; } +void RoomMessageEvent::setPlainBody(const QString& newPlainBody) +{ + editJson()[ContentKey] = + assembleContentJson(newPlainBody, rawMsgtype(), content(), relatesTo()); +} + +void RoomMessageEvent::setMsgType(MsgType newMsgType) +{ + editJson()[ContentKey] = + assembleContentJson(plainBody(), msgTypeToJson(newMsgType), content(), relatesTo()); +} + void RoomMessageEvent::setContent(std::unique_ptr content) { editJson()[ContentKey] = diff --git a/Quotient/events/roommessageevent.h b/Quotient/events/roommessageevent.h index 26d99b97..87a25206 100644 --- a/Quotient/events/roommessageevent.h +++ b/Quotient/events/roommessageevent.h @@ -59,6 +59,12 @@ class QUOTIENT_API RoomMessageEvent : public RoomEvent { //! \return an event content object if the event has content, nullptr otherwise. std::unique_ptr content() const; + //! Update the message JSON with the given plain body + void setPlainBody(const QString& newPlainBody); + + //! Update the message JSON with the given message type + void setMsgType(MsgType newMsgType); + //! Update the message JSON with the given content void setContent(std::unique_ptr content);