summary refs log tree commit diff
path: root/include/Utils.h
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-05 16:38:41 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-05 16:38:41 +0300
commited9501023ae57e668a930e5d3accbb47ad3d7812 (patch)
tree11d0150f0bd3bae0013e67cbd3e184b778e9946b /include/Utils.h
parentAdd compile option for address sanitizers (diff)
downloadnheko-ed9501023ae57e668a930e5d3accbb47ad3d7812.tar.xz
Add support for retrieving the notification events (#33)
Diffstat (limited to 'include/Utils.h')
-rw-r--r--include/Utils.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/Utils.h b/include/Utils.h

index c9dc460a..6fea4962 100644 --- a/include/Utils.h +++ b/include/Utils.h
@@ -32,6 +32,9 @@ firstChar(const QString &input); QString humanReadableFileSize(uint64_t bytes); +QString +event_body(const mtx::events::collections::TimelineEvents &event); + //! Match widgets/events with a description message. template<class T> QString @@ -131,6 +134,37 @@ erase_if(ContainerT &items, const PredicateT &predicate) } } +inline mtx::events::EventType +event_type(const mtx::events::collections::TimelineEvents &event) +{ + return mpark::visit([](auto msg) { return msg.type; }, event); +} + +inline std::string +event_id(const mtx::events::collections::TimelineEvents &event) +{ + return mpark::visit([](auto msg) { return msg.event_id; }, event); +} + +inline QString +eventId(const mtx::events::collections::TimelineEvents &event) +{ + return QString::fromStdString(event_id(event)); +} + +inline QString +event_sender(const mtx::events::collections::TimelineEvents &event) +{ + return mpark::visit([](auto msg) { return QString::fromStdString(msg.sender); }, event); +} + +template<class T> +QString +message_body(const mtx::events::collections::TimelineEvents &event) +{ + return QString::fromStdString(mpark::get<T>(event).content.body); +} + //! Calculate the Levenshtein distance between two strings with character skipping. int levenshtein_distance(const std::string &s1, const std::string &s2);