aboutsummaryrefslogtreecommitdiff
path: root/lib/events/roommemberevent.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events/roommemberevent.h')
-rw-r--r--lib/events/roommemberevent.h131
1 files changed, 54 insertions, 77 deletions
diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h
index db25d026..9f063136 100644
--- a/lib/events/roommemberevent.h
+++ b/lib/events/roommemberevent.h
@@ -1,89 +1,66 @@
-/******************************************************************************
- * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// SPDX-FileCopyrightText: 2015 Felix Rohrbach <kde@fxrh.de>
+// SPDX-FileCopyrightText: 2017 Kitsune Ral <Kitsune-Ral@users.sf.net>
+// SPDX-FileCopyrightText: 2019 Karol Kosek <krkkx@protonmail.com>
+// SPDX-License-Identifier: LGPL-2.1-or-later
#pragma once
#include "stateevent.h"
-#include "eventcontent.h"
+#include "quotient_common.h"
-namespace QMatrixClient
-{
- class MemberEventContent: public EventContent::Base
- {
- public:
- enum MembershipType : size_t { Invite = 0, Join, Knock, Leave, Ban,
- Undefined };
-
- explicit MemberEventContent(MembershipType mt = MembershipType::Join)
- : membership(mt)
- { }
- explicit MemberEventContent(const QJsonObject& json);
- explicit MemberEventContent(const QJsonValue& jv)
- : MemberEventContent(jv.toObject())
- { }
+namespace Quotient {
+class QUOTIENT_API MemberEventContent {
+public:
+ using MembershipType
+ [[deprecated("Use Quotient::Membership instead")]] = Membership;
- MembershipType membership;
- bool isDirect = false;
- QString displayName;
- QUrl avatarUrl;
+ QUO_IMPLICIT MemberEventContent(Membership ms) : membership(ms) {}
+ explicit MemberEventContent(const QJsonObject& json);
+ QJsonObject toJson() const;
- protected:
- void fillJson(QJsonObject* o) const override;
- };
+ Membership membership;
+ /// (Only for invites) Whether the invite is to a direct chat
+ bool isDirect = false;
+ Omittable<QString> displayName;
+ Omittable<QUrl> avatarUrl;
+ QString reason;
+};
- using MembershipType = MemberEventContent::MembershipType;
-
- class RoomMemberEvent: public StateEvent<MemberEventContent>
- {
- Q_GADGET
- public:
- DEFINE_EVENT_TYPEID("m.room.member", RoomMemberEvent)
+using MembershipType [[deprecated("Use Membership instead")]] = Membership;
- using MembershipType = MemberEventContent::MembershipType;
+class QUOTIENT_API RoomMemberEvent
+ : public KeyedStateEventBase<RoomMemberEvent, MemberEventContent> {
+ Q_GADGET
+public:
+ QUO_EVENT(RoomMemberEvent, "m.room.member")
- explicit RoomMemberEvent(const QJsonObject& obj)
- : StateEvent(typeId(), obj)
- { }
- RoomMemberEvent(MemberEventContent&& c)
- : StateEvent(typeId(), matrixTypeId(), c.toJson())
- { }
+ using MembershipType
+ [[deprecated("Use Quotient::Membership instead")]] = Membership;
- // This is a special constructor enabling RoomMemberEvent to be
- // a base class for more specific member events.
- RoomMemberEvent(Type type, const QJsonObject& fullJson)
- : StateEvent(type, fullJson)
- { }
+ using KeyedStateEventBase::KeyedStateEventBase;
- MembershipType membership() const { return content().membership; }
- QString userId() const
- { return fullJson()["state_key"_ls].toString(); }
- 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)
- };
- REGISTER_EVENT_TYPE(RoomMemberEvent)
- DEFINE_EVENTTYPE_ALIAS(RoomMember, RoomMemberEvent)
-} // namespace QMatrixClient
+ Membership membership() const { return content().membership; }
+ QString userId() const { return stateKey(); }
+ bool isDirect() const { return content().isDirect; }
+ Omittable<QString> newDisplayName() const { return content().displayName; }
+ Omittable<QUrl> newAvatarUrl() const { return content().avatarUrl; }
+ [[deprecated("Use newDisplayName() instead")]] QString displayName() const
+ {
+ return newDisplayName().value_or(QString());
+ }
+ [[deprecated("Use newAvatarUrl() instead")]] QUrl avatarUrl() const
+ {
+ return newAvatarUrl().value_or(QUrl());
+ }
+ QString reason() const { return content().reason; }
+ bool changesMembership() const;
+ bool isBan() const;
+ bool isUnban() const;
+ bool isInvite() const;
+ bool isRejectedInvite() const;
+ bool isJoin() const;
+ bool isLeave() const;
+ bool isRename() const;
+ bool isAvatarUpdate() const;
+};
+} // namespace Quotient