Skip to content

Commit

Permalink
Add some helper functions to allow the editing of the message type an…
Browse files Browse the repository at this point in the history
…d 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
  • Loading branch information
nvrWhere committed Nov 16, 2024
1 parent 8f5b4ea commit 4d2994d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Quotient/events/roommessageevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ std::unique_ptr<Base> 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<Base> content)
{
editJson()[ContentKey] =
Expand Down
6 changes: 6 additions & 0 deletions Quotient/events/roommessageevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventContent::Base> 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<EventContent::Base> content);

Expand Down

0 comments on commit 4d2994d

Please sign in to comment.