diff options
author | Hubert Chathi <uhoreg@debian.org> | 2019-01-14 11:21:45 -0500 |
---|---|---|
committer | Hubert Chathi <uhoreg@debian.org> | 2019-01-14 11:21:45 -0500 |
commit | d488348d41b1abecd858a2625099dc94a8b05eac (patch) | |
tree | 8736c10809e5fac1dd7527e2562e948f09d109ae | |
parent | 34da172eadf142cb13825086ab10e5627fff2668 (diff) | |
parent | 863848b2158e3278ae65d25de0b189a6008c60d1 (diff) | |
download | libquotient-d488348d41b1abecd858a2625099dc94a8b05eac.tar.gz libquotient-d488348d41b1abecd858a2625099dc94a8b05eac.zip |
Merge branch 'upstream' (v0.4.2.1)
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/qmc-example.cpp | 46 | ||||
-rw-r--r-- | lib/events/stateevent.cpp | 12 |
3 files changed, 58 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a1950b3..7a9b7d11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,7 +140,7 @@ add_library(QMatrixClient ${libqmatrixclient_SRCS} ${libqmatrixclient_cswellknown_SRCS} ${libqmatrixclient_asdef_SRCS} ${libqmatrixclient_isdef_SRCS}) set(API_VERSION "0.4") -set_property(TARGET QMatrixClient PROPERTY VERSION "${API_VERSION}.0") +set_property(TARGET QMatrixClient PROPERTY VERSION "${API_VERSION}.2.1") set_property(TARGET QMatrixClient PROPERTY SOVERSION ${API_VERSION} ) set_property(TARGET QMatrixClient PROPERTY INTERFACE_QMatrixClient_MAJOR_VERSION ${API_VERSION}) diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index 9c86d4a9..206501a5 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -5,6 +5,7 @@ #include "csapi/room_send.h" #include "csapi/joining.h" #include "csapi/leaving.h" +#include "events/simplestateevents.h" #include <QtCore/QCoreApplication> #include <QtCore/QStringBuilder> @@ -27,6 +28,7 @@ class QMCTest : public QObject void onNewRoom(Room* r); void startTests(); void sendMessage(); + void setTopic(); void addAndRemoveTag(); void sendAndRedact(); void checkRedactionOutcome(const QString& evtIdToRedact, @@ -143,6 +145,7 @@ void QMCTest::startTests() { cout << "Starting tests" << endl; sendMessage(); + setTopic(); addAndRemoveTag(); sendAndRedact(); markDirectChat(); @@ -168,6 +171,49 @@ void QMCTest::sendMessage() // Independently, check when it shows up in the timeline. } +void QMCTest::setTopic() +{ + running.push_back("State setting test"); + running.push_back("Fake state event immunity test"); + auto initialTopic = targetRoom->topic(); + + 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* context = new QObject; + connect(targetRoom, &Room::topicChanged, context, + [this,newTopic,fakeTopic,initialTopic,context] { + if (targetRoom->topic() == newTopic) + { + QMC_CHECK("State setting test", true); + // Don't reset the topic yet if the negative test still runs + if (!running.contains("Fake state event immunity test")) + targetRoom->setTopic(initialTopic); + + context->deleteLater(); + } + }); + } + + { + auto* context = new QObject; + connect(targetRoom, &Room::pendingEventAboutToMerge, context, + [this,fakeTopic,initialTopic,context] (const RoomEvent* e, int) { + if (e->contentJson().value("topic").toString() != fakeTopic) + return; // Wait on for the right event + + QMC_CHECK("Fake state event immunity test", !e->isStateEvent()); + if (!running.contains("State setting test")) + targetRoom->setTopic(initialTopic); + context->deleteLater(); + }); + } +} + void QMCTest::addAndRemoveTag() { running.push_back("Tagging test"); diff --git a/lib/events/stateevent.cpp b/lib/events/stateevent.cpp index fd5d2642..877d0fae 100644 --- a/lib/events/stateevent.cpp +++ b/lib/events/stateevent.cpp @@ -21,7 +21,17 @@ using namespace QMatrixClient; [[gnu::unused]] static auto stateEventTypeInitialised = - RoomEvent::factory_t::chainFactory<StateEventBase>(); + RoomEvent::factory_t::addMethod( + [] (const QJsonObject& json, const QString& matrixType) -> StateEventPtr + { + if (!json.contains("state_key")) + return nullptr; + + if (auto e = StateEventBase::factory_t::make(json, matrixType)) + return e; + + return nullptr; + }); bool StateEventBase::repeatsState() const { |