From 581a6976eeb7c35930cb19e89eae0fd3bf11a785 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 24 Aug 2016 14:29:54 +0900 Subject: Move plain body from Base (former MessageEventContent) inside RoomMessageEvent According to the spec, this key has the same status as msgtype: both should exist in any message. Besides, it's always supposed to be a plain text so there's no polymorphism allowed here. --- events/roommessageevent.cpp | 10 ++++++++-- events/roommessageevent.h | 16 +++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'events') diff --git a/events/roommessageevent.cpp b/events/roommessageevent.cpp index 03e84444..a111ef12 100644 --- a/events/roommessageevent.cpp +++ b/events/roommessageevent.cpp @@ -31,6 +31,7 @@ class RoomMessageEvent::Private QString userId; MessageEventType msgtype; + QString plainBody; QDateTime hsob_ts; MessageEventContent::Base* content; }; @@ -57,9 +58,14 @@ MessageEventType RoomMessageEvent::msgtype() const return d->msgtype; } +QString RoomMessageEvent::plainBody() const +{ + return d->plainBody; +} + QString RoomMessageEvent::body() const { - return d->content->body; + return plainBody(); } QDateTime RoomMessageEvent::hsob_ts() const @@ -179,7 +185,7 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj) if( content.contains("body") ) { - e->d->content->body = content.value("body").toString(); + e->d->plainBody = content.value("body").toString(); } else { qDebug() << "RoomMessageEvent: body not found"; } diff --git a/events/roommessageevent.h b/events/roommessageevent.h index 219f74f0..27cf5fd8 100644 --- a/events/roommessageevent.h +++ b/events/roommessageevent.h @@ -32,11 +32,7 @@ namespace QMatrixClient namespace MessageEventContent { - class Base - { - public: - QString body; - }; + class Base { }; } class RoomMessageEvent: public Event @@ -47,7 +43,17 @@ namespace QMatrixClient QString userId() const; MessageEventType msgtype() const; + + QString plainBody() const; + + /** + * Same as plainBody() for now; might change for "best-looking body" + * in the future. For richer contents, use content-specific data. + * + * @deprecated + */ QString body() const; + QDateTime hsob_ts() const; MessageEventContent::Base* content() const; -- cgit v1.2.3