summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-05-30 16:37:51 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-05-30 16:38:11 +0200
commit9eddcfc42f3cd4e513f72d9b7fef9a98b43a378d (patch)
tree565f982881fdefdf8b2f3a0cfea14b4064863a99
parentTranslated using Weblate (Italian) (diff)
downloadnheko-9eddcfc42f3cd4e513f72d9b7fef9a98b43a378d.tar.xz
Remove some redundant functions
-rw-r--r--src/Cache.cpp14
-rw-r--r--src/ChatPage.cpp6
-rw-r--r--src/EventAccessors.cpp6
-rw-r--r--src/EventAccessors.h3
-rw-r--r--src/Utils.h36
-rw-r--r--src/popups/UserMentions.cpp11
-rw-r--r--src/timeline/TimelineModel.cpp4
7 files changed, 30 insertions, 50 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 1061e60e..009cbabc 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -31,6 +31,7 @@
 
 #include "Cache.h"
 #include "Cache_p.h"
+#include "EventAccessors.h"
 #include "Logging.h"
 #include "Utils.h"
 
@@ -1947,13 +1948,14 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
 
                 json obj = json::object();
 
-                obj["event"] = utils::serialize_event(e);
+                obj["event"] = mtx::accessors::serialize_event(e);
                 obj["token"] = res.prev_batch;
 
-                lmdb::dbi_put(txn,
-                              db,
-                              lmdb::val(std::to_string(utils::event_timestamp(e))),
-                              lmdb::val(obj.dump()));
+                lmdb::dbi_put(
+                  txn,
+                  db,
+                  lmdb::val(std::to_string(obj["event"]["origin_server_ts"].get<uint64_t>())),
+                  lmdb::val(obj.dump()));
         }
 }
 
@@ -2026,7 +2028,7 @@ Cache::saveTimelineMentions(lmdb::txn &txn,
         using namespace mtx::events::state;
 
         for (const auto &notif : res) {
-                const auto event_id = utils::event_id(notif.event);
+                const auto event_id = mtx::accessors::event_id(notif.event);
 
                 // double check that we have the correct room_id...
                 if (room_id.compare(notif.room_id) != 0) {
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 2b55b91e..c7f5164a 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -26,6 +26,7 @@
 #include "Cache.h"
 #include "Cache_p.h"
 #include "ChatPage.h"
+#include "EventAccessors.h"
 #include "Logging.h"
 #include "MainWindow.h"
 #include "MatrixClient.h"
@@ -885,7 +886,7 @@ void
 ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
 {
         for (const auto &item : res.notifications) {
-                const auto event_id = utils::event_id(item.event);
+                const auto event_id = mtx::accessors::event_id(item.event);
 
                 try {
                         if (item.read) {
@@ -895,7 +896,8 @@ ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
 
                         if (!cache::isNotificationSent(event_id)) {
                                 const auto room_id = QString::fromStdString(item.room_id);
-                                const auto user_id = utils::event_sender(item.event);
+                                const auto user_id =
+                                  QString::fromStdString(mtx::accessors::sender(item.event));
 
                                 // We should only sent one notification per event.
                                 cache::markSentNotification(event_id);
diff --git a/src/EventAccessors.cpp b/src/EventAccessors.cpp
index 7f28eb46..da4e324a 100644
--- a/src/EventAccessors.cpp
+++ b/src/EventAccessors.cpp
@@ -400,3 +400,9 @@ mtx::accessors::media_width(const mtx::events::collections::TimelineEvents &even
 {
         return std::visit(EventMediaWidth{}, event);
 }
+
+nlohmann::json
+mtx::accessors::serialize_event(const mtx::events::collections::TimelineEvents &event)
+{
+        return std::visit([](const auto &e) { return nlohmann::json{e}; }, event);
+}
diff --git a/src/EventAccessors.h b/src/EventAccessors.h
index c9ac4d00..a7577d86 100644
--- a/src/EventAccessors.h
+++ b/src/EventAccessors.h
@@ -63,4 +63,7 @@ media_height(const mtx::events::collections::TimelineEvents &event);
 
 uint64_t
 media_width(const mtx::events::collections::TimelineEvents &event);
+
+nlohmann::json
+serialize_event(const mtx::events::collections::TimelineEvents &event);
 }
diff --git a/src/Utils.h b/src/Utils.h
index 80f2aa70..07a4a648 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -186,42 +186,6 @@ erase_if(ContainerT &items, const PredicateT &predicate)
         }
 }
 
-inline uint64_t
-event_timestamp(const mtx::events::collections::TimelineEvents &event)
-{
-        return std::visit([](auto msg) { return msg.origin_server_ts; }, event);
-}
-
-inline nlohmann::json
-serialize_event(const mtx::events::collections::TimelineEvents &event)
-{
-        return std::visit([](auto msg) { return json(msg); }, event);
-}
-
-inline mtx::events::EventType
-event_type(const mtx::events::collections::TimelineEvents &event)
-{
-        return std::visit([](auto msg) { return msg.type; }, event);
-}
-
-inline std::string
-event_id(const mtx::events::collections::TimelineEvents &event)
-{
-        return std::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 std::visit([](auto msg) { return QString::fromStdString(msg.sender); }, event);
-}
-
 template<class T>
 QString
 message_body(const mtx::events::collections::TimelineEvents &event)
diff --git a/src/popups/UserMentions.cpp b/src/popups/UserMentions.cpp
index 2e70dbd3..23a679f1 100644
--- a/src/popups/UserMentions.cpp
+++ b/src/popups/UserMentions.cpp
@@ -8,9 +8,9 @@
 
 #include "Cache.h"
 #include "ChatPage.h"
+#include "EventAccessors.h"
 #include "Logging.h"
 #include "UserMentions.h"
-//#include "timeline/TimelineItem.h"
 
 using namespace popups;
 
@@ -75,12 +75,15 @@ UserMentions::initializeMentions(const QMap<QString, mtx::responses::Notificatio
 
         for (const auto &item : notifs) {
                 for (const auto &notif : item.notifications) {
-                        const auto event_id = QString::fromStdString(utils::event_id(notif.event));
+                        const auto event_id =
+                          QString::fromStdString(mtx::accessors::event_id(notif.event));
 
                         try {
                                 const auto room_id = QString::fromStdString(notif.room_id);
-                                const auto user_id = utils::event_sender(notif.event);
-                                const auto body    = utils::event_body(notif.event);
+                                const auto user_id =
+                                  QString::fromStdString(mtx::accessors::sender(notif.event));
+                                const auto body =
+                                  QString::fromStdString(mtx::accessors::body(notif.event));
 
                                 pushItem(event_id,
                                          user_id,
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index b5b05768..c454c6b2 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -808,7 +808,7 @@ TimelineModel::escapeEmoji(QString str) const
 void
 TimelineModel::viewRawMessage(QString id) const
 {
-        std::string ev = utils::serialize_event(events.value(id)).dump(4);
+        std::string ev = mtx::accessors::serialize_event(events.value(id)).dump(4);
         auto dialog    = new dialogs::RawMessage(QString::fromStdString(ev));
         Q_UNUSED(dialog);
 }
@@ -822,7 +822,7 @@ TimelineModel::viewDecryptedRawMessage(QString id) const
                 event = decryptEvent(*e).event;
         }
 
-        std::string ev = utils::serialize_event(event).dump(4);
+        std::string ev = mtx::accessors::serialize_event(event).dump(4);
         auto dialog    = new dialogs::RawMessage(QString::fromStdString(ev));
         Q_UNUSED(dialog);
 }