diff --git a/Quotient/room.cpp b/Quotient/room.cpp index d963655fd..bca9abb83 100644 --- a/Quotient/room.cpp +++ b/Quotient/room.cpp @@ -52,6 +52,7 @@ #include "events/roomcanonicalaliasevent.h" #include "events/roomcreateevent.h" #include "events/roommemberevent.h" +#include "events/roommessageevent.h" #include "events/roompowerlevelsevent.h" #include "events/roomtombstoneevent.h" #include "events/simplestateevents.h" @@ -2121,28 +2122,37 @@ void Room::discardMessage(const QString& txnId) emit pendingEventDiscarded(); } -QString Room::postMessage(const QString& plainText, MessageEventType type, std::optional relatesTo) +QString Room::postEmote(const QString& plainText, std::optional html, std::optional relatesTo) { - return post(plainText, type, nullptr, relatesTo)->transactionId(); + std::unique_ptr content = nullptr; + if (html) { + content = std::make_unique(*html, u"text/html"_s); + } + + return post(plainText, MessageEventType::Emote, std::move(content), relatesTo)->transactionId(); } -QString Room::postPlainText(const QString& plainText, std::optional relatesTo) +QString Room::postNotice(const QString& plainText, std::optional html, std::optional relatesTo) { - return postMessage(plainText, MessageEventType::Text, relatesTo); + std::unique_ptr content = nullptr; + if (html) { + content = std::make_unique(*html, u"text/html"_s); + } + + return post(plainText, MessageEventType::Notice, std::move(content), relatesTo)->transactionId(); } -QString Room::postHtmlMessage(const QString& plainText, const QString& html, - MessageEventType type, std::optional relatesTo) +QString Room::postPlainText(const QString& plainText, std::optional relatesTo) { - return post(plainText, type, - std::make_unique(html, u"text/html"_s), - relatesTo) - ->transactionId(); + return post(plainText, MessageEventType::Text, nullptr, relatesTo)->transactionId(); } QString Room::postHtmlText(const QString& plainText, const QString& html, std::optional relatesTo) { - return postHtmlMessage(plainText, html, MessageEventType::Text, relatesTo); + return post(plainText, MessageEventType::Text, + std::make_unique(html, u"text/html"_s), + relatesTo) + ->transactionId(); } QString Room::postReaction(const QString& eventId, const QString& key) @@ -2215,11 +2225,6 @@ QString Room::postFile(const QString& plainText, url); } -QString Room::postEvent(RoomEvent* event) -{ - return d->sendEvent(RoomEventPtr(event))->transactionId(); -} - const PendingEventItem& Room::post(RoomEventPtr event) { return d->sendEvent(std::move(event)); diff --git a/Quotient/room.h b/Quotient/room.h index 27d53269e..e13f20b78 100644 --- a/Quotient/room.h +++ b/Quotient/room.h @@ -721,10 +721,29 @@ class QUOTIENT_API Room : public QObject { return post(makeEvent(std::forward(args)...)); } + /// Send a plain text message + QString postPlainText(const QString& plainText, std::optional relatesTo = std::nullopt); + + /// Send a rich text message + QString postHtmlText(const QString& plainText, const QString& html, std::optional relatesTo = std::nullopt); + + /// Send a m.emote message + QString postEmote(const QString& plainText, std::optional html = std::nullopt, std::optional relatesTo = std::nullopt); + + /// Send an m.notice message + QString postNotice(const QString& plainText, std::optional html = std::nullopt, std::optional relatesTo = std::nullopt); + + /// Send a file with the given content QString postFile(const QString& plainText, std::unique_ptr fileContent, std::optional relatesTo = std::nullopt); + /// Send the given Json as a message + QString postJson(const QString& matrixType, const QJsonObject& eventContent); + + /// Send a reaction on a given event with a given key + QString postReaction(const QString& eventId, const QString& key); + PendingEventItem::future_type whenMessageMerged(QString txnId) const; //! Send a request to update the room state with the given event @@ -750,24 +769,6 @@ public Q_SLOTS: /** Check whether the room should be upgraded */ void checkVersion(); - QString postMessage(const QString& plainText, MessageEventType type, std::optional relatesTo = std::nullopt); - QString postPlainText(const QString& plainText, std::optional relatesTo = std::nullopt); - QString postHtmlMessage(const QString& plainText, const QString& html, - MessageEventType type = MessageEventType::Text, - std::optional relatesTo = std::nullopt); - QString postHtmlText(const QString& plainText, const QString& html, std::optional relatesTo = std::nullopt); - /// Send a reaction on a given event with a given key - QString postReaction(const QString& eventId, const QString& key); - - /** Post a pre-created room message event - * - * Takes ownership of the event, deleting it once the matching one - * arrives with the sync - * \return transaction id associated with the event. - */ - [[deprecated("Use post() instead")]] - QString postEvent(RoomEvent* event); - QString postJson(const QString& matrixType, const QJsonObject& eventContent); QString retryMessage(const QString& txnId); void discardMessage(const QString& txnId); diff --git a/quotest/quotest.cpp b/quotest/quotest.cpp index 2c982c92c..36aefc7e6 100644 --- a/quotest/quotest.cpp +++ b/quotest/quotest.cpp @@ -169,8 +169,7 @@ void TestSuite::finishTest(const TestToken& token, bool condition, if (condition) { clog << item << " successful" << endl; if (targetRoom) - targetRoom->postMessage(origin % ": "_L1 % QString::fromUtf8(item) % " successful"_L1, - MessageEventType::Notice); + targetRoom->postNotice(origin % ": "_L1 % QString::fromUtf8(item) % " successful"_L1); } else { clog << item << " FAILED at " << file << ":" << line << endl; if (targetRoom)