aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHubert Chathi <uhoreg@debian.org>2020-04-20 18:01:38 -0400
committerHubert Chathi <uhoreg@debian.org>2020-04-20 18:01:38 -0400
commit035d428becd62869b88793bb48d59410056b1f31 (patch)
tree0cd837955fa1037c74ee524a089ff1b788b75861 /examples
parent688dc682e0c6ae12dc87d781ffe53c974dad60df (diff)
parentd8e1f4ee70902e2b9e5e9c699423d7f3fafe6238 (diff)
downloadlibquotient-035d428becd62869b88793bb48d59410056b1f31.tar.gz
libquotient-035d428becd62869b88793bb48d59410056b1f31.zip
Update upstream source from tag 'upstream/0.5.3.2'
Update to upstream version '0.5.3.2' with Debian dir 49a325a077f4a2ebcd5b73adf3782a6fb5ecb3fe
Diffstat (limited to 'examples')
-rw-r--r--examples/qmc-example.cpp74
1 files changed, 61 insertions, 13 deletions
diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp
index bd9190b9..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;
@@ -183,7 +187,7 @@ void QMCTest::loadMembers()
// The dedicated qmc-test room is too small to test
// lazy-loading-then-full-loading; use #qmatrixclient:matrix.org instead.
// TODO: #264
- auto* r = c->room(QStringLiteral("!PCzUtxtOjUySxSelof:matrix.org"));
+ auto* r = c->roomByAlias(QStringLiteral("#qmatrixclient:matrix.org"));
if (!r)
{
cout << "#test:matrix.org is not found in the test user's rooms" << endl;
@@ -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()
@@ -344,8 +388,9 @@ void QMCTest::setTopic()
const auto newTopic = c->generateTxnId();
targetRoom->setTopic(newTopic); // Sets the state by proper means
const auto fakeTopic = c->generateTxnId();
- targetRoom->postJson(RoomTopicEvent::matrixTypeId(), // Fake state event
- RoomTopicEvent(fakeTopic).contentJson());
+ auto fakeTxnId =
+ targetRoom->postJson(RoomTopicEvent::matrixTypeId(), // Fake state event
+ RoomTopicEvent(fakeTopic).contentJson());
connectUntil(targetRoom, &Room::topicChanged, this,
[this,newTopic,fakeTopic,initialTopic] {
@@ -353,22 +398,25 @@ void QMCTest::setTopic()
{
QMC_CHECK(stateTestName, true);
// Don't reset the topic yet if the negative test still runs
- if (!running.contains(fakeStateTestName))
- targetRoom->setTopic(initialTopic);
+ targetRoom->setTopic(initialTopic);
return true;
}
return false;
});
- connectUntil(targetRoom, &Room::pendingEventAboutToMerge, this,
- [this,fakeTopic,initialTopic] (const RoomEvent* e, int) {
- if (e->contentJson().value("topic").toString() != fakeTopic)
- return false; // Wait on for the right event
+ connectUntil(targetRoom, &Room::pendingEventChanged, this,
+ [this, fakeTxnId](int pendingIdx) {
+ const auto& pendingEvents = targetRoom->pendingEvents();
+ Q_ASSERT(pendingIdx >= 0 && pendingIdx < int(pendingEvents.size()));
- QMC_CHECK(fakeStateTestName, !e->isStateEvent());
- if (!running.contains(fakeStateTestName))
- targetRoom->setTopic(initialTopic);
+ const auto& pendingItem = pendingEvents[pendingIdx];
+ if (pendingItem->transactionId() != fakeTxnId
+ || pendingItem.deliveryStatus() <= EventStatus::Departed)
+ return false;
+
+ QMC_CHECK(fakeStateTestName, pendingItem.deliveryStatus()
+ == EventStatus::SendingFailed);
return true;
});
}