aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/events/callanswerevent.cpp5
-rw-r--r--lib/events/callhangupevent.cpp5
-rw-r--r--lib/events/callinviteevent.cpp5
-rw-r--r--lib/events/encryptedevent.cpp3
-rw-r--r--lib/events/encryptionevent.h4
-rw-r--r--lib/events/event.h12
-rw-r--r--lib/events/reactionevent.h3
-rw-r--r--lib/events/receiptevent.cpp12
-rw-r--r--lib/events/receiptevent.h10
-rw-r--r--lib/events/roomcanonicalaliasevent.h4
-rw-r--r--lib/events/roomevent.cpp5
-rw-r--r--lib/events/roomkeyevent.h2
-rw-r--r--lib/events/roommemberevent.h10
-rw-r--r--lib/events/typingevent.cpp8
-rw-r--r--lib/events/typingevent.h7
-rw-r--r--lib/room.cpp11
16 files changed, 27 insertions, 79 deletions
diff --git a/lib/events/callanswerevent.cpp b/lib/events/callanswerevent.cpp
index d6622b30..bf096534 100644
--- a/lib/events/callanswerevent.cpp
+++ b/lib/events/callanswerevent.cpp
@@ -18,11 +18,6 @@
#include "callanswerevent.h"
-#include "event.h"
-#include "logging.h"
-
-#include <QtCore/QJsonDocument>
-
/*
m.call.answer
{
diff --git a/lib/events/callhangupevent.cpp b/lib/events/callhangupevent.cpp
index d41849c3..f2117f38 100644
--- a/lib/events/callhangupevent.cpp
+++ b/lib/events/callhangupevent.cpp
@@ -18,11 +18,6 @@
#include "callhangupevent.h"
-#include "event.h"
-#include "logging.h"
-
-#include <QtCore/QJsonDocument>
-
/*
m.call.hangup
{
diff --git a/lib/events/callinviteevent.cpp b/lib/events/callinviteevent.cpp
index 54faac8d..63f331de 100644
--- a/lib/events/callinviteevent.cpp
+++ b/lib/events/callinviteevent.cpp
@@ -18,11 +18,6 @@
#include "callinviteevent.h"
-#include "event.h"
-#include "logging.h"
-
-#include <QtCore/QJsonDocument>
-
/*
m.call.invite
{
diff --git a/lib/events/encryptedevent.cpp b/lib/events/encryptedevent.cpp
index dccfa540..117aae37 100644
--- a/lib/events/encryptedevent.cpp
+++ b/lib/events/encryptedevent.cpp
@@ -1,9 +1,6 @@
#include "encryptedevent.h"
-#include "room.h"
-
using namespace Quotient;
-using namespace QtOlm;
EncryptedEvent::EncryptedEvent(const QJsonObject& ciphertext,
const QString& senderKey)
diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h
index cbd3ba4a..cbb6d786 100644
--- a/lib/events/encryptionevent.h
+++ b/lib/events/encryptionevent.h
@@ -48,6 +48,7 @@ public:
DEFINE_EVENT_TYPEID("m.room.encryption", EncryptionEvent)
using EncryptionType = EncryptionEventContent::EncryptionType;
+ Q_ENUM(EncryptionType)
explicit EncryptionEvent(const QJsonObject& obj = {}) // TODO: apropriate
// default value
@@ -64,9 +65,6 @@ public:
QString algorithm() const { return content().algorithm; }
int rotationPeriodMs() const { return content().rotationPeriodMs; }
int rotationPeriodMsgs() const { return content().rotationPeriodMsgs; }
-
-private:
- Q_ENUM(EncryptionType)
};
REGISTER_EVENT_TYPE(EncryptionEvent)
diff --git a/lib/events/event.h b/lib/events/event.h
index b12dc9ad..626a0229 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -21,10 +21,6 @@
#include "converters.h"
#include "logging.h"
-#ifdef ENABLE_EVENTTYPE_ALIAS
-# define USE_EVENTTYPE_ALIAS 1
-#endif
-
namespace Quotient {
// === event_ptr_tt<> and type casting facilities ===
@@ -45,14 +41,6 @@ inline TargetEventT* weakPtrCast(const event_ptr_tt<EventT>& ptr)
return static_cast<TargetEventT*>(rawPtr(ptr));
}
-/// Re-wrap a smart pointer to base into a smart pointer to derived
-template <typename TargetT, typename SourceT>
-[[deprecated("Consider using eventCast() or visit() instead")]]
-inline event_ptr_tt<TargetT> ptrCast(event_ptr_tt<SourceT>&& ptr)
-{
- return std::unique_ptr<TargetT>(static_cast<TargetT*>(ptr.release()));
-}
-
// === Standard Matrix key names and basicEventJson() ===
static const auto TypeKey = QStringLiteral("type");
diff --git a/lib/events/reactionevent.h b/lib/events/reactionevent.h
index 75c6528c..48b0bc6c 100644
--- a/lib/events/reactionevent.h
+++ b/lib/events/reactionevent.h
@@ -64,9 +64,6 @@ public:
{
return content<EventRelation>(QStringLiteral("m.relates_to"));
}
-
-private:
- EventRelation _relation;
};
REGISTER_EVENT_TYPE(ReactionEvent)
diff --git a/lib/events/receiptevent.cpp b/lib/events/receiptevent.cpp
index bf050cb2..deb3c4e8 100644
--- a/lib/events/receiptevent.cpp
+++ b/lib/events/receiptevent.cpp
@@ -40,10 +40,11 @@ Example of a Receipt Event:
using namespace Quotient;
-ReceiptEvent::ReceiptEvent(const QJsonObject& obj) : Event(typeId(), obj)
+EventsWithReceipts ReceiptEvent::eventsWithReceipts() const
{
+ EventsWithReceipts result;
const auto& contents = contentJson();
- _eventsWithReceipts.reserve(contents.size());
+ result.reserve(contents.size());
for (auto eventIt = contents.begin(); eventIt != contents.end(); ++eventIt) {
if (eventIt.key().isEmpty()) {
qCWarning(EPHEMERAL)
@@ -51,15 +52,16 @@ ReceiptEvent::ReceiptEvent(const QJsonObject& obj) : Event(typeId(), obj)
qCDebug(EPHEMERAL) << "ReceiptEvent content follows:\n" << contents;
continue;
}
- const QJsonObject reads =
+ const auto reads =
eventIt.value().toObject().value("m.read"_ls).toObject();
QVector<Receipt> receipts;
receipts.reserve(reads.size());
for (auto userIt = reads.begin(); userIt != reads.end(); ++userIt) {
- const QJsonObject user = userIt.value().toObject();
+ const auto user = userIt.value().toObject();
receipts.push_back(
{ userIt.key(), fromJson<QDateTime>(user["ts"_ls]) });
}
- _eventsWithReceipts.push_back({ eventIt.key(), std::move(receipts) });
+ result.push_back({ eventIt.key(), std::move(receipts) });
}
+ return result;
}
diff --git a/lib/events/receiptevent.h b/lib/events/receiptevent.h
index dd54a476..b7adea44 100644
--- a/lib/events/receiptevent.h
+++ b/lib/events/receiptevent.h
@@ -37,15 +37,9 @@ using EventsWithReceipts = QVector<ReceiptsForEvent>;
class ReceiptEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.receipt", ReceiptEvent)
- explicit ReceiptEvent(const QJsonObject& obj);
+ explicit ReceiptEvent(const QJsonObject& obj) : Event(typeId(), obj) {}
- const EventsWithReceipts& eventsWithReceipts() const
- {
- return _eventsWithReceipts;
- }
-
-private:
- EventsWithReceipts _eventsWithReceipts;
+ EventsWithReceipts eventsWithReceipts() const;
};
REGISTER_EVENT_TYPE(ReceiptEvent)
} // namespace Quotient
diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h
index fadfece0..4a21b7cc 100644
--- a/lib/events/roomcanonicalaliasevent.h
+++ b/lib/events/roomcanonicalaliasevent.h
@@ -61,13 +61,13 @@ public:
explicit RoomCanonicalAliasEvent(const QString& canonicalAlias,
const QStringList& altAliases = {})
- : StateEvent(typeId(), matrixTypeId(), QString(),
+ : StateEvent(typeId(), matrixTypeId(), {},
canonicalAlias, altAliases)
{ }
explicit RoomCanonicalAliasEvent(QString&& canonicalAlias,
QStringList&& altAliases = {})
- : StateEvent(typeId(), matrixTypeId(), QString(),
+ : StateEvent(typeId(), matrixTypeId(), {},
std::move(canonicalAlias), std::move(altAliases))
{ }
diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp
index 3d87ef18..a2dbc07d 100644
--- a/lib/events/roomevent.cpp
+++ b/lib/events/roomevent.cpp
@@ -34,9 +34,8 @@ RoomEvent::RoomEvent(Type type, event_mtype_t matrixType,
RoomEvent::RoomEvent(Type type, const QJsonObject& json) : Event(type, json)
{
- const auto unsignedData = json[UnsignedKeyL].toObject();
- const auto redaction = unsignedData[RedactedCauseKeyL];
- if (redaction.isObject())
+ if (const auto redaction = unsignedJson()[RedactedCauseKeyL];
+ redaction.isObject())
_redactedBecause = makeEvent<RedactionEvent>(redaction.toObject());
}
diff --git a/lib/events/roomkeyevent.h b/lib/events/roomkeyevent.h
index 3a781474..b8cd2eae 100644
--- a/lib/events/roomkeyevent.h
+++ b/lib/events/roomkeyevent.h
@@ -8,7 +8,7 @@ class RoomKeyEvent : public Event
public:
DEFINE_EVENT_TYPEID("m.room_key", RoomKeyEvent)
- RoomKeyEvent(const QJsonObject& obj);
+ explicit RoomKeyEvent(const QJsonObject& obj);
QString algorithm() const { return content<QString>("algorithm"_ls); }
QString roomId() const { return content<QString>(RoomIdKeyL); }
diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h
index 35fd69a9..cebaaf10 100644
--- a/lib/events/roommemberevent.h
+++ b/lib/events/roommemberevent.h
@@ -54,13 +54,10 @@ public:
DEFINE_EVENT_TYPEID("m.room.member", RoomMemberEvent)
using MembershipType = MemberEventContent::MembershipType;
+ Q_ENUM(MembershipType)
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,
@@ -82,7 +79,7 @@ public:
{}
MembershipType membership() const { return content().membership; }
- QString userId() const { return fullJson()[StateKeyKeyL].toString(); }
+ 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; }
@@ -104,9 +101,6 @@ public:
bool isLeave() const;
bool isRename() const;
bool isAvatarUpdate() const;
-
-private:
- Q_ENUM(MembershipType)
};
template <>
diff --git a/lib/events/typingevent.cpp b/lib/events/typingevent.cpp
index 0c5fc6ba..e102fc79 100644
--- a/lib/events/typingevent.cpp
+++ b/lib/events/typingevent.cpp
@@ -18,13 +18,9 @@
#include "typingevent.h"
-#include <QtCore/QJsonArray>
-
using namespace Quotient;
-TypingEvent::TypingEvent(const QJsonObject& obj) : Event(typeId(), obj)
+QStringList TypingEvent::users() const
{
- const auto& array = contentJson()["user_ids"_ls].toArray();
- for (const auto& user : array)
- _users.push_back(user.toString());
+ return fromJson<QStringList>(contentJson()["user_ids"_ls]);
}
diff --git a/lib/events/typingevent.h b/lib/events/typingevent.h
index 1cf4e69d..97e1f9cc 100644
--- a/lib/events/typingevent.h
+++ b/lib/events/typingevent.h
@@ -25,12 +25,9 @@ class TypingEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.typing", TypingEvent)
- TypingEvent(const QJsonObject& obj);
+ explicit TypingEvent(const QJsonObject& obj) : Event(typeId(), obj) {}
- const QStringList& users() const { return _users; }
-
-private:
- QStringList _users;
+ QStringList users() const;
};
REGISTER_EVENT_TYPE(TypingEvent)
} // namespace Quotient
diff --git a/lib/room.cpp b/lib/room.cpp
index 3b5a80a4..7ac3463e 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -2073,7 +2073,7 @@ RoomEventPtr makeRedacted(const RoomEvent& target,
QStringLiteral("membership") };
// clang-format on
- std::vector<std::pair<Event::Type, QStringList>> keepContentKeysMap {
+ std::vector<std::pair<event_type_t, QStringList>> keepContentKeysMap {
{ RoomMemberEvent::typeId(), { QStringLiteral("membership") } },
{ RoomCreateEvent::typeId(), { QStringLiteral("creator") } },
{ RoomPowerLevelsEvent::typeId(),
@@ -2621,7 +2621,7 @@ Room::Changes Room::processEphemeralEvent(EventPtr&& event)
et.start();
if (auto* evt = eventCast<TypingEvent>(event)) {
d->usersTyping.clear();
- for (const QString& userId : qAsConst(evt->users())) {
+ for (const auto& userId : evt->users()) {
auto u = user(userId);
if (memberJoinState(u) == JoinState::Join)
d->usersTyping.append(u);
@@ -2633,7 +2633,8 @@ Room::Changes Room::processEphemeralEvent(EventPtr&& event)
}
if (auto* evt = eventCast<ReceiptEvent>(event)) {
int totalReceipts = 0;
- for (const auto& p : qAsConst(evt->eventsWithReceipts())) {
+ const auto& eventsWithReceipts = evt->eventsWithReceipts();
+ for (const auto& p : eventsWithReceipts) {
totalReceipts += p.receipts.size();
{
if (p.receipts.size() == 1)
@@ -2669,11 +2670,11 @@ Room::Changes Room::processEphemeralEvent(EventPtr&& event)
}
}
}
- if (evt->eventsWithReceipts().size() > 3 || totalReceipts > 10
+ if (eventsWithReceipts.size() > 3 || totalReceipts > 10
|| et.nsecsElapsed() >= profilerMinNsecs())
qCDebug(PROFILER)
<< "*** Room::processEphemeralEvent(receipts):"
- << evt->eventsWithReceipts().size() << "event(s) with"
+ << eventsWithReceipts.size() << "event(s) with"
<< totalReceipts << "receipt(s)," << et;
}
return changes;