diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-11-27 20:14:53 +0100 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-11-27 20:14:53 +0100 |
commit | 0425fd280e7eee7a4c9bcf18f79910f181322c42 (patch) | |
tree | ec8e044711866266d38fc8c78f6e7ece8cf447d4 /lib/events/event.h | |
parent | 0a46049ef26270933ecf6fea7395b03e6aee783e (diff) | |
download | libquotient-0425fd280e7eee7a4c9bcf18f79910f181322c42.tar.gz libquotient-0425fd280e7eee7a4c9bcf18f79910f181322c42.zip |
Event::content() -> contentPart()
There's a clash between Event::content() (a template function) and
RoomMessageEvent::content() (plain member). Out of these two, the name
more fits to the RME's member function - strictly speaking,
Event::content() retrieves a part of content, and so is renamed.
In addition, contentPart() defaults to QJsonValue now, which is pretty
intuitive (the function returns values from a JSON object) and allows
to implement more elaborate logic such as
if (const auto v = contentPart<>("key"_ls); v.isObject()) {
// foo
} else if (v.isString()) {
// bar
} else {
// boo
}
Diffstat (limited to 'lib/events/event.h')
-rw-r--r-- | lib/events/event.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/events/event.h b/lib/events/event.h index 89efb7f8..024e45ef 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -224,18 +224,25 @@ public: const QJsonObject contentJson() const; const QJsonObject unsignedJson() const; - template <typename T> - T content(const QString& key) const + template <typename T = QJsonValue> + const T contentPart(const QString& key) const { return fromJson<T>(contentJson()[key]); } - template <typename T> - T content(QLatin1String key) const + template <typename T = QJsonValue> + const T contentPart(QLatin1String key) const { return fromJson<T>(contentJson()[key]); } + template <typename T> + [[deprecated("Use contentPart() to get a part of the event content")]] // + T content(const QString& key) const + { + return contentPart<T>(key); + } + friend QDebug operator<<(QDebug dbg, const Event& e) { QDebugStateSaver _dss { dbg }; |