aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-12-24 11:26:11 +0300
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-12-24 11:26:11 +0300
commit0373153481e4a08f1dfb194e672188d74ce07d85 (patch)
tree4527748fdc738ce71bfc18b6e063e9a150528649
parent79b9f6d928cbd516a610d845891f4054df05e0c4 (diff)
downloadlibquotient-0373153481e4a08f1dfb194e672188d74ce07d85.tar.gz
libquotient-0373153481e4a08f1dfb194e672188d74ce07d85.zip
RoomMemberEvent: introduce the reason field (MSC2367)
See https://github.com/matrix-org/matrix-doc/pull/2367. Closes #370.
-rw-r--r--lib/events/roommemberevent.cpp14
-rw-r--r--lib/events/roommemberevent.h7
2 files changed, 15 insertions, 6 deletions
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 <typename... ArgTs>
@@ -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;