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.h115
1 files changed, 33 insertions, 82 deletions
diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h
index 783b8207..9f063136 100644
--- a/lib/events/roommemberevent.h
+++ b/lib/events/roommemberevent.h
@@ -1,91 +1,57 @@
-/******************************************************************************
- * 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 "eventcontent.h"
#include "stateevent.h"
+#include "quotient_common.h"
namespace Quotient {
-class MemberEventContent : public EventContent::Base {
+class QUOTIENT_API MemberEventContent {
public:
- enum MembershipType : size_t {
- Invite = 0,
- Join,
- Knock,
- Leave,
- Ban,
- Undefined
- };
+ using MembershipType
+ [[deprecated("Use Quotient::Membership instead")]] = Membership;
- explicit MemberEventContent(MembershipType mt = Join) : membership(mt) {}
+ QUO_IMPLICIT MemberEventContent(Membership ms) : membership(ms) {}
explicit MemberEventContent(const QJsonObject& json);
+ QJsonObject toJson() const;
- MembershipType membership;
+ Membership membership;
+ /// (Only for invites) Whether the invite is to a direct chat
bool isDirect = false;
- QString displayName;
- QUrl avatarUrl;
+ Omittable<QString> displayName;
+ Omittable<QUrl> avatarUrl;
QString reason;
-
-protected:
- void fillJson(QJsonObject* o) const override;
};
-using MembershipType = MemberEventContent::MembershipType;
+using MembershipType [[deprecated("Use Membership instead")]] = Membership;
-class RoomMemberEvent : public StateEvent<MemberEventContent> {
+class QUOTIENT_API RoomMemberEvent
+ : public KeyedStateEventBase<RoomMemberEvent, MemberEventContent> {
Q_GADGET
public:
- DEFINE_EVENT_TYPEID("m.room.member", RoomMemberEvent)
-
- using MembershipType = MemberEventContent::MembershipType;
+ QUO_EVENT(RoomMemberEvent, "m.room.member")
- explicit RoomMemberEvent(const QJsonObject& obj) : StateEvent(typeId(), obj)
- {}
- [[deprecated("Use RoomMemberEvent(userId, contentArgs) instead")]]
- RoomMemberEvent(MemberEventContent&& c)
- : StateEvent(typeId(), matrixTypeId(), QString(), c)
- {}
- template <typename... ArgTs>
- RoomMemberEvent(const QString& userId, ArgTs&&... contentArgs)
- : StateEvent(typeId(), matrixTypeId(), userId,
- std::forward<ArgTs>(contentArgs)...)
- {}
+ using MembershipType
+ [[deprecated("Use Quotient::Membership instead")]] = Membership;
- /// A special constructor to create unknown RoomMemberEvents
- /**
- * This is needed in order to use RoomMemberEvent as a "base event
- * class" in cases like GetMembersByRoomJob when RoomMemberEvents
- * (rather than RoomEvents or StateEvents) are resolved from JSON.
- * For such cases loadEvent<> requires an underlying class to be
- * constructible with unknownTypeId() instead of its genuine id.
- * Don't use it directly.
- * \sa GetMembersByRoomJob, loadEvent, unknownTypeId
- */
- RoomMemberEvent(Type type, const QJsonObject& fullJson)
- : StateEvent(type, fullJson)
- {}
+ using KeyedStateEventBase::KeyedStateEventBase;
- MembershipType membership() const { return content().membership; }
- QString userId() const { return fullJson()[StateKeyKeyL].toString(); }
+ Membership membership() const { return content().membership; }
+ QString userId() const { return stateKey(); }
bool isDirect() const { return content().isDirect; }
- QString displayName() const { return content().displayName; }
- QUrl avatarUrl() const { return content().avatarUrl; }
+ 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;
@@ -96,20 +62,5 @@ public:
bool isLeave() const;
bool isRename() const;
bool isAvatarUpdate() const;
-
-private:
- Q_ENUM(MembershipType)
};
-
-template <>
-class EventFactory<RoomMemberEvent> {
-public:
- static event_ptr_tt<RoomMemberEvent> make(const QJsonObject& json,
- const QString&)
- {
- return makeEvent<RoomMemberEvent>(json);
- }
-};
-
-REGISTER_EVENT_TYPE(RoomMemberEvent)
} // namespace Quotient