diff --git a/Quotient/room.cpp b/Quotient/room.cpp index e48e20736..5f28bad27 100644 --- a/Quotient/room.cpp +++ b/Quotient/room.cpp @@ -2121,29 +2121,6 @@ void Room::discardMessage(const QString& txnId) emit pendingEventDiscarded(); } -QString Room::postMessage(const QString& plainText, MessageEventType type) -{ - return post(plainText, type)->transactionId(); -} - -QString Room::postPlainText(const QString& plainText) -{ - return postMessage(plainText, MessageEventType::Text); -} - -QString Room::postHtmlMessage(const QString& plainText, const QString& html, - MessageEventType type) -{ - return post(plainText, type, - std::make_unique(html, u"text/html"_s)) - ->transactionId(); -} - -QString Room::postHtmlText(const QString& plainText, const QString& html) -{ - return postHtmlMessage(plainText, html); -} - QString Room::postReaction(const QString& eventId, const QString& key) { return post(eventId, key)->transactionId(); @@ -2198,7 +2175,8 @@ QString Room::Private::doPostFile(event_ptr_tt fileEvent, cons } QString Room::postFile(const QString& plainText, - std::unique_ptr fileContent) + std::unique_ptr fileContent, + std::optional relatesTo) { Q_ASSERT(fileContent != nullptr); const auto url = fileContent->url(); @@ -2208,15 +2186,11 @@ QString Room::postFile(const QString& plainText, return d->doPostFile(makeEvent(plainText, RoomMessageEvent::rawMsgTypeForFile(localFile), - std::move(fileContent)), + std::move(fileContent), + relatesTo), 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 1059266e5..fe36f408b 100644 --- a/Quotient/room.h +++ b/Quotient/room.h @@ -721,8 +721,37 @@ class QUOTIENT_API Room : public QObject { return post(makeEvent(std::forward(args)...)); } + //! \brief Send a text type message + //! + //! This means MessageEventType Text, Emote or Notice. + template + QString postText(const QString& plainText, + const std::optional& html = std::nullopt, + const std::optional& relatesTo = std::nullopt) + { + static_assert(type == MessageEventType::Text || + type == MessageEventType::Emote || + type == MessageEventType::Notice , + "MessageEvent type is not a text message" + ); + + std::unique_ptr content = nullptr; + if (html) { + content = std::make_unique(*html, u"text/html"_s); + } + return post(plainText, type, std::move(content), relatesTo)->transactionId(); + } + + //! Send a file with the given content QString postFile(const QString& plainText, - std::unique_ptr fileContent); + 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; @@ -749,23 +778,6 @@ public Q_SLOTS: /** Check whether the room should be upgraded */ void checkVersion(); - QString postMessage(const QString& plainText, MessageEventType type); - QString postPlainText(const QString& plainText); - QString postHtmlMessage(const QString& plainText, const QString& html, - MessageEventType type = MessageEventType::Text); - QString postHtmlText(const QString& plainText, const QString& html); - /// 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..ad1e4dfca 100644 --- a/quotest/quotest.cpp +++ b/quotest/quotest.cpp @@ -169,12 +169,11 @@ 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->postText(origin % ": "_L1 % QString::fromUtf8(item) % " successful"_L1); } else { clog << item << " FAILED at " << file << ":" << line << endl; if (targetRoom) - targetRoom->postPlainText(origin % ": "_L1 % QString::fromUtf8(item) % " FAILED at "_L1 + targetRoom->postText(origin % ": "_L1 % QString::fromUtf8(item) % " FAILED at "_L1 % QString::fromUtf8(file) % ", line "_L1 % QString::number(line)); } @@ -364,7 +363,7 @@ TEST_IMPL(loadMembers) TEST_IMPL(sendMessage) { - auto txnId = targetRoom->postPlainText("Hello, "_L1 % origin % " is here"_L1); + auto txnId = targetRoom->postText("Hello, "_L1 % origin % " is here"_L1); if (!validatePendingEvent(txnId)) { clog << "Invalid pending event right after submitting" << endl; FAIL_TEST(); @@ -463,7 +462,7 @@ TEST_IMPL(sendFile) if (id != txnId) return false; - targetRoom->postPlainText(origin % ": File upload failed: "_L1 % error); + targetRoom->postText(origin % ": File upload failed: "_L1 % error); tf->deleteLater(); FAIL_TEST(); }); @@ -923,7 +922,7 @@ void TestManager::conclude() htmlReport += "
Did not finish:"_L1 + QString::fromUtf8(dnfList); } - auto txnId = room->postHtmlText(plainReport, htmlReport); + auto txnId = room->postText(plainReport, htmlReport); // Now just wait until all the pending events reach the server connectUntil(room, &Room::messageSent, this, [this, txnId, room, plainReport] {