aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-25 19:42:13 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-25 19:42:13 +0900
commit8590054a675bc5d2b07fff1acbb084d67c068113 (patch)
treeae831ca83e798d404f308be21dd799ca8d23335d
parentcb54a2a5f9e83a5076eb501e60e88846a4aa28df (diff)
downloadlibquotient-8590054a675bc5d2b07fff1acbb084d67c068113.tar.gz
libquotient-8590054a675bc5d2b07fff1acbb084d67c068113.zip
StateEvent<>: introduce Prev structure and prevSenderId() accessor
Also switch prev_content() from accidental snake case to camel case (old name still provided for compatibility).
-rw-r--r--events/event.h28
1 files changed, 23 insertions, 5 deletions
diff --git a/events/event.h b/events/event.h
index 6ed5ba49..b5a4d94e 100644
--- a/events/event.h
+++ b/events/event.h
@@ -256,6 +256,21 @@ namespace QMatrixClient
};
template <typename ContentT>
+ struct Prev
+ {
+ template <typename... ContentParamTs>
+ explicit Prev(const QJsonObject& unsignedJson,
+ ContentParamTs&&... contentParams)
+ : senderId(unsignedJson.value("prev_sender").toString())
+ , content(unsignedJson.value("prev_content").toObject(),
+ std::forward<ContentParamTs>(contentParams)...)
+ { }
+
+ QString senderId;
+ ContentT content;
+ };
+
+ template <typename ContentT>
class StateEvent: public StateEventBase
{
public:
@@ -270,9 +285,8 @@ namespace QMatrixClient
{
auto unsignedData = obj.value("unsigned").toObject();
if (unsignedData.contains("prev_content"))
- _prev.reset(new ContentT(
- unsignedData.value("prev_content").toObject(),
- std::forward<ContentParamTs>(contentParams)...));
+ _prev = std::make_unique<Prev<ContentT>>(unsignedData,
+ std::forward<ContentParamTs>(contentParams)...);
}
template <typename... ContentParamTs>
explicit StateEvent(Type type, ContentParamTs&&... contentParams)
@@ -283,11 +297,15 @@ namespace QMatrixClient
QJsonObject toJson() const { return _content.toJson(); }
ContentT content() const { return _content; }
- ContentT* prev_content() const { return _prev.data(); }
+ /** @deprecated Use prevContent instead */
+ ContentT* prev_content() const { return prevContent(); }
+ ContentT* prevContent() const
+ { return _prev ? &_prev->content : nullptr; }
+ QString prevSenderId() const { return _prev ? _prev->senderId : ""; }
protected:
ContentT _content;
- QScopedPointer<ContentT> _prev;
+ std::unique_ptr<Prev<ContentT>> _prev;
};
} // namespace QMatrixClient
Q_DECLARE_METATYPE(QMatrixClient::Event*)