diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-03-25 14:34:31 +0100 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-03-26 22:52:01 +0100 |
commit | 16a0a88b3db9e8c3f1c8ff80139b77a31f2da287 (patch) | |
tree | e210b9c7cd0d2cf615d1f1b5cd7f673c027dba4d /examples | |
parent | 5b7032e414899b5f9e8f19aec567eaed5e0fc4c2 (diff) | |
download | libquotient-16a0a88b3db9e8c3f1c8ff80139b77a31f2da287.tar.gz libquotient-16a0a88b3db9e8c3f1c8ff80139b77a31f2da287.zip |
Support for receiving m.reaction events
Continuation of the #341 backport.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/qmc-example.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index 2aaaf147..64514619 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -6,6 +6,7 @@ #include "csapi/joining.h" #include "csapi/leaving.h" #include "events/simplestateevents.h" +#include "events/reactionevent.h" #include <QtCore/QCoreApplication> #include <QtCore/QStringBuilder> @@ -26,12 +27,14 @@ class QMCTest : public QObject QMCTest(Connection* conn, QString testRoomName, QString source); private slots: + // clang-format off void setupAndRun(); void onNewRoom(Room* r); void run(); void doTests(); void loadMembers(); void sendMessage(); + void sendReaction(const QString& targetEvtId); void sendFile(); void checkFileSendingOutcome(const QString& txnId, const QString& fileName); @@ -44,6 +47,7 @@ class QMCTest : public QObject const Connection::DirectChatsMap& added); void conclude(); void finalize(); + // clang-format on private: QScopedPointer<Connection, QScopedPointerDeleteLater> c; @@ -230,8 +234,48 @@ void QMCTest::sendMessage() is<RoomMessageEvent>(*evt) && !evt->id().isEmpty() && pendingEvents[size_t(pendingIdx)]->transactionId() == evt->transactionId()); + sendReaction(evt->id()); return true; - }); + }); +} + +void QMCTest::sendReaction(const QString& targetEvtId) +{ + running.push_back("Reaction sending"); + cout << "Reacting to the newest message in the room" << endl; + Q_ASSERT(targetRoom->timelineSize() > 0); + const auto key = QStringLiteral("+1"); + auto txnId = targetRoom->postReaction(targetEvtId, key); + if (!validatePendingEvent(txnId)) { + cout << "Invalid pending event right after submitting" << endl; + QMC_CHECK("Reaction sending", false); + return; + } + + // TODO: Check that it came back as a reaction event and that it attached to + // the right event + connectUntil(targetRoom, &Room::updatedEvent, this, + [this, txnId, key, + targetEvtId](const QString& actualTargetEvtId) { + if (actualTargetEvtId != targetEvtId) + return false; + const auto reactions = targetRoom->relatedEvents( + targetEvtId, EventRelation::Annotation()); + // It's a test room, assuming no interference there should + // be exactly one reaction + if (reactions.size() != 1) { + QMC_CHECK("Reaction sending", false); + } else { + const auto* evt = + eventCast<const ReactionEvent>(reactions.back()); + QMC_CHECK("Reaction sending", + is<ReactionEvent>(*evt) + && !evt->id().isEmpty() + && evt->relation().key == key + && evt->transactionId() == txnId); + } + return true; + }); } void QMCTest::sendFile() |