libQuotient
A Qt library for building matrix clients
roommemberevent.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2015 Felix Rohrbach <kde@fxrh.de>
2 // SPDX-FileCopyrightText: 2017 Kitsune Ral <Kitsune-Ral@users.sf.net>
3 // SPDX-FileCopyrightText: 2019 Karol Kosek <krkkx@protonmail.com>
4 // SPDX-License-Identifier: LGPL-2.1-or-later
5 
6 #pragma once
7 
8 #include "stateevent.h"
9 #include <Quotient/quotient_common.h>
10 
11 namespace Quotient {
12 class QUOTIENT_API MemberEventContent {
13 public:
14  Q_IMPLICIT MemberEventContent(Membership ms) : membership(ms) {}
15  explicit MemberEventContent(const QJsonObject& json);
16  QJsonObject toJson() const;
17 
18  Membership membership;
19  /// (Only for invites) Whether the invite is to a direct chat
20  bool isDirect = false;
21  std::optional<QString> displayName;
22  std::optional<QUrl> avatarUrl;
23  QString reason;
24 };
25 
26 class QUOTIENT_API RoomMemberEvent
27  : public KeyedStateEventBase<RoomMemberEvent, MemberEventContent> {
28  Q_GADGET
29 public:
30  QUO_EVENT(RoomMemberEvent, "m.room.member")
31 
32  static bool isValid(const QJsonObject& fullJson)
33  {
34  return !fullJson[StateKeyKey].toString().isEmpty();
35  }
36 
37  using KeyedStateEventBase::KeyedStateEventBase;
38 
39  Membership membership() const { return content().membership; }
40  QString userId() const { return stateKey(); }
41  bool isDirect() const { return content().isDirect; }
42  std::optional<QString> newDisplayName() const { return content().displayName; }
43  std::optional<QUrl> newAvatarUrl() const { return content().avatarUrl; }
44  QString reason() const { return content().reason; }
45  bool changesMembership() const;
46  bool isBan() const;
47  bool isUnban() const;
48  bool isInvite() const;
49  bool isRejectedInvite() const;
50  bool isJoin() const;
51  bool isLeave() const;
52  bool isRename() const;
53  bool isAvatarUpdate() const;
54 };
55 } // namespace Quotient