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 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/events/roommemberevent.cpp') 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; +} -- cgit v1.2.3