From ed9501023ae57e668a930e5d3accbb47ad3d7812 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 5 May 2018 16:38:41 +0300 Subject: Add support for retrieving the notification events (#33) --- include/Utils.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'include/Utils.h') 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 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 +QString +message_body(const mtx::events::collections::TimelineEvents &event) +{ + return QString::fromStdString(mpark::get(event).content.body); +} + //! Calculate the Levenshtein distance between two strings with character skipping. int levenshtein_distance(const std::string &s1, const std::string &s2); -- cgit 1.5.1