From 6b60ff77135c3717159f760e82f14841c50816aa Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 26 May 2020 22:53:21 +0200 Subject: Rename settings to be more consistent --- src/ChatPage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ChatPage.cpp') diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 90abc63e..2b55b91e 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -255,7 +255,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) text_input_, &TextInputWidget::startedTyping, this, &ChatPage::sendTypingNotifications); connect(typingRefresher_, &QTimer::timeout, this, &ChatPage::sendTypingNotifications); connect(text_input_, &TextInputWidget::stoppedTyping, this, [this]() { - if (!userSettings_->isTypingNotificationsEnabled()) + if (!userSettings_->typingNotifications()) return; typingRefresher_->stop(); @@ -482,7 +482,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) activateWindow(); }); - setGroupViewState(userSettings_->isGroupViewEnabled()); + setGroupViewState(userSettings_->groupView()); connect(userSettings_.data(), &UserSettings::groupViewStateChanged, @@ -1207,7 +1207,7 @@ ChatPage::unbanUser(QString userid, QString reason) void ChatPage::sendTypingNotifications() { - if (!userSettings_->isTypingNotificationsEnabled()) + if (!userSettings_->typingNotifications()) return; http::client()->start_typing( @@ -1343,7 +1343,7 @@ ChatPage::hideSideBars() void ChatPage::showSideBars() { - if (userSettings_->isGroupViewEnabled()) + if (userSettings_->groupView()) communitiesList_->show(); sideBar_->show(); -- cgit 1.5.1 From 9eddcfc42f3cd4e513f72d9b7fef9a98b43a378d Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 30 May 2020 16:37:51 +0200 Subject: Remove some redundant functions --- src/Cache.cpp | 14 ++++++++------ src/ChatPage.cpp | 6 ++++-- src/EventAccessors.cpp | 6 ++++++ src/EventAccessors.h | 3 +++ src/Utils.h | 36 ------------------------------------ src/popups/UserMentions.cpp | 11 +++++++---- src/timeline/TimelineModel.cpp | 4 ++-- 7 files changed, 30 insertions(+), 50 deletions(-) (limited to 'src/ChatPage.cpp') 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())), + lmdb::val(obj.dump())); } } @@ -2026,7 +2028,7 @@ Cache::saveTimelineMentions(lmdb::txn &txn, using namespace mtx::events::state; for (const auto ¬if : 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 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