diff --git a/Quotient/room.cpp b/Quotient/room.cpp index 88c5ffa19..244634579 100644 --- a/Quotient/room.cpp +++ b/Quotient/room.cpp @@ -2238,6 +2238,13 @@ QString Room::Private::doPostFile(event_ptr_tt fileEvent, cons QString Room::postFile(const QString& plainText, std::unique_ptr fileContent) +{ + return postFile(plainText, std::move(fileContent), std::nullopt); +} + +QString Room::postFile(const QString& plainText, + std::unique_ptr fileContent, + std::optional relatesTo) { Q_ASSERT(fileContent != nullptr); const auto url = fileContent->url(); @@ -2247,7 +2254,7 @@ QString Room::postFile(const QString& plainText, return d->doPostFile(makeEvent(plainText, RoomMessageEvent::rawMsgTypeForFile(localFile), - std::move(fileContent)), + std::move(fileContent), relatesTo), url); } diff --git a/Quotient/room.h b/Quotient/room.h index a0f900b35..2bffc9cef 100644 --- a/Quotient/room.h +++ b/Quotient/room.h @@ -726,8 +726,31 @@ 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"); + + return post( + plainText, type, + html ? std::make_unique(*html, u"text/html"_s) + : nullptr, + relatesTo) + ->transactionId(); + } + QString postFile(const QString& plainText, std::unique_ptr fileContent); + QString postFile(const QString& plainText, + std::unique_ptr fileContent, + std::optional relatesTo); PendingEventItem::future_type whenMessageMerged(QString txnId) const; @@ -754,11 +777,16 @@ public Q_SLOTS: /** Check whether the room should be upgraded */ void checkVersion(); + [[deprecated("Use postText() instead")]] QString postMessage(const QString& plainText, MessageEventType type); + [[deprecated("Use postText() instead")]] QString postPlainText(const QString& plainText); + [[deprecated("Use postText() instead")]] QString postHtmlMessage(const QString& plainText, const QString& html, MessageEventType type = MessageEventType::Text); + [[deprecated("Use postText() instead")]] 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); diff --git a/quotest/quotest.cpp b/quotest/quotest.cpp index cec6b4315..4d58627c7 100644 --- a/quotest/quotest.cpp +++ b/quotest/quotest.cpp @@ -184,14 +184,14 @@ void TestSuite::finishTest(const TestToken& token, bool condition, std::source_l 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 " << loc.file_name() << ":" << loc.line() << endl; if (targetRoom) - targetRoom->postPlainText(origin % ": "_L1 % QString::fromUtf8(item) % " FAILED at "_L1 - % QString::fromUtf8(loc.file_name()) % ", line "_L1 - % QString::number(loc.line())); + targetRoom->postText(origin % ": "_L1 % QString::fromUtf8(item) % " FAILED at "_L1 + % QString::fromUtf8(loc.file_name()) % ", line "_L1 + % QString::number(loc.line())); } emit finishedItem(item, condition); @@ -380,7 +380,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(); @@ -478,7 +478,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(); }); @@ -906,7 +906,7 @@ TEST_IMPL(visitResources) TEST_IMPL(thread) { - auto rootTxnId = targetRoom->postPlainText("Threadroot"_L1); + auto rootTxnId = targetRoom->postText("Threadroot"_L1); connect(targetRoom, &Room::pendingEventAboutToMerge, this, [this, thisTest, rootTxnId](Quotient::RoomEvent* rootEvt) { if (rootEvt->transactionId() == rootTxnId) { const auto relation = EventRelation::replyInThread(rootEvt->id(), true, rootEvt->id()); @@ -976,7 +976,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] { const auto& pendingEvents = room->pendingEvents();