Skip to content

Commit

Permalink
RoomMemberEvent: a set of is*() facility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal committed Aug 6, 2018
1 parent 8bd8aaf commit c0e75a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/events/roommemberevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace QMatrixClient
return MembershipType::Undefined;
}
};

}

MemberEventContent::MemberEventContent(const QJsonObject& json)
Expand All @@ -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;
}
5 changes: 5 additions & 0 deletions lib/events/roommemberevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c0e75a5

Please sign in to comment.