From baee19241daffd50e0b32559cda64d5b6ede09a2 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 13 Jun 2017 17:30:13 +0900 Subject: Initial support for local echo The Room class has gained a new internal container, unsyncedEvents, storing locally-created Event objects that are about to be sent or are sent but not yet synced. These objects are supposed to be complete enough to be displayed by clients in a usual way; access to them is provided by Room::pendingEvents() accessor. A set of pendingEvent* signals has been added to notify clients about changes in this container (adding, removal, status update). Yet unsent events don't have Event::id() at all; sent but yet unsynced ones have Event::id() but have almost nothing else except the content for now (probably a sender and an (at least local) timestamp are worth adding). Also: SendEventJob is removed in favor of GTAD-generated SendMessageJob. --- examples/qmc-example.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index 4de42623..d24b6ed0 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -2,7 +2,7 @@ #include "connection.h" #include "room.h" #include "user.h" -#include "jobs/sendeventjob.h" +#include "csapi/room_send.h" #include "csapi/joining.h" #include "csapi/leaving.h" @@ -87,8 +87,8 @@ void QMCTest::setup(const QString& testRoomName) c->sync(10000); else if (targetRoom) { - auto j = c->callApi(targetRoom->id(), - RoomMessageEvent(origin % ": All tests finished")); + auto j = c->sendMessage(targetRoom->id(), + RoomMessageEvent(origin % ": All tests finished")); connect(j, &BaseJob::finished, this, &QMCTest::leave); } else @@ -176,7 +176,7 @@ void QMCTest::sendAndRedact() { running.push_back("Redaction"); cout << "Sending a message to redact" << endl; - auto* job = targetRoom->connection()->callApi(targetRoom->id(), + auto* job = targetRoom->connection()->sendMessage(targetRoom->id(), RoomMessageEvent(origin % ": Message to redact")); connect(job, &BaseJob::success, targetRoom, [job,this] { cout << "Message to redact has been succesfully sent, redacting" << endl; -- cgit v1.2.3 From c7e4d01c479452aad4616ee2d5a285f4fe0565aa Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 27 Jul 2018 14:31:28 +0900 Subject: Update tests (WIP) --- examples/qmc-example.cpp | 54 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'examples') diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index d24b6ed0..8670b263 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -26,9 +26,10 @@ class QMCTest : public QObject void setup(const QString& testRoomName); void onNewRoom(Room* r); void startTests(); + void sendMessage(); void addAndRemoveTag(); void sendAndRedact(); - void checkRedactionOutcome(QString evtIdToRedact, + void checkRedactionOutcome(const QString& evtIdToRedact, RoomEventsRange events); void markDirectChat(); void checkDirectChatOutcome( @@ -87,9 +88,8 @@ void QMCTest::setup(const QString& testRoomName) c->sync(10000); else if (targetRoom) { - auto j = c->sendMessage(targetRoom->id(), - RoomMessageEvent(origin % ": All tests finished")); - connect(j, &BaseJob::finished, this, &QMCTest::leave); + targetRoom->postMessage(origin % ": All tests finished"); + connect(targetRoom, &Room::pendingEventMerged, this, &QMCTest::leave); } else finalize(); @@ -142,11 +142,32 @@ void QMCTest::onNewRoom(Room* r) void QMCTest::startTests() { cout << "Starting tests" << endl; + sendMessage(); addAndRemoveTag(); sendAndRedact(); markDirectChat(); } +void QMCTest::sendMessage() +{ + running.push_back("Message sending"); + cout << "Sending a message" << endl; + auto txnId = targetRoom->postMessage("Hello, " % origin % " is here"); + auto& pending = targetRoom->pendingEvents(); + if (pending.empty()) + { + QMC_CHECK("Message sending", false); + return; + } + auto it = std::find_if(pending.begin(), pending.end(), + [&txnId] (const RoomEventPtr& e) { + return e->transactionId() == txnId; + }); + QMC_CHECK("Message sending", it != pending.end()); + // TODO: Wait when it actually gets sent; check that it obtained an id + // Independently, check when it shows up in the timeline. +} + void QMCTest::addAndRemoveTag() { running.push_back("Tagging test"); @@ -176,19 +197,22 @@ void QMCTest::sendAndRedact() { running.push_back("Redaction"); cout << "Sending a message to redact" << endl; - auto* job = targetRoom->connection()->sendMessage(targetRoom->id(), - RoomMessageEvent(origin % ": Message to redact")); - connect(job, &BaseJob::success, targetRoom, [job,this] { - cout << "Message to redact has been succesfully sent, redacting" << endl; - targetRoom->redactEvent(job->eventId(), origin); - // Make sure to save the event id because the job is about to end. - connect(targetRoom, &Room::aboutToAddNewMessages, this, - std::bind(&QMCTest::checkRedactionOutcome, - this, job->eventId(), _1)); - }); + if (auto* job = targetRoom->connection()->sendMessage(targetRoom->id(), + RoomMessageEvent(origin % ": message to redact"))) + { + connect(job, &BaseJob::success, targetRoom, [job,this] { + cout << "Redacting the message" << endl; + targetRoom->redactEvent(job->eventId(), origin); + // Make sure to save the event id because the job is about to end. + connect(targetRoom, &Room::aboutToAddNewMessages, this, + std::bind(&QMCTest::checkRedactionOutcome, + this, job->eventId(), _1)); + }); + } else + QMC_CHECK("Redaction", false); } -void QMCTest::checkRedactionOutcome(QString evtIdToRedact, +void QMCTest::checkRedactionOutcome(const QString& evtIdToRedact, RoomEventsRange events) { static bool checkSucceeded = false; -- cgit v1.2.3