From 0373153481e4a08f1dfb194e672188d74ce07d85 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 24 Dec 2019 11:26:11 +0300 Subject: RoomMemberEvent: introduce the reason field (MSC2367) See https://github.com/matrix-org/matrix-doc/pull/2367. Closes #370. --- lib/events/roommemberevent.cpp | 14 ++++++++++---- lib/events/roommemberevent.h | 7 +++++-- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'lib/events') diff --git a/lib/events/roommemberevent.cpp b/lib/events/roommemberevent.cpp index d0787170..d4b2be45 100644 --- a/lib/events/roommemberevent.cpp +++ b/lib/events/roommemberevent.cpp @@ -52,6 +52,7 @@ MemberEventContent::MemberEventContent(const QJsonObject& json) , isDirect(json["is_direct"_ls].toBool()) , displayName(sanitized(json["displayname"_ls].toString())) , avatarUrl(json["avatar_url"_ls].toString()) + , reason(json["reason"_ls].toString()) {} void MemberEventContent::fillJson(QJsonObject* o) const @@ -64,18 +65,23 @@ void MemberEventContent::fillJson(QJsonObject* o) const o->insert(QStringLiteral("displayname"), displayName); if (avatarUrl.isValid()) o->insert(QStringLiteral("avatar_url"), avatarUrl.toString()); + if (!reason.isEmpty()) + o->insert(QStringLiteral("reason"), reason); +} + +bool RoomMemberEvent::changesMembership() const +{ + return !prevContent() || prevContent()->membership != membership(); } bool RoomMemberEvent::isInvite() const { - return membership() == MembershipType::Invite - && (!prevContent() || prevContent()->membership != membership()); + return membership() == MembershipType::Invite && changesMembership(); } bool RoomMemberEvent::isJoin() const { - return membership() == MembershipType::Join - && (!prevContent() || prevContent()->membership != membership()); + return membership() == MembershipType::Join && changesMembership(); } bool RoomMemberEvent::isLeave() const diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h index 6a34fd7f..0ca439e1 100644 --- a/lib/events/roommemberevent.h +++ b/lib/events/roommemberevent.h @@ -40,6 +40,7 @@ public: bool isDirect = false; QString displayName; QUrl avatarUrl; + QString reason; protected: void fillJson(QJsonObject* o) const override; @@ -56,8 +57,8 @@ public: explicit RoomMemberEvent(const QJsonObject& obj) : StateEvent(typeId(), obj) {} - [[deprecated("Use RoomMemberEvent(userId, contentArgs) " - "instead")]] RoomMemberEvent(MemberEventContent&& c) + [[deprecated("Use RoomMemberEvent(userId, contentArgs) instead")]] + RoomMemberEvent(MemberEventContent&& c) : StateEvent(typeId(), matrixTypeId(), QString(), c) {} template @@ -85,6 +86,8 @@ public: bool isDirect() const { return content().isDirect; } QString displayName() const { return content().displayName; } QUrl avatarUrl() const { return content().avatarUrl; } + QString reason() const { return content().reason; } + bool changesMembership() const; bool isInvite() const; bool isJoin() const; bool isLeave() const; -- cgit v1.2.3