Skip to content

Commit

Permalink
RoomMemberEvent: introduce the reason field (MSC2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal committed Dec 24, 2019
1 parent 79b9f6d commit 0373153
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lib/events/roommemberevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/events/roommemberevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MemberEventContent : public EventContent::Base {
bool isDirect = false;
QString displayName;
QUrl avatarUrl;
QString reason;

protected:
void fillJson(QJsonObject* o) const override;
Expand All @@ -56,8 +57,8 @@ class RoomMemberEvent : public StateEvent<MemberEventContent> {

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>
Expand Down Expand Up @@ -85,6 +86,8 @@ class RoomMemberEvent : public StateEvent<MemberEventContent> {
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;
Expand Down

0 comments on commit 0373153

Please sign in to comment.