diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-07-06 20:13:38 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-07-06 20:13:38 +0900 |
commit | 025e5ab7d90ce8cf474567457301de32d5a3e34a (patch) | |
tree | a56ab34bff688275a9deabd920539bebc247cc8e /lib/events/simplestateevents.h | |
parent | cbb4f219d5c79f81706019c0679222d5ccee4a4c (diff) | |
download | libquotient-025e5ab7d90ce8cf474567457301de32d5a3e34a.tar.gz libquotient-025e5ab7d90ce8cf474567457301de32d5a3e34a.zip |
Be stricter on usage of stateKey
A few places in the library dealt with state events without any notion
of state_key inside events, including StateEvent[Base] and relevant
functions in Room. A number of workarounds have been made; e.g.,
Room::setMemberState() accepted userId as a separate parameter, ignoring
the state key inside the RoomMemberEvent already passed to it, and
Room::setLocalAliases() had a bug in the initial version where the
function still tried to pass aliases in an event with an empty state
key. This commit fixes this shortcoming: StateEventBase now gets
stateKey as one more parameter, Room::Private::getCurrentState()
respects stateKey and returns properly constructed stub events, and
Room::setMemberState() gives way to a more generic Room::setState() that
works uniformly with whatever state event you pass to it.
Diffstat (limited to 'lib/events/simplestateevents.h')
-rw-r--r-- | lib/events/simplestateevents.h | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/events/simplestateevents.h b/lib/events/simplestateevents.h index 2c23d9ca..dc6a0868 100644 --- a/lib/events/simplestateevents.h +++ b/lib/events/simplestateevents.h @@ -20,8 +20,6 @@ #include "stateevent.h" -#include "converters.h" - namespace QMatrixClient { namespace EventContent @@ -63,7 +61,7 @@ namespace QMatrixClient explicit _Name() : _Name(value_type()) { } \ template <typename T> \ explicit _Name(T&& value) \ - : StateEvent(typeId(), matrixTypeId(), \ + : StateEvent(typeId(), matrixTypeId(), QString(), \ QStringLiteral(#_ContentKey), \ std::forward<T>(value)) \ { } \ @@ -78,9 +76,6 @@ namespace QMatrixClient DEFINE_SIMPLE_STATE_EVENT(RoomNameEvent, "m.room.name", QString, name) DEFINE_EVENTTYPE_ALIAS(RoomName, RoomNameEvent) - DEFINE_SIMPLE_STATE_EVENT(RoomAliasesEvent, "m.room.aliases", - QStringList, aliases) - DEFINE_EVENTTYPE_ALIAS(RoomAliases, RoomAliasesEvent) DEFINE_SIMPLE_STATE_EVENT(RoomCanonicalAliasEvent, "m.room.canonical_alias", QString, alias) DEFINE_EVENTTYPE_ALIAS(RoomCanonicalAlias, RoomCanonicalAliasEvent) @@ -89,4 +84,21 @@ namespace QMatrixClient DEFINE_SIMPLE_STATE_EVENT(EncryptionEvent, "m.room.encryption", QString, algorithm) DEFINE_EVENTTYPE_ALIAS(RoomEncryption, EncryptionEvent) + + class RoomAliasesEvent + : public StateEvent<EventContent::SimpleContent<QStringList>> + { + public: + DEFINE_EVENT_TYPEID("m.room.aliases", RoomAliasesEvent) + explicit RoomAliasesEvent(const QJsonObject& obj) + : StateEvent(typeId(), obj, QStringLiteral("aliases")) + { } + RoomAliasesEvent(const QString& server, const QStringList& aliases) + : StateEvent(typeId(), matrixTypeId(), server, + QStringLiteral("aliases"), aliases) + { } + QString server() const { return stateKey(); } + QStringList aliases() const { return content().value; } + }; + REGISTER_EVENT_TYPE(RoomAliasesEvent) } // namespace QMatrixClient |