From c0e75a52504a3d31bcca0d4c39745d4d6c1fe917 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 6 Aug 2018 12:01:22 +0900 Subject: RoomMemberEvent: a set of is*() facility methods --- lib/events/roommemberevent.cpp | 32 ++++++++++++++++++++++++++++++++ lib/events/roommemberevent.h | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/lib/events/roommemberevent.cpp b/lib/events/roommemberevent.cpp index 79e4af2d..eaa3302c 100644 --- a/lib/events/roommemberevent.cpp +++ b/lib/events/roommemberevent.cpp @@ -48,6 +48,7 @@ namespace QMatrixClient return MembershipType::Undefined; } }; + } MemberEventContent::MemberEventContent(const QJsonObject& json) @@ -68,3 +69,34 @@ void MemberEventContent::fillJson(QJsonObject* o) const if (avatarUrl.isValid()) o->insert(QStringLiteral("avatar_url"), avatarUrl.toString()); } + +bool RoomMemberEvent::isInvite() const +{ + return membership() == MembershipType::Invite && + (!prevContent() || prevContent()->membership != membership()); +} + +bool RoomMemberEvent::isJoin() const +{ + return membership() == MembershipType::Join && + (!prevContent() || prevContent()->membership != membership()); +} + +bool RoomMemberEvent::isLeave() const +{ + return membership() == MembershipType::Leave && + prevContent() && prevContent()->membership != membership() && + prevContent()->membership != MembershipType::Ban; +} + +bool RoomMemberEvent::isRename() const +{ + auto prevName = prevContent() ? prevContent()->displayName : QString(); + return displayName() != prevName; +} + +bool RoomMemberEvent::isAvatarUpdate() const +{ + auto prevAvatarUrl = prevContent() ? prevContent()->avatarUrl : QUrl(); + return avatarUrl() != prevAvatarUrl; +} diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h index f3e4f53a..db25d026 100644 --- a/lib/events/roommemberevent.h +++ b/lib/events/roommemberevent.h @@ -75,6 +75,11 @@ namespace QMatrixClient bool isDirect() const { return content().isDirect; } QString displayName() const { return content().displayName; } QUrl avatarUrl() const { return content().avatarUrl; } + bool isInvite() const; + bool isJoin() const; + bool isLeave() const; + bool isRename() const; + bool isAvatarUpdate() const; private: REGISTER_ENUM(MembershipType) -- cgit v1.2.3