diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-10-01 13:14:30 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-10-01 13:14:30 +0900 |
commit | f71d16b56ab90e494d6a41c276210a4ce593987e (patch) | |
tree | 72a029da3aea15952c673c1bc15a44f29f6e51b2 /lib/room.cpp | |
parent | d0a0f8cda88d644ca38b2b90024303fbe362602c (diff) | |
download | libquotient-f71d16b56ab90e494d6a41c276210a4ce593987e.tar.gz libquotient-f71d16b56ab90e494d6a41c276210a4ce593987e.zip |
Room::getCurrentState()
Diffstat (limited to 'lib/room.cpp')
-rw-r--r-- | lib/room.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index e2195193..aae84416 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -202,25 +202,31 @@ public: void getPreviousContent(int limit = 10); - template <typename EventT> - const EventT* getCurrentState(const QString& stateKey = {}) const + const StateEventBase* getCurrentState(const StateEventKey& evtKey) const { - const StateEventKey evtKey { EventT::matrixTypeId(), stateKey }; const auto* evt = currentState.value(evtKey, nullptr); if (!evt) { if (stubbedState.find(evtKey) == stubbedState.end()) { // In the absence of a real event, make a stub as-if an event // with empty content has been received. Event classes should be // prepared for empty/invalid/malicious content anyway. - stubbedState.emplace(evtKey, - loadStateEvent(EventT::matrixTypeId(), {}, - stateKey)); + stubbedState.emplace(evtKey, loadStateEvent(evtKey.first, {}, + evtKey.second)); qCDebug(STATE) << "A new stub event created for key {" << evtKey.first << evtKey.second << "}"; } evt = stubbedState[evtKey].get(); Q_ASSERT(evt); } + Q_ASSERT(evt->matrixType() == evtKey.first + && evt->stateKey() == evtKey.second); + return evt; + } + + template <typename EventT> + const EventT* getCurrentState(const QString& stateKey = {}) const + { + const auto* evt = getCurrentState({ EventT::matrixTypeId(), stateKey }); Q_ASSERT(evt->type() == EventT::typeId() && evt->matrixType() == EventT::matrixTypeId()); return static_cast<const EventT*>(evt); @@ -1105,6 +1111,12 @@ bool Room::usesEncryption() const return !d->getCurrentState<EncryptionEvent>()->algorithm().isEmpty(); } +const StateEventBase* Room::getCurrentState(const QString& evtType, + const QString& stateKey) const +{ + return d->getCurrentState({ evtType, stateKey }); +} + RoomEventPtr Room::decryptMessage(EncryptedEvent* encryptedEvent) { if (encryptedEvent->algorithm() == OlmV1Curve25519AesSha2AlgoKey) { |