aboutsummaryrefslogtreecommitdiff
path: root/events
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-07 15:10:19 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-07 15:12:48 +0900
commitb7c1ff183384738f170d53128c684681cb34f3b7 (patch)
treeaf916b51d057c1edaacf32695609c155c0e4533e /events
parent6a9b1876bf8ebeca398c9c57ef90e01c25a7ada6 (diff)
downloadlibquotient-b7c1ff183384738f170d53128c684681cb34f3b7.tar.gz
libquotient-b7c1ff183384738f170d53128c684681cb34f3b7.zip
RoomEvent/RoomMemberEvent: do not store what can be calculated on the fly
Basically, segments of originalJsonObject() are used as-you-go instead of parsing them upon event creation.
Diffstat (limited to 'events')
-rw-r--r--events/event.cpp27
-rw-r--r--events/event.h14
-rw-r--r--events/roommemberevent.h7
3 files changed, 33 insertions, 15 deletions
diff --git a/events/event.cpp b/events/event.cpp
index c7345a13..7bc25a07 100644
--- a/events/event.cpp
+++ b/events/event.cpp
@@ -88,11 +88,12 @@ EventPtr _impl::doMakeEvent<Event>(const QJsonObject& obj)
RoomEvent::RoomEvent(Event::Type type) : Event(type) { }
RoomEvent::RoomEvent(Type type, const QJsonObject& rep)
- : Event(type, rep), _id(rep["event_id"].toString())
- , _roomId(rep["room_id"].toString())
- , _senderId(rep["sender"].toString())
- , _serverTimestamp(
- QMatrixClient::fromJson<QDateTime>(rep["origin_server_ts"]))
+ : Event(type, rep)
+ , _id(rep["event_id"].toString())
+// , _roomId(rep["room_id"].toString())
+// , _senderId(rep["sender"].toString())
+// , _serverTimestamp(
+// QMatrixClient::fromJson<QDateTime>(rep["origin_server_ts"]))
{
// if (_id.isEmpty())
// {
@@ -124,6 +125,22 @@ RoomEvent::RoomEvent(Type type, const QJsonObject& rep)
RoomEvent::~RoomEvent() = default; // Let the smart pointer do its job
+QDateTime RoomEvent::timestamp() const
+{
+ return QMatrixClient::fromJson<QDateTime>(
+ originalJsonObject().value("origin_server_ts"));
+}
+
+QString RoomEvent::roomId() const
+{
+ return originalJsonObject().value("room_id").toString();
+}
+
+QString RoomEvent::senderId() const
+{
+ return originalJsonObject().value("sender_id").toString();
+}
+
QString RoomEvent::redactionReason() const
{
return isRedacted() ? _redactedBecause->reason() : QString{};
diff --git a/events/event.h b/events/event.h
index b5a4d94e..968bc1ad 100644
--- a/events/event.h
+++ b/events/event.h
@@ -167,10 +167,10 @@ namespace QMatrixClient
RoomEvent(Type type, const QJsonObject& rep);
~RoomEvent();
- const QString& id() const { return _id; }
- const QDateTime& timestamp() const { return _serverTimestamp; }
- const QString& roomId() const { return _roomId; }
- const QString& senderId() const { return _senderId; }
+ QString id() const { return _id; }
+ QDateTime timestamp() const;
+ QString roomId() const;
+ QString senderId() const;
bool isRedacted() const { return bool(_redactedBecause); }
const RedactionEvent* redactedBecause() const
{
@@ -202,9 +202,9 @@ namespace QMatrixClient
private:
QString _id;
- QString _roomId;
- QString _senderId;
- QDateTime _serverTimestamp;
+// QString _roomId;
+// QString _senderId;
+// QDateTime _serverTimestamp;
event_ptr_tt<RedactionEvent> _redactedBecause;
QString _txnId;
};
diff --git a/events/roommemberevent.h b/events/roommemberevent.h
index d0c63f15..224f29c2 100644
--- a/events/roommemberevent.h
+++ b/events/roommemberevent.h
@@ -53,16 +53,17 @@ namespace QMatrixClient
explicit RoomMemberEvent(const QJsonObject& obj)
: StateEvent(Type::RoomMember, obj)
- , _userId(obj["state_key"].toString())
+// , _userId(obj["state_key"].toString())
{ }
MembershipType membership() const { return content().membership; }
- QString userId() const { return _userId; }
+ QString userId() const
+ { return originalJsonObject().value("state_key").toString(); }
QString displayName() const { return content().displayName; }
QUrl avatarUrl() const { return content().avatarUrl; }
private:
- QString _userId;
+// QString _userId;
REGISTER_ENUM(MembershipType)
};
} // namespace QMatrixClient