diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-11-28 12:42:03 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-11-28 12:42:03 +0900 |
commit | 357625eb55e2f4569bb487ffe14a9236188e25f3 (patch) | |
tree | d39340ab74f25a23a5855f679973628f7457fd87 /events/roommemberevent.cpp | |
parent | 94e6636d8225a0561ed7df3fa8081c5b0183610c (diff) | |
parent | 8f762a2458db773f6db24b568b2e944427297c2b (diff) | |
download | libquotient-357625eb55e2f4569bb487ffe14a9236188e25f3.tar.gz libquotient-357625eb55e2f4569bb487ffe14a9236188e25f3.zip |
Merge branch 'master' into kitsune-gtad
Diffstat (limited to 'events/roommemberevent.cpp')
-rw-r--r-- | events/roommemberevent.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/events/roommemberevent.cpp b/events/roommemberevent.cpp index 19f116d2..76df5f2e 100644 --- a/events/roommemberevent.cpp +++ b/events/roommemberevent.cpp @@ -20,23 +20,45 @@ #include "logging.h" +#include <array> + using namespace QMatrixClient; -static const auto membershipStrings = - { "invite", "join", "knock", "leave", "ban" }; +static const std::array<QString, 5> membershipStrings = { { + QStringLiteral("invite"), QStringLiteral("join"), + QStringLiteral("knock"), QStringLiteral("leave"), + QStringLiteral("ban") +} }; -RoomMemberEvent::RoomMemberEvent(const QJsonObject& obj) - : RoomEvent(Type::RoomMember, obj), _userId(obj["state_key"].toString()) +namespace QMatrixClient { - const auto contentObj = contentJson(); - _displayName = contentObj["displayname"].toString(); - _avatarUrl = contentObj["avatar_url"].toString(); - QString membershipString = contentObj["membership"].toString(); - for (auto it = membershipStrings.begin(); it != membershipStrings.end(); ++it) - if (membershipString == *it) + template <> + struct FromJson<MembershipType> + { + MembershipType operator()(const QJsonValue& jv) const { - _membership = MembershipType(it - membershipStrings.begin()); - return; + const auto& membershipString = jv.toString(); + for (auto it = membershipStrings.begin(); + it != membershipStrings.end(); ++it) + if (membershipString == *it) + return MembershipType(it - membershipStrings.begin()); + + qCWarning(EVENTS) << "Unknown MembershipType: " << membershipString; + return MembershipType::Join; } - qCWarning(EVENTS) << "Unknown MembershipType: " << membershipString; + }; +} + +MemberEventContent::MemberEventContent(const QJsonObject& json) + : membership(fromJson<MembershipType>(json["membership"])) + , displayName(json["displayname"].toString()) + , avatarUrl(json["avatar_url"].toString()) +{ } + +void MemberEventContent::fillJson(QJsonObject* o) const +{ + Q_ASSERT(o); + o->insert("membership", membershipStrings[membership]); + o->insert("displayname", displayName); + o->insert("avatar_url", avatarUrl.toString()); } |